Skip missing glyphs when drawing 2d canvas text.

This commit is contained in:
Josh Matthews 2020-08-07 13:57:57 -04:00
parent 8067a2fe94
commit 8ecc1a80a7
3 changed files with 27 additions and 3 deletions

View file

@ -527,11 +527,33 @@ impl GenericDrawTarget for raqote::DrawTarget {
pattern: &canvas_data::Pattern,
options: &DrawOptions,
) {
self.draw_text(
let mut start = pathfinder_geometry::vector::vec2f(start.x, start.y);
let mut ids = Vec::new();
let mut positions = Vec::new();
for c in text.chars() {
let id = match font.glyph_for_char(c) {
Some(id) => id,
None => {
warn!("Skipping non-existent glyph {}", c);
continue;
},
};
ids.push(id);
positions.push(Point2D::new(start.x(), start.y()));
let advance = match font.advance(id) {
Ok(advance) => advance,
Err(e) => {
warn!("Skipping glyph {} with missing advance: {:?}", c, e);
continue;
},
};
start += advance * point_size / 24. / 96.;
}
self.draw_glyphs(
font,
point_size,
text,
start,
&ids,
&positions,
&pattern.source(),
options.as_raqote(),
);