[paint] Set up root transform in one place

Instead of spreading this in all the tables,
make hb_paint_funcs_t provide a push/pop_root_transform
that does all the setup.
This commit is contained in:
Matthias Clasen 2022-12-17 12:44:16 -05:00 committed by Behdad Esfahbod
parent c6dd56cc64
commit 686e627bdf
5 changed files with 22 additions and 46 deletions

View File

@ -335,21 +335,13 @@ struct glyf_accelerator_t
bool paint_glyph (hb_font_t *font, hb_codepoint_t gid, hb_paint_funcs_t *funcs, void *data) const
{
int xscale, yscale;
unsigned int upem;
hb_font_get_scale (font, &xscale, &yscale);
upem = hb_face_get_upem (hb_font_get_face (font));
funcs->push_transform (data, xscale/(float)upem, 0,
0, yscale/(float)upem,
0, 0);
funcs->push_root_transform (data, font);
funcs->push_clip_glyph (data, gid);
funcs->color (data, 0xffff, 1.);
funcs->pop_clip (data);
funcs->pop_transform (data);
funcs->pop_root_transform (data);
return false;
}

View File

@ -555,21 +555,13 @@ bool _get_path (const OT::cff1::accelerator_t *cff, hb_font_t *font, hb_codepoin
bool OT::cff1::accelerator_t::paint_glyph (hb_font_t *font, hb_codepoint_t glyph, hb_paint_funcs_t *funcs, void *data) const
{
int xscale, yscale;
unsigned int upem;
hb_font_get_scale (font, &xscale, &yscale);
upem = hb_face_get_upem (hb_font_get_face (font));
funcs->push_transform (data, xscale/(float)upem, 0,
0, yscale/(float)upem,
0, 0);
funcs->push_root_transform (data, font);
funcs->push_clip_glyph (data, glyph);
funcs->color (data, 0xffff, 1.);
funcs->pop_clip (data);
funcs->pop_transform (data);
funcs->pop_root_transform (data);
return false;
}

View File

@ -145,21 +145,13 @@ bool OT::cff2::accelerator_t::get_extents (hb_font_t *font,
bool OT::cff2::accelerator_t::paint_glyph (hb_font_t *font, hb_codepoint_t glyph, hb_paint_funcs_t *funcs, void *data) const
{
int xscale, yscale;
unsigned int upem;
hb_font_get_scale (font, &xscale, &yscale);
upem = hb_face_get_upem (hb_font_get_face (font));
funcs->push_transform (data, xscale/(float)upem, 0,
0, yscale/(float)upem,
0, 0);
funcs->push_root_transform (data, font);
funcs->push_clip_glyph (data, glyph);
funcs->color (data, 0xffff, 1.);
funcs->pop_clip (data);
funcs->pop_transform (data);
funcs->pop_root_transform (data);
return false;
}

View File

@ -1929,24 +1929,15 @@ struct COLR
hb_paint_context_t c (this, funcs, data, instancer);
int xscale, yscale;
unsigned int upem;
hb_font_get_scale (font, &xscale, &yscale);
upem = hb_face_get_upem (hb_font_get_face (font));
const Paint *paint = get_base_glyph_paint (glyph);
if (paint)
{
// COLRv1 glyph
// FIXME handle slant
funcs->push_transform (data, xscale/(float)upem, 0,
0, yscale/(float)upem,
0, 0);
c.funcs->push_root_transform (data, font);
c.recurse (*paint);
c.funcs->pop_transform (c.data);
c.funcs->pop_root_transform (c.data);
return true;
}
@ -1955,10 +1946,7 @@ struct COLR
if (record && ((hb_codepoint_t) record->glyphId == glyph))
{
// COLRv0 glyph
// FIXME handle slant
funcs->push_transform (data, xscale/(float)upem, 0,
0, yscale/(float)upem,
0, 0);
funcs->push_root_transform (data, font);
for (const auto &r : (this+layersZ).as_array (numLayers)
.sub_array (record->firstLayerIdx, record->numLayers))
@ -1968,7 +1956,7 @@ struct COLR
c.funcs->pop_clip (c.data);
}
c.funcs->pop_transform (c.data);
c.funcs->pop_root_transform (c.data);
return true;
}

View File

@ -132,6 +132,18 @@ struct hb_paint_funcs_t
mode,
!user_data ? nullptr : user_data->pop_group); }
void push_root_transform (void *paint_data,
hb_font_t *font)
{
int xscale, yscale;
float upem;
hb_font_get_scale (font, &xscale, &yscale);
upem = hb_face_get_upem (hb_font_get_face (font));
func.push_transform (this, paint_data, xscale/upem, 0, 0, yscale/upem, 0, 0,
!user_data ? nullptr : user_data->push_transform); }
void pop_root_transform (void *paint_data)
{ func.pop_transform (this, paint_data,
!user_data ? nullptr : user_data->pop_transform); }
};
DECLARE_NULL_INSTANCE (hb_paint_funcs_t);