Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use line_gap as top padding #144

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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