Embed text fonts and fix preview table rule coordinates

This commit is contained in:
gloamxun committed 2026-10-19 21:07:25 +08:00
1 parent b119c57e8e
commit 2856506d65
6 files changed
+37 -35

No files matched your search

+3 -4
View File
@@ -127,10 +127,9 @@ page
breaks, basic display and inline math, figures, simple tables, breaks, basic display and inline math, figures, simple tables,
section/figure/table references, numeric citations from a manual bibliography or a section/figure/table references, numeric citations from a manual bibliography or a
local `.bib` file, and natbib-style author-year citations for the arXiv template. A4 pages use 25 mm margins unless local `.bib` file, and natbib-style author-year citations for the arXiv template. A4 pages use 25 mm margins unless
`geometry` sets them. The PDF uses the Base-14 Times/Courier faces without `geometry` sets them. The PDF always embeds its Liberation Serif/Mono/Sans
embedding when all text fits the standard WinAnsi encoding, and falls back to faces (and any CJK fallback), so glyphs do not depend on fonts installed in the
embedded Liberation Serif/Sans/Mono for other characters; CJK text uses an reader; PDFs are therefore larger than Base-14 output but render reliably.
installed fallback font.
### LaTeX compatibility layer ### LaTeX compatibility layer
+3 -2
View File
@@ -18,8 +18,9 @@ author-year citations and plainnat bibliography formatting with duplicate-year
`2014a`/`2014b` suffixes; hyperref-style green `\href`/`\url`/citation text; `2014a`/`2014b` suffixes; hyperref-style green `\href`/`\url`/citation text;
`\vbox`/`\vtop` vertical-material capture with inline splicing `\vbox`/`\vtop` vertical-material capture with inline splicing
(`build_positioned_pages` is the only page builder and no separate break (`build_positioned_pages` is the only page builder and no separate break
planner remains); conditional Base-14 font embedding and natural-width centered planner remains); embedded Liberation fonts (no Base-14 dependency on the
table layout; `\multicolumn` column spans with alignment and partial reader) and natural-width centered table layout with preview/PDF coordinate
parity; `\multicolumn` column spans with alignment and partial
`\cmidrule(r){a-b}`/`\cline{a-b}` rules; footnote capture in figure/table `\cmidrule(r){a-b}`/`\cline{a-b}` rules; footnote capture in figure/table
captions with the insertion area reserved on the caption page. captions with the insertion area reserved on the caption page.
+7 -5
View File
@@ -120,9 +120,10 @@ See `docs/ROADMAP.md` for concrete implementation plans.
- `examples/hello.tex`, `examples/boxes.tex`, `examples/compat.tex` compile to - `examples/hello.tex`, `examples/boxes.tex`, `examples/compat.tex` compile to
one A4 page each; the arXiv template project compiles to 3 Letter pages. one A4 page each; the arXiv template project compiles to 3 Letter pages.
- ASCII-only documents use non-embedded Base-14 Times/Courier (arXiv PDF is - All text faces are embedded Liberation Serif/Mono/Sans (arXiv PDF is about
about 0.7 MB); documents with accented/non-WinAnsi text embed Liberation 3.6 MB and `pdffonts` reports only embedded CID TrueType faces); this avoids
faces. Tables use natural column widths and centered rules. viewer-dependent glyph substitution. Tables use natural column widths and
centered rules; preview and PDF share the same table line coordinates.
- `cargo fmt --check` passes; `cargo test --offline` (53 tests: 49 compiler - `cargo fmt --check` passes; `cargo test --offline` (53 tests: 49 compiler
integration tests + 4 server tests) covers the three examples, the arXiv integration tests + 4 server tests) covers the three examples, the arXiv
fixture, figure/table floats (top and bottom), newpage, page styles and `\thispagestyle`, SVG/PDF output, fixture, figure/table floats (top and bottom), newpage, page styles and `\thispagestyle`, SVG/PDF output,
@@ -134,10 +135,11 @@ See `docs/ROADMAP.md` for concrete implementation plans.
- Compiler integration tests: 49; server tests: 4; total 53. - Compiler integration tests: 49; server tests: 4; total 53.
- `cargo fmt --check` passes. - `cargo fmt --check` passes.
- arXiv fixture: 3 Letter pages, ~701 KB, Base-14 Times/Courier only. - arXiv fixture: 3 Letter pages, ~3.6 MB, embedded Liberation faces only.
- Title/author/date/Introduction baselines within 0.3 pt of the XeLaTeX - Title/author/date/Introduction baselines within 0.3 pt of the XeLaTeX
reference; page 1 keeps the closing section-2 line above the footnote. reference; page 1 keeps the closing section-2 line above the footnote.
- Table 61.6 mm wide (reference 61.2 mm) with `\multicolumn` spans and - Table 61.6 mm wide (reference 61.2 mm) with `\multicolumn` spans and
partial `\cmidrule` rules. partial `\cmidrule` rules; table rules in the SVG preview use absolute page
coordinates, matching the PDF.
- Remaining blocker: PDF link annotations (`/Annots`); printpdf 0.3.4 has - Remaining blocker: PDF link annotations (`/Annots`); printpdf 0.3.4 has
no annotation API, so clickable `\href`/`\url` need a writer extension. no annotation API, so clickable `\href`/`\url` need a writer extension.
+7 -8
View File
@@ -1923,13 +1923,12 @@ struct FontInputs {
impl FontInputs { impl FontInputs {
fn load(model: &DocumentModel) -> Result<Self, String> { fn load(model: &DocumentModel) -> Result<Self, String> {
let latin_dir = latin_font_directory()?; let latin_dir = latin_font_directory()?;
// Use the Base-14 faces when every text character is representable; // Always embed the metric-compatible Liberation faces. Base-14 Times
// otherwise embed the metric-compatible Liberation faces. // depends on the viewer having the exact WinAnsi faces installed and
let builtin = if document_needs_embedded_latin(model) { // produced broken glyphs in some readers, so portability wins over the
None // smaller PDF.
} else { let _needs_embedded_latin = document_needs_embedded_latin(model);
Some(fonts::Builtin::Times) let builtin = None;
};
let latin_fonts = fonts::from_files(&latin_dir, "LiberationSerif", builtin) let latin_fonts = fonts::from_files(&latin_dir, "LiberationSerif", builtin)
.map_err(|error| format!("could not load Latin fonts: {error}"))?; .map_err(|error| format!("could not load Latin fonts: {error}"))?;
let cjk_path = document_contains_cjk(model) let cjk_path = document_contains_cjk(model)
@@ -1947,7 +1946,7 @@ impl FontInputs {
.transpose()?; .transpose()?;
let monospace_fonts = if let Some(mono_dir) = &monospace_dir { let monospace_fonts = if let Some(mono_dir) = &monospace_dir {
Some( Some(
fonts::from_files(mono_dir, "LiberationMono", Some(fonts::Builtin::Courier)) fonts::from_files(mono_dir, "LiberationMono", None)
.map_err(|error| format!("could not load monospaced fonts: {error}"))?, .map_err(|error| format!("could not load monospaced fonts: {error}"))?,
) )
} else { } else {
+2 -2
View File
@@ -185,7 +185,7 @@ fn write_table(
write_table_rule( write_table_rule(
output, output,
table_x, table_x,
cursor, f64::from(y) + cursor,
&column_offsets, &column_offsets,
column_count, column_count,
rule, rule,
@@ -225,7 +225,7 @@ fn write_table(
write_table_rule( write_table_rule(
output, output,
table_x, table_x,
cursor, f64::from(y) + cursor,
&column_offsets, &column_offsets,
column_count, column_count,
rule, rule,
+15 -14
View File
@@ -1070,22 +1070,18 @@ After.
} }
#[test] #[test]
fn ascii_documents_use_base14_fonts_without_embedding() { fn ascii_documents_embed_the_latin_font() {
let source = r"\documentclass{article} let source = r"\documentclass{article}
\begin{document} \begin{document}
Plain text that only needs the standard Times encoding. Plain text that only needs the standard Times encoding.
\end{document}"; \end{document}";
let pdf = CompilerSession::default() let pdf = CompilerSession::default()
.compile(source, "base14.tex") .compile(source, "embedded.tex")
.expect("base14 PDF"); .expect("embedded PDF");
let text = String::from_utf8_lossy(&pdf); let text = String::from_utf8_lossy(&pdf);
assert!( assert!(
text.contains("Times-Roman"), text.contains("FontFile2"),
"expected a Base-14 Times face" "Latin text should embed a TrueType program so viewers do not substitute"
);
assert!(
!text.contains("FontFile2"),
"ASCII text should not embed a TrueType program"
); );
} }
@@ -1113,10 +1109,15 @@ fn arxiv_table_rules_follow_a_narrow_centered_table() {
.nth(1) .nth(1)
.and_then(|rest| rest.split('"').next()) .and_then(|rest| rest.split('"').next())
.and_then(|value| value.parse::<f64>().ok()); .and_then(|value| value.parse::<f64>().ok());
if let (Some(x1), Some(x2)) = (x1, x2) { let y1 = tag
.split("y1=\"")
.nth(1)
.and_then(|rest| rest.split('\"').next())
.and_then(|value| value.parse::<f64>().ok());
if let (Some(x1), Some(x2), Some(y1)) = (x1, x2, y1) {
let width = x2 - x1; let width = x2 - x1;
if x1 > 20.0 && width > 40.0 && width < 140.0 { if x1 > 20.0 && width > 40.0 && width < 140.0 {
table_rules.push((x1, width)); table_rules.push((x1, width, y1));
} }
} }
} }
@@ -1127,12 +1128,12 @@ fn arxiv_table_rules_follow_a_narrow_centered_table() {
assert!( assert!(
table_rules table_rules
.iter() .iter()
.all(|(x, width)| *x > 20.0 && *width < 140.0), .all(|(x, width, y)| *x > 20.0 && *width < 140.0 && *y > 20.0),
"table rules should be centered and narrower than the text block: {table_rules:?}" "table rules should be centered, below the page top, and narrower than the text block: {table_rules:?}"
); );
let widest = table_rules let widest = table_rules
.iter() .iter()
.map(|(_, width)| *width) .map(|(_, width, _)| *width)
.fold(0.0_f64, f64::max); .fold(0.0_f64, f64::max);
assert!( assert!(
(60.5..62.5).contains(&widest), (60.5..62.5).contains(&widest),