SDL_Rect draw_wrapped_text(CVideo* gui, const SDL_Rect& area, int font_size, const SDL_Color& color, const std::string& text, int x, int y, int max_width) { std::string wrapped_text = word_wrap_text(text, font_size, max_width); return font::draw_text(gui, area, font_size, color, wrapped_text, x, y, false); }
static duk_ret_t js_Font_wordWrapString(duk_context* ctx) { const char* text = duk_to_string(ctx, 0); int width = duk_require_int(ctx, 1); font_t* font; int num_lines; wraptext_t* wraptext; int i; duk_push_this(ctx); font = duk_require_sphere_obj(ctx, -1, "Font"); duk_pop(ctx); wraptext = word_wrap_text(font, text, width); num_lines = get_wraptext_line_count(wraptext); duk_push_array(ctx); for (i = 0; i < num_lines; ++i) { duk_push_string(ctx, get_wraptext_line(wraptext, i)); duk_put_prop_index(ctx, -2, i); } free_wraptext(wraptext); return 1; }