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",
|
"log",
|
||||||
"lyon_geom 0.14.1",
|
"lyon_geom 0.14.1",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
|
"pathfinder_geometry",
|
||||||
"pixels",
|
"pixels",
|
||||||
"raqote",
|
"raqote",
|
||||||
"servo_arc",
|
"servo_arc",
|
||||||
|
|
|
@ -31,6 +31,7 @@ ipc-channel = "0.14"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
lyon_geom = "0.14"
|
lyon_geom = "0.14"
|
||||||
num-traits = "0.2"
|
num-traits = "0.2"
|
||||||
|
pathfinder_geometry = "0.5"
|
||||||
pixels = { path = "../pixels" }
|
pixels = { path = "../pixels" }
|
||||||
raqote = { version = "0.8", features = ["text"] }
|
raqote = { version = "0.8", features = ["text"] }
|
||||||
servo_arc = { path = "../servo_arc" }
|
servo_arc = { path = "../servo_arc" }
|
||||||
|
|
|
@ -527,11 +527,33 @@ impl GenericDrawTarget for raqote::DrawTarget {
|
||||||
pattern: &canvas_data::Pattern,
|
pattern: &canvas_data::Pattern,
|
||||||
options: &DrawOptions,
|
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,
|
font,
|
||||||
point_size,
|
point_size,
|
||||||
text,
|
&ids,
|
||||||
start,
|
&positions,
|
||||||
&pattern.source(),
|
&pattern.source(),
|
||||||
options.as_raqote(),
|
options.as_raqote(),
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue