Skip to content

Commit ff44b3f

Browse files
committed
Adjust baseline for fallback fonts
1 parent cf101ad commit ff44b3f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/renderer/fonts/caching_shaper.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ impl CachingShaper {
390390

391391
// Scale fallback fonts to have the same width as the primary one
392392
let scale = (font_pair.font_info.unwrap().1 * current_size) / self.info().1;
393+
let baseline_offset = self.baseline_offset();
393394

394395
let mut shaper = self
395396
.shape_context
@@ -406,12 +407,19 @@ impl CachingShaper {
406407

407408
let mut glyph_data = Vec::new();
408409

410+
let metrics = &font_pair.font_info.unwrap().0;
411+
// Push the baseline down if there's not enough space above it.
412+
// This only happens for fallback fonts.
413+
let y_offset = ((metrics.ascent + metrics.leading / 2.0) * current_size
414+
- baseline_offset)
415+
.max(0.0);
416+
409417
shaper.shape_with(|glyph_cluster| {
410418
//Align to the grid at the start of each cluster
411419
let mut x_offset = glyph_width * glyph_cluster.data as f32;
412420

413421
for glyph in glyph_cluster.glyphs {
414-
let position = (x_offset + glyph.x, -glyph.y);
422+
let position = (x_offset + glyph.x, -glyph.y + y_offset);
415423
glyph_data.push((glyph.id, position));
416424
x_offset += glyph.advance;
417425
}

0 commit comments

Comments
 (0)