Apply CMR10 italic corrections at line ends

This commit is contained in:
gloamxun committed 2026-10-20 21:27:39 +08:00
1 parent 7e0090c7a5
commit 060405fca6
2 files changed
+28 -5

No files matched your search

+24 -1
View File
@@ -8,6 +8,9 @@ pub struct HorizontalBox {
pub depth: i64, pub depth: i64,
/// The source character when this box came from text, for display lists. /// The source character when this box came from text, for display lists.
pub character: Option<char>, pub character: Option<char>,
/// TeX italic correction in scaled points.
#[serde(default)]
pub italic: i64,
} }
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
@@ -113,6 +116,7 @@ pub fn text_items(text: &str, style: &ParagraphStyle) -> Vec<HorizontalItem> {
height: style.line_height, height: style.line_height,
depth: 0, depth: 0,
character: Some(character), character: Some(character),
italic: 0,
})); }));
} }
} }
@@ -277,6 +281,7 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra
height: style.line_height, height: style.line_height,
depth: 0, depth: 0,
character: Some('-'), character: Some('-'),
italic: 0,
})); }));
} else if *no_break_width > 0 { } else if *no_break_width > 0 {
line.push(HorizontalItem::Box(HorizontalBox { line.push(HorizontalItem::Box(HorizontalBox {
@@ -284,6 +289,7 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra
height: style.line_height, height: style.line_height,
depth: 0, depth: 0,
character: None, character: None,
italic: 0,
})); }));
} }
} }
@@ -305,7 +311,11 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra
HorizontalItem::Discretionary { .. } => 0, HorizontalItem::Discretionary { .. } => 0,
}) })
.sum(); .sum();
max_width = max_width.max(width); let italic = match line.last() {
Some(HorizontalItem::Box(box_item)) => box_item.italic,
_ => 0,
};
max_width = max_width.max(width + italic);
lines.push(line); lines.push(line);
} }
Paragraph { Paragraph {
@@ -380,6 +390,7 @@ pub fn text_items_with_font(
height: style.line_height, height: style.line_height,
depth: 0, depth: 0,
character: Some(character), character: Some(character),
italic: font.italic(character),
})); }));
let boundary = character_index + 1; let boundary = character_index + 1;
if !ligated if !ligated
@@ -459,6 +470,18 @@ mod tests {
assert!(paragraph.line_count() >= 2); assert!(paragraph.line_count() >= 2);
} }
#[test]
fn cmr10_italic_correction_extends_the_line_width() {
let font = crate::cmr10::Cmr10Metrics::default();
let style = ParagraphStyle {
line_width: 400 * 65_536,
..ParagraphStyle::default()
};
let paragraph = layout_paragraph_with_font("f", &style, &font);
assert!(paragraph.width > font.width('f'));
assert_eq!(paragraph.width - font.width('f'), font.italic('f'));
}
#[test] #[test]
fn cmr10_breaks_match_pdftex_at_180pt() { fn cmr10_breaks_match_pdftex_at_180pt() {
let font = crate::cmr10::Cmr10Metrics::new(); let font = crate::cmr10::Cmr10Metrics::new();
+4 -4
View File
@@ -250,9 +250,9 @@ v1 remains the production renderer; the route-D core is additive and tested inde
M3 painter: `Page::display_list()` and `Halign::display_list()` produce absolute text, rule and line primitives. `DisplayList::to_svg()` writes a standalone SVG; paragraph glyphs and math atoms are painted at their measured positions. M3 painter: `Page::display_list()` and `Halign::display_list()` produce absolute text, rule and line primitives. `DisplayList::to_svg()` writes a standalone SVG; paragraph glyphs and math atoms are painted at their measured positions.
PDF writer: `crates/texrra-tex-core/src/pdf.rs` writes multi-page PDF 1.4 with five embedded Liberation Type0/CID faces (Identity-H + ToUnicode + `/W` arrays), filled rectangles, diagonal rules, raw-RGB `/XObject` images, `/Annots` URI links and arbitrary `/special` operators. Ligature substitution, italic correction and full NFSS family switching remain open. PDF writer: `crates/texrra-tex-core/src/pdf.rs` writes multi-page PDF 1.4 with five embedded Liberation Type0/CID faces (Identity-H + ToUnicode + `/W` arrays), filled rectangles, diagonal rules, raw-RGB `/XObject` images, `/Annots` URI links and arbitrary `/special` operators. Ligature substitution and line-end italic correction are implemented; full NFSS family switching remains open.
M5 (partial): display-list text carries `FontFace::{Roman,Bold,Italic,BoldItalic,Mono}`. Roman/Bold/Italic/BoldItalic/Mono text are painted with embedded Liberation Type0/CID fonts, each with a ToUnicode CMap and `/W` width array. `cmr10.tfm` is parsed at runtime for widths, heights/depths, kern pairs and ff/fi/fl/ffi/ffl ligatures; true NFSS family switching and italic correction remain open. M5 (partial): display-list text carries `FontFace::{Roman,Bold,Italic,BoldItalic,Mono}`. Roman/Bold/Italic/BoldItalic/Mono text are painted with embedded Liberation Type0/CID fonts, each with a ToUnicode CMap and `/W` width array. `cmr10.tfm` is parsed at runtime for widths, heights/depths, kern pairs and ff/fi/fl/ffi/ffl ligatures; line-end italic correction is applied; true NFSS family switching remains open.
M6 (partial): `DisplayItem::Image` becomes a PDF XObject; `DisplayItem::Link` becomes `/Annots /Subtype /Link /URI`; `DisplayItem::Special` injects raw content-stream operators. SVG previews show images as grey rectangles and specials as comments. M6 (partial): `DisplayItem::Image` becomes a PDF XObject; `DisplayItem::Link` becomes `/Annots /Subtype /Link /URI`; `DisplayItem::Special` injects raw content-stream operators. SVG previews show images as grey rectangles and specials as comments.
@@ -262,7 +262,7 @@ M3 (partial): `Unit::halign` normalizes column widths, intercolumn gaps, row hei
Math coverage includes fractions/roots, scripts, `\left...\right` with body-scaled delimiters, `\middle`, `\big`/`\Big`/`\bigg`/`\Bigg` and their `l`/`r` forms, control-sequence delimiters, accents (dot/check/breve/acute/grave/ring), `\text`/`\mathrm`, `\overbrace`/`\underbrace`, `\overset`/`\underset`, `\binom`, `\cancel`/`\bcancel`/`\xcancel`, `\bmod`/`\pmod`, fence symbols, `\operatorname*` and `\mathop` limits. Math coverage includes fractions/roots, scripts, `\left...\right` with body-scaled delimiters, `\middle`, `\big`/`\Big`/`\bigg`/`\Bigg` and their `l`/`r` forms, control-sequence delimiters, accents (dot/check/breve/acute/grave/ring), `\text`/`\mathrm`, `\overbrace`/`\underbrace`, `\overset`/`\underset`, `\binom`, `\cancel`/`\bcancel`/`\xcancel`, `\bmod`/`\pmod`, fence symbols, `\operatorname*` and `\mathop` limits.
The crate currently has 132 unit tests plus one route-D integration test. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 215 tests (132 route-D unit, 1 route-D integration, 71 v1 integration, 6 server, 4 v1 unit, 1 doctest). v1 remains the live server path. The crate currently has 133 unit tests plus one route-D integration test. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 216 tests (133 route-D unit, 1 route-D integration, 71 v1 integration, 6 server, 4 v1 unit, 1 doctest). v1 remains the live server path.
### M0 incremental demo ### M0 incremental demo
@@ -289,7 +289,7 @@ deliberately open rather than approximated:
- **M1**: TeX tolerance/demerits are still fitted to a few fixtures; multi-width - **M1**: TeX tolerance/demerits are still fitted to a few fixtures; multi-width
pdfTeX line breaks and full hyphenation demerits are not reproduced generally. pdfTeX line breaks and full hyphenation demerits are not reproduced generally.
- **M5**: `cmr10.tfm` is parsed at runtime with widths, glyph heights/depths and kern pairs. all five text faces embed Liberation Serif/Mono as Type0/Identity-H with `/W` widths; ff/fi/fl/ffi/ffl ligatures come from TFM, but full NFSS family switching and italic correction are not implemented. - **M5**: `cmr10.tfm` is parsed at runtime with widths, glyph heights/depths and kern pairs. all five text faces embed Liberation Serif/Mono as Type0/Identity-H with `/W` widths; ff/fi/fl/ffi/ffl ligatures come from TFM, and CMR10 italic corrections are applied at line ends; full NFSS family switching is not implemented.
- **M6**: `\output`, `\insert`, mark/float output policies, class-file execution and - **M6**: `\output`, `\insert`, mark/float output policies, class-file execution and
math limit policies are only partially modeled; `OutputRoutine::wants_break` can force a page break between units, but `\output` is still Rust code rather than interpreted tokens. math limit policies are only partially modeled; `OutputRoutine::wants_break` can force a page break between units, but `\output` is still Rust code rather than interpreted tokens.
- **M7**: `POST /api/route-d/preview` and `/api/route-d/edit/{unit}` expose - **M7**: `POST /api/route-d/preview` and `/api/route-d/edit/{unit}` expose