BLF: Refactor of blf_font_boundbox_foreach_glyph
Refactor of `BLF_boundbox_foreach_glyph` and simplification of its usage by only passing translated glyph bounds to callbacks. See D15765 for more details. Differential Revision: https://developer.blender.org/D15765 Reviewed by Campbell Barton
This commit is contained in:
@@ -1858,33 +1858,6 @@ static void widget_draw_text_ime_underline(const uiFontStyle *fstyle,
|
||||
}
|
||||
#endif /* WITH_INPUT_IME */
|
||||
|
||||
struct UnderlineData {
|
||||
size_t str_offset; /* The string offset of the underlined character. */
|
||||
int width_px; /* The underline width in pixels. */
|
||||
int r_offset_px[2]; /* Write the X,Y offset here. */
|
||||
};
|
||||
|
||||
static bool widget_draw_text_underline_calc_position(const char *UNUSED(str),
|
||||
const size_t str_step_ofs,
|
||||
const rcti *glyph_step_bounds,
|
||||
const int UNUSED(glyph_advance_x),
|
||||
const rcti *glyph_bounds,
|
||||
const int UNUSED(glyph_bearing[2]),
|
||||
void *user_data)
|
||||
{
|
||||
struct UnderlineData *ul_data = user_data;
|
||||
if (ul_data->str_offset == str_step_ofs) {
|
||||
/* Full width of this glyph including both bearings. */
|
||||
const int width = glyph_bounds->xmin + BLI_rcti_size_x(glyph_bounds) + glyph_bounds->xmin;
|
||||
ul_data->r_offset_px[0] = glyph_step_bounds->xmin + ((width - ul_data->width_px) / 2);
|
||||
/* One line-width below the lower glyph bounds. */
|
||||
ul_data->r_offset_px[1] = glyph_bounds->ymin - U.pixelsize;
|
||||
/* Early exit. */
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void widget_draw_text(const uiFontStyle *fstyle,
|
||||
const uiWidgetColors *wcol,
|
||||
uiBut *but,
|
||||
@@ -2150,26 +2123,18 @@ static void widget_draw_text(const uiFontStyle *fstyle,
|
||||
}
|
||||
|
||||
if (ul_index != -1) {
|
||||
int ul_width = round_fl_to_int(BLF_width(fstyle->uifont_id, "_", 2));
|
||||
|
||||
struct UnderlineData ul_data = {
|
||||
.str_offset = ul_index,
|
||||
.width_px = ul_width,
|
||||
};
|
||||
|
||||
BLF_boundbox_foreach_glyph(fstyle->uifont_id,
|
||||
drawstr_ofs,
|
||||
ul_index + 1,
|
||||
widget_draw_text_underline_calc_position,
|
||||
&ul_data);
|
||||
|
||||
const int pos_x = rect->xmin + font_xofs + ul_data.r_offset_px[0];
|
||||
const int pos_y = rect->ymin + font_yofs + ul_data.r_offset_px[1];
|
||||
|
||||
/* Use text output because direct drawing doesn't always work. See T89246. */
|
||||
BLF_position(fstyle->uifont_id, pos_x, pos_y, 0.0f);
|
||||
BLF_color4ubv(fstyle->uifont_id, wcol->text);
|
||||
BLF_draw(fstyle->uifont_id, "_", 2);
|
||||
rcti bounds;
|
||||
if (BLF_str_offset_to_glyph_bounds(fstyle->uifont_id, drawstr_ofs, ul_index, &bounds) &&
|
||||
!BLI_rcti_is_empty(&bounds)) {
|
||||
int ul_width = round_fl_to_int(BLF_width(fstyle->uifont_id, "_", 2));
|
||||
int pos_x = rect->xmin + font_xofs + bounds.xmin +
|
||||
(bounds.xmax - bounds.xmin - ul_width) / 2;
|
||||
int pos_y = rect->ymin + font_yofs + bounds.ymin - U.pixelsize;
|
||||
/* Use text output because direct drawing doesn't always work. See T89246. */
|
||||
BLF_position(fstyle->uifont_id, (float)pos_x, pos_y, 0.0f);
|
||||
BLF_color4ubv(fstyle->uifont_id, wcol->text);
|
||||
BLF_draw(fstyle->uifont_id, "_", 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user