diff options
22 files changed, 109 insertions, 131 deletions
diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h index 8f77f8c984d..b25166f4b18 100644 --- a/source/blender/blenfont/BLF_api.h +++ b/source/blender/blenfont/BLF_api.h @@ -82,14 +82,14 @@ int BLF_draw_mono(int fontid, const char *str, size_t len, int cwidth); /* This function return the bounding box of the string * and are not multiplied by the aspect. */ -void BLF_boundbox(int fontid, const char *str, struct rctf *box); +void BLF_boundbox(int fontid, const char *str, size_t len, struct rctf *box); /* The next both function return the width and height * of the string, using the current font and both value * are multiplied by the aspect of the font. */ -float BLF_width(int fontid, const char *str); -float BLF_height(int fontid, const char *str); +float BLF_width(int fontid, const char *str, size_t len); +float BLF_height(int fontid, const char *str, size_t len); /* Return dimensions of the font without any sample text. */ float BLF_height_max(int fontid); @@ -100,7 +100,7 @@ float BLF_ascender(int fontid); /* The following function return the width and height of the string, but * just in one call, so avoid extra freetype2 stuff. */ -void BLF_width_and_height(int fontid, const char *str, float *width, float *height); +void BLF_width_and_height(int fontid, const char *str, size_t len, float *r_width, float *r_height); /* For fixed width fonts only, returns the width of a * character. @@ -111,9 +111,9 @@ float BLF_fixed_width(int fontid); * of the string, using the default font and both value * are multiplied by the aspect of the font. */ -void BLF_width_and_height_default(const char *str, float *width, float *height); -float BLF_width_default(const char *str); -float BLF_height_default(const char *str); +void BLF_width_and_height_default(const char *str, size_t len, float *r_width, float *r_height); +float BLF_width_default(const char *str, size_t len); +float BLF_height_default(const char *str, size_t len); /* Set rotation for default font. */ void BLF_rotation_default(float angle); diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c index 130eaaecba5..746ee3c0d93 100644 --- a/source/blender/blenfont/intern/blf.c +++ b/source/blender/blenfont/intern/blf.c @@ -592,44 +592,44 @@ int BLF_draw_mono(int fontid, const char *str, size_t len, int cwidth) return columns; } -void BLF_boundbox(int fontid, const char *str, rctf *box) +void BLF_boundbox(int fontid, const char *str, size_t len, rctf *box) { FontBLF *font = blf_get(fontid); if (font) { - blf_font_boundbox(font, str, box); + blf_font_boundbox(font, str, len, box); } } -void BLF_width_and_height(int fontid, const char *str, float *width, float *height) +void BLF_width_and_height(int fontid, const char *str, size_t len, float *r_width, float *r_height) { FontBLF *font = blf_get(fontid); if (font && font->glyph_cache) { - blf_font_width_and_height(font, str, width, height); + blf_font_width_and_height(font, str, len, r_width, r_height); } else { - *width = *height = 0.0f; + *r_width = *r_height = 0.0f; } } -void BLF_width_and_height_default(const char *str, float *width, float *height) +void BLF_width_and_height_default(const char *str, size_t len, float *r_width, float *r_height) { if (!blf_global_font_init()) { - *width = *height = 0.0f; + *r_width = *r_height = 0.0f; return; } BLF_size(global_font_default, global_font_points, global_font_dpi); - BLF_width_and_height(global_font_default, str, width, height); + BLF_width_and_height(global_font_default, str, len, r_width, r_height); } -float BLF_width(int fontid, const char *str) +float BLF_width(int fontid, const char *str, size_t len) { FontBLF *font = blf_get(fontid); if (font && font->glyph_cache) { - return blf_font_width(font, str); + return blf_font_width(font, str, len); } return 0.0f; @@ -646,21 +646,21 @@ float BLF_fixed_width(int fontid) return 0.0f; } -float BLF_width_default(const char *str) +float BLF_width_default(const char *str, size_t len) { if (!blf_global_font_init()) return 0.0f; BLF_size(global_font_default, global_font_points, global_font_dpi); - return BLF_width(global_font_default, str); + return BLF_width(global_font_default, str, len); } -float BLF_height(int fontid, const char *str) +float BLF_height(int fontid, const char *str, size_t len) { FontBLF *font = blf_get(fontid); if (font && font->glyph_cache) { - return blf_font_height(font, str); + return blf_font_height(font, str, len); } return 0.0f; @@ -710,14 +710,14 @@ float BLF_ascender(int fontid) return 0.0f; } -float BLF_height_default(const char *str) +float BLF_height_default(const char *str, size_t len) { if (!blf_global_font_init()) return 0.0f; BLF_size(global_font_default, global_font_points, global_font_dpi); - return BLF_height(global_font_default, str); + return BLF_height(global_font_default, str, len); } void BLF_rotation(int fontid, float angle) diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index 998b415a6af..40943225223 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -415,7 +415,7 @@ void blf_font_buffer(FontBLF *font, const char *str) } } -void blf_font_boundbox(FontBLF *font, const char *str, rctf *box) +void blf_font_boundbox(FontBLF *font, const char *str, size_t len, rctf *box) { unsigned int c; GlyphBLF *g, *g_prev = NULL; @@ -435,7 +435,7 @@ void blf_font_boundbox(FontBLF *font, const char *str, rctf *box) blf_font_ensure_ascii_table(font); - while (str[i]) { + while ((i < len) && str[i]) { BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table); if (c == BLI_UTF8_ERR) @@ -468,7 +468,7 @@ void blf_font_boundbox(FontBLF *font, const char *str, rctf *box) } } -void blf_font_width_and_height(FontBLF *font, const char *str, float *width, float *height) +void blf_font_width_and_height(FontBLF *font, const char *str, size_t len, float *width, float *height) { float xa, ya; rctf box; @@ -482,12 +482,12 @@ void blf_font_width_and_height(FontBLF *font, const char *str, float *width, flo ya = 1.0f; } - blf_font_boundbox(font, str, &box); + blf_font_boundbox(font, str, len, &box); *width = (BLI_rctf_size_x(&box) * xa); *height = (BLI_rctf_size_y(&box) * ya); } -float blf_font_width(FontBLF *font, const char *str) +float blf_font_width(FontBLF *font, const char *str, size_t len) { float xa; rctf box; @@ -497,11 +497,11 @@ float blf_font_width(FontBLF *font, const char *str) else xa = 1.0f; - blf_font_boundbox(font, str, &box); + blf_font_boundbox(font, str, len, &box); return BLI_rctf_size_x(&box) * xa; } -float blf_font_height(FontBLF *font, const char *str) +float blf_font_height(FontBLF *font, const char *str, size_t len) { float ya; rctf box; @@ -511,7 +511,7 @@ float blf_font_height(FontBLF *font, const char *str) else ya = 1.0f; - blf_font_boundbox(font, str, &box); + blf_font_boundbox(font, str, len, &box); return BLI_rctf_size_y(&box) * ya; } diff --git a/source/blender/blenfont/intern/blf_internal.h b/source/blender/blenfont/intern/blf_internal.h index 7d4b39dd337..9f6bad9b00d 100644 --- a/source/blender/blenfont/intern/blf_internal.h +++ b/source/blender/blenfont/intern/blf_internal.h @@ -55,10 +55,10 @@ void blf_font_draw(struct FontBLF *font, const char *str, size_t len); void blf_font_draw_ascii(struct FontBLF *font, const char *str, size_t len); int blf_font_draw_mono(struct FontBLF *font, const char *str, size_t len, int cwidth); void blf_font_buffer(struct FontBLF *font, const char *str); -void blf_font_boundbox(struct FontBLF *font, const char *str, struct rctf *box); -void blf_font_width_and_height(struct FontBLF *font, const char *str, float *width, float *height); -float blf_font_width(struct FontBLF *font, const char *str); -float blf_font_height(struct FontBLF *font, const char *str); +void blf_font_boundbox(struct FontBLF *font, const char *str, size_t len, struct rctf *box); +void blf_font_width_and_height(struct FontBLF *font, const char *str, size_t len, float *width, float *height); +float blf_font_width(struct FontBLF *font, const char *str, size_t len); +float blf_font_height(struct FontBLF *font, const char *str, size_t len); float blf_font_fixed_width(struct FontBLF *font); void blf_font_free(struct FontBLF *font); diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index e4278bae293..d59a23c1c30 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -1636,6 +1636,9 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec /* this could be an argument if we want to operate on non linear float imbuf's * for now though this is only used for renders which use scene settings */ +#define TEXT_SIZE_CHECK(str, w, h) \ + ((str[0]) && ((void)(h = h_fixed), (w = BLF_width(mono, str, sizeof(str))))) + #define BUFF_MARGIN_X 2 #define BUFF_MARGIN_Y 1 @@ -1665,9 +1668,8 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec x = 0; y = height; - if (stamp_data.file[0]) { + if (TEXT_SIZE_CHECK(stamp_data.file, w, h)) { /* Top left corner */ - BLF_width_and_height(mono, stamp_data.file, &w, &h); h = h_fixed; y -= h; /* also a little of space to the background. */ @@ -1683,8 +1685,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec } /* Top left corner, below File */ - if (stamp_data.note[0]) { - BLF_width_and_height(mono, stamp_data.note, &w, &h); h = h_fixed; + if (TEXT_SIZE_CHECK(stamp_data.note, w, h)) { y -= h; /* and space for background. */ @@ -1699,8 +1700,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec } /* Top left corner, below File (or Note) */ - if (stamp_data.date[0]) { - BLF_width_and_height(mono, stamp_data.date, &w, &h); h = h_fixed; + if (TEXT_SIZE_CHECK(stamp_data.date, w, h)) { y -= h; /* and space for background. */ @@ -1715,8 +1715,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec } /* Top left corner, below File, Date or Note */ - if (stamp_data.rendertime[0]) { - BLF_width_and_height(mono, stamp_data.rendertime, &w, &h); h = h_fixed; + if (TEXT_SIZE_CHECK(stamp_data.rendertime, w, h)) { y -= h; /* and space for background. */ @@ -1731,8 +1730,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec y = 0; /* Bottom left corner, leaving space for timing */ - if (stamp_data.marker[0]) { - BLF_width_and_height(mono, stamp_data.marker, &w, &h); h = h_fixed; + if (TEXT_SIZE_CHECK(stamp_data.marker, w, h)) { /* extra space for background. */ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display, @@ -1747,8 +1745,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec } /* Left bottom corner */ - if (stamp_data.time[0]) { - BLF_width_and_height(mono, stamp_data.time, &w, &h); h = h_fixed; + if (TEXT_SIZE_CHECK(stamp_data.time, w, h)) { /* extra space for background */ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display, @@ -1762,8 +1759,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec x += w + pad; } - if (stamp_data.frame[0]) { - BLF_width_and_height(mono, stamp_data.frame, &w, &h); h = h_fixed; + if (TEXT_SIZE_CHECK(stamp_data.frame, w, h)) { /* extra space for background. */ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display, @@ -1777,8 +1773,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec x += w + pad; } - if (stamp_data.camera[0]) { - BLF_width_and_height(mono, stamp_data.camera, &w, &h); h = h_fixed; + if (TEXT_SIZE_CHECK(stamp_data.camera, w, h)) { /* extra space for background. */ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display, @@ -1790,8 +1785,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec x += w + pad; } - if (stamp_data.cameralens[0]) { - BLF_width_and_height(mono, stamp_data.cameralens, &w, &h); h = h_fixed; + if (TEXT_SIZE_CHECK(stamp_data.cameralens, w, h)) { /* extra space for background. */ buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display, @@ -1800,8 +1794,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec BLF_draw_buffer(mono, stamp_data.cameralens); } - if (stamp_data.scene[0]) { - BLF_width_and_height(mono, stamp_data.scene, &w, &h); h = h_fixed; + if (TEXT_SIZE_CHECK(stamp_data.scene, w, h)) { /* Bottom right corner, with an extra space because blenfont is too strict! */ x = width - w - 2; @@ -1815,8 +1808,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec BLF_draw_buffer(mono, stamp_data.scene); } - if (stamp_data.strip[0]) { - BLF_width_and_height(mono, stamp_data.strip, &w, &h); h = h_fixed; + if (TEXT_SIZE_CHECK(stamp_data.strip, w, h)) { /* Top right corner, with an extra space because blenfont is too strict! */ x = width - w - pad; @@ -1833,6 +1825,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec /* cleanup the buffer. */ BLF_buffer(mono, NULL, NULL, 0, 0, 0, NULL); +#undef TEXT_SIZE_CHECK #undef BUFF_MARGIN_X #undef BUFF_MARGIN_Y } diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h index 9d541b56bf4..0300b7bc685 100644 --- a/source/blender/editors/include/UI_interface.h +++ b/source/blender/editors/include/UI_interface.h @@ -903,7 +903,7 @@ void uiIDContextProperty(struct bContext *C, struct PointerRNA *ptr, struct Prop /* Styled text draw */ void uiStyleFontSet(struct uiFontStyle *fs); void uiStyleFontDrawExt(struct uiFontStyle *fs, const struct rcti *rect, const char *str, - float *r_xofs, float *r_yofs); + size_t len, float *r_xofs, float *r_yofs); void uiStyleFontDraw(struct uiFontStyle *fs, struct rcti *rect, const char *str); void uiStyleFontDrawRotated(struct uiFontStyle *fs, struct rcti *rect, const char *str); diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c index c82026eace6..46ee1700a06 100644 --- a/source/blender/editors/interface/interface.c +++ b/source/blender/editors/interface/interface.c @@ -218,7 +218,7 @@ static void ui_text_bounds_block(uiBlock *block, float offset) for (bt = block->buttons.first; bt; bt = bt->next) { if (bt->type != SEPR) { - j = BLF_width(style->widget.uifont_id, bt->drawstr); + j = BLF_width(style->widget.uifont_id, bt->drawstr, sizeof(bt->drawstr)); if (j > i) i = j; } diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c index ee6663d7954..1ed0c128a20 100644 --- a/source/blender/editors/interface/interface_handlers.c +++ b/source/blender/editors/interface/interface_handlers.c @@ -1616,8 +1616,7 @@ void ui_button_text_password_hide(char password_str[UI_MAX_DRAW_STR], uiBut *but /* save original string */ BLI_strncpy(password_str, but->drawstr, UI_MAX_DRAW_STR); - for (i = 0; i < len; i++) - but->drawstr[i] = '*'; + memset(but->drawstr, '*', len); but->drawstr[i] = '\0'; } } @@ -1656,9 +1655,9 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, con ui_button_text_password_hide(password_str, but, FALSE); origstr = MEM_mallocN(sizeof(char) * data->maxlen, "ui_textedit origstr"); - + BLI_strncpy(origstr, but->drawstr, data->maxlen); - + /* XXX solve generic, see: #widget_draw_text_icon */ if (but->type == NUM || but->type == NUMSLI) { startx += (int)(0.5f * (BLI_rctf_size_y(&but->rect))); @@ -1680,7 +1679,7 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, con while (i > 0) { if (BLI_str_cursor_step_prev_utf8(origstr, but->ofs, &i)) { /* 0.25 == scale factor for less sensitivity */ - if (BLF_width(fstyle->uifont_id, origstr + i) > (startx - x) * 0.25f) { + if (BLF_width(fstyle->uifont_id, origstr + i, BLF_DRAW_STR_DUMMY_MAX) > (startx - x) * 0.25f) { break; } } @@ -1702,7 +1701,7 @@ static void ui_textedit_set_cursor_pos(uiBut *but, uiHandleButtonData *data, con but->pos = pos_prev = strlen(origstr) - but->ofs; while (true) { - cdist = startx + BLF_width(fstyle->uifont_id, origstr + but->ofs); + cdist = startx + BLF_width(fstyle->uifont_id, origstr + but->ofs, BLF_DRAW_STR_DUMMY_MAX); /* check if position is found */ if (cdist < x) { diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c index a6216b486ad..2f37d8e6e98 100644 --- a/source/blender/editors/interface/interface_regions.c +++ b/source/blender/editors/interface/interface_regions.c @@ -660,7 +660,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but) h = BLF_height_max(data->fstyle.uifont_id); for (a = 0, fontw = 0, fonth = 0; a < data->totline; a++) { - w = BLF_width(data->fstyle.uifont_id, data->lines[a]); + w = BLF_width(data->fstyle.uifont_id, data->lines[a], sizeof(data->lines[a])); fontw = max_ff(fontw, (float)w); fonth += (a == 0) ? h : h + TIP_MARGIN_Y; } diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c index 1c6263c9dd5..38d9f4fcc12 100644 --- a/source/blender/editors/interface/interface_style.c +++ b/source/blender/editors/interface/interface_style.c @@ -144,7 +144,7 @@ static uiFont *uifont_to_blfont(int id) void uiStyleFontDrawExt(uiFontStyle *fs, const rcti *rect, const char *str, - float *r_xofs, float *r_yofs) + size_t len, float *r_xofs, float *r_yofs) { float height; int xofs = 0, yofs; @@ -155,14 +155,14 @@ void uiStyleFontDrawExt(uiFontStyle *fs, const rcti *rect, const char *str, yofs = ceil(0.5f * (BLI_rcti_size_y(rect) - height)); if (fs->align == UI_STYLE_TEXT_CENTER) { - xofs = floor(0.5f * (BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str))); + xofs = floor(0.5f * (BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, len))); /* don't center text if it chops off the start of the text, 2 gives some margin */ if (xofs < 2) { xofs = 2; } } else if (fs->align == UI_STYLE_TEXT_RIGHT) { - xofs = BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str) - 0.1f * U.widget_unit; + xofs = BLI_rcti_size_x(rect) - BLF_width(fs->uifont_id, str, len) - 0.1f * U.widget_unit; } /* clip is very strict, so we give it some space */ @@ -194,7 +194,7 @@ void uiStyleFontDraw(uiFontStyle *fs, rcti *rect, const char *str) { float xofs, yofs; uiStyleFontDrawExt(fs, rect, str, - &xofs, &yofs); + BLF_DRAW_STR_DUMMY_MAX, &xofs, &yofs); } /* drawn same as above, but at 90 degree angle */ @@ -215,7 +215,7 @@ void uiStyleFontDrawRotated(uiFontStyle *fs, rcti *rect, const char *str) /* rotate counter-clockwise for now (assumes left-to-right language)*/ xofs += height; - yofs = BLF_width(fs->uifont_id, str) + 5; + yofs = BLF_width(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX) + 5; angle = (float)M_PI / 2.0f; /* translate rect to vertical */ @@ -298,7 +298,7 @@ int UI_GetStringWidth(const char *str) BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT); uiStyleFontSet(fstyle); - width = BLF_width(fstyle->uifont_id, str); + width = BLF_width(fstyle->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); if (fstyle->kerning == 1) BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT); diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c index 8926a16481d..6bb6081d135 100644 --- a/source/blender/editors/interface/interface_templates.c +++ b/source/blender/editors/interface/interface_templates.c @@ -3299,7 +3299,7 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C) ui_abs = uiLayoutAbsolute(layout, FALSE); block = uiLayoutGetBlock(ui_abs); - width = BLF_width(style->widget.uifont_id, report->message); + width = BLF_width(style->widget.uifont_id, report->message, report->len); width = min_ii((int)(rti->widthfac * width), width); width = max_ii(width, 10); diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c index 0691eb4a9b8..27f16a6fd5c 100644 --- a/source/blender/editors/interface/interface_widgets.c +++ b/source/blender/editors/interface/interface_widgets.c @@ -967,11 +967,11 @@ static void ui_text_clip_left(uiFontStyle *fstyle, uiBut *but, const rcti *rect) BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT); but->ofs = 0; - but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr); + but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr, sizeof(but->drawstr)); while (but->strwidth > okwidth) { ui_text_clip_give_next_off(but); - but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs); + but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, sizeof(but->drawstr) - but->ofs); if (but->strwidth < 10) break; } @@ -1001,10 +1001,10 @@ static void ui_text_clip_cursor(uiFontStyle *fstyle, uiBut *but, const rcti *rec if (but->ofs > but->pos) but->ofs = but->pos; - if (BLF_width(fstyle->uifont_id, but->drawstr) <= okwidth) + if (BLF_width(fstyle->uifont_id, but->drawstr, sizeof(but->drawstr)) <= okwidth) but->ofs = 0; - but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs); + but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, sizeof(but->drawstr) - but->ofs); while (but->strwidth > okwidth) { float width; @@ -1014,7 +1014,7 @@ static void ui_text_clip_cursor(uiFontStyle *fstyle, uiBut *but, const rcti *rec BLI_strncpy_utf8(buf, but->drawstr, sizeof(buf)); /* string position of cursor */ buf[but->pos] = 0; - width = BLF_width(fstyle->uifont_id, buf + but->ofs); + width = BLF_width(fstyle->uifont_id, buf + but->ofs, sizeof(buf) - but->ofs); /* if cursor is at 20 pixels of right side button we clip left */ if (width > okwidth - 20) { @@ -1032,7 +1032,7 @@ static void ui_text_clip_cursor(uiFontStyle *fstyle, uiBut *but, const rcti *rec but->drawstr[len - bytes] = 0; } - but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs); + but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, sizeof(but->drawstr) - but->ofs); if (but->strwidth < 10) break; } @@ -1061,7 +1061,7 @@ static void ui_text_clip_right_label(uiFontStyle *fstyle, uiBut *but, const rcti if (fstyle->kerning == 1) /* for BLF_width */ BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT); - but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr); + but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr, sizeof(but->drawstr)); but->ofs = 0; @@ -1089,7 +1089,7 @@ static void ui_text_clip_right_label(uiFontStyle *fstyle, uiBut *but, const rcti drawstr_len -= bytes; // BLI_assert(strlen(but->drawstr) == drawstr_len); - but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs); + but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, sizeof(but->drawstr) - but->ofs); if (but->strwidth < 10) break; } @@ -1097,7 +1097,7 @@ static void ui_text_clip_right_label(uiFontStyle *fstyle, uiBut *but, const rcti /* after the leading text is gone, chop off the : and following space, with ofs */ while ((but->strwidth > okwidth) && (but->ofs < 2)) { ui_text_clip_give_next_off(but); - but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs); + but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, sizeof(but->drawstr) - but->ofs); if (but->strwidth < 10) break; } @@ -1115,7 +1115,7 @@ static void ui_text_clip_right_label(uiFontStyle *fstyle, uiBut *but, const rcti but->drawstr[drawstr_len] = 0; // BLI_assert(strlen(but->drawstr) == drawstr_len); - but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs); + but->strwidth = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, sizeof(but->drawstr) - but->ofs); if (but->strwidth < 10) break; } @@ -1146,7 +1146,7 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b /* text button selection and cursor */ if (but->editstr && but->pos != -1) { - short t = 0, pos = 0, ch; + short t = 0, pos = 0; short selsta_tmp, selend_tmp, selsta_draw, selwidth_draw; if ((but->selend - but->selsta) > 0) { @@ -1157,23 +1157,13 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b if (but->drawstr[0] != 0) { if (but->selsta >= but->ofs) { - ch = but->drawstr[selsta_tmp]; - but->drawstr[selsta_tmp] = 0; - - selsta_draw = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs); - - but->drawstr[selsta_tmp] = ch; + selsta_draw = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, selsta_tmp - but->ofs); } else { selsta_draw = 0; } - - ch = but->drawstr[selend_tmp]; - but->drawstr[selend_tmp] = 0; - - selwidth_draw = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs); - - but->drawstr[selend_tmp] = ch; + + selwidth_draw = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, selend_tmp - but->ofs); glColor4ubv((unsigned char *)wcol->item); glRects(rect->xmin + selsta_draw, rect->ymin + 2, rect->xmin + selwidth_draw, rect->ymax - 2); @@ -1184,12 +1174,7 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b pos = but->pos; if (pos >= but->ofs) { if (but->drawstr[0] != 0) { - ch = but->drawstr[pos]; - but->drawstr[pos] = 0; - - t = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs) / but->aspect; - - but->drawstr[pos] = ch; + t = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, pos - but->ofs) / but->aspect; } glColor3f(0.20, 0.6, 0.9); @@ -1216,7 +1201,8 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b glColor4ubv((unsigned char *)wcol->text); - uiStyleFontDrawExt(fstyle, rect, but->drawstr + but->ofs, &font_xofs, &font_yofs); + uiStyleFontDrawExt(fstyle, rect, but->drawstr + but->ofs, + sizeof(but->drawstr) - but->ofs, &font_xofs, &font_yofs); if (but->menu_key != '\0') { char fixedbuf[128]; @@ -1239,7 +1225,7 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b } fixedbuf[ul_index] = '\0'; - ul_advance = BLF_width(fstyle->uifont_id, fixedbuf); + ul_advance = BLF_width(fstyle->uifont_id, fixedbuf, ul_index); BLF_position(fstyle->uifont_id, rect->xmin + font_xofs + ul_advance, rect->ymin + font_yofs, 0.0f); BLF_draw(fstyle->uifont_id, "_", 2); @@ -3528,7 +3514,7 @@ void ui_draw_menu_item(uiFontStyle *fstyle, rcti *rect, const char *name, int ic cpoin = strchr(name, UI_SEP_CHAR); if (cpoin) { *cpoin = 0; - rect->xmax -= BLF_width(fstyle->uifont_id, cpoin + 1) + 10; + rect->xmax -= BLF_width(fstyle->uifont_id, cpoin + 1, INT_MAX) + 10; } } @@ -3574,7 +3560,7 @@ void ui_draw_preview_item(uiFontStyle *fstyle, rcti *rect, const char *name, int widget_draw_preview(iconid, 1.0f, rect); - BLF_width_and_height(fstyle->uifont_id, name, &font_dims[0], &font_dims[1]); + BLF_width_and_height(fstyle->uifont_id, name, BLF_DRAW_STR_DUMMY_MAX, &font_dims[0], &font_dims[1]); /* text rect */ trect.xmin += 0; diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c index e3787789165..6bb623155a5 100644 --- a/source/blender/editors/interface/view2d.c +++ b/source/blender/editors/interface/view2d.c @@ -2196,7 +2196,7 @@ void UI_view2d_text_cache_draw(ARegion *ar) int col_pack_prev = 0; /* investigate using BLF_ascender() */ - const float default_height = strings.first ? BLF_height_default("28") : 0.0f; + const float default_height = strings.first ? BLF_height_default("28", 3) : 0.0f; // glMatrixMode(GL_PROJECTION); // glPushMatrix(); diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index 83a261bc140..8b89c2f0553 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -1825,7 +1825,7 @@ void ED_region_info_draw(ARegion *ar, const char *text, int block, float fill_co /* box fill entire width or just around text */ if (!block) - rect.xmax = min_ii(rect.xmax, rect.xmin + BLF_width(fontid, text) + 1.2f * U.widget_unit); + rect.xmax = min_ii(rect.xmax, rect.xmin + BLF_width(fontid, text, BLF_DRAW_STR_DUMMY_MAX) + 1.2f * U.widget_unit); rect.ymax = BLI_rcti_size_y(&ar->winrct); diff --git a/source/blender/editors/space_clip/clip_dopesheet_draw.c b/source/blender/editors/space_clip/clip_dopesheet_draw.c index 059b8ace7b9..e85b055bc59 100644 --- a/source/blender/editors/space_clip/clip_dopesheet_draw.c +++ b/source/blender/editors/space_clip/clip_dopesheet_draw.c @@ -341,7 +341,7 @@ void clip_draw_dopesheet_channels(const bContext *C, ARegion *ar) else UI_ThemeColor(TH_TEXT); - font_height = BLF_height(fontid, channel->name); + font_height = BLF_height(fontid, channel->name, sizeof(channel->name)); BLF_position(fontid, v2d->cur.xmin + CHANNEL_PAD, y - font_height / 2.0f, 0.0f); BLF_draw(fontid, channel->name, strlen(channel->name)); diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c index 38e7f87f478..3ca9a9478fa 100644 --- a/source/blender/editors/space_clip/clip_draw.c +++ b/source/blender/editors/space_clip/clip_draw.c @@ -87,7 +87,7 @@ void clip_draw_curfra_label(const int framenr, const float x, const float y) BLF_size(fontid, 11.0f, U.dpi); BLI_snprintf(numstr, sizeof(numstr), "%d", framenr); - BLF_width_and_height(fontid, numstr, &font_dims[0], &font_dims[1]); + BLF_width_and_height(fontid, numstr, sizeof(numstr), &font_dims[0], &font_dims[1]); glRecti(x, y, x + font_dims[0] + 6.0f, y + font_dims[1] + 4.0f); diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c index ff0add36bdc..d329d505138 100644 --- a/source/blender/editors/space_file/filesel.c +++ b/source/blender/editors/space_file/filesel.c @@ -435,7 +435,7 @@ float file_string_width(const char *str) { uiStyle *style = UI_GetStyle(); uiStyleFontSet(&style->widget); - return BLF_width(style->widget.uifont_id, str); + return BLF_width(style->widget.uifont_id, str, BLF_DRAW_STR_DUMMY_MAX); } float file_font_pointsize(void) diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c index 89e57955339..3d5f6a6ce7e 100644 --- a/source/blender/editors/space_image/image_draw.c +++ b/source/blender/editors/space_image/image_draw.c @@ -195,21 +195,21 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, int color_manage, int use_def BLI_snprintf(str, sizeof(str), "X:%-4d Y:%-4d |", x, y); BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_Y, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); - dx += BLF_width(blf_mono_font, str); + dx += BLF_width(blf_mono_font, str, sizeof(str)); if (zp) { glColor3ub(255, 255, 255); BLI_snprintf(str, sizeof(str), " Z:%-.4f |", 0.5f + 0.5f * (((float)*zp) / (float)0x7fffffff)); BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); - dx += BLF_width(blf_mono_font, str); + dx += BLF_width(blf_mono_font, str, sizeof(str)); } if (zpf) { glColor3ub(255, 255, 255); BLI_snprintf(str, sizeof(str), " Z:%-.3f |", *zpf); BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); - dx += BLF_width(blf_mono_font, str); + dx += BLF_width(blf_mono_font, str, sizeof(str)); } if (channels >= 3) { @@ -222,7 +222,7 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, int color_manage, int use_def BLI_snprintf(str, sizeof(str), " R:-"); BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); - dx += BLF_width(blf_mono_font, str); + dx += BLF_width(blf_mono_font, str, sizeof(str)); glColor3ubv(green); if (fp) @@ -233,7 +233,7 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, int color_manage, int use_def BLI_snprintf(str, sizeof(str), " G:-"); BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); - dx += BLF_width(blf_mono_font, str); + dx += BLF_width(blf_mono_font, str, sizeof(str)); glColor3ubv(blue); if (fp) @@ -244,7 +244,7 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, int color_manage, int use_def BLI_snprintf(str, sizeof(str), " B:-"); BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); - dx += BLF_width(blf_mono_font, str); + dx += BLF_width(blf_mono_font, str, sizeof(str)); if (channels == 4) { glColor3ub(255, 255, 255); @@ -256,7 +256,7 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, int color_manage, int use_def BLI_snprintf(str, sizeof(str), "- "); BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); - dx += BLF_width(blf_mono_font, str); + dx += BLF_width(blf_mono_font, str, sizeof(str)); } if (color_manage) { @@ -276,7 +276,7 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, int color_manage, int use_def BLI_snprintf(str, sizeof(str), " | CM R:%-.4f G:%-.4f B:%-.4f", rgba[0], rgba[1], rgba[2]); BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); - dx += BLF_width(blf_mono_font, str); + dx += BLF_width(blf_mono_font, str, sizeof(str)); } } @@ -350,12 +350,12 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, int color_manage, int use_def BLI_snprintf(str, sizeof(str), "V:%-.4f", val); BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); - dx += BLF_width(blf_mono_font, str); + dx += BLF_width(blf_mono_font, str, sizeof(str)); BLI_snprintf(str, sizeof(str), " L:%-.4f", lum); BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); - dx += BLF_width(blf_mono_font, str); + dx += BLF_width(blf_mono_font, str, sizeof(str)); } else if (channels >= 3) { rgb_to_hsv(finalcol[0], finalcol[1], finalcol[2], &hue, &sat, &val); @@ -364,22 +364,22 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, int color_manage, int use_def BLI_snprintf(str, sizeof(str), "H:%-.4f", hue); BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); - dx += BLF_width(blf_mono_font, str); + dx += BLF_width(blf_mono_font, str, sizeof(str)); BLI_snprintf(str, sizeof(str), " S:%-.4f", sat); BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); - dx += BLF_width(blf_mono_font, str); + dx += BLF_width(blf_mono_font, str, sizeof(str)); BLI_snprintf(str, sizeof(str), " V:%-.4f", val); BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); - dx += BLF_width(blf_mono_font, str); + dx += BLF_width(blf_mono_font, str, sizeof(str)); BLI_snprintf(str, sizeof(str), " L:%-.4f", lum); BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0); BLF_draw_ascii(blf_mono_font, str, sizeof(str)); - dx += BLF_width(blf_mono_font, str); + dx += BLF_width(blf_mono_font, str, sizeof(str)); } (void)dx; diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index 3040789852f..d4af66b7eb9 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -406,7 +406,7 @@ static void node_draw_frame_label(bNodeTree *ntree, bNode *node, const float asp /* title color */ UI_ThemeColorBlendShade(TH_TEXT, color_id, 0.8f, 10); - width = BLF_width(fontid, label); + width = BLF_width(fontid, label, sizeof(label)); ascender = BLF_ascender(fontid); /* 'x' doesn't need aspect correction */ diff --git a/source/blender/editors/space_view3d/view3d_ruler.c b/source/blender/editors/space_view3d/view3d_ruler.c index 64b747b389b..6aa34baeac6 100644 --- a/source/blender/editors/space_view3d/view3d_ruler.c +++ b/source/blender/editors/space_view3d/view3d_ruler.c @@ -541,7 +541,7 @@ static void ruler_info_draw_pixel(const struct bContext *C, ARegion *ar, void *a ruler_item_as_string(ruler_item, unit, numstr, sizeof(numstr), prec); - BLF_width_and_height(blf_mono_font, numstr, &numstr_size[0], &numstr_size[1]); + BLF_width_and_height(blf_mono_font, numstr, sizeof(numstr), &numstr_size[0], &numstr_size[1]); pos[0] = co_ss[1][0] + (cap_size * 2.0f); pos[1] = co_ss[1][1] - (numstr_size[1] / 2.0f); @@ -627,7 +627,7 @@ static void ruler_info_draw_pixel(const struct bContext *C, ARegion *ar, void *a ruler_item_as_string(ruler_item, unit, numstr, sizeof(numstr), prec); - BLF_width_and_height(blf_mono_font, numstr, &numstr_size[0], &numstr_size[1]); + BLF_width_and_height(blf_mono_font, numstr, sizeof(numstr), &numstr_size[0], &numstr_size[1]); mid_v2_v2v2(pos, co_ss[0], co_ss[2]); diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index f88d8366b8d..2ae94fb6d5a 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -1758,7 +1758,7 @@ static void drawAutoKeyWarning(TransInfo *UNUSED(t), ARegion *ar) ED_region_visible_rect(ar, &rect); - BLF_width_and_height_default(printable, &printable_size[0], &printable_size[1]); + BLF_width_and_height_default(printable, BLF_DRAW_STR_DUMMY_MAX, &printable_size[0], &printable_size[1]); xco = rect.xmax - (int)printable_size[0] - 10; yco = rect.ymax - (int)printable_size[1] - 10; diff --git a/source/blender/python/generic/blf_py_api.c b/source/blender/python/generic/blf_py_api.c index 5b5438defee..768c5506b8c 100644 --- a/source/blender/python/generic/blf_py_api.c +++ b/source/blender/python/generic/blf_py_api.c @@ -180,7 +180,7 @@ static PyObject *py_blf_dimensions(PyObject *UNUSED(self), PyObject *args) if (!PyArg_ParseTuple(args, "is:blf.dimensions", &fontid, &text)) return NULL; - BLF_width_and_height(fontid, text, &r_width, &r_height); + BLF_width_and_height(fontid, text, INT_MAX, &r_width, &r_height); ret = PyTuple_New(2); PyTuple_SET_ITEM(ret, 0, PyFloat_FromDouble(r_width)); |