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,
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
`geometry` sets them. The PDF uses the Base-14 Times/Courier faces without
embedding when all text fits the standard WinAnsi encoding, and falls back to
embedded Liberation Serif/Sans/Mono for other characters; CJK text uses an
installed fallback font.
`geometry` sets them. The PDF always embeds its Liberation Serif/Mono/Sans
faces (and any CJK fallback), so glyphs do not depend on fonts installed in the
reader; PDFs are therefore larger than Base-14 output but render reliably.
### 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;
`\vbox`/`\vtop` vertical-material capture with inline splicing
(`build_positioned_pages` is the only page builder and no separate break
planner remains); conditional Base-14 font embedding and natural-width centered
table layout; `\multicolumn` column spans with alignment and partial
planner remains); embedded Liberation fonts (no Base-14 dependency on the
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
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
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
about 0.7 MB); documents with accented/non-WinAnsi text embed Liberation
faces. Tables use natural column widths and centered rules.
- All text faces are embedded Liberation Serif/Mono/Sans (arXiv PDF is about
3.6 MB and `pdffonts` reports only embedded CID TrueType faces); this avoids
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
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,
@@ -134,10 +135,11 @@ See `docs/ROADMAP.md` for concrete implementation plans.
- Compiler integration tests: 49; server tests: 4; total 53.
- `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
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
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
no annotation API, so clickable `\href`/`\url` need a writer extension.
+7 -8
View File
@@ -1923,13 +1923,12 @@ struct FontInputs {
impl FontInputs {
fn load(model: &DocumentModel) -> Result<Self, String> {
let latin_dir = latin_font_directory()?;
// Use the Base-14 faces when every text character is representable;
// otherwise embed the metric-compatible Liberation faces.
let builtin = if document_needs_embedded_latin(model) {
None
} else {
Some(fonts::Builtin::Times)
};
// Always embed the metric-compatible Liberation faces. Base-14 Times
// depends on the viewer having the exact WinAnsi faces installed and
// produced broken glyphs in some readers, so portability wins over the
// smaller PDF.
let _needs_embedded_latin = document_needs_embedded_latin(model);
let builtin = None;
let latin_fonts = fonts::from_files(&latin_dir, "LiberationSerif", builtin)
.map_err(|error| format!("could not load Latin fonts: {error}"))?;
let cjk_path = document_contains_cjk(model)
@@ -1947,7 +1946,7 @@ impl FontInputs {
.transpose()?;
let monospace_fonts = if let Some(mono_dir) = &monospace_dir {
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}"))?,
)
} else {
+2 -2
View File
@@ -185,7 +185,7 @@ fn write_table(
write_table_rule(
output,
table_x,
cursor,
f64::from(y) + cursor,
&column_offsets,
column_count,
rule,
@@ -225,7 +225,7 @@ fn write_table(
write_table_rule(
output,
table_x,
cursor,
f64::from(y) + cursor,
&column_offsets,
column_count,
rule,
+15 -14
View File
@@ -1070,22 +1070,18 @@ After.
}
#[test]
fn ascii_documents_use_base14_fonts_without_embedding() {
fn ascii_documents_embed_the_latin_font() {
let source = r"\documentclass{article}
\begin{document}
Plain text that only needs the standard Times encoding.
\end{document}";
let pdf = CompilerSession::default()
.compile(source, "base14.tex")
.expect("base14 PDF");
.compile(source, "embedded.tex")
.expect("embedded PDF");
let text = String::from_utf8_lossy(&pdf);
assert!(
text.contains("Times-Roman"),
"expected a Base-14 Times face"
);
assert!(
!text.contains("FontFile2"),
"ASCII text should not embed a TrueType program"
text.contains("FontFile2"),
"Latin text should embed a TrueType program so viewers do not substitute"
);
}
@@ -1113,10 +1109,15 @@ fn arxiv_table_rules_follow_a_narrow_centered_table() {
.nth(1)
.and_then(|rest| rest.split('"').next())
.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;
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!(
table_rules
.iter()
.all(|(x, width)| *x > 20.0 && *width < 140.0),
"table rules should be centered and narrower than the text block: {table_rules:?}"
.all(|(x, width, y)| *x > 20.0 && *width < 140.0 && *y > 20.0),
"table rules should be centered, below the page top, and narrower than the text block: {table_rules:?}"
);
let widest = table_rules
.iter()
.map(|(_, width)| *width)
.map(|(_, width, _)| *width)
.fold(0.0_f64, f64::max);
assert!(
(60.5..62.5).contains(&widest),