Blender Font (BLF): add length argument to string width/height functions

This also fixes a crash editing buttons longer then UI_MAX_DRAW_STR
This commit is contained in:
Campbell Barton 2013-12-02 20:33:45 +11:00
parent f64ae4cbe5
commit 1815225faa
22 changed files with 109 additions and 131 deletions

@ -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 /* This function return the bounding box of the string
* and are not multiplied by the aspect. * 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 /* The next both function return the width and height
* of the string, using the current font and both value * of the string, using the current font and both value
* are multiplied by the aspect of the font. * are multiplied by the aspect of the font.
*/ */
float BLF_width(int fontid, const char *str); float BLF_width(int fontid, const char *str, size_t len);
float BLF_height(int fontid, const char *str); float BLF_height(int fontid, const char *str, size_t len);
/* Return dimensions of the font without any sample text. */ /* Return dimensions of the font without any sample text. */
float BLF_height_max(int fontid); 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 /* The following function return the width and height of the string, but
* just in one call, so avoid extra freetype2 stuff. * 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 /* For fixed width fonts only, returns the width of a
* character. * character.
@ -111,9 +111,9 @@ float BLF_fixed_width(int fontid);
* of the string, using the default font and both value * of the string, using the default font and both value
* are multiplied by the aspect of the font. * are multiplied by the aspect of the font.
*/ */
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);
float BLF_width_default(const char *str); float BLF_width_default(const char *str, size_t len);
float BLF_height_default(const char *str); float BLF_height_default(const char *str, size_t len);
/* Set rotation for default font. */ /* Set rotation for default font. */
void BLF_rotation_default(float angle); void BLF_rotation_default(float angle);

@ -592,44 +592,44 @@ int BLF_draw_mono(int fontid, const char *str, size_t len, int cwidth)
return columns; 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); FontBLF *font = blf_get(fontid);
if (font) { 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); FontBLF *font = blf_get(fontid);
if (font && font->glyph_cache) { 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 { 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()) { if (!blf_global_font_init()) {
*width = *height = 0.0f; *r_width = *r_height = 0.0f;
return; return;
} }
BLF_size(global_font_default, global_font_points, global_font_dpi); 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); FontBLF *font = blf_get(fontid);
if (font && font->glyph_cache) { if (font && font->glyph_cache) {
return blf_font_width(font, str); return blf_font_width(font, str, len);
} }
return 0.0f; return 0.0f;
@ -646,21 +646,21 @@ float BLF_fixed_width(int fontid)
return 0.0f; 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()) if (!blf_global_font_init())
return 0.0f; return 0.0f;
BLF_size(global_font_default, global_font_points, global_font_dpi); 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); FontBLF *font = blf_get(fontid);
if (font && font->glyph_cache) { if (font && font->glyph_cache) {
return blf_font_height(font, str); return blf_font_height(font, str, len);
} }
return 0.0f; return 0.0f;
@ -710,14 +710,14 @@ float BLF_ascender(int fontid)
return 0.0f; 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()) if (!blf_global_font_init())
return 0.0f; return 0.0f;
BLF_size(global_font_default, global_font_points, global_font_dpi); 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) void BLF_rotation(int fontid, float angle)

@ -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; unsigned int c;
GlyphBLF *g, *g_prev = NULL; 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); 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); BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
if (c == BLI_UTF8_ERR) 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; float xa, ya;
rctf box; rctf box;
@ -482,12 +482,12 @@ void blf_font_width_and_height(FontBLF *font, const char *str, float *width, flo
ya = 1.0f; ya = 1.0f;
} }
blf_font_boundbox(font, str, &box); blf_font_boundbox(font, str, len, &box);
*width = (BLI_rctf_size_x(&box) * xa); *width = (BLI_rctf_size_x(&box) * xa);
*height = (BLI_rctf_size_y(&box) * ya); *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; float xa;
rctf box; rctf box;
@ -497,11 +497,11 @@ float blf_font_width(FontBLF *font, const char *str)
else else
xa = 1.0f; xa = 1.0f;
blf_font_boundbox(font, str, &box); blf_font_boundbox(font, str, len, &box);
return BLI_rctf_size_x(&box) * xa; 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; float ya;
rctf box; rctf box;
@ -511,7 +511,7 @@ float blf_font_height(FontBLF *font, const char *str)
else else
ya = 1.0f; ya = 1.0f;
blf_font_boundbox(font, str, &box); blf_font_boundbox(font, str, len, &box);
return BLI_rctf_size_y(&box) * ya; return BLI_rctf_size_y(&box) * ya;
} }

@ -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); 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); 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_buffer(struct FontBLF *font, const char *str);
void blf_font_boundbox(struct FontBLF *font, const char *str, struct rctf *box); 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, float *width, float *height); 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); float blf_font_width(struct FontBLF *font, const char *str, size_t len);
float blf_font_height(struct FontBLF *font, const char *str); float blf_font_height(struct FontBLF *font, const char *str, size_t len);
float blf_font_fixed_width(struct FontBLF *font); float blf_font_fixed_width(struct FontBLF *font);
void blf_font_free(struct FontBLF *font); void blf_font_free(struct FontBLF *font);

@ -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 /* 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 */ * 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_X 2
#define BUFF_MARGIN_Y 1 #define BUFF_MARGIN_Y 1
@ -1665,9 +1668,8 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
x = 0; x = 0;
y = height; y = height;
if (stamp_data.file[0]) { if (TEXT_SIZE_CHECK(stamp_data.file, w, h)) {
/* Top left corner */ /* Top left corner */
BLF_width_and_height(mono, stamp_data.file, &w, &h); h = h_fixed;
y -= h; y -= h;
/* also a little of space to the background. */ /* 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 */ /* Top left corner, below File */
if (stamp_data.note[0]) { if (TEXT_SIZE_CHECK(stamp_data.note, w, h)) {
BLF_width_and_height(mono, stamp_data.note, &w, &h); h = h_fixed;
y -= h; y -= h;
/* and space for background. */ /* 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) */ /* Top left corner, below File (or Note) */
if (stamp_data.date[0]) { if (TEXT_SIZE_CHECK(stamp_data.date, w, h)) {
BLF_width_and_height(mono, stamp_data.date, &w, &h); h = h_fixed;
y -= h; y -= h;
/* and space for background. */ /* 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 */ /* Top left corner, below File, Date or Note */
if (stamp_data.rendertime[0]) { if (TEXT_SIZE_CHECK(stamp_data.rendertime, w, h)) {
BLF_width_and_height(mono, stamp_data.rendertime, &w, &h); h = h_fixed;
y -= h; y -= h;
/* and space for background. */ /* and space for background. */
@ -1731,8 +1730,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
y = 0; y = 0;
/* Bottom left corner, leaving space for timing */ /* Bottom left corner, leaving space for timing */
if (stamp_data.marker[0]) { if (TEXT_SIZE_CHECK(stamp_data.marker, w, h)) {
BLF_width_and_height(mono, stamp_data.marker, &w, &h); h = h_fixed;
/* extra space for background. */ /* extra space for background. */
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display, 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 */ /* Left bottom corner */
if (stamp_data.time[0]) { if (TEXT_SIZE_CHECK(stamp_data.time, w, h)) {
BLF_width_and_height(mono, stamp_data.time, &w, &h); h = h_fixed;
/* extra space for background */ /* extra space for background */
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display, 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; x += w + pad;
} }
if (stamp_data.frame[0]) { if (TEXT_SIZE_CHECK(stamp_data.frame, w, h)) {
BLF_width_and_height(mono, stamp_data.frame, &w, &h); h = h_fixed;
/* extra space for background. */ /* extra space for background. */
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display, 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; x += w + pad;
} }
if (stamp_data.camera[0]) { if (TEXT_SIZE_CHECK(stamp_data.camera, w, h)) {
BLF_width_and_height(mono, stamp_data.camera, &w, &h); h = h_fixed;
/* extra space for background. */ /* extra space for background. */
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display, 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; x += w + pad;
} }
if (stamp_data.cameralens[0]) { if (TEXT_SIZE_CHECK(stamp_data.cameralens, w, h)) {
BLF_width_and_height(mono, stamp_data.cameralens, &w, &h); h = h_fixed;
/* extra space for background. */ /* extra space for background. */
buf_rectfill_area(rect, rectf, width, height, scene->r.bg_stamp, display, 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); BLF_draw_buffer(mono, stamp_data.cameralens);
} }
if (stamp_data.scene[0]) { if (TEXT_SIZE_CHECK(stamp_data.scene, w, h)) {
BLF_width_and_height(mono, stamp_data.scene, &w, &h); h = h_fixed;
/* Bottom right corner, with an extra space because blenfont is too strict! */ /* Bottom right corner, with an extra space because blenfont is too strict! */
x = width - w - 2; 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); BLF_draw_buffer(mono, stamp_data.scene);
} }
if (stamp_data.strip[0]) { if (TEXT_SIZE_CHECK(stamp_data.strip, w, h)) {
BLF_width_and_height(mono, stamp_data.strip, &w, &h); h = h_fixed;
/* Top right corner, with an extra space because blenfont is too strict! */ /* Top right corner, with an extra space because blenfont is too strict! */
x = width - w - pad; x = width - w - pad;
@ -1833,6 +1825,7 @@ void BKE_stamp_buf(Scene *scene, Object *camera, unsigned char *rect, float *rec
/* cleanup the buffer. */ /* cleanup the buffer. */
BLF_buffer(mono, NULL, NULL, 0, 0, 0, NULL); BLF_buffer(mono, NULL, NULL, 0, 0, 0, NULL);
#undef TEXT_SIZE_CHECK
#undef BUFF_MARGIN_X #undef BUFF_MARGIN_X
#undef BUFF_MARGIN_Y #undef BUFF_MARGIN_Y
} }

@ -903,7 +903,7 @@ void uiIDContextProperty(struct bContext *C, struct PointerRNA *ptr, struct Prop
/* Styled text draw */ /* Styled text draw */
void uiStyleFontSet(struct uiFontStyle *fs); void uiStyleFontSet(struct uiFontStyle *fs);
void uiStyleFontDrawExt(struct uiFontStyle *fs, const struct rcti *rect, const char *str, 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 uiStyleFontDraw(struct uiFontStyle *fs, struct rcti *rect, const char *str);
void uiStyleFontDrawRotated(struct uiFontStyle *fs, struct rcti *rect, const char *str); void uiStyleFontDrawRotated(struct uiFontStyle *fs, struct rcti *rect, const char *str);

@ -218,7 +218,7 @@ static void ui_text_bounds_block(uiBlock *block, float offset)
for (bt = block->buttons.first; bt; bt = bt->next) { for (bt = block->buttons.first; bt; bt = bt->next) {
if (bt->type != SEPR) { 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; if (j > i) i = j;
} }

@ -1616,8 +1616,7 @@ void ui_button_text_password_hide(char password_str[UI_MAX_DRAW_STR], uiBut *but
/* save original string */ /* save original string */
BLI_strncpy(password_str, but->drawstr, UI_MAX_DRAW_STR); BLI_strncpy(password_str, but->drawstr, UI_MAX_DRAW_STR);
for (i = 0; i < len; i++) memset(but->drawstr, '*', len);
but->drawstr[i] = '*';
but->drawstr[i] = '\0'; 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); ui_button_text_password_hide(password_str, but, FALSE);
origstr = MEM_mallocN(sizeof(char) * data->maxlen, "ui_textedit origstr"); origstr = MEM_mallocN(sizeof(char) * data->maxlen, "ui_textedit origstr");
BLI_strncpy(origstr, but->drawstr, data->maxlen); BLI_strncpy(origstr, but->drawstr, data->maxlen);
/* XXX solve generic, see: #widget_draw_text_icon */ /* XXX solve generic, see: #widget_draw_text_icon */
if (but->type == NUM || but->type == NUMSLI) { if (but->type == NUM || but->type == NUMSLI) {
startx += (int)(0.5f * (BLI_rctf_size_y(&but->rect))); 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) { while (i > 0) {
if (BLI_str_cursor_step_prev_utf8(origstr, but->ofs, &i)) { if (BLI_str_cursor_step_prev_utf8(origstr, but->ofs, &i)) {
/* 0.25 == scale factor for less sensitivity */ /* 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; 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; but->pos = pos_prev = strlen(origstr) - but->ofs;
while (true) { 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 */ /* check if position is found */
if (cdist < x) { if (cdist < x) {

@ -660,7 +660,7 @@ ARegion *ui_tooltip_create(bContext *C, ARegion *butregion, uiBut *but)
h = BLF_height_max(data->fstyle.uifont_id); h = BLF_height_max(data->fstyle.uifont_id);
for (a = 0, fontw = 0, fonth = 0; a < data->totline; a++) { 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); fontw = max_ff(fontw, (float)w);
fonth += (a == 0) ? h : h + TIP_MARGIN_Y; fonth += (a == 0) ? h : h + TIP_MARGIN_Y;
} }

@ -144,7 +144,7 @@ static uiFont *uifont_to_blfont(int id)
void uiStyleFontDrawExt(uiFontStyle *fs, const rcti *rect, const char *str, 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; float height;
int xofs = 0, yofs; 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)); yofs = ceil(0.5f * (BLI_rcti_size_y(rect) - height));
if (fs->align == UI_STYLE_TEXT_CENTER) { 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 */ /* don't center text if it chops off the start of the text, 2 gives some margin */
if (xofs < 2) { if (xofs < 2) {
xofs = 2; xofs = 2;
} }
} }
else if (fs->align == UI_STYLE_TEXT_RIGHT) { 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 */ /* 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; float xofs, yofs;
uiStyleFontDrawExt(fs, rect, str, uiStyleFontDrawExt(fs, rect, str,
&xofs, &yofs); BLF_DRAW_STR_DUMMY_MAX, &xofs, &yofs);
} }
/* drawn same as above, but at 90 degree angle */ /* 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)*/ /* rotate counter-clockwise for now (assumes left-to-right language)*/
xofs += height; 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; angle = (float)M_PI / 2.0f;
/* translate rect to vertical */ /* translate rect to vertical */
@ -298,7 +298,7 @@ int UI_GetStringWidth(const char *str)
BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT); BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
uiStyleFontSet(fstyle); 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) if (fstyle->kerning == 1)
BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT); BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);

@ -3299,7 +3299,7 @@ void uiTemplateReportsBanner(uiLayout *layout, bContext *C)
ui_abs = uiLayoutAbsolute(layout, FALSE); ui_abs = uiLayoutAbsolute(layout, FALSE);
block = uiLayoutGetBlock(ui_abs); 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 = min_ii((int)(rti->widthfac * width), width);
width = max_ii(width, 10); width = max_ii(width, 10);

@ -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); BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
but->ofs = 0; 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) { while (but->strwidth > okwidth) {
ui_text_clip_give_next_off(but); 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; 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) if (but->ofs > but->pos)
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->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) { while (but->strwidth > okwidth) {
float width; 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)); BLI_strncpy_utf8(buf, but->drawstr, sizeof(buf));
/* string position of cursor */ /* string position of cursor */
buf[but->pos] = 0; 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 cursor is at 20 pixels of right side button we clip left */
if (width > okwidth - 20) { 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->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; 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 */ if (fstyle->kerning == 1) /* for BLF_width */
BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT); 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; but->ofs = 0;
@ -1089,7 +1089,7 @@ static void ui_text_clip_right_label(uiFontStyle *fstyle, uiBut *but, const rcti
drawstr_len -= bytes; drawstr_len -= bytes;
// BLI_assert(strlen(but->drawstr) == drawstr_len); // 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; 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 */ /* after the leading text is gone, chop off the : and following space, with ofs */
while ((but->strwidth > okwidth) && (but->ofs < 2)) { while ((but->strwidth > okwidth) && (but->ofs < 2)) {
ui_text_clip_give_next_off(but); 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; 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; but->drawstr[drawstr_len] = 0;
// BLI_assert(strlen(but->drawstr) == drawstr_len); // 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; 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 */ /* text button selection and cursor */
if (but->editstr && but->pos != -1) { 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; short selsta_tmp, selend_tmp, selsta_draw, selwidth_draw;
if ((but->selend - but->selsta) > 0) { 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->drawstr[0] != 0) {
if (but->selsta >= but->ofs) { if (but->selsta >= but->ofs) {
ch = but->drawstr[selsta_tmp]; selsta_draw = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, selsta_tmp - but->ofs);
but->drawstr[selsta_tmp] = 0;
selsta_draw = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs);
but->drawstr[selsta_tmp] = ch;
} }
else { else {
selsta_draw = 0; selsta_draw = 0;
} }
ch = but->drawstr[selend_tmp]; selwidth_draw = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, selend_tmp - but->ofs);
but->drawstr[selend_tmp] = 0;
selwidth_draw = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs);
but->drawstr[selend_tmp] = ch;
glColor4ubv((unsigned char *)wcol->item); glColor4ubv((unsigned char *)wcol->item);
glRects(rect->xmin + selsta_draw, rect->ymin + 2, rect->xmin + selwidth_draw, rect->ymax - 2); 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; pos = but->pos;
if (pos >= but->ofs) { if (pos >= but->ofs) {
if (but->drawstr[0] != 0) { if (but->drawstr[0] != 0) {
ch = but->drawstr[pos]; t = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs, pos - but->ofs) / but->aspect;
but->drawstr[pos] = 0;
t = BLF_width(fstyle->uifont_id, but->drawstr + but->ofs) / but->aspect;
but->drawstr[pos] = ch;
} }
glColor3f(0.20, 0.6, 0.9); 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); 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') { if (but->menu_key != '\0') {
char fixedbuf[128]; char fixedbuf[128];
@ -1239,7 +1225,7 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
} }
fixedbuf[ul_index] = '\0'; 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_position(fstyle->uifont_id, rect->xmin + font_xofs + ul_advance, rect->ymin + font_yofs, 0.0f);
BLF_draw(fstyle->uifont_id, "_", 2); 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); cpoin = strchr(name, UI_SEP_CHAR);
if (cpoin) { if (cpoin) {
*cpoin = 0; *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); 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 */ /* text rect */
trect.xmin += 0; trect.xmin += 0;

@ -2196,7 +2196,7 @@ void UI_view2d_text_cache_draw(ARegion *ar)
int col_pack_prev = 0; int col_pack_prev = 0;
/* investigate using BLF_ascender() */ /* 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); // glMatrixMode(GL_PROJECTION);
// glPushMatrix(); // glPushMatrix();

@ -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 */ /* box fill entire width or just around text */
if (!block) 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); rect.ymax = BLI_rcti_size_y(&ar->winrct);

@ -341,7 +341,7 @@ void clip_draw_dopesheet_channels(const bContext *C, ARegion *ar)
else else
UI_ThemeColor(TH_TEXT); 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, BLF_position(fontid, v2d->cur.xmin + CHANNEL_PAD,
y - font_height / 2.0f, 0.0f); y - font_height / 2.0f, 0.0f);
BLF_draw(fontid, channel->name, strlen(channel->name)); BLF_draw(fontid, channel->name, strlen(channel->name));

@ -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); BLF_size(fontid, 11.0f, U.dpi);
BLI_snprintf(numstr, sizeof(numstr), "%d", framenr); 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); glRecti(x, y, x + font_dims[0] + 6.0f, y + font_dims[1] + 4.0f);

@ -435,7 +435,7 @@ float file_string_width(const char *str)
{ {
uiStyle *style = UI_GetStyle(); uiStyle *style = UI_GetStyle();
uiStyleFontSet(&style->widget); 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) float file_font_pointsize(void)

@ -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); BLI_snprintf(str, sizeof(str), "X:%-4d Y:%-4d |", x, y);
BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_Y, 0); BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_Y, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str)); 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) { if (zp) {
glColor3ub(255, 255, 255); glColor3ub(255, 255, 255);
BLI_snprintf(str, sizeof(str), " Z:%-.4f |", 0.5f + 0.5f * (((float)*zp) / (float)0x7fffffff)); 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_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str)); 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) { if (zpf) {
glColor3ub(255, 255, 255); glColor3ub(255, 255, 255);
BLI_snprintf(str, sizeof(str), " Z:%-.3f |", *zpf); BLI_snprintf(str, sizeof(str), " Z:%-.3f |", *zpf);
BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0); BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str)); 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) { 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:-"); BLI_snprintf(str, sizeof(str), " R:-");
BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0); BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str)); 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); glColor3ubv(green);
if (fp) 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:-"); BLI_snprintf(str, sizeof(str), " G:-");
BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0); BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str)); 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); glColor3ubv(blue);
if (fp) 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:-"); BLI_snprintf(str, sizeof(str), " B:-");
BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0); BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str)); 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) { if (channels == 4) {
glColor3ub(255, 255, 255); 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), "- "); BLI_snprintf(str, sizeof(str), "- ");
BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0); BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str)); 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) { 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]); 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_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str)); 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); BLI_snprintf(str, sizeof(str), "V:%-.4f", val);
BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0); BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str)); 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); BLI_snprintf(str, sizeof(str), " L:%-.4f", lum);
BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0); BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str)); 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) { else if (channels >= 3) {
rgb_to_hsv(finalcol[0], finalcol[1], finalcol[2], &hue, &sat, &val); 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); BLI_snprintf(str, sizeof(str), "H:%-.4f", hue);
BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0); BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str)); 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); BLI_snprintf(str, sizeof(str), " S:%-.4f", sat);
BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0); BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str)); 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); BLI_snprintf(str, sizeof(str), " V:%-.4f", val);
BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0); BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str)); 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); BLI_snprintf(str, sizeof(str), " L:%-.4f", lum);
BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0); BLF_position(blf_mono_font, dx, 0.3f * UI_UNIT_X, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str)); 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; (void)dx;

@ -406,7 +406,7 @@ static void node_draw_frame_label(bNodeTree *ntree, bNode *node, const float asp
/* title color */ /* title color */
UI_ThemeColorBlendShade(TH_TEXT, color_id, 0.8f, 10); 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); ascender = BLF_ascender(fontid);
/* 'x' doesn't need aspect correction */ /* 'x' doesn't need aspect correction */

@ -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); 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[0] = co_ss[1][0] + (cap_size * 2.0f);
pos[1] = co_ss[1][1] - (numstr_size[1] / 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); 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]); mid_v2_v2v2(pos, co_ss[0], co_ss[2]);

@ -1758,7 +1758,7 @@ static void drawAutoKeyWarning(TransInfo *UNUSED(t), ARegion *ar)
ED_region_visible_rect(ar, &rect); 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; xco = rect.xmax - (int)printable_size[0] - 10;
yco = rect.ymax - (int)printable_size[1] - 10; yco = rect.ymax - (int)printable_size[1] - 10;

@ -180,7 +180,7 @@ static PyObject *py_blf_dimensions(PyObject *UNUSED(self), PyObject *args)
if (!PyArg_ParseTuple(args, "is:blf.dimensions", &fontid, &text)) if (!PyArg_ParseTuple(args, "is:blf.dimensions", &fontid, &text))
return NULL; 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); ret = PyTuple_New(2);
PyTuple_SET_ITEM(ret, 0, PyFloat_FromDouble(r_width)); PyTuple_SET_ITEM(ret, 0, PyFloat_FromDouble(r_width));