Skip to content

Commit

Permalink
feat: try to give a proper advanced width for varaible font
Browse files Browse the repository at this point in the history
  • Loading branch information
zimond committed Jun 6, 2024
1 parent 2d51abc commit c5369e9
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,25 @@ impl Font {
y_max: units as i16,
})
})?;
let lsb = f.glyph_hor_side_bearing(glyph_id).unwrap_or(0);
let aw = f.glyph_hor_advance(glyph_id)?;
// FIXME: for variable fonts, this is not the same with harfbuzz, mainly
// because of phantom points not implemented in ttf-parser. More on this issue:
// https://github.com/RazrFalcon/rustybuzz/issues/91#issuecomment-1951036351
// here we simply copy rustybuzz's logic to ensure the "wrong" advance is always
// larger than the "actual" width, which could add some space to texts, but
// at least enough room.
let advanced_x = if f.is_variable() && f.has_non_default_variation_coordinates() {
(bbox.x_max + bbox.x_min) as u16
} else {
aw
};
Some(CharMetrics {
c,
glyph_id,
advanced_x: f.glyph_hor_advance(glyph_id)?,
advanced_x,
bbox,
lsb: f.glyph_hor_side_bearing(glyph_id).unwrap_or(0),
lsb,
units,
height,
missing: false,
Expand Down

0 comments on commit c5369e9

Please sign in to comment.