Paint ligature boxes as their component letters

This commit is contained in:
gloamxun committed 2026-10-20 22:59:31 +08:00
1 parent 67915402a6
commit ff3fff343d
3 files changed
+32 -3

No files matched your search

+18
View File
@@ -1600,6 +1600,24 @@ mod tests {
assert_eq!(before, after);
}
#[test]
fn ligature_boxes_paint_their_component_letters() {
let unit = Unit::paragraph(1, "office");
let page = Page {
items: unit.items,
insertions: Vec::new(),
marks: Vec::new(),
floats: Vec::new(),
sources: Vec::new(),
hash: 0,
};
let list = page.display_list();
assert!(list.items.iter().any(|item| matches!(
item,
crate::render::DisplayItem::Text { text, .. } if text == "ff"
)));
}
#[test]
fn paragraph_widths_come_from_cmr10_not_fixed_cells() {
let width = |source: &str| {
+12 -1
View File
@@ -250,6 +250,17 @@ fn escape(text: &str) -> String {
.replace('>', ">")
}
fn character_text(character: char) -> String {
match character {
'\u{FB00}' => "ff".to_owned(),
'\u{FB01}' => "fi".to_owned(),
'\u{FB02}' => "fl".to_owned(),
'\u{FB03}' => "ffi".to_owned(),
'\u{FB04}' => "ffl".to_owned(),
_ => character.to_string(),
}
}
impl Halign {
/// Convert the table into text and rule primitives, with the table origin
/// at `(0, 0)`.
@@ -403,7 +414,7 @@ impl Page {
x,
y: baseline,
size,
text: character.to_string(),
text: character_text(character),
});
}
x += box_.width;
+2 -2
View File
@@ -254,7 +254,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, 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; 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.
@@ -264,7 +264,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 140 unit tests plus one route-D integration test. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 235 tests (140 route-D unit, 1 route-D integration, 71 v1 integration, 18 server, 4 v1 unit, 1 doctest). v1 remains the live server path.
The crate currently has 141 unit tests plus one route-D integration test. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 236 tests (141 route-D unit, 1 route-D integration, 71 v1 integration, 18 server, 4 v1 unit, 1 doctest). v1 remains the live server path.
### M0 incremental demo