Skip to content

Commit 5c12db6

Browse files
committed
push_clip()/pop_clip() in paint_v0
Necessary for getting the proper glyph extents, and matches HarfBuzz.
1 parent 56c33b9 commit 5c12db6

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/tables/colr.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,15 +937,16 @@ impl<'a> Table<'a> {
937937
let layers = self.layers.slice(start..end)?;
938938

939939
for layer in layers {
940+
painter.outline_glyph(layer.glyph_id);
941+
painter.push_clip();
940942
if layer.palette_index == 0xFFFF {
941943
// A special case.
942-
painter.outline_glyph(layer.glyph_id);
943944
painter.paint(Paint::Solid(foreground_color));
944945
} else {
945946
let color = self.palettes.get(palette, layer.palette_index)?;
946-
painter.outline_glyph(layer.glyph_id);
947947
painter.paint(Paint::Solid(color));
948948
}
949+
painter.pop_clip();
949950
}
950951

951952
Some(())

tests/tables/colr.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,23 +65,35 @@ fn basic() {
6565
assert_eq!(
6666
paint(2).unwrap(), vec![
6767
Command::OutlineGlyph(GlyphId(12)),
68+
Command::PushClip,
6869
Command::Paint(c.clone()),
70+
Command::PopClip,
6971
Command::OutlineGlyph(GlyphId(13)),
70-
Command::Paint(a.clone())]
71-
);
72+
Command::PushClip,
73+
Command::Paint(a.clone()),
74+
Command::PopClip
75+
]);
7276

7377
assert_eq!(paint(3).unwrap(), vec![
7478
Command::OutlineGlyph(GlyphId(10)),
79+
Command::PushClip,
7580
Command::Paint(c.clone()),
81+
Command::PopClip,
7682
Command::OutlineGlyph(GlyphId(11)),
83+
Command::PushClip,
7784
Command::Paint(b.clone()),
85+
Command::PopClip,
7886
Command::OutlineGlyph(GlyphId(12)),
87+
Command::PushClip,
7988
Command::Paint(c.clone()),
89+
Command::PopClip,
8090
]);
8191

8292
assert_eq!(paint(7).unwrap(), vec![
8393
Command::OutlineGlyph(GlyphId(11)),
94+
Command::PushClip,
8495
Command::Paint(b.clone()),
96+
Command::PopClip,
8597
]);
8698
}
8799

0 commit comments

Comments
 (0)