From 3d94e28dff3f18a45b2b2aa0c1f9b84efe8c5e3f Mon Sep 17 00:00:00 2001 From: GloamXun Date: Wed, 21 Oct 2026 09:18:15 +0800 Subject: [PATCH] Carry TFM glyph height and depth into paragraph boxes --- crates/texrra-tex-core/src/paragraph.rs | 29 ++++++++++++++++++++++--- docs/TEX_CORE.md | 4 ++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/crates/texrra-tex-core/src/paragraph.rs b/crates/texrra-tex-core/src/paragraph.rs index 7a4f12d..fb83051 100755 --- a/crates/texrra-tex-core/src/paragraph.rs +++ b/crates/texrra-tex-core/src/paragraph.rs @@ -347,7 +347,7 @@ pub fn layout_items(items: &[HorizontalItem], style: &ParagraphStyle) -> Paragra /// Convert text using TFM character widths and fontdimen glue parameters. pub fn text_items_with_font( text: &str, - style: &ParagraphStyle, + _style: &ParagraphStyle, font: &crate::cmr10::Cmr10Metrics, ) -> Vec { let mut items = Vec::new(); @@ -408,8 +408,8 @@ pub fn text_items_with_font( previous_character = Some(character); items.push(HorizontalItem::Box(HorizontalBox { width: font.width(slot), - height: style.line_height, - depth: 0, + height: font.height(character), + depth: font.depth(character), character: Some(character), italic: font.italic(character), })); @@ -491,6 +491,29 @@ mod tests { assert!(paragraph.line_count() >= 2); } + #[test] + fn cmr10_boxes_carry_glyph_height_and_depth() { + let font = crate::cmr10::Cmr10Metrics::new(); + let style = ParagraphStyle { + line_width: 400 * 65_536, + ..ParagraphStyle::default() + }; + let paragraph = layout_paragraph_with_font("Ag", &style, &font); + let boxes: Vec<&HorizontalBox> = paragraph.lines[0] + .iter() + .filter_map(|item| match item { + HorizontalItem::Box(box_) => Some(box_), + _ => None, + }) + .collect(); + assert_eq!(boxes.len(), 2); + assert_eq!(boxes[0].height, font.height('A')); + assert_eq!(boxes[0].depth, font.depth('A')); + assert_eq!(boxes[1].height, font.height('g')); + assert_eq!(boxes[1].depth, font.depth('g')); + assert_ne!(boxes[0].depth, boxes[1].depth); + } + #[test] fn cmr10_italic_correction_extends_the_line_width() { let font = crate::cmr10::Cmr10Metrics::default(); diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index 62c781a..2a33464 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -260,7 +260,7 @@ M3 painter: `Page::display_list()` and `Halign::display_list()` produce absolute 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; line-end and math-script italic corrections and monospace/sans paragraph faces are applied; true NFSS family switching remains open. `Unit::paragraph` now builds its item stream with `layout_paragraph_with_font`, so CMR10 advances, kerns and ligatures drive paragraph widths; the painter emits 10pt glyphs and the Type0 `/W` array reports CMR10 advances, and ligature boxes paint their component letters, so `pdftotext` keeps word boundaries instead of inserting spaces between letters. +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 and math-script italic corrections and monospace/sans paragraph faces are applied; true NFSS family switching remains open. `Unit::paragraph` now builds its item stream with `layout_paragraph_with_font`, so CMR10 advances, kerns and ligatures drive paragraph widths; each glyph box also carries the TFM height/depth, and the painter emits 10pt glyphs and the Type0 `/W` array reports CMR10 advances, and ligature boxes paint their component letters, so `pdftotext` keeps word boundaries instead of inserting spaces between letters. 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. @@ -270,7 +270,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 163 unit tests plus three route-D integration tests. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 263 tests (163 route-D unit, 3 route-D integration, 71 v1 integration, 19 server, 4 v1 unit, 1 core unit, 2 binary units). v1 remains the live server path. +The crate currently has 164 unit tests plus three route-D integration tests. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 264 tests (164 route-D unit, 3 route-D integration, 71 v1 integration, 19 server, 4 v1 unit, 1 core unit, 2 binary units). v1 remains the live server path. ### M0 incremental demo