Move line height calculation to LayoutLine
This commit is contained in:
parent
31d3ceca51
commit
21e88ebc45
3 changed files with 17 additions and 11 deletions
|
|
@ -126,17 +126,9 @@ impl<'b> Iterator for LayoutRunIter<'b> {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut line_height_opt: Option<f32> = None;
|
let line_height = layout_line
|
||||||
for glyph in layout_line.glyphs.iter() {
|
.line_height_opt
|
||||||
if let Some(glyph_line_height) = glyph.line_height_opt {
|
.unwrap_or(self.buffer.metrics.line_height);
|
||||||
line_height_opt = match line_height_opt {
|
|
||||||
Some(line_height) => Some(line_height.max(glyph_line_height)),
|
|
||||||
None => Some(glyph_line_height),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let line_height = line_height_opt.unwrap_or(self.buffer.metrics.line_height);
|
|
||||||
let line_top = self.line_top;
|
let line_top = self.line_top;
|
||||||
let glyph_height = layout_line.max_ascent + layout_line.max_descent;
|
let glyph_height = layout_line.max_ascent + layout_line.max_descent;
|
||||||
let centering_offset = (line_height - glyph_height) / 2.0;
|
let centering_offset = (line_height - glyph_height) / 2.0;
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,8 @@ pub struct LayoutLine {
|
||||||
pub max_ascent: f32,
|
pub max_ascent: f32,
|
||||||
/// Maximum descent of the glyphs in line
|
/// Maximum descent of the glyphs in line
|
||||||
pub max_descent: f32,
|
pub max_descent: f32,
|
||||||
|
/// Maximum line height of any spans in line
|
||||||
|
pub line_height_opt: Option<f32>,
|
||||||
/// Glyphs in line
|
/// Glyphs in line
|
||||||
pub glyphs: Vec<LayoutGlyph>,
|
pub glyphs: Vec<LayoutGlyph>,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
12
src/shape.rs
12
src/shape.rs
|
|
@ -1453,6 +1453,16 @@ impl ShapeLine {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut line_height_opt: Option<f32> = None;
|
||||||
|
for glyph in glyphs.iter() {
|
||||||
|
if let Some(glyph_line_height) = glyph.line_height_opt {
|
||||||
|
line_height_opt = match line_height_opt {
|
||||||
|
Some(line_height) => Some(line_height.max(glyph_line_height)),
|
||||||
|
None => Some(glyph_line_height),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
layout_lines.push(LayoutLine {
|
layout_lines.push(LayoutLine {
|
||||||
w: if align != Align::Justified {
|
w: if align != Align::Justified {
|
||||||
visual_line.w
|
visual_line.w
|
||||||
|
|
@ -1463,6 +1473,7 @@ impl ShapeLine {
|
||||||
},
|
},
|
||||||
max_ascent,
|
max_ascent,
|
||||||
max_descent,
|
max_descent,
|
||||||
|
line_height_opt,
|
||||||
glyphs,
|
glyphs,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -1473,6 +1484,7 @@ impl ShapeLine {
|
||||||
w: 0.0,
|
w: 0.0,
|
||||||
max_ascent: 0.0,
|
max_ascent: 0.0,
|
||||||
max_descent: 0.0,
|
max_descent: 0.0,
|
||||||
|
line_height_opt: None,
|
||||||
glyphs: Default::default(),
|
glyphs: Default::default(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue