From d5b691725bfbf0afd5dc3a1b550ea2485181a66c Mon Sep 17 00:00:00 2001 From: valadaptive Date: Thu, 6 Mar 2025 13:41:21 -0500 Subject: [PATCH] push_clip()/pop_clip() in paint_v0 Necessary for getting the proper glyph extents, and matches HarfBuzz. --- src/tables/colr.rs | 9 +++++---- tests/tables/colr.rs | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/tables/colr.rs b/src/tables/colr.rs index eb716f2..3a6aaa8 100644 --- a/src/tables/colr.rs +++ b/src/tables/colr.rs @@ -825,8 +825,8 @@ impl<'a> Table<'a> { /// Returns `true` if the current table has version 0. /// - /// A simple table can only emit `outline_glyph` and `paint` - /// [`Painter`] methods. + /// A simple table can only emit `outline_glyph`, `paint`, `push_clip`, and + /// `pop_clip` [`Painter`] methods. pub fn is_simple(&self) -> bool { self.version == 0 } @@ -937,15 +937,16 @@ impl<'a> Table<'a> { let layers = self.layers.slice(start..end)?; for layer in layers { + painter.outline_glyph(layer.glyph_id); + painter.push_clip(); if layer.palette_index == 0xFFFF { // A special case. - painter.outline_glyph(layer.glyph_id); painter.paint(Paint::Solid(foreground_color)); } else { let color = self.palettes.get(palette, layer.palette_index)?; - painter.outline_glyph(layer.glyph_id); painter.paint(Paint::Solid(color)); } + painter.pop_clip(); } Some(()) diff --git a/tests/tables/colr.rs b/tests/tables/colr.rs index f0db049..b371714 100644 --- a/tests/tables/colr.rs +++ b/tests/tables/colr.rs @@ -65,23 +65,35 @@ fn basic() { assert_eq!( paint(2).unwrap(), vec![ Command::OutlineGlyph(GlyphId(12)), + Command::PushClip, Command::Paint(c.clone()), + Command::PopClip, Command::OutlineGlyph(GlyphId(13)), - Command::Paint(a.clone())] - ); + Command::PushClip, + Command::Paint(a.clone()), + Command::PopClip + ]); assert_eq!(paint(3).unwrap(), vec![ Command::OutlineGlyph(GlyphId(10)), + Command::PushClip, Command::Paint(c.clone()), + Command::PopClip, Command::OutlineGlyph(GlyphId(11)), + Command::PushClip, Command::Paint(b.clone()), + Command::PopClip, Command::OutlineGlyph(GlyphId(12)), + Command::PushClip, Command::Paint(c.clone()), + Command::PopClip, ]); assert_eq!(paint(7).unwrap(), vec![ Command::OutlineGlyph(GlyphId(11)), + Command::PushClip, Command::Paint(b.clone()), + Command::PopClip, ]); }