Use per-face Computer Modern TFMs for paragraph layout

This commit is contained in:
gloamxun committed 2026-10-21 12:23:08 +08:00
1 parent 7cb5b42429
commit 521c87d952
9 files changed
+136 -26

No files matched your search

+16 -2
View File
@@ -468,8 +468,8 @@ impl Unit {
font: ParagraphFont,
) -> Self {
let source = source.into();
let mut paragraph =
layout_paragraph_with_font(&source, &style, &crate::cmr10::Cmr10Metrics::new());
let metrics = crate::cmr10::Cmr10Metrics::for_paragraph_font(font);
let mut paragraph = layout_paragraph_with_font(&source, &style, &metrics);
paragraph.font = font;
Self {
id,
@@ -1558,6 +1558,20 @@ mod tests {
assert_eq!(engine.checkpoints()[1].unit_index, 1);
}
#[test]
fn bold_paragraphs_use_cmbx10_advances() {
fn width(unit: &Unit) -> i64 {
match unit.items.first() {
Some(VerticalItem::Paragraph(paragraph)) => paragraph.width,
_ => panic!("expected paragraph"),
}
}
let text = "mmmmmmmmmm iiiiiiiiii";
let roman = Unit::paragraph_with_face(1, text, ParagraphFont::Roman);
let bold = Unit::paragraph_with_face(2, text, ParagraphFont::Bold);
assert_ne!(width(&roman), width(&bold));
}
#[test]
fn editing_a_paragraph_preserves_its_font_face() {
let document = Document::new(