Use a minimal font tier for Latin-1 documents
This commit is contained in:
1 parent
aaa9dee477
commit
79305d7c79
16 files changed
+58
-6
No files matched your search
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1
-1
@@ -81,4 +81,4 @@ the requested size and an x offset.
|
||||
Done: the paragraph now places against the full body goal and the title-note reserve is applied after it; `arxiv_fixture_is_three_letter_pages` asserts that page 1 contains the closing `See` line and keeps a 3 mm gap above the footnote.
|
||||
|
||||
|
||||
- Fonts: pyftsubset bundles with retained glyph ids and filtered kern table bring the arXiv PDF to about 1.8 MB; exact per-document glyph subsetting remains a follow-up.
|
||||
- Fonts: pyftsubset bundles with retained glyph ids and filtered kern table bring the arXiv PDF to about 1.2 MB; exact per-document glyph subsetting remains a follow-up.
|
||||
+3
-3
@@ -128,7 +128,7 @@ See `docs/ROADMAP.md` for concrete implementation plans.
|
||||
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` (57 tests: 53 compiler
|
||||
- `cargo fmt --check` passes; `cargo test --offline` (58 tests: 53 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,
|
||||
project API, static frontend assets, path traversal, the legacy
|
||||
@@ -139,7 +139,7 @@ See `docs/ROADMAP.md` for concrete implementation plans.
|
||||
|
||||
- Compiler integration tests: 53; server tests: 4; total 57.
|
||||
- `cargo fmt --check` passes.
|
||||
- arXiv fixture: 3 Letter pages, ~1.8 MB; four serif faces and one monospace face embedded (bold/italic monospace falls back to the regular face). The bundled SubsetTTF faces are pyftsubset outputs with retained glyph ids and a filtered legacy kern table.
|
||||
- arXiv fixture: 3 Letter pages, ~1.2 MB; four serif faces and one monospace face embedded (bold/italic monospace falls back to the regular face). The bundled SubsetTTF faces are pyftsubset outputs with retained glyph ids and a filtered legacy kern table; a second smaller Latin-1/Greek tier is selected when the document charset fits.
|
||||
- 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.1 mm wide (reference 61.2 mm) with `\multicolumn` spans and
|
||||
@@ -148,4 +148,4 @@ See `docs/ROADMAP.md` for concrete implementation plans.
|
||||
- PDF link annotations are added by reopening the finished PDF with lopdf,
|
||||
since printpdf 0.3.4 has no annotation API.
|
||||
|
||||
- Fonts: bundled reserved-glyph subsets in `assets/fonts-subset/` are used when the document charset is covered; arXiv PDF is about 1.8 MB with 57 tests.
|
||||
- Fonts: bundled reserved-glyph subsets in `assets/fonts-subset/` are used when the document charset is covered; arXiv PDF is about 1.2 MB with 58 tests.
|
||||
+41
-2
@@ -2097,7 +2097,13 @@ struct FontInputs {
|
||||
impl FontInputs {
|
||||
fn load(model: &DocumentModel) -> Result<Self, String> {
|
||||
let subset_dir = document_fits_subset_fonts(model)
|
||||
.then(subset_font_directory)
|
||||
.then(|| {
|
||||
if document_fits_min_subset_fonts(model) {
|
||||
subset_font_directory_min()
|
||||
} else {
|
||||
subset_font_directory()
|
||||
}
|
||||
})
|
||||
.flatten();
|
||||
let latin_dir = match &subset_dir {
|
||||
Some(dir) => dir.clone(),
|
||||
@@ -3123,6 +3129,24 @@ fn builtin_safe_char(ch: char) -> bool {
|
||||
)
|
||||
}
|
||||
|
||||
fn minimal_subset_safe_char(ch: char) -> bool {
|
||||
let code = ch as u32;
|
||||
matches!(code,
|
||||
0x09..=0x0A
|
||||
| 0x20..=0x7E
|
||||
| 0xA0..=0xFF
|
||||
| 0x370..=0x3FF
|
||||
| 0x2000..=0x206F
|
||||
| 0x2070..=0x209F
|
||||
| 0x20A0..=0x20CF
|
||||
| 0x2100..=0x214F
|
||||
| 0x2190..=0x21FF
|
||||
| 0x2200..=0x22FF
|
||||
| 0x25A0..=0x25FF
|
||||
| 0xF0000..=0xFFFFF
|
||||
)
|
||||
}
|
||||
|
||||
fn subset_safe_char(ch: char) -> bool {
|
||||
let code = ch as u32;
|
||||
matches!(code,
|
||||
@@ -3144,7 +3168,15 @@ fn subset_safe_char(ch: char) -> bool {
|
||||
}
|
||||
|
||||
fn document_fits_subset_fonts(model: &DocumentModel) -> bool {
|
||||
let text_fits = |text: &str| text.chars().all(subset_safe_char);
|
||||
document_fits_font_charset(model, subset_safe_char)
|
||||
}
|
||||
|
||||
fn document_fits_min_subset_fonts(model: &DocumentModel) -> bool {
|
||||
document_fits_font_charset(model, minimal_subset_safe_char)
|
||||
}
|
||||
|
||||
fn document_fits_font_charset(model: &DocumentModel, safe: fn(char) -> bool) -> bool {
|
||||
let text_fits = |text: &str| text.chars().all(safe);
|
||||
let runs_fit = |runs: &[Run]| {
|
||||
runs.iter()
|
||||
.filter(|run| run.math.is_none())
|
||||
@@ -3200,6 +3232,13 @@ fn subset_font_directory() -> Option<PathBuf> {
|
||||
.then_some(dir)
|
||||
}
|
||||
|
||||
fn subset_font_directory_min() -> Option<PathBuf> {
|
||||
let dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("assets/fonts-subset-min");
|
||||
dir.join("LiberationSerif-Regular.ttf")
|
||||
.is_file()
|
||||
.then_some(dir)
|
||||
}
|
||||
|
||||
fn document_needs_embedded_latin(model: &DocumentModel) -> bool {
|
||||
let text_needs_embedding = |text: &str| text.chars().any(|ch| !builtin_safe_char(ch));
|
||||
let runs_need_embedding = |runs: &[Run]| {
|
||||
|
||||
@@ -128,6 +128,19 @@ fn arxiv_pdf_embeds_a_single_monospace_face() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ascii_document_uses_the_minimal_font_tier() {
|
||||
let source = "\\documentclass{article}\n\\begin{document}\nHello world.\n\\end{document}\n";
|
||||
let pdf = CompilerSession::default()
|
||||
.compile(source, "minimal-tier.tex")
|
||||
.expect("ASCII PDF");
|
||||
assert!(
|
||||
pdf.len() < 1_200_000,
|
||||
"ASCII document should use the minimal subset tier, got {} bytes",
|
||||
pdf.len()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn arxiv_fixture_is_three_letter_pages() {
|
||||
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||
|
||||
Reference in new issue
Block a user