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
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -544,6 +544,7 @@ dependencies = [
|
|||
"log",
|
||||
"lyon_geom 0.14.1",
|
||||
"num-traits",
|
||||
"pathfinder_geometry",
|
||||
"pixels",
|
||||
"raqote",
|
||||
"servo_arc",
|
||||
|
|
|
@ -31,6 +31,7 @@ ipc-channel = "0.14"
|
|||
log = "0.4"
|
||||
lyon_geom = "0.14"
|
||||
num-traits = "0.2"
|
||||
pathfinder_geometry = "0.5"
|
||||
pixels = { path = "../pixels" }
|
||||
raqote = { version = "0.8", features = ["text"] }
|
||||
servo_arc = { path = "../servo_arc" }
|
||||
|
|
|
@ -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