diff --git a/crates/texrra-tex-core/src/paragraph.rs b/crates/texrra-tex-core/src/paragraph.rs index a5108ee..a9e6fe8 100755 --- a/crates/texrra-tex-core/src/paragraph.rs +++ b/crates/texrra-tex-core/src/paragraph.rs @@ -8,6 +8,9 @@ pub struct HorizontalBox { pub depth: i64, /// The source character when this box came from text, for display lists. pub character: Option, + /// TeX italic correction in scaled points. + #[serde(default)] + pub italic: i64, } #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] @@ -113,6 +116,7 @@ pub fn text_items(text: &str, style: &ParagraphStyle) -> Vec { height: style.line_height, depth: 0, character: Some(character), + italic: 0, })); } } @@ -277,6 +281,7 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra height: style.line_height, depth: 0, character: Some('-'), + italic: 0, })); } else if *no_break_width > 0 { line.push(HorizontalItem::Box(HorizontalBox { @@ -284,6 +289,7 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra height: style.line_height, depth: 0, character: None, + italic: 0, })); } } @@ -305,7 +311,11 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra HorizontalItem::Discretionary { .. } => 0, }) .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); } Paragraph { @@ -380,6 +390,7 @@ pub fn text_items_with_font( height: style.line_height, depth: 0, character: Some(character), + italic: font.italic(character), })); let boundary = character_index + 1; if !ligated @@ -459,6 +470,18 @@ mod tests { 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] fn cmr10_breaks_match_pdftex_at_180pt() { let font = crate::cmr10::Cmr10Metrics::new(); diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index afc5200..b473c45 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -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. -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. @@ -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. -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 @@ -289,7 +289,7 @@ deliberately open rather than approximated: - **M1**: TeX tolerance/demerits are still fitted to a few fixtures; multi-width 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 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