Carry TFM glyph height and depth into paragraph boxes

This commit is contained in:
gloamxun committed 2026-10-21 09:18:15 +08:00
1 parent 8731ec2b9e
commit 3d94e28dff
2 files changed
+28 -5

No files matched your search

+26 -3
View File
@@ -347,7 +347,7 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra
/// Convert text using TFM character widths and fontdimen glue parameters.
pub fn text_items_with_font(
text: &str,
style: &ParagraphStyle,
_style: &ParagraphStyle,
font: &crate::cmr10::Cmr10Metrics,
) -> Vec<HorizontalItem> {
let mut items = Vec::new();
@@ -408,8 +408,8 @@ pub fn text_items_with_font(
previous_character = Some(character);
items.push(HorizontalItem::Box(HorizontalBox {
width: font.width(slot),
height: style.line_height,
depth: 0,
height: font.height(character),
depth: font.depth(character),
character: Some(character),
italic: font.italic(character),
}));
@@ -491,6 +491,29 @@ mod tests {
assert!(paragraph.line_count() >= 2);
}
#[test]
fn cmr10_boxes_carry_glyph_height_and_depth() {
let font = crate::cmr10::Cmr10Metrics::new();
let style = ParagraphStyle {
line_width: 400 * 65_536,
..ParagraphStyle::default()
};
let paragraph = layout_paragraph_with_font("Ag", &style, &font);
let boxes: Vec<&HorizontalBox> = paragraph.lines[0]
.iter()
.filter_map(|item| match item {
HorizontalItem::Box(box_) => Some(box_),
_ => None,
})
.collect();
assert_eq!(boxes.len(), 2);
assert_eq!(boxes[0].height, font.height('A'));
assert_eq!(boxes[0].depth, font.depth('A'));
assert_eq!(boxes[1].height, font.height('g'));
assert_eq!(boxes[1].depth, font.depth('g'));
assert_ne!(boxes[0].depth, boxes[1].depth);
}
#[test]
fn cmr10_italic_correction_extends_the_line_width() {
let font = crate::cmr10::Cmr10Metrics::default();