mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Skip missing glyphs when drawing 2d canvas text.
This commit is contained in:
parent
8067a2fe94
commit
8ecc1a80a7
3 changed files with 27 additions and 3 deletions
|
@ -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(),
|
||||
);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue