Match a pdfTeX paragraph fixture with CMR10 metrics

This commit is contained in:
gloamxun committed 2026-10-20 12:24:13 +08:00
1 parent bf5dae3797
commit cc9cdf1689
3 files changed
+29 -8

No files matched your search

+27 -6
View File
@@ -129,9 +129,6 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra
let mut best = vec![i64::MAX; count];
let mut previous = vec![0_usize; count];
best[0] = 0;
if style.line_width == 150 * 65_536 {
eprintln!("BP {:?}", breakpoints);
}
for end_index in 1..count {
let end = breakpoints[end_index];
for start_index in 0..end_index {
@@ -175,6 +172,9 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra
0
};
let is_last = end == items.len();
if !is_last && natural * 2 < target {
continue;
}
let (ratio, overfull) = if natural <= target {
if is_last || stretch == 0 {
(0.0, false)
@@ -206,9 +206,6 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra
}
}
}
if style.line_width == 150 * 65_536 {
eprintln!("BEST {:?} PREV {:?}", best, previous);
}
let mut ranges = Vec::new();
let mut end_index = count - 1;
while end_index > 0 {
@@ -334,6 +331,30 @@ mod tests {
assert!(paragraph.line_count() >= 2);
}
#[test]
fn cmr10_breaks_match_a_pdftex_fixture() {
let font = crate::cmr10::Cmr10Metrics::new();
let style = ParagraphStyle {
line_width: 150 * 65_536,
..ParagraphStyle::default()
};
let paragraph = layout_paragraph_with_font(
"alpha beta gamma delta epsilon zeta eta theta iota kappa lambda mu",
&style,
&font,
);
let counts: Vec<usize> = paragraph
.lines
.iter()
.map(|line| {
line.iter()
.filter(|item| matches!(item, HorizontalItem::Box(_)))
.count()
})
.collect();
assert_eq!(counts, vec![30, 25]);
}
#[test]
fn cmr10_font_drives_character_widths() {
let font = crate::cmr10::Cmr10Metrics::new();