Skip to content

Commit 6b0e485

Browse files
committed
Use precalculated glyph bounds for saved yaml files
1 parent 2366155 commit 6b0e485

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

wrench/src/yaml_frame_reader.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,21 +146,26 @@ impl YamlFrameReader {
146146
panic!("text item had neither text nor glyphs!");
147147
}
148148

149-
let glyphs = if item["text"].is_badvalue() {
149+
let (glyphs, rect) = if item["text"].is_badvalue() {
150150
// if glyphs are specified, then the glyph positions can have the
151151
// origin baked in.
152152
let origin = item["origin"].as_point().unwrap_or(Point2D::new(0.0, 0.0));
153153
let glyph_indices = item["glyphs"].as_vec_u32().unwrap();
154154
let glyph_offsets = item["offsets"].as_vec_f32().unwrap();
155155
assert!(glyph_offsets.len() == glyph_indices.len() * 2);
156156

157-
glyph_indices.iter().enumerate().map(|k| {
157+
let glyphs = glyph_indices.iter().enumerate().map(|k| {
158158
GlyphInstance {
159159
index: *k.1,
160160
x: origin.x + glyph_offsets[k.0*2],
161161
y: origin.y + glyph_offsets[k.0*2+1],
162162
}
163-
}).collect()
163+
}).collect();
164+
// TODO(gw): We could optionally use the WR API to query glyph dimensions
165+
// here and calculate the bounding region here if we want to.
166+
let rect = item["bounds"].as_rect()
167+
.expect("Text items with glyphs require bounds [for now]");
168+
(glyphs, rect)
164169
} else {
165170
if native_key.is_none() {
166171
panic!("Can't layout simple ascii text with raw font [for now]");
@@ -174,15 +179,15 @@ impl YamlFrameReader {
174179

175180
let mut x = origin.x;
176181
let y = origin.y;
177-
glyph_indices.iter().zip(glyph_advances).map(|arg| {
182+
let glyphs = glyph_indices.iter().zip(glyph_advances).map(|arg| {
178183
let gi = GlyphInstance { index: *arg.0 as u32, x: x, y: y };
179184
x = x + arg.1;
180185
gi
181-
}).collect()
186+
}).collect();
187+
let rect = Rect::new(Point2D::new(0.0, 0.0), wrench.window_size_f32());
188+
(glyphs, rect)
182189
};
183190

184-
let rect = Rect::new(Point2D::new(0.0, 0.0), wrench.window_size_f32());
185-
186191
let (builder, aux_builder) = self.both_builders();
187192
let clip = item["clip"].as_clip_region(aux_builder).unwrap_or(*clip_region);
188193
// FIXME this is the full bounds of the glyphs; we should calculate this more accurately

0 commit comments

Comments
 (0)