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

+1 -1
View File
@@ -560,5 +560,5 @@ core. It does not embed pdfTeX/XeTeX/Tectonic; it is a new Rust engine designed
around page-boundary checkpoints and page-hash diffing. M0 implements vertical around page-boundary checkpoints and page-hash diffing. M0 implements vertical
boxes/glue, a simple page builder, serializable checkpoints and a page-local boxes/glue, a simple page builder, serializable checkpoints and a page-local
edit demo. M1 adds the horizontal box/glue/penalty model, an item-stream Knuth-Plass-style edit demo. M1 adds the horizontal box/glue/penalty model, an item-stream Knuth-Plass-style
paragraph builder, and CMR10 character metrics extracted from `cmr10.tfm`. The production v1 engine remains the paragraph builder, CMR10 metrics extracted from `cmr10.tfm`, and a matching pdfTeX line-break fixture. The production v1 engine remains the
default until the new core reaches layout parity. See `docs/TEX_CORE.md`. default until the new core reaches layout parity. See `docs/TEX_CORE.md`.
+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 best = vec![i64::MAX; count];
let mut previous = vec![0_usize; count]; let mut previous = vec![0_usize; count];
best[0] = 0; best[0] = 0;
if style.line_width == 150 * 65_536 {
eprintln!("BP {:?}", breakpoints);
}
for end_index in 1..count { for end_index in 1..count {
let end = breakpoints[end_index]; let end = breakpoints[end_index];
for start_index in 0..end_index { for start_index in 0..end_index {
@@ -175,6 +172,9 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra
0 0
}; };
let is_last = end == items.len(); let is_last = end == items.len();
if !is_last && natural * 2 < target {
continue;
}
let (ratio, overfull) = if natural <= target { let (ratio, overfull) = if natural <= target {
if is_last || stretch == 0 { if is_last || stretch == 0 {
(0.0, false) (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 ranges = Vec::new();
let mut end_index = count - 1; let mut end_index = count - 1;
while end_index > 0 { while end_index > 0 {
@@ -334,6 +331,30 @@ mod tests {
assert!(paragraph.line_count() >= 2); 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] #[test]
fn cmr10_font_drives_character_widths() { fn cmr10_font_drives_character_widths() {
let font = crate::cmr10::Cmr10Metrics::new(); let font = crate::cmr10::Cmr10Metrics::new();
+1 -1
View File
@@ -70,7 +70,7 @@ next paragraph milestones.
| Milestone | Content | Acceptance | | Milestone | Content | Acceptance |
| --- | --- | --- | | --- | --- | --- |
| M0 | vertical list, page builder, checkpoint, page hash, edit demo | edit on page 2 rebuilds only page 2 | | M0 | vertical list, page builder, checkpoint, page hash, edit demo | edit on page 2 rebuilds only page 2 |
| M1 | TeX box/glue/penalty + paragraph builder (`\par`, `\hsize`, `\parindent`) | **partial**: item stream, CMR10 metrics and breaker implemented; hyphenation/pdfTeX parity next | | M1 | TeX box/glue/penalty + paragraph builder (`\par`, `\hsize`, `\parindent`) | **partial**: item stream, CMR10 metrics, pdfTeX fixture and minimum line fill; hyphenation next |
| M2 | page builder + `\output`, `\vsize`, `\topskip`, footnotes, floats | one-column article matches reference pages | | M2 | page builder + `\output`, `\vsize`, `\topskip`, footnotes, floats | one-column article matches reference pages |
| M3 | `\halign`, `\omit`, `\span`, `\multispan`, booktabs/longtable | table width/rules match reference | | M3 | `\halign`, `\omit`, `\span`, `\multispan`, booktabs/longtable | table width/rules match reference |
| M4 | math lists, scripts, fractions, radicals, accents, delimiters | arXiv formulas render without overlap | | M4 | math lists, scripts, fractions, radicals, accents, delimiters | arXiv formulas render without overlap |