Font::pair_kerning returns 0f32 for all glyph pairs
Created by: Lisoph
I found out through debugging that at this line, both id().0
expressions evaluate to 0
in my case, which is probably why the kerning computation fails.
Below is my layouting code which calls the pair_kerning function. It's very similar to the code used in the gpu_cache example. I also use the same font as in that example. What's important to note, is that my g.id()
and last_id
both are valid.
/// Layout the glyphs like a paragraph with wrapping lines.
fn layout_paragraph<'a>(&'a self, font: &'a Font) -> Vec<PositionedGlyph<'a>> {
let v_metrics = font.v_metrics(self.scale);
let advance_y = v_metrics.ascent - v_metrics.descent + v_metrics.line_gap;
let mut last_glyph: Option<GlyphId> = None;
let mut caret = GlyphPoint { x: 0f32, y: 0f32 };
let mut glyphs = Vec::new();
for c in self.text.chars() {
if c.is_control() {
match c {
'\n' => {
caret.x = 0f32;
caret.y += advance_y;
}
_ => {}
}
} else {
if let Some(g) = font.glyph(c) {
let g = g.scaled(self.scale);
if let Some(last_id) = last_glyph {
caret.x += font.pair_kerning(self.scale, g.id(), last_id);
}
last_glyph = Some(g.id());
let g = g.positioned(caret);
glyphs.push(g);
}
}
}
glyphs
}