From 1633e441deeef747535ac8b69c447bdc81c63d04 Mon Sep 17 00:00:00 2001 From: GloamXun Date: Tue, 20 Oct 2026 21:35:37 +0800 Subject: [PATCH] Paint monospace paragraphs with the embedded mono face --- crates/texrra-tex-core/src/lib.rs | 15 +++++++++++++++ crates/texrra-tex-core/src/paragraph.rs | 1 + crates/texrra-tex-core/src/render.rs | 1 + docs/TEX_CORE.md | 4 ++-- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/crates/texrra-tex-core/src/lib.rs b/crates/texrra-tex-core/src/lib.rs index 8430693..d9ed821 100644 --- a/crates/texrra-tex-core/src/lib.rs +++ b/crates/texrra-tex-core/src/lib.rs @@ -1939,6 +1939,21 @@ mod tests { assert!(text.trim_end().ends_with("%%EOF")); } + #[test] + fn mono_paragraph_paints_with_a_mono_face() { + let unit = Unit::paragraph_with_face(1, "code 123", ParagraphFont::Mono); + let page = Page { + items: unit.items, + insertions: Vec::new(), + marks: Vec::new(), + floats: Vec::new(), + sources: Vec::new(), + hash: 0, + }; + let svg = page.display_list().to_svg(); + assert!(svg.contains("font-family=\"monospace\"")); + } + #[test] fn bold_paragraph_paints_with_a_bold_face() { let document = Document::new( diff --git a/crates/texrra-tex-core/src/paragraph.rs b/crates/texrra-tex-core/src/paragraph.rs index a9e6fe8..c84df81 100755 --- a/crates/texrra-tex-core/src/paragraph.rs +++ b/crates/texrra-tex-core/src/paragraph.rs @@ -72,6 +72,7 @@ pub enum ParagraphFont { Roman, Bold, Italic, + Mono, } impl Default for ParagraphFont { diff --git a/crates/texrra-tex-core/src/render.rs b/crates/texrra-tex-core/src/render.rs index 7eab6f1..db87345 100755 --- a/crates/texrra-tex-core/src/render.rs +++ b/crates/texrra-tex-core/src/render.rs @@ -367,6 +367,7 @@ impl Page { ParagraphFont::Roman => FontFace::Roman, ParagraphFont::Bold => FontFace::Bold, ParagraphFont::Italic => FontFace::Italic, + ParagraphFont::Mono => FontFace::Mono, }; let lines = paragraph.lines.len().max(1) as i64; let line_height = (paragraph.height / lines).max(1); diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index 3c52334..e05b0f3 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -252,7 +252,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 are applied; true 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 a monospace paragraph face are 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 135 unit tests plus one route-D integration test. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 218 tests (135 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 136 unit tests plus one route-D integration test. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 219 tests (136 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