mirror of
https://github.com/harfbuzz/harfbuzz.git
synced 2025-04-04 21:15:06 +00:00
[COLRv1] Push font transform trickery to hb-cairo
This simplifies the renderers but pushes the burdon to clients of the paint API. I am ambivalent about this change. All paint clients need to be updated. This reduces one vector of allocations from hb-fontations paint implementation however.
This commit is contained in:
parent
c867bc976a
commit
24a00e7f84
4 changed files with 5 additions and 30 deletions
|
@ -938,13 +938,9 @@ struct PaintGlyph
|
||||||
void paint_glyph (hb_paint_context_t *c) const
|
void paint_glyph (hb_paint_context_t *c) const
|
||||||
{
|
{
|
||||||
TRACE_PAINT (this);
|
TRACE_PAINT (this);
|
||||||
c->funcs->push_inverse_font_transform (c->data, c->font);
|
|
||||||
c->funcs->push_clip_glyph (c->data, gid, c->font);
|
c->funcs->push_clip_glyph (c->data, gid, c->font);
|
||||||
c->funcs->push_font_transform (c->data, c->font);
|
|
||||||
c->recurse (this+paint);
|
c->recurse (this+paint);
|
||||||
c->funcs->pop_transform (c->data);
|
|
||||||
c->funcs->pop_clip (c->data);
|
c->funcs->pop_clip (c->data);
|
||||||
c->funcs->pop_transform (c->data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HBUINT8 format; /* format = 10 */
|
HBUINT8 format; /* format = 10 */
|
||||||
|
@ -2819,13 +2815,8 @@ void PaintColrGlyph::paint_glyph (hb_paint_context_t *c) const
|
||||||
if (unlikely (!node.visit (gid)))
|
if (unlikely (!node.visit (gid)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
c->funcs->push_inverse_font_transform (c->data, c->font);
|
|
||||||
if (c->funcs->color_glyph (c->data, gid, c->font))
|
if (c->funcs->color_glyph (c->data, gid, c->font))
|
||||||
{
|
|
||||||
c->funcs->pop_transform (c->data);
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
c->funcs->pop_transform (c->data);
|
|
||||||
|
|
||||||
const COLR *colr_table = c->get_colr_table ();
|
const COLR *colr_table = c->get_colr_table ();
|
||||||
const Paint *paint = colr_table->get_base_glyph_paint (gid);
|
const Paint *paint = colr_table->get_base_glyph_paint (gid);
|
||||||
|
|
|
@ -416,7 +416,6 @@ struct HbColorPainter<'a> {
|
||||||
color_records: &'a [ColorRecord],
|
color_records: &'a [ColorRecord],
|
||||||
foreground: hb_color_t,
|
foreground: hb_color_t,
|
||||||
composite_mode: Vec<CompositeMode>,
|
composite_mode: Vec<CompositeMode>,
|
||||||
clip_transform_stack: Vec<bool>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HbColorPainter<'_> {
|
impl HbColorPainter<'_> {
|
||||||
|
@ -546,20 +545,16 @@ impl ColorPainter for HbColorPainter<'_> {
|
||||||
}
|
}
|
||||||
fn push_clip_glyph(&mut self, glyph: GlyphId) {
|
fn push_clip_glyph(&mut self, glyph: GlyphId) {
|
||||||
let gid = u32::from(glyph);
|
let gid = u32::from(glyph);
|
||||||
self.clip_transform_stack.push(true);
|
|
||||||
unsafe {
|
unsafe {
|
||||||
hb_paint_push_inverse_font_transform(self.paint_funcs, self.paint_data, self.font);
|
|
||||||
hb_paint_push_clip_glyph(
|
hb_paint_push_clip_glyph(
|
||||||
self.paint_funcs,
|
self.paint_funcs,
|
||||||
self.paint_data,
|
self.paint_data,
|
||||||
gid as hb_codepoint_t,
|
gid as hb_codepoint_t,
|
||||||
self.font,
|
self.font,
|
||||||
);
|
);
|
||||||
hb_paint_push_font_transform(self.paint_funcs, self.paint_data, self.font);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn push_clip_box(&mut self, bbox: BoundingBox) {
|
fn push_clip_box(&mut self, bbox: BoundingBox) {
|
||||||
self.clip_transform_stack.push(false);
|
|
||||||
unsafe {
|
unsafe {
|
||||||
hb_paint_push_clip_rectangle(
|
hb_paint_push_clip_rectangle(
|
||||||
self.paint_funcs,
|
self.paint_funcs,
|
||||||
|
@ -572,16 +567,9 @@ impl ColorPainter for HbColorPainter<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn pop_clip(&mut self) {
|
fn pop_clip(&mut self) {
|
||||||
let pop_transforms = self.clip_transform_stack.pop().unwrap_or(false);
|
|
||||||
if pop_transforms {
|
|
||||||
self.pop_transform();
|
|
||||||
}
|
|
||||||
unsafe {
|
unsafe {
|
||||||
hb_paint_pop_clip(self.paint_funcs, self.paint_data);
|
hb_paint_pop_clip(self.paint_funcs, self.paint_data);
|
||||||
}
|
}
|
||||||
if pop_transforms {
|
|
||||||
self.pop_transform();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fn fill(&mut self, brush: Brush) {
|
fn fill(&mut self, brush: Brush) {
|
||||||
match brush {
|
match brush {
|
||||||
|
@ -767,7 +755,6 @@ extern "C" fn _hb_fontations_paint_glyph(
|
||||||
color_records,
|
color_records,
|
||||||
foreground,
|
foreground,
|
||||||
composite_mode: Vec::new(),
|
composite_mode: Vec::new(),
|
||||||
clip_transform_stack: Vec::new(),
|
|
||||||
};
|
};
|
||||||
unsafe {
|
unsafe {
|
||||||
hb_paint_push_font_transform(paint_funcs, paint_data, font);
|
hb_paint_push_font_transform(paint_funcs, paint_data, font);
|
||||||
|
|
|
@ -193,7 +193,7 @@ hb_cairo_paint_color_glyph (hb_paint_funcs_t *pfuncs HB_UNUSED,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
hb_cairo_push_clip_glyph (hb_paint_funcs_t *pfuncs HB_UNUSED,
|
hb_cairo_push_clip_glyph (hb_paint_funcs_t *pfuncs,
|
||||||
void *paint_data,
|
void *paint_data,
|
||||||
hb_codepoint_t glyph,
|
hb_codepoint_t glyph,
|
||||||
hb_font_t *font,
|
hb_font_t *font,
|
||||||
|
@ -204,7 +204,11 @@ hb_cairo_push_clip_glyph (hb_paint_funcs_t *pfuncs HB_UNUSED,
|
||||||
|
|
||||||
cairo_save (cr);
|
cairo_save (cr);
|
||||||
cairo_new_path (cr);
|
cairo_new_path (cr);
|
||||||
|
|
||||||
|
hb_paint_push_inverse_font_transform (pfuncs, paint_data, font);
|
||||||
hb_font_draw_glyph (font, glyph, hb_cairo_draw_get_funcs (), cr);
|
hb_font_draw_glyph (font, glyph, hb_cairo_draw_get_funcs (), cr);
|
||||||
|
hb_paint_push_font_transform (pfuncs, paint_data, font);
|
||||||
|
|
||||||
cairo_close_path (cr);
|
cairo_close_path (cr);
|
||||||
cairo_clip (cr);
|
cairo_clip (cr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -316,15 +316,11 @@ _hb_ft_paint (hb_ft_paint_context_t *c,
|
||||||
break;
|
break;
|
||||||
case FT_COLR_PAINTFORMAT_GLYPH:
|
case FT_COLR_PAINTFORMAT_GLYPH:
|
||||||
{
|
{
|
||||||
c->funcs->push_inverse_font_transform (c->data, c->font);
|
|
||||||
c->ft_font->lock.unlock ();
|
c->ft_font->lock.unlock ();
|
||||||
c->funcs->push_clip_glyph (c->data, paint.u.glyph.glyphID, c->font);
|
c->funcs->push_clip_glyph (c->data, paint.u.glyph.glyphID, c->font);
|
||||||
c->ft_font->lock.lock ();
|
c->ft_font->lock.lock ();
|
||||||
c->funcs->push_font_transform (c->data, c->font);
|
|
||||||
c->recurse (paint.u.glyph.paint);
|
c->recurse (paint.u.glyph.paint);
|
||||||
c->funcs->pop_transform (c->data);
|
|
||||||
c->funcs->pop_clip (c->data);
|
c->funcs->pop_clip (c->data);
|
||||||
c->funcs->pop_transform (c->data);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FT_COLR_PAINTFORMAT_COLR_GLYPH:
|
case FT_COLR_PAINTFORMAT_COLR_GLYPH:
|
||||||
|
@ -335,16 +331,13 @@ _hb_ft_paint (hb_ft_paint_context_t *c,
|
||||||
if (unlikely (!node.visit (gid)))
|
if (unlikely (!node.visit (gid)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
c->funcs->push_inverse_font_transform (c->data, c->font);
|
|
||||||
c->ft_font->lock.unlock ();
|
c->ft_font->lock.unlock ();
|
||||||
if (c->funcs->color_glyph (c->data, gid, c->font))
|
if (c->funcs->color_glyph (c->data, gid, c->font))
|
||||||
{
|
{
|
||||||
c->ft_font->lock.lock ();
|
c->ft_font->lock.lock ();
|
||||||
c->funcs->pop_transform (c->data);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
c->ft_font->lock.lock ();
|
c->ft_font->lock.lock ();
|
||||||
c->funcs->pop_transform (c->data);
|
|
||||||
|
|
||||||
FT_OpaquePaint other_paint = {0};
|
FT_OpaquePaint other_paint = {0};
|
||||||
if (FT_Get_Color_Glyph_Paint (ft_face, gid,
|
if (FT_Get_Color_Glyph_Paint (ft_face, gid,
|
||||||
|
|
Loading…
Add table
Reference in a new issue