BLF: Subpixel Positioning, Anti-aliasing, Hinting #105441
|
@ -411,11 +411,6 @@ BLI_INLINE GlyphBLF *blf_glyph_from_utf8_and_step(FontBLF *font,
|
|||
return g;
|
||||
}
|
||||
|
||||
BLI_INLINE ft_pix blf_pen_advance(FontBLF *font, ft_pix v, ft_pix step)
|
||||
{
|
||||
return v + step;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
@ -447,7 +442,7 @@ static void blf_font_draw_ex(FontBLF *font,
|
|||
}
|
||||
/* do not return this loop if clipped, we want every character tested */
|
||||
blf_glyph_draw(font, gc, g, ft_pix_to_int_floor(pen_x), ft_pix_to_int_floor(pen_y));
|
||||
pen_x = blf_pen_advance(font, pen_x, g->advance_x);
|
||||
pen_x += g->advance_x;
|
||||
}
|
||||
|
||||
blf_batch_draw_end();
|
||||
|
@ -642,7 +637,7 @@ static void blf_font_draw_buffer_ex(FontBLF *font,
|
|||
continue;
|
||||
}
|
||||
blf_glyph_draw_buffer(buf_info, g, pen_x, pen_y_basis);
|
||||
pen_x = blf_pen_advance(font, pen_x, g->advance_x);
|
||||
pen_x += g->advance_x;
|
||||
}
|
||||
|
||||
if (r_info) {
|
||||
|
@ -674,8 +669,7 @@ static bool blf_font_width_to_strlen_glyph_process(
|
|||
if (UNLIKELY(g == nullptr)) {
|
||||
return false; /* continue the calling loop. */
|
||||
}
|
||||
*pen_x += blf_kerning(font, g_prev, g);
|
||||
*pen_x = blf_pen_advance(font, *pen_x, g->advance_x);
|
||||
*pen_x += blf_kerning(font, g_prev, g) + g->advance_x;
|
||||
|
||||
/* When true, break the calling loop. */
|
||||
return (ft_pix_to_int(*pen_x) >= width_i);
|
||||
|
@ -781,7 +775,7 @@ static void blf_font_boundbox_ex(FontBLF *font,
|
|||
if (UNLIKELY(g == nullptr)) {
|
||||
continue;
|
||||
}
|
||||
const ft_pix pen_x_next = blf_pen_advance(font, pen_x, g->advance_x);
|
||||
const ft_pix pen_x_next = pen_x + g->advance_x;
|
||||
|
||||
const ft_pix gbox_xmin = pen_x;
|
||||
const ft_pix gbox_xmax = pen_x_next;
|
||||
|
@ -942,7 +936,7 @@ void blf_font_boundbox_foreach_glyph(FontBLF *font,
|
|||
if (user_fn(str, i_curr, &bounds, user_data) == false) {
|
||||
break;
|
||||
}
|
||||
pen_x = blf_pen_advance(font, pen_x, g->advance_x);
|
||||
pen_x += g->advance_x;
|
||||
}
|
||||
|
||||
blf_glyph_cache_release(font);
|
||||
|
@ -1088,7 +1082,7 @@ static void blf_font_wrap_apply(FontBLF *font,
|
|||
*
|
||||
* This is _only_ done when we know for sure the character is ascii (newline or a space).
|
||||
*/
|
||||
pen_x_next = blf_pen_advance(font, pen_x, g->advance_x);
|
||||
pen_x_next = pen_x + g->advance_x;
|
||||
if (UNLIKELY((pen_x_next >= wrap.wrap_width) && (wrap.start != wrap.last[0]))) {
|
||||
do_draw = true;
|
||||
}
|
||||
|
|
|
@ -1160,7 +1160,7 @@ static void blf_glyph_calc_rect_test(rcti *rect, GlyphBLF *g, const int x, const
|
|||
* width used by BLF_width. This allows that the text slightly
|
||||
* overlaps the clipping border to achieve better alignment. */
|
||||
rect->xmin = x + g->pos[0] + 1;
|
||||
rect->xmax = rect->xmin + MIN2(ft_pix_to_int(g->advance_x), g->dims[0]);
|
||||
rect->xmax = x + MIN2(ft_pix_to_int(g->advance_x), g->dims[0]);
|
||||
rect->ymin = y;
|
||||
rect->ymax = rect->ymin - g->dims[1];
|
||||
}
|
||||
|
|
|
@ -44,31 +44,13 @@ typedef int32_t ft_pix;
|
|||
|
||||
/* Macros copied from `include/freetype/internal/ftobjs.h`. */
|
||||
|
||||
/**
|
||||
* FIXME(@ideasman42): Follow rounding from Blender 3.1x and older.
|
||||
* This is what users will expect and changing this creates wider spaced text.
|
||||
* Use this macro to communicate that rounding should be used, using floor is to avoid
|
||||
* user visible changes, which can be reviewed and handled separately.
|
||||
*/
|
||||
#define USE_LEGACY_SPACING
|
||||
|
||||
#define FT_PIX_FLOOR(x) ((x) & ~63)
|
||||
#define FT_PIX_ROUND(x) FT_PIX_FLOOR((x) + 32)
|
||||
#define FT_PIX_CEIL(x) ((x) + 63)
|
||||
|
||||
#ifdef USE_LEGACY_SPACING
|
||||
# define FT_PIX_DEFAULT_ROUNDING(x) FT_PIX_FLOOR(x)
|
||||
#else
|
||||
# define FT_PIX_DEFAULT_ROUNDING(x) FT_PIX_ROUND(x)
|
||||
#endif
|
||||
|
||||
BLI_INLINE int ft_pix_to_int(ft_pix v)
|
||||
{
|
||||
#ifdef USE_LEGACY_SPACING
|
||||
return (int)(v >> 6);
|
||||
#else
|
||||
return (int)(FT_PIX_DEFAULT_ROUNDING(v) >> 6);
|
||||
#endif
|
||||
}
|
||||
|
||||
BLI_INLINE int ft_pix_to_int_floor(ft_pix v)
|
||||
|
@ -93,7 +75,6 @@ BLI_INLINE ft_pix ft_pix_from_float(float v)
|
|||
|
||||
#undef FT_PIX_ROUND
|
||||
#undef FT_PIX_CEIL
|
||||
#undef FT_PIX_DEFAULT_ROUNDING
|
||||
|
||||
/** \} */
|
||||
|
||||
|
|
Loading…
Reference in New Issue