Skip to content

Commit

Permalink
Use line_gap as top padding
Browse files Browse the repository at this point in the history
Fixes #143
  • Loading branch information
alexheretic committed Dec 15, 2021
1 parent 87cb6ae commit 845a116
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions layout/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Unreleased
* Use font line_gap as top-padding for layouts to address issues with glyphs taller than the font ascent.

# 0.2.3
* Default layouts: Keep word trailing space width if ending in a hard break or end of all glyphs _e.g. `"Foo \n"`_ _(This particularly changes the layout of right & centre aligned text ending in spaces)_.

Expand Down
3 changes: 2 additions & 1 deletion layout/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,11 +723,12 @@ mod layout_test {
],
);

let sfont = A_FONT.as_scaled(40.0);
for g in glyphs {
println!("{:?}", (g.glyph.scale, g.glyph.position));
// all glyphs should have the same ascent drawing position
let y_pos = g.glyph.position.y;
assert_relative_eq!(y_pos, A_FONT.as_scaled(40.0).ascent());
assert_relative_eq!(y_pos, sfont.ascent() + sfont.line_gap());
}
}

Expand Down
4 changes: 4 additions & 0 deletions layout/src/lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ impl Line {
return Vec::new();
}

// use line_gap as top-padding for all lines
// fixes issues with glyphs taller than the ascent
let screen_y = screen_y + self.max_v_metrics.line_gap;

// implement v-aligns when they're are supported
let screen_left = match h_align {
HorizontalAlign::Left => point(screen_x, screen_y),
Expand Down

0 comments on commit 845a116

Please sign in to comment.