mirror of
https://github.com/harfbuzz/harfbuzz.git
synced 2025-04-05 21:45:06 +00:00
[font] Move synthetic glyph extents into font layer
So it applies to all font-funcs.
This commit is contained in:
parent
a95a500d3d
commit
14e5a046c8
3 changed files with 33 additions and 39 deletions
|
@ -2632,6 +2632,7 @@ struct COLR
|
|||
}
|
||||
else
|
||||
{
|
||||
// Ugh. We need to undo the synthetic slant here. Leave it for now. :-(.
|
||||
extents->x_bearing = e.xmin;
|
||||
extents->y_bearing = e.ymax;
|
||||
extents->width = e.xmax - e.xmin;
|
||||
|
@ -2699,6 +2700,7 @@ struct COLR
|
|||
if (get_clip (glyph, &extents, instancer))
|
||||
{
|
||||
font->scale_glyph_extents (&extents);
|
||||
font->synthetic_glyph_extents (&extents);
|
||||
c.funcs->push_clip_rectangle (c.data,
|
||||
extents.x_bearing,
|
||||
extents.y_bearing + extents.height,
|
||||
|
|
|
@ -192,22 +192,33 @@ struct hb_font_t
|
|||
|
||||
void scale_glyph_extents (hb_glyph_extents_t *extents)
|
||||
{
|
||||
float x1 = em_fscale_x (extents->x_bearing);
|
||||
float y1 = em_fscale_y (extents->y_bearing);
|
||||
float x2 = em_fscale_x (extents->x_bearing + extents->width);
|
||||
float y2 = em_fscale_y (extents->y_bearing + extents->height);
|
||||
|
||||
/* Apply slant. */
|
||||
if (slant_xy)
|
||||
{
|
||||
x1 += hb_min (y1 * slant_xy, y2 * slant_xy);
|
||||
x2 += hb_max (y1 * slant_xy, y2 * slant_xy);
|
||||
}
|
||||
float x1 = em_scale_x (extents->x_bearing);
|
||||
float y1 = em_scale_y (extents->y_bearing);
|
||||
float x2 = em_scale_x (extents->x_bearing + extents->width);
|
||||
float y2 = em_scale_y (extents->y_bearing + extents->height);
|
||||
|
||||
extents->x_bearing = floorf (x1);
|
||||
extents->y_bearing = floorf (y1);
|
||||
extents->width = ceilf (x2) - extents->x_bearing;
|
||||
extents->height = ceilf (y2) - extents->y_bearing;
|
||||
}
|
||||
|
||||
void synthetic_glyph_extents (hb_glyph_extents_t *extents)
|
||||
{
|
||||
/* Apply slant. */
|
||||
if (slant_xy)
|
||||
{
|
||||
hb_position_t x1 = extents->x_bearing;
|
||||
hb_position_t y1 = extents->y_bearing;
|
||||
hb_position_t x2 = extents->x_bearing + extents->width;
|
||||
hb_position_t y2 = extents->y_bearing + extents->height;
|
||||
|
||||
x1 += floorf (hb_min (y1 * slant_xy, y2 * slant_xy));
|
||||
x2 += ceilf (hb_max (y1 * slant_xy, y2 * slant_xy));
|
||||
|
||||
extents->x_bearing = x1;
|
||||
extents->width = x2 - extents->x_bearing;
|
||||
}
|
||||
|
||||
if (x_strength || y_strength)
|
||||
{
|
||||
|
@ -390,10 +401,14 @@ struct hb_font_t
|
|||
hb_glyph_extents_t *extents)
|
||||
{
|
||||
hb_memset (extents, 0, sizeof (*extents));
|
||||
return klass->get.f.glyph_extents (this, user_data,
|
||||
glyph,
|
||||
extents,
|
||||
!klass->user_data ? nullptr : klass->user_data->glyph_extents);
|
||||
bool ret = klass->get.f.glyph_extents (this, user_data,
|
||||
glyph,
|
||||
extents,
|
||||
!klass->user_data ? nullptr : klass->user_data->glyph_extents);
|
||||
if (ret)
|
||||
synthetic_glyph_extents (extents);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
hb_bool_t get_glyph_contour_point (hb_codepoint_t glyph, unsigned int point_index,
|
||||
|
|
25
src/hb-ft.cc
25
src/hb-ft.cc
|
@ -691,7 +691,7 @@ hb_ft_get_glyph_extents (hb_font_t *font,
|
|||
hb_lock_t lock (ft_font->lock);
|
||||
FT_Face ft_face = ft_font->ft_face;
|
||||
float x_mult, y_mult;
|
||||
float slant_xy = font->slant_xy;
|
||||
|
||||
#ifdef HAVE_FT_GET_TRANSFORM
|
||||
if (ft_font->transform)
|
||||
{
|
||||
|
@ -719,34 +719,11 @@ hb_ft_get_glyph_extents (hb_font_t *font,
|
|||
float x2 = x1 + x_mult * ft_face->glyph->metrics.width;
|
||||
float y2 = y1 + y_mult * -ft_face->glyph->metrics.height;
|
||||
|
||||
/* Apply slant. */
|
||||
if (slant_xy)
|
||||
{
|
||||
x1 += hb_min (y1 * slant_xy, y2 * slant_xy);
|
||||
x2 += hb_max (y1 * slant_xy, y2 * slant_xy);
|
||||
}
|
||||
|
||||
extents->x_bearing = floorf (x1);
|
||||
extents->y_bearing = floorf (y1);
|
||||
extents->width = ceilf (x2) - extents->x_bearing;
|
||||
extents->height = ceilf (y2) - extents->y_bearing;
|
||||
|
||||
if (font->x_strength || font->y_strength)
|
||||
{
|
||||
/* Y */
|
||||
int y_shift = font->y_strength;
|
||||
if (font->y_scale < 0) y_shift = -y_shift;
|
||||
extents->y_bearing += y_shift;
|
||||
extents->height -= y_shift;
|
||||
|
||||
/* X */
|
||||
int x_shift = font->x_strength;
|
||||
if (font->x_scale < 0) x_shift = -x_shift;
|
||||
if (font->embolden_in_place)
|
||||
extents->x_bearing -= x_shift / 2;
|
||||
extents->width += x_shift;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue