You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(render): embed real fonts in a layout's vector PDF (#1815, part 1) - #1828
Part of #1815 (items 1, 2 and 5: real fonts). The layers (item 4) are on main since #1834, and this branch has main merged into it, so its PDFs have both real fonts and layers. Halos as text (item 3) come in a later PR.
A layout's vector PDF now sets its text in the fonts it is drawn in, each face embedded as a subset of its glyphs (a Type 0 font over a CID font, Identity-H, with a ToUnicode map), so a vector editor opens it as text it can edit. A face that can't be embedded is set in Type 3 outlines as before, and the export names it with the reason. "pdf": {"text": "outlines"} on layout.export keeps today's output for print shops that ask for outlined type.
The same A4 layout (Natural Earth countries, labels, legend, scale and footer) exported from this branch and opened in VectorCraft 0.24. Left, "text": "outlines": no text objects, 762 objects, each letter a path (boxed in red). Right, the default: 54 editable text objects and 153 objects in all (each text object boxed in green).
What changes
render::pdf::Options gains text: Text (Fonts or Outlines) next to feat(render): layers in vector PDFs (#1815, layers) #1834's layers. write_with(pages, title, options) returns the bytes and the faces set in outlines. It gathers every glyph each face sets across the pages before writing anything, so a face is embedded or not as a whole and its glyphs' codes are the subset's.
pdf/embed.rs decides per face, from its file (FontRef::font_data):
the face of the file that draws these glyphs as the export does: same glyph count and units per em, same advance and outline for every glyph used, at the file's default instance. In a collection (.ttc), the first face that draws them alike;
the OS/2 fsType: Restricted (2), no subsetting (0x100) and bitmap only (0x200) fall back to outlines;
the subset from subsetter. An error falls back to outlines, and so does a panic in it, caught on native builds. In the browser, where wasm32 aborts on a panic, no user file reaches it: fonts are read from disk, so the web has only the face bundled with the app;
limits: 8 MB for one face's subset, 32 MB for all of a document's faces.
pdf/fonts.rs writes an embedded face as a Type 0 font over a CIDFontType2 (TrueType outlines, FontFile2, CIDToGIDMap /Identity) or a CIDFontType0 (CFF, FontFile3 /OpenType, which makes the document PDF 1.6). Each font has /W widths from the face's own advances, a descriptor with the face's metrics, and a two-byte ToUnicode map. The content sets those faces' glyphs as two-byte CIDs, and everything else is as before.
layout.export takes "pdf": {"text": "fonts" | "outlines"} (default fonts; any other value is refused). Publish › Export and Print in the app use fonts.
Print and PDF download in the app embed fonts by default; outlines stay available through layout.export's pdf option ("pdf": {"text": "outlines"}).
Cancel is looked at between faces (each face is subset in one step); once cancelled, the faces left are set in outlines and the export writes nothing.
Never silent: one notice names the faces set in outlines, each with why, for example The PDF sets the text of 1 face as outlines, not as text a vector editor can edit: Ubuntu Light (its licence forbids embedding).
docs/user-guide/layouts.md describes it.
Choices in this proposal
A synthetic italic stays real text. The renderer slants a face with no italic as a shear of its outlines. The PDF already writes that shear in the text matrix (Tm), so the embedded upright face, sheared, draws the same glyphs, and an editor reads it as skewed text. The issue listed synthetic italics as a Type 3 case, but that would give up editable text for nothing. There is no synthetic bold to fall back for: the renderer's bold is the bold file, or a variable font's wght, which the next point covers.
A variable font drawn at another instance than its file's default falls back to outlines (reason: "it is drawn at another weight or width than its file's default"). Instancing it would need subsetter's variable-fonts feature, which brings in skrifa, write-fonts and kurbo. A variable face drawn at its default, as the regular usually is, is embedded. That case hasn't been checked with a variable font: subsetter writes only glyf/loca, CFF, head, hhea/hmtx, maxp, name and post (plus cvt, fpgm and prep), so the variation tables are left out and glyf holds the default outlines that embed matched. A test waits for a variable-font asset.
Only layout.export (and the app's layout export and print) changes in this PR. The map view's PDF (Print Map), reports and presentations still call pdf::write: its text stays in Type 3 (with feat(render): layers in vector PDFs (#1815, layers) #1834's layers), so nothing there changes without its own notice. Moving them over is one call each, for a later PR.
Glyphs are matched by drawing, not by name. The face index in a collection and "is this the default instance" both come from comparing each glyph used with a fresh parse of the file. So a face embedded is one whose file draws the same, glyph for glyph.
New dependencies (two maintainers' approval, per docs/maintaining.md)
Crate
Licence
Why
Already in the tree?
subsetter 0.2.6, default-features = false
MIT OR Apache-2.0
Subsets TrueType and CFF faces for PDF embedding, from the typst project, pure Rust, #![deny(unsafe_code)]. Writing a subsetter (glyf closure over composites, loca, hmtx, CFF charstrings and subrs) is what #1342 left out as too large.
No; its only dependency, rustc-hash 2, already is
ttf-parser 0.25 (direct)
MIT OR Apache-2.0
fsType, names and metrics for the descriptor
Yes, the same version, through ab_glyph
The questions in docs/maintaining.md:
wasm32:cargo build --target wasm32-unknown-unknown -p subsetter builds; it is pure Rust with no system or C library.
Licences: both are in deny.toml's list. cargo xtask notices refreshed THIRD-PARTY-LICENSES.txt.
Build time and size, measured on Windows x64 in release: subsetter compiles in about 5 s, and a binary that calls subsetter::subset is 161 KB larger than one that doesn't (308 KB against 147 KB).
What it does better: the tests below. On real files, the PDF is smaller too: the A4 layout above is 124.7 KB with fonts against 133.7 KB with outlines.
pdf-writer, which the issue mentioned for the font dictionaries, isn't used: the dictionaries are about 60 lines on the PDF code RustGIS already has.
Verification
The issue's reproduction with PyMuPDF (page.get_fonts()):
the layout above: Type3 ×2 before; Type0 ×2 (SegoeUI, SegoeUI-Semibold) after, with page.get_text() unchanged (817 characters);
a 850 × 550 pt layout with 337 texts: Type0 ×6 (Segoe UI regular, semibold and bold; Georgia, Georgia Bold and Georgia Italic), the same 2,193 characters. In VectorCraft it went from 0 text objects and 3,830 objects to 178 text objects and 2,373 objects.
PNG and PDF still match. The A4 page at 600 dpi was rendered with MuPDF from both PDFs and compared with the layout's own PNG export: mean difference 4.10 grey levels with fonts against 4.16 with outlines. On the longest footer line, the fonts text lies 1 px from the PNG and the outlines text 3 px, because MuPDF places Type 3 glyphs slightly short.
Inkscape isn't installed on this PC, so the editor check was done in VectorCraft only.
CFF faces (.otf) were checked against outlines on two free faces installed here: Source Sans Pro Bold (a name-keyed CFF) and Harano Aji Gothic Medium (a CID-keyed CFF, with Latin and Japanese). Rendered by MuPDF at 300 dpi, Text::Fonts and Text::Outlines match: no pixel differs by more than 64 levels and the ink is the same. The text reads back too, including 地図 日本語. Subsetter makes CID equal the subset's GID for both kinds.
Tests:
pdf::embed::tests::text_in_fonts_is_its_face_embedded: a layout text and a map label (in a group, the second slanted as a synthetic italic) come out as Type 0 over CIDFontType2 with CIDToGIDMap /Identity and no Type 3. The subset is a valid font and a quarter of the file's size or less. The ToUnicode map reads back A ç ã o, and the content sets two-byte CIDs. Text::Outlines gives exactly pdf::write's bytes.
a_cff_face_is_a_cid_font_type0: a CFF face of the test's own (crates/render/testdata/test-cff.otf, 712 bytes, made with fontTools by the script in testdata/README.md, so no third-party font is redistributed) comes out as a CIDFontType0 over a FontFile3 /OpenType with no CIDToGIDMap, in PDF 1.6. Each CID draws its character's glyph (same advance and outline in the subset), and /W holds its width. The TrueType test checks the same through a shared helper.
a_face_that_forbids_embedding_is_set_in_outlines: fsType patched to 2 gives Type 3 and one Outlined { face: "Ubuntu Light", why: "its licence forbids embedding" }.
only_the_face_as_drawn_is_embedded: a static face is embedded; another face's glyph doesn't count as drawing alike; past the room left, TooLarge with its message.
embedding_a_scrambled_font_file_never_panics: 64 files, cut short and scrambled in glyf, the table directory and hmtx, that ab_glyph still parses: embedding and naming each never panics.
engine a_layout_pdf_sets_its_text_in_its_fonts: layout.export with a text and labelled countries gives Type 0 fonts and no Type 3, says nothing, and has the title's O ç ã in its maps. "outlines" gives Type 3 only; "fonts" matches the default byte for byte; {"text": "curves"}, "outlines" (not an object), {"text": 1} and the misspelled {"txt": …} are refused, the last naming the keys "pdf" takes (layers, text). The test's PDF is removed however the test ends.
layouts_compose_export_and_round_trip now expects Type 0 in the default export.
cargo fmt, cargo clippy --workspace --all-targets -D warnings, and the render and engine tests pass locally (Windows), except two tests that fail on this PC on main too: gdal_formats_open needs GDAL 3.8 (3.7.1 here), and reload::wrong_geometry gets a Windows message in Portuguese.
Size
About 480 lines of non-test code with doc comments (pdf/embed.rs 180, pdf/fonts.rs 130, pdf.rs 90, layout.export 65) and 185 lines of tests. That is over the 300–400 line target. Gathering, deciding, writing and the option only work together: the content's codes depend on the decision made before any page is written, so this part can't be split further without leaving a PDF writer that can't use what it embeds.
… part 1)
A layout's PDF now sets its text in the faces it is drawn in, each
embedded as a subset of its glyphs (Type 0 over CIDFontType2 or
CIDFontType0, Identity-H, ToUnicode), so vector editors open it as
editable text. A face whose licence forbids embedding or subsetting,
one drawn at another instance than its variable file's default, or one
whose file can't be subset is set in Type 3 outlines as before, and the
export names it with why. `"pdf": {"text": "outlines"}` on
layout.export keeps today's output.
New dependencies: subsetter 0.2 (MIT OR Apache-2.0, without its
variable-fonts feature) and ttf-parser 0.25 as a direct dependency
(already in the tree through ab_glyph).
Part of opengeos#1815.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
No actionable comments were generated in the recent review.
Walkthrough
PDF export now embeds font subsets by default in layout exports when the font can be embedded and subset. Type 3 outlines remain available as a fallback or explicit mode. The renderer reports faces that it outlines and supports TrueType and CFF subsets.
Changes: PDF Font Export
Layer / File(s)
Summary
Font subset eligibility and creation Cargo.toml, crates/render/Cargo.toml, crates/render/src/pdf/embed.rs, crates/render/testdata/README.md, ATTRIBUTION.md, THIRD-PARTY-LICENSES.txt, apps/rustgis-python/THIRD-PARTY-LICENSES.txt
The renderer adds subsetter and ttf-parser, checks whether font faces can be embedded and subset, and records reasons when embedding is refused. Tests cover TrueType and CFF subsets, permission refusals, size limits, face matching, and malformed font data. The CFF test font and dependency notices are documented.
PDF font placement and writing crates/render/src/pdf.rs, crates/render/src/pdf/fonts.rs, crates/render/src/pdf/content.rs
PDF rendering gathers glyphs and writes embedded Type 0 fonts with widths and Unicode maps. Glyphs without an embedded face continue through the Type 3 path.
Layout export options and reporting crates/engine/src/cmd/layout.rs, crates/engine/src/tests.rs, docs/user-guide/layouts.md
layout.export accepts "fonts" or "outlines" for pdf.text, defaults to "fonts", and rejects other values. Export reports outlined faces, listing up to ten faces and any additional count. Tests and documentation cover these options and outcomes.
sequenceDiagram
participant LayoutExport
participant PdfWriter
participant FontEmbed
participant PdfFonts
LayoutExport->>PdfWriter: Request PDF with font text mode
PdfWriter->>FontEmbed: Match faces and create subsets
FontEmbed-->>PdfWriter: Subsets or refusal reasons
PdfWriter->>PdfFonts: Write embedded fonts and outline fallbacks
PdfWriter-->>LayoutExport: PDF bytes and outlined-face records
Loading
Possibly related issues
opengeos/RustGIS#1815 requests embedded TrueType/OpenType subsets, Type 3 fallback, and a layout export text option. This change implements those behaviors.
Suggested reviewers:giswqs, mavrick-f
Merge Risk: Minimal · up to fd713
Layout PDF export now embeds font subsets by default and falls back to outlines when a face cannot be embedded. No concrete merge-blocking risk was identified in the supplied change.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title "feat(render): embed real fonts in a layout's vector PDF (#1815, part 1)" matches the main change. The PR embeds real font subsets as Type 0 fonts in layout vector PDFs, with Type 3 outlines…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Description check
The description follows the repository template closely. It has the Summary (what changes and why, with a clear design rationale and a list of changes), the Testing section (detailed tests, reproducti…
Full details: Title check
Explanation
The title "feat(render): embed real fonts in a layout's vector PDF (#1815, part 1)" matches the main change. The PR embeds real font subsets as Type 0 fonts in layout vector PDFs, with Type 3 outlines as the fallback. The title names the feature, the scope (render, layout vector PDF), and the issue part. It is specific and concise, and the changeset supports it.
Full details: Description check
Explanation
The description follows the repository template closely. It has the Summary (what changes and why, with a clear design rationale and a list of changes), the Testing section (detailed tests, reproduction with PyMuPDF, PNG comparison, CFF checks, and local cargo fmt/clippy/test results with two known failing tests explained), and a UI evidence section that includes a before/after image and VectorCraft comparison. It also covers new dependencies with licence and build-time details, which the repository's maintaining guide asks for. The 'Related issue' section is not filled in as the template requires; the description says 'Part of #1815' in the opening line, which partly satisfies it. The 'Related issue' section should be explicitly set as a heading with 'Part of #1815' (items 1, 2 and 5), and the description should keep the template's section headings. These are minor gaps, so the description is mostly complete.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
A rabbit checks the glyphs in flight And tucks font subsets out of sight If permissions close the door Type 3 draws the letters more Unicode maps keep text in view Then hops away with PDFs new
Recent review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: ASSERTIVE
Plan: Advanced
Run ID: 41f61fa5-fa0a-472c-a6bd-b97d022e7eea
Commits
Reviewing files that changed from the base of the PR and between deee8d6 and fd71354.
Files selected for processing: 1
docs/user-guide/layouts.md
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Cancel is not looked at between faces (AGENTS.md, "Never hold the window"). Confidence: medium-low (about 55%).
The loop embeds each face in turn. Every embed call reads the whole face and subsets it, and the input is not capped (only the output is, at 8 MB). Nothing in write_with calls rustgis_data::progress::check(), and its doc comment does not say that a face's subset is one unchecked step. So Cancel only takes effect after the whole PDF is written.
The render crate already uses rustgis_data::progress::check(), so the check is available. Adding it here means write_with must return a Result so the cancel can propagate. The other option is a doc note saying each face's subset is one long step that does not look at Cancel. Either fix is fine; the current code has neither.
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 12d65d4: write_with checks rustgis_data::progress::check() before each face. Once cancelled, the faces left are set in outlines without a notice, since the engine checks Cancel again after the bytes are made and a cancelled export writes nothing. That keeps write_with's signature. The doc comment now says each face is subset in one step, with Cancel looked at between faces.
The reason will be displayed to describe this comment to others. Learn more.
catch_unwind may not contain a subsetter panic in the browser build. Confidence: medium-low (about 45%).
On wasm32-unknown-unknown the default panic strategy is abort, so catch_unwind cannot catch a panic. A subsetter panic on the web would then take down the whole app, not fall back to outlines. The doc comment on line 87 ("Never panics, whatever the file holds") and the PR text ("a panic caught in it") hold only for native builds.
Either scope the claim in the doc comment to native targets, or handle the web case explicitly. I have not verified the panic strategy for this target by building it.
The reason will be displayed to describe this comment to others. Learn more.
Checked: in the browser no user file reaches the subsetter. Every face the renderer draws in is read from disk with std::fs (the interface fonts, installed families, the serif, and the CJK and script faces), and on wasm32 those reads fail. So the web has only the label face bundled with the app (egui's Ubuntu Light), which is well-formed. In 12d65d4 the doc comment limits the panic claim to native builds and says why the browser is safe, and the PR text says the same.
The reason will be displayed to describe this comment to others. Learn more.
Doc overstates what was checked. Confidence: high (about 70%).
The PR text says only VectorCraft was tested, and that Inkscape was not installed. This sentence presents Inkscape, Illustrator and Affinity as opening the PDF as editable text, which is unverified. Suggest naming only the editor that was checked:
Suggested change
editor (Inkscape, Illustrator, Affinity, VectorCraft) opens it as text that can be edited; it can
editor (such as VectorCraft, where it was checked) opens it as text that can be edited; it can
The reason will be displayed to describe this comment to others. Learn more.
Test gap: the CID-to-GID mapping and the /W widths are not checked by any test. Confidence: medium (about 40%) that this hides a bug; the gap itself is certain.
gids comes from remapped_gids(), and the widths are read from gids[cid]. If that iterator's order is not the new-GID order, every glyph gets the wrong width. text_in_fonts_is_its_face_embedded checks the CMap and the content codes, but never the /W entries. The only check on placement is the manual MuPDF comparison in the PR text.
Suggest a test that parses the /W entry for one CID and compares it with that glyph's advance × 1000. I have not verified the crate's ordering; that test would settle it.
The reason will be displayed to describe this comment to others. Learn more.
Added in 12d65d4. text_in_fonts_is_its_face_embedded now goes through the ToUnicode map for each CID. It checks that the subset's glyph at that CID has the face's own advance and outline for the character, which covers the CIDToGIDMap /Identity mapping and the order of remapped_gids(). It also checks that the /W entry is that advance × 1000. It passes, so the order was right; the test now holds it.
Bugs. No confirmed bugs. One low-confidence crash-path concern:
The subsetter panic guard does not work in the browser build. catch_unwind cannot catch a panic on wasm32-unknown-unknown, which uses abort, so the "a panic caught in it" claim holds only natively. Confidence about 45%. Inline at crates/render/src/pdf/embed.rs:120.
Security. Nothing found. Font files are treated as hostile: ttf-parser and subsetter are used, the fsType licence checks run, the 8 MB and 32 MB limits apply, there is no unsafe, and the input is parsed with get/Option rather than indexing. The hostile-file test covers the native path only.
Performance. Nothing separate from the cancellation point below. Subsetting per face reads the full input font, which is not capped.
Quality.
Test gap: no test checks the /W widths or the CID-to-GID mapping, which depends on remapped_gids() ordering. A wrong order would misplace glyphs silently. Confidence about 40% that it is a bug. Inline at crates/render/src/pdf/fonts.rs:189.
Nit: Refused::TooLarge(usize) picks its message by comparing the number to MAX_SUBSET. Two variants would be clearer (crates/render/src/pdf/embed.rs:57).
Nit: pdf_text in crates/engine/src/cmd/layout.rs:4475 has an awkward nested match. None | Some(Value::Null) => Fonts would be clearer.
Nit: pdf_text validates pdf.text even for PNG and SVG exports. That is harmless, but worth a sentence in the doc.
AGENTS.md.
Cancellation (Never hold the window): write_with has no Cancel check between faces, and its doc comment says nothing about it. Confidence about 55%. Inline at crates/render/src/pdf.rs:266.
Docs overstate verification: docs/user-guide/layouts.md:374 names Inkscape, Illustrator and Affinity as editors that open the PDF as text, but only VectorCraft was tested. Confidence about 70%. Inline with a suggestion.
What I checked and found sound:
Fonts are written after every page is drawn (pdf.rs:323).
Font resources are listed per page as /T{id}.
Drawing::glyphs drops empty runs, so an empty face cannot reach gather.
write() with Text::Outlines still produces the same output.
Both layout_bytes_with callers are updated (engine and ui-egui).
clippy.toml allows unwrap in tests.
The notices use format!, which matches the rest of the file.
Prior reviews. No review threads exist on this PR, so there were no earlier concerns to leave alone.
Change size
Compared: the whole PR against main (merge base c603c32 to PR head 8b25bf8).
- Test that each CID is its character's glyph: the subset's glyph has
the face's own advance and outline, and /W has its width.
- Look at Cancel between faces in pdf::write_with; once cancelled, the
faces left are set in outlines (a cancelled export writes nothing).
- embed(): the panic guard holds natively; in the browser only the
bundled face reaches the subsetter. Said in its doc comment.
- Docs name only the editor checked (VectorCraft).
- Refused::SubsetTooLarge and DocumentTooLarge in place of
TooLarge(usize); pdf_text matches the value directly and says it is
checked for PNG and SVG exports too.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
The CFF branch has no test. Confidence: high that the gap exists; medium-low (about 35%) that it hides a bug.
Every test in this PR uses the bundled Ubuntu Light, which is TrueType. The CIDFontType0 / FontFile3 /OpenType path, the PDF 1.6 gate in pdf.rs, and the CIDToGIDMap-less CID font are never exercised, though the PR text presents them as working.
The risk is in the CID mapping. This branch writes CIDs equal to the subset's new glyph IDs (Identity-H). That only selects the right glyph if the subset's CFF charset maps new GID to CID one-to-one. For a CID-keyed CFF (common in CJK OpenType files), a reader resolves the CID through the charset, so a mismatch would draw the wrong glyphs without any error. I have not verified how subsetter 0.2.6 rewrites the charset for CID-keyed input.
Suggest a test that embeds a CFF face (a small generated or committed OpenType CFF font, with its licence noted in ATTRIBUTION.md), reads each CID back through the ToUnicode map, and compares the outline with the face's own glyph. That would settle both the untested path and the CID question.
Two free CFF faces installed here were checked against outlines: Source Sans Pro Bold (name-keyed) and Harano Aji Gothic Medium (CID-keyed, Latin and Japanese). Rendered by MuPDF at 300 dpi, Text::Fonts and Text::Outlines match (no pixel differs by more than 64 levels, same ink), and the text reads back, including 地図 日本語. For both kinds, each CID's glyph in the subset has the face's own advance and outline. Subsetter writes every font CID-keyed with CID = new GID, so the mapping is the TrueType one.
a_cff_face_is_a_cid_font_type0 now covers the branch with a CFF face of the test's own: crates/render/testdata/test-cff.otf, 712 bytes, made with fontTools by the script in testdata/README.md. The free CFF faces at hand reserve their names under the OFL, so a subset of them can't be committed as is. The test checks the CIDFontType0, the FontFile3 /OpenType, no CIDToGIDMap, PDF 1.6, and each CID's glyph and /W width. The TrueType test checks the same through a shared helper.
The reason will be displayed to describe this comment to others. Learn more.
This synchronous path now subsets every face on the UI thread. Confidence: medium (about 45%).
layout_bytes runs on the UI thread, and its callers at lines 3667 and 3671 (browser download and Print) call it directly. The path already rendered every page synchronously, so the freeze predates this PR. The PR adds per-face subsetting here, up to 32 MB of font data per document, with no progress and no way to cancel it.
AGENTS.md asks that work whose cost grows with its input run off the UI thread, and this change makes that cost larger on this path. Either move Print and download onto a background run, or say in the doc comment why this path stays on the UI thread.
The reason will be displayed to describe this comment to others. Learn more.
Agreed, the freeze predates this PR: the browser's download and Print already draw every page on the interface thread, and subsetting adds to it. Moving that path off the interface thread is a follow-up of its own, with the export's progress and Cancel, rather than part of this PR.
I found no crash paths, injection issues or silent data loss in the changed code. Two concerns are worth a look: the CFF branch has no test, and a desktop path now does more work on the UI thread. I checked the font-name sanitising, the hex-encoded ToUnicode and CMap output, the notices, the cancel handling and the wasm reach of the font readers.
Bugs
crates/render/src/pdf/fonts.rs:204 (confidence about 35%): the CFF branch (CIDFontType0, FontFile3 /OpenType, PDF 1.6) is never exercised by a test. Every test uses the bundled TrueType face. For CID-keyed CFF, writing CIDs equal to the subset's new glyph IDs could select the wrong glyphs, but I could not verify how subsetter rewrites the charset.
Security
No findings. Font names are sanitised before they reach the PDF, and the browser's font readers are disk-only, so no user file reaches the subsetter there. The native panic containment is in place.
Performance
crates/ui-egui/src/lib.rs:1687 (confidence about 45%): the browser-download and Print path calls layout_bytes synchronously on the UI thread. The PR adds up to 32 MB of per-face subsetting there with no Cancel. The freeze predates this PR, but the PR makes it heavier.
Quality
Nit, grouped: docs/user-guide/layouts.md lines 2183–2187 run past 100 columns. Per AGENTS.md, this can wait for the release quality pass.
Nit, grouped: the "fonts" / "outlines" error assertions in the engine test accept either of two messages, so they would pass on a wording change that broke the message.
AGENTS.md
The "Never hold the window" concern above is the only rule point. The new dependencies carry MIT/Apache licences, the notices were regenerated, and the layout.export cancel check is in place.
Prior threads: There are 4 earlier threads, all answered by the author and each checked against the head code. I left them alone, so 0 concerns were re-raised.
Change size (whole PR against main; compared: the whole PR against main, merge base c603c32 to PR head 12d65d4)
…pengeos#1815)
A CFF face of the test's own (testdata/test-cff.otf, 712 bytes, made
with fontTools by the script in testdata/README.md) is embedded as a
CIDFontType0 over an OpenType FontFile3 in PDF 1.6, each CID drawing its
character's glyph with its width in /W. The TrueType test checks the
same through the shared helper.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
AGENTS.md (Assets): test-cff.otf has no row in ATTRIBUTION.md. Confidence: about 75%.
AGENTS.md says every asset file has a row in ATTRIBUTION.md. This PR adds crates/render/testdata/test-cff.otf, a binary font, and ATTRIBUTION.md is not in the diff. The file is made by the author with fontTools, so no third-party licence applies. It still needs a row, as the existing QGIS test corpus does, saying who made it and under what licence (RustGIS's own, per this README). Please add that row.
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 9cd5902: ATTRIBUTION.md has a row for crates/render/testdata/test-cff.otf, made by the RustGIS project with fontTools by the script in testdata/README.md, under Apache-2.0.
Bugs: None found. I traced the glyph gathering, the embed decision, the Type 0 / CID font writer, the ToUnicode map, /W widths, the content codes, the PDF version gate, the cancel path and the export validation. The earlier reviews' concerns (cancel between faces, the browser panic claim, the /W test, the CFF test, the overstated doc sentence) are all answered and fixed in the code. Confidence in "no new bug": about 80%. I could not compile or run the tests here.
Security: None found. Embedding is gated on fsType. The font name written into the PDF is sanitised to alphanumerics, - and _. Hex-only ToUnicode output. Subsetter errors and panics on native fall back to outlines.
Performance: None new beyond the UI-thread subsetting already raised on ui-egui/src/lib.rs (the author agreed to a follow-up). Streams are compressed by Doc::stream, so the uncompressed-font concern does not apply.
Quality (grouped nits, not posted inline):
crates/render/src/pdf/embed.rs:342: the comment in only_the_face_as_drawn_is_embedded says "read from this one's bytes", but the test compares the bundled face with a different file's face (Hack). The comment should say that.
docs/user-guide/layouts.md around line 2258 has lines over 100 columns.
The embed doc comment (lines 1648–1653) has some awkward grammar.
AGENTS.md:
crates/render/testdata/test-cff.otf is an asset with no row in ATTRIBUTION.md. Posted inline on crates/render/testdata/README.md. Confidence about 75%.
I left 5 earlier concerns alone because they are already raised and answered: cancel between faces, the browser panic claim, the missing /W test, the missing CFF test, and the overstated VectorCraft sentence. I also left the UI-thread subsetting concern alone, since it is already raised and the author agreed to a follow-up.
Change size
Compared with the base branch (merge base c603c32 to PR head 58c6894). Whole PR, not the latest push.
…#1815)
A misspelled key ({"txt": "outlines"}) left the text in fonts with
nothing said. It is now refused, naming the keys "pdf" takes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
Comment is wrong, and the refusal branches are untested. Confidence: high that the gap exists; the comment is a clarity point.
The "hack" check does not run embed. It only asserts that draws_alike is false for another file's glyph, so Refused::Instance and Refused::NotInFile are never exercised, and neither is the PR text's claim that a variable face drawn at another instance falls back to outlines. The bundled faces are all static, so an instance test would need a variable font asset. Refused::NotInFile is also close to unreachable: font.font_data() is the file the glyphs came from, so a fresh parse of the same bytes should always draw alike. That leaves the reason wording only reachable for a collection with more than 64 faces.
The comment should say what the assertion does, for example // Another file's glyphs draw otherwise, so a face is never matched to one.
Per AGENTS.md, an extra test for code that already works can wait for the release quality pass, so I'm not requesting it in this PR.
The reason will be displayed to describe this comment to others. Learn more.
Fixed the comment in 01e8018: "Another file's glyphs draw otherwise, so a face is never matched to one." The test's doc now says why the refusal branches have no test. Refused::Instance needs a variable font drawn at another weight, and no bundled face is one, so its test waits for a variable-font asset. Refused::NotInFile is all but unreachable, since font_data is the very file the face was read from.
The reason will be displayed to describe this comment to others. Learn more.
face_name may name the wrong member of a collection. Confidence: about 35%.
same_face compares only glyph count and units per em, and face_name takes the first collection face that passes. A .ttc whose faces share those numbers (regional variants of one family are the likely case) would be named after the wrong face in the "set in outlines" notice. Nothing is lost, since the notice still says which face was refused, but the name can mislead.
The fix would be to pass the glyphs used into face_name and compare with draws_alike, as embed does. I have not verified whether any real collection hits this, so I'm treating it as a possibility.
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 01e8018: face_name now takes the glyphs used and names the face of the collection that draws them as the export does. It shares drawn_as with embed, so the notice names the same face that embed matched. Where no face draws them alike (another instance of a variable font), it falls back to the first face with as many glyphs and units per em, as before.
None confirmed. I traced the glyph-to-CID path (remapped_gids() indexing, /W widths, ToUnicode, TJ positioning), the cancel path, and the licence checks, and found no defect.
Security
None found. The subsetter call is wrapped in catch_unwind, and the browser path reads no user font bytes. I checked the web font download: it lands in egui's extra_fonts, not in the render crate's faces.
Performance
Nothing new. Subsetting runs synchronously on the UI thread for the browser download and the desktop Print path (ui-egui/src/lib.rs ~1687 and ~3671). This was raised earlier and the author replied that it is a follow-up, so I left it alone.
Quality
embed.rs:342: the comment in only_the_face_as_drawn_is_embedded misdescribes the check, and the Refused::Instance / NotInFile branches have no test. Confidence high. Deferred to the quality pass per AGENTS.md.
embed.rs:84: same_face may make face_name name the wrong member of a .ttc. Confidence about 35%; the notice still names a refused face, so nothing is lost.
AGENTS.md
No new violations found. The Cancel, progress, never-silent, ATTRIBUTION, wasm and no-unwrap rules are met in the changed code.
Already raised (left alone): 7 earlier threads. Four are fixed in the code and verified: Cancel between faces, the /W widths test, the CFF test, and the ATTRIBUTION row. The layouts.md wording is fixed. The wasm catch_unwind concern is answered and I agree with the answer. The UI-thread subsetting concern still stands and is not repeated.
Not verified: I did not build or run the tests (no shell was used for this review). I did not check subsetter's CID-keyed CFF output beyond the author's manual MuPDF check.
Change size
Compared with main (merge base c603c32 to PR head 9cd5902). Not truncated.
…ce (opengeos#1815)
face_name takes the glyphs used and names the collection face that draws
them as the export does (as embed picks it, through the shared
drawn_as), falling back to the first with as many glyphs and units per
em. The test comment says what its check does, and the test doc why
Refused::Instance and NotInFile have no test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
Variable fonts drawn at their default instance have no test, and the subset's variation tables are unchecked. Confidence: about 30%.
The PR text says "a variable face drawn at its default ... is embedded", but no test in this PR embeds a variable font. Every bundled face is static, and the new CFF face is static too. This line passes the file to subsetter::subset unchanged, so the result depends on whether subsetter 0.2.6 without the variable-fonts feature drops fvar/gvar/avar/HVAR/STAT or keeps some of them. If it keeps fvar or gvar while renumbering glyphs, the embedded file could be invalid or draw differently in a reader, and nothing here would notice.
I could not check subsetter's table handling offline. Suggest a test that embeds a variable face at its default (a small committed or generated one, licence noted in ATTRIBUTION.md) and checks that the subset has no variation tables and that its glyphs match the default outlines, as the CFF test does.
The reason will be displayed to describe this comment to others. Learn more.
No code change for now. From subsetter 0.2.6's source (_subset in its lib.rs), the subset is written only from the tables it processes: glyf/loca (with cvt, fpgm and prep), CFF, head, hhea/hmtx, maxp, name and post. fvar, gvar, avar, HVAR and STAT are never processed, so they aren't in the subset. Its glyf holds the default outlines, which embed has already matched to the drawn glyphs one by one. Without the feature, a CFF2 face is refused (Unimplemented) and set in outlines. I haven't run a variable face through it, though. That test needs a variable-font asset and comes later, and the PR text will say that this case wasn't checked.
I read the full diff, the base-branch AGENTS.md, and the surrounding render and engine code (pdf.rs, content.rs, layout.rs). I checked that every layout_bytes_with and pdf::write caller matches its signature, that the TJ positioning uses the same widths as /W, that Doc::stream compresses font subsets, and that the release profile does not set panic = "abort", so catch_unwind works natively. I found no crash path, no silent data loss, and no broken AGENTS.md rule in the new code. Nine earlier review threads are already on this PR; I left those alone, since the author answered each one and the code they point at is addressed or still reasoned about in the replies.
Bugs
None confirmed.
Security
Low confidence (about 15%, not verified): embed.rs relies on subsetter to bound composite-glyph recursion for hostile fonts. A stack overflow there would abort the process, and catch_unwind would not catch it. I could not check subsetter 0.2.6's source offline.
Performance
None raised. drawn_as and draws_alike work is bounded by the glyphs used in each face, and the subset budgets cap the output.
Quality
Inline comment posted (about 30%): no test embeds a variable font at its default instance, although the PR text claims that path works. Whether subsetter drops fvar/gvar is unverified.
Test a_hostile_font_file_never_panics (embed.rs near line 380) passes even if subsetter panics. embed converts that panic into Refused::Unreadable, so the test checks only the parser side. Its name overstates what it proves.
docs/user-guide/layouts.md line 2290 runs about 115 columns, against the file's roughly 100-column wrap.
The engine test a_layout_pdf_sets_its_text_in_its_fonts compares "fonts" output by length, not bytes. A byte comparison would be stricter.
The temp PDF in that test is removed only on success, so a failed assertion leaves it behind.
These quality points may wait for the release quality pass, per AGENTS.md.
AGENTS.md
Checked and compliant: no new unwrap/expect/indexing in non-test code; ATTRIBUTION.md has the new test font row; notices are one per export with a count; cancel is checked between faces; the new dependencies are MIT/Apache-2.0 and pure Rust.
Already raised and answered, left alone: the Print/download path in ui-egui still renders and subsets on the UI thread. The author replied that moving it is a follow-up.
Already raised earlier (left alone): 9 threads. Two were outdated and their fixes are in the diff; the rest are resolved by replies from the author.
Change size
Compared with main (merge base c603c32 to PR head 01e8018).
pdf::Options holds layers and text; write_with returns the bytes and
the faces set in outlines; layout.export reads both keys of "pdf"
(layers, text). Also: the scrambled-font test named for what it checks,
the "fonts" default compared byte for byte and its PDF removed however
the test ends, the guide's paragraph wrapped.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
The lossy path of this notice has no test. Confidence: about 60%.
AGENTS.md asks for both sides: lossy input gives the notice, clean input none. The only engine assertion here is the clean one (!said.iter().any(|t| t.contains("as outlines")) in a_layout_pdf_sets_its_text_in_its_fonts). Nothing checks the notice's wording, the singular/plural branch, the 10-face cap, or the and N more tail, and no engine test reaches a refused face, since the bundled faces all embed.
Suggest making this helper pub(crate) and testing it directly with 1, 2 and 11 Outlined entries, asserting one notice with the right count and tail, and nothing for an empty list.
The reason will be displayed to describe this comment to others. Learn more.
Added in deee8d6. outlined_notice is pub(crate), and the new engine test a_pdf_says_which_faces_it_sets_in_outlines calls it with 0, 1, 2 and 11 faces. No faces gives no notice, one gives the singular, two give one plural notice, and eleven list the first ten and end with "and 1 more".
I read the full code diff and checked it against the surrounding code. I found no confirmed bugs. One gap against the repo's test rule is posted inline. Two lower-confidence notes are below.
Bugs
None confirmed. I checked:
The embedded font path and the CID//W mapping, including remapped_gids order and the place/gather glyph sets, which agree.
Variable fonts: the bold serif and bold label faces use set_variation, so drawn_as finds no default-instance match and they fall back to outlines, as the docs say.
write_with callers and Options literals: none is broken by the signature change.
Font stream compression: Doc::stream(…, false) compresses the subset.
Security
Low confidence, about 15%, not verified: subsetter runs on user-installed font files with no input cap, and this PR only caps the output. catch_unwind cannot stop a stack overflow or an abort, and on wasm32 it cannot catch a panic at all. The PR's answer is that the web reads no user files, which I did not check. Whether the crate bounds composite-glyph recursion is also unverified.
Quality
About 60%: the lossy path of the new notice has no test. This is posted inline at crates/engine/src/cmd/layout.rs:4770.
About 30%: outlined_notice runs at layout.rs:4764, before the export's Cancel check at layout.rs:4953. A cancelled export can therefore still say that faces were set in outlines, about a file that is never written.
AGENTS.md
The engine check for Cancel after the bytes are built is present (layout.rs:4953), so a cancelled export writes nothing.
THIRD-PARTY-LICENSES.txt is refreshed in both notice files, which are the only two in the repo.
ATTRIBUTION.md has a row for test-cff.otf.
No unsafe, and no unwrap/expect in non-test code.
Already raised
The 10 earlier threads were not reposted. All were fixed or answered in the PR. I left alone the UI-thread Print path (ui-egui lib.rs 1751 and 3792), which the author deferred. This PR does not change that code.
Change size
Compared with main (merge base 4b2e903 to PR head e9728a9), across the whole PR.
The reason will be displayed to describe this comment to others. Learn more.
Low confidence (about 25%): a name-keyed CFF in a CIDFontType0 relies on the viewer treating the CID as a GID.
The CFF branch writes CIDFontType0 over FontFile3 /OpenType with Identity-H and no CIDToGIDMap, so each CID is looked up as a glyph index in the subset. That is only well defined if the subset's CFF is CID-keyed (its charset maps GID to CID). a_cff_face_is_a_cid_font_type0 builds test-cff.otf with fontTools' FontBuilder, which produces a name-keyed CFF, and the test checks the CID-to-glyph mapping with ttf-parser, not with a PDF reader. The PR's rendering checks are MuPDF and VectorCraft, and the CID-keyed Harano Aji case is the only CID-keyed check.
I have not verified how subsetter 0.2.6 rewrites the charset for name-keyed input, or how Acrobat and pdf.js handle a non-CID-keyed CFF under CIDFontType0. Suggest one of: confirm in a second reader that a name-keyed .otf draws correctly, or note in the doc comment that the CID-as-GID mapping was checked only in MuPDF and VectorCraft.
The reason will be displayed to describe this comment to others. Learn more.
Checked: subsetter 0.2.6 writes every CFF subset CID-keyed, so the CIDFontType0 has the CID-keyed CFF the spec asks for. I read the embedded FontFile3 /OpenType back with fontTools from PDFs of two faces. One is Source Sans Pro Bold, name-keyed in its own file; the other is Harano Aji Gothic Medium, CID-keyed. In both subsets the CFF Top DICT has ROS (Adobe, Identity, 0) and an FDArray, and the charset is .notdef, cid00001, cid00002, … in order, so CID n is GID n. That's the identity Identity-H and no CIDToGIDMap rely on, and subsetter's docs say so ("The subsetter will convert SID-keyed fonts to CID-keyed ones and an identity mapping from GID to CID for all fonts"). MuPDF draws both the same as their outlines, and the test font's subset is checked CID by CID in a_cff_face_is_a_cid_font_type0.
None confirmed. I traced the glyph path end to end: gathering, the subset remapper, CID to GID, /W widths, ToUnicode, the resource dictionary, and the cancel path. The Type 0 and CFF branches look right. The Type 3 path is unchanged apart from the two-byte code change.
Low confidence (about 25%): the CFF branch writes a CIDFontType0 over a name-keyed CFF with Identity-H and no CIDToGIDMap. That relies on the viewer treating each CID as a GID. The test checks this with ttf-parser, and only MuPDF and VectorCraft were used for rendering checks. Inline comment posted at crates/render/src/pdf/fonts.rs:204.
Security
None found. Licence flags (fsType restricted, no subsetting, bitmap-only) are checked before subsetting. The subsetter call is inside catch_unwind, and the size and budget limits are enforced.
Performance
Nit: drawn_as runs again inside face_name for each refused face. The cost is small. The subsetter itself is not interruptible, but the cancel check runs between faces, as the PR states.
Quality
Nit (release quality pass): layout_bytes_with's doc comment line is now over 100 columns.
Nit: Refused::NotInFile is practically unreachable, as the PR's own comment says.
Nit: face_name truncates names at 80 characters without saying so. This only affects the notice text.
AGENTS.md
No new violations found. Checked: no unwrap, expect or panic in non-test code; the new notice is said through Session::warn with one notice and a count; the ATTRIBUTION row and THIRD-PARTY-LICENSES are updated; the engine uses plain format! for notices, which matches the rest of the crate.
Already raised and answered, left alone: the UI-thread cost of layout_bytes for Print and download. The author deferred it to a follow-up, and the doc comment still doesn't say why the path stays on the UI thread.
I left 11 existing review threads alone. Of those, 9 are answered or fixed in the PR, and 2 are the UI-thread and Cancel items described above.
Change size
Compared with main (merge base 4b2e903 to PR head deee8d6).
The reason will be displayed to describe this comment to others. Learn more.
The list of faces set in outlines is incomplete. Confidence: about 70%.
This sentence lists when a face falls back to outlines: a licence that forbids embedding or subsetting, a variable font drawn at another weight, or a file that can't be read. The code has two more refusals that the guide doesn't name: a subset over 8 MB (Refused::SubsetTooLarge), and a document whose embedded faces would pass 32 MB in total (Refused::DocumentTooLarge). A licence that allows bitmaps only (fsType 0x200) also falls back, and the sentence doesn't mention it.
The export still says which faces fell back and why, so nothing is silent. But a reader who hits the size limit won't find it in the guide. Suggest adding those cases to the sentence, with the limits (8 MB per face, 32 MB per document).
The reason will be displayed to describe this comment to others. Learn more.
Fixed in fd71354. The sentence now lists every reason embed refuses a face, from Refused: the licence forbids embedding or subsetting, or allows bitmaps only; the face is drawn at another weight or width than its variable file's default; the file doesn't hold it as drawn; the file can't be subset (damaged, or a CFF2 variable font, which subsetter refuses without its variable-fonts feature); the subset would pass 8 MB; or the document's embedded faces would pass 32 MB.
No high-confidence bugs found. I checked the cancel path (progress::check is thread-local, and the export runs on the thread that calls write_with), the CID-to-GID mapping and /W widths, the fsType checks, the variable-font handling (set_variation faces fall back to outlines), and the empty-run filter in Drawing::glyphs.
Low (about 20%): Fonts::place (crates/render/src/pdf/fonts.rs:80-90) falls through to a Type 3 font for a real face when the glyph is missing from the remapper. That would duplicate the face with no notice. gather covers every glyph on every vector page, so I could not reach this path, and I did not post it inline.
Security
None found. Font parsing is wrapped in catch_unwind on native builds. The browser claim holds because the web build only reads bundled faces, as the earlier thread explains.
Performance
Low (about 30%): faces are subset one after another, although each subset is independent. AGENTS.md asks for threads "where practical". Output must stay bit-identical, and Cancel is checked between faces, so a parallel version would need care. This is a possible follow-up, not a defect.
Quality
Nit: the doc comment on layout_bytes_with (crates/engine/src/cmd/layout.rs, about line 4626) runs past 100 columns.
Covered by the inline comment below: the user guide's list of faces that fall back to outlines is incomplete.
AGENTS.md
Asset attribution, the new dependencies' licences, the THIRD-PARTY-LICENSES refresh, and the notice and test coverage on both sides (lossy and clean input) all follow the rules.
Already raised earlier (left alone): 11 concerns from earlier threads on this PR. I did not repeat them: Cancel between faces, the web panic claim, the /W test, the CFF test, the README attribution, the collection naming, variable-font coverage, the CID-as-GID mapping, the Inkscape wording, the UI-thread subsetting, the Refused test comment, and the notice test. The author's replies answered them.
Inline comment posted:docs/user-guide/layouts.md:405. The fallback list omits the 8 MB per-face and 32 MB per-document limits and the bitmap-only case (about 70% confidence).
Change size
Compared with main (merge base 4b2e903 to PR head deee8d6).
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Assert notice content without fixing the complete sentence.
A harmless wording change will fail this assertion even when the notice reports the correct face and reason. Check the notice count, face name, reason, and singular/plural terms separately. Remove the fixed prose prefixes and suffixes from the related assertions.
Based on learnings: “avoid asserting on exact user-facing copy” and prefer “key substrings.”
Source: Learnings
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: ASSERTIVE
Plan: Advanced
Run ID: 3486e08d-6acd-43c4-9a86-fe32b183f566
Commits
Reviewing files that changed from the base of the PR and between 4b2e903 and deee8d6.
Files ignored due to path filters: 2
Cargo.lock is excluded by !**/*.lock
crates/render/testdata/test-cff.otf is excluded by !**/*.otf
Files selected for processing: 13
ATTRIBUTION.md
Cargo.toml
THIRD-PARTY-LICENSES.txt
apps/rustgis-python/THIRD-PARTY-LICENSES.txt
crates/engine/src/cmd/layout.rs
crates/engine/src/tests.rs
crates/render/Cargo.toml
crates/render/src/pdf.rs
crates/render/src/pdf/content.rs
crates/render/src/pdf/embed.rs
crates/render/src/pdf/fonts.rs
crates/render/testdata/README.md
docs/user-guide/layouts.md
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Possible silent fallback to outlines for an embedded face. Confidence: about 25%.
If remapper.get(id.0) returns None for a glyph of an embedded face, place falls through to the Type 3 path for that glyph, and nothing is said. gather should cover every Item::Glyphs on the vector pages, so I could not find a way to reach this today. It is still a silent change of text form on a path the notice is meant to cover. Suggest either returning an error from place that write_with turns into an Outlined entry, or counting these fallbacks and saying so in the notice. Lowest priority if gather is confirmed complete.
The reason will be displayed to describe this comment to others. Learn more.
Not reachable today: gather walks every Item::Glyphs on the vector pages, groups included, before any page is written, and place only sees those runs, so every glyph of an embedded face has a CID. The Type 3 fall-through is a guard, not a path. Leaving it as is.
The reason will be displayed to describe this comment to others. Learn more.
gather registers a face before checking that it has glyphs. Confidence: about 40%, low impact.
used.push((run.font, Vec::new())) runs on the first GlyphRun for a face, even if that run has no glyphs. write_with would then subset the face with only .notdef, count it against the 32 MB budget, write an empty Type 0 font with an empty /W and ToUnicode, and move the document to PDF 1.6 for a CFF face. The text layout builds runs from non-empty chunks (text.rs), so I could not find a caller that produces an empty run. Suggested fix, so the face is only registered once it has a glyph:
The reason will be displayed to describe this comment to others. Learn more.
No empty run gets there: Drawing::glyphs refuses a run with no glyphs (vector.rs, !run.glyphs.is_empty()), and it is the only place an Item::Glyphs is made. So a face is registered only by a run that has glyphs. Leaving it as is.
I found no bugs that would produce wrong output or a crash on the paths I traced. The findings below are low-confidence and low-impact, and I posted two of them inline.
Bugs
Possible silent fallback to outlines for an embedded face (crates/render/src/pdf/fonts.rs:85). If a glyph of an embedded face is missing from the remapper, place falls back to Type 3 without a notice. gather appears to cover every glyph, so I could not reach this path. Confidence: about 25%. Posted inline.
Empty runs register a face (crates/render/src/pdf.rs:437). gather adds a face on its first run even when the run has no glyphs. That would embed a .notdef-only subset and possibly set PDF 1.6. The text layout builds runs only from non-empty chunks, so I found no caller that triggers it. Confidence: about 40%, low impact. Posted inline with a suggested fix.
Security
None found. The new parsing runs on font files, and catch_unwind guards the subsetter. Confidence: about 60% that nothing is missing.
Panic containment covers only the subsetter. drawn_as, draws_alike and face_name run ab_glyph and ttf-parser on the same file without a guard. I expect ttf-parser not to panic on malformed input, so the risk is low. Confidence: about 20%. Not posted.
Performance
None significant. Font streams are compressed by Doc::stream, which deflates data over 64 bytes. The per-face work is bounded by the glyphs used.
Quality
A few doc lines in crates/engine/src/cmd/layout.rs exceed 100 columns. These are style points, so they can wait for the release quality pass.
AGENTS.md
The rules I checked are met. The notices use one notice per kind with a count, the new tests cover both lossy and clean input, and no unwrap or expect appears in non-test code.
The UI-thread subsetting for browser download and Print was raised in an earlier thread. The author deferred it, and I left it alone.
The test-cff.otf attribution row is present in ATTRIBUTION.md.
I left 13 earlier review concerns alone because they were already raised: 11 were answered or fixed by the author, and 2 were outdated. The panic-scope and UI-thread points are the only ones still open.
Change size
Compared with main (merge base 4b2e903 to PR head fd71354). Trees are not truncated.
…1875)
* feat(render): embed real fonts in a layout's vector PDF (#1815, part 1)
A layout's PDF now sets its text in the faces it is drawn in, each
embedded as a subset of its glyphs (Type 0 over CIDFontType2 or
CIDFontType0, Identity-H, ToUnicode), so vector editors open it as
editable text. A face whose licence forbids embedding or subsetting,
one drawn at another instance than its variable file's default, or one
whose file can't be subset is set in Type 3 outlines as before, and the
export names it with why. `"pdf": {"text": "outlines"}` on
layout.export keeps today's output.
New dependencies: subsetter 0.2 (MIT OR Apache-2.0, without its
variable-fonts feature) and ttf-parser 0.25 as a direct dependency
(already in the tree through ab_glyph).
Part of #1815.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(render): review round 1 for embedded PDF fonts (#1815)
- Test that each CID is its character's glyph: the subset's glyph has
the face's own advance and outline, and /W has its width.
- Look at Cancel between faces in pdf::write_with; once cancelled, the
faces left are set in outlines (a cancelled export writes nothing).
- embed(): the panic guard holds natively; in the browser only the
bundled face reaches the subsetter. Said in its doc comment.
- Docs name only the editor checked (VectorCraft).
- Refused::SubsetTooLarge and DocumentTooLarge in place of
TooLarge(usize); pdf_text matches the value directly and says it is
checked for PNG and SVG exports too.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test(render): CFF faces embed as CIDFontType0 with the right glyphs (#1815)
A CFF face of the test's own (testdata/test-cff.otf, 712 bytes, made
with fontTools by the script in testdata/README.md) is embedded as a
CIDFontType0 over an OpenType FontFile3 in PDF 1.6, each CID drawing its
character's glyph with its width in /W. The TrueType test checks the
same through the shared helper.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(engine): refuse an unknown key in layout.export's "pdf" (#1815)
A misspelled key ({"txt": "outlines"}) left the text in fonts with
nothing said. It is now refused, naming the keys "pdf" takes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* docs: attribute the CFF test font (#1815)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(render): name the collection face that draws the text in the notice (#1815)
face_name takes the glyphs used and names the collection face that draws
them as the export does (as embed picks it, through the shared
drawn_as), falling back to the first with as many glyphs and units per
em. The test comment says what its check does, and the test doc why
Refused::Instance and NotInFile have no test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* test(engine): the outlined-faces notice, none, one, two and eleven (#1815)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* feat(render): a label's halo is text in vector PDFs (#1815, halos)
A halo is a copy of its text under it, filled and stroked as wide as the
halo: in an embedded face, the same font in text rendering mode 2,
marked as an artifact; in outlines (or a face set in Type 3), its glyph
outlines filled and stroked, as before. GlyphRun gets halo, Canvas a
halo mode that text.rs sets the label's own text in; the SVG strokes
halo runs.
Part of #1815. Depends on #1828.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(render): a halo of no width draws nothing (#1815, halos)
Canvas::halo with a width that is not a positive number drew its text as
plain text in the halo colour in a PDF or SVG, where the pixels draw
nothing. It now draws nothing.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(render): a subset tag follows its face file (#1815, halos)
The six-letter tag also hashes the face file's size and bytes, so two
files with the same PostScript name and glyphs get two tags.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(render): an SVG halo copy is hidden from screen readers (#1815, halos)
The halo's copy of a label is aria-hidden instead of repeating the
text's aria-label, so a screen reader reads the label once (the PDF
marks it an artifact). The subset-tag test moves above the CFF test's
doc comment.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(render): the subset tag hashes every byte (#1815, halos)
The tag folded the file in eight-byte words, and a multiplication only
carries bits upwards, so the high bytes of each word never reached the
low bits the letters are read from: two subsets of one face could get
the same tag. It is now FNV-1a a byte at a time, and the test changes
each byte of a word in turn.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: elpidioassinaturas <elpidiofilho@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…date (#1950)
The nightly Fuzz run has failed every night since the toolchain action's
pin moved to its stable branch (#1530): the fuzz jobs got stable Rust, and
cargo-fuzz's -Zsanitizer flag needs nightly. The job now asks for nightly
by name, so the pin can stay where Dependabot keeps it.
fuzz/Cargo.lock lacked subsetter and rustc-hash, which rustgis-render has
needed since #1828, so the licence job's --locked check refused it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #1815 (items 1, 2 and 5: real fonts). The layers (item 4) are on
mainsince #1834, and this branch hasmainmerged into it, so its PDFs have both real fonts and layers. Halos as text (item 3) come in a later PR.A layout's vector PDF now sets its text in the fonts it is drawn in, each face embedded as a subset of its glyphs (a Type 0 font over a CID font, Identity-H, with a ToUnicode map), so a vector editor opens it as text it can edit. A face that can't be embedded is set in Type 3 outlines as before, and the export names it with the reason.
"pdf": {"text": "outlines"}onlayout.exportkeeps today's output for print shops that ask for outlined type.The same A4 layout (Natural Earth countries, labels, legend, scale and footer) exported from this branch and opened in VectorCraft 0.24. Left,
"text": "outlines": no text objects, 762 objects, each letter a path (boxed in red). Right, the default: 54 editable text objects and 153 objects in all (each text object boxed in green).What changes
render::pdf::Optionsgainstext: Text(FontsorOutlines) next to feat(render): layers in vector PDFs (#1815, layers) #1834'slayers.write_with(pages, title, options)returns the bytes and the faces set in outlines. It gathers every glyph each face sets across the pages before writing anything, so a face is embedded or not as a whole and its glyphs' codes are the subset's.pdf/embed.rsdecides per face, from its file (FontRef::font_data):.ttc), the first face that draws them alike;fsType: Restricted (2), no subsetting (0x100) and bitmap only (0x200) fall back to outlines;subsetter. An error falls back to outlines, and so does a panic in it, caught on native builds. In the browser, where wasm32 aborts on a panic, no user file reaches it: fonts are read from disk, so the web has only the face bundled with the app;pdf/fonts.rswrites an embedded face as a Type 0 font over aCIDFontType2(TrueType outlines,FontFile2,CIDToGIDMap /Identity) or aCIDFontType0(CFF,FontFile3 /OpenType, which makes the document PDF 1.6). Each font has/Wwidths from the face's own advances, a descriptor with the face's metrics, and a two-byte ToUnicode map. The content sets those faces' glyphs as two-byte CIDs, and everything else is as before.layout.exporttakes"pdf": {"text": "fonts" | "outlines"}(defaultfonts; any other value is refused). Publish › Export and Print in the app usefonts.layout.export'spdfoption ("pdf": {"text": "outlines"}).The PDF sets the text of 1 face as outlines, not as text a vector editor can edit: Ubuntu Light (its licence forbids embedding).docs/user-guide/layouts.mddescribes it.Choices in this proposal
Tm), so the embedded upright face, sheared, draws the same glyphs, and an editor reads it as skewed text. The issue listed synthetic italics as a Type 3 case, but that would give up editable text for nothing. There is no synthetic bold to fall back for: the renderer's bold is the bold file, or a variable font'swght, which the next point covers.variable-fontsfeature, which brings in skrifa, write-fonts and kurbo. A variable face drawn at its default, as the regular usually is, is embedded. That case hasn't been checked with a variable font: subsetter writes onlyglyf/loca,CFF,head,hhea/hmtx,maxp,nameandpost(pluscvt,fpgmandprep), so the variation tables are left out andglyfholds the default outlines thatembedmatched. A test waits for a variable-font asset.layout.export(and the app's layout export and print) changes in this PR. The map view's PDF (Print Map), reports and presentations still callpdf::write: its text stays in Type 3 (with feat(render): layers in vector PDFs (#1815, layers) #1834's layers), so nothing there changes without its own notice. Moving them over is one call each, for a later PR.New dependencies (two maintainers' approval, per docs/maintaining.md)
subsetter0.2.6,default-features = false#![deny(unsafe_code)]. Writing a subsetter (glyf closure over composites, loca, hmtx, CFF charstrings and subrs) is what #1342 left out as too large.rustc-hash2, already isttf-parser0.25 (direct)fsType, names and metrics for the descriptorThe questions in docs/maintaining.md:
cargo build --target wasm32-unknown-unknown -p subsetterbuilds; it is pure Rust with no system or C library.deny.toml's list.cargo xtask noticesrefreshedTHIRD-PARTY-LICENSES.txt.subsetter::subsetis 161 KB larger than one that doesn't (308 KB against 147 KB).pdf-writer, which the issue mentioned for the font dictionaries, isn't used: the dictionaries are about 60 lines on the PDF code RustGIS already has.Verification
page.get_fonts()):Type3×2 before;Type0×2 (SegoeUI,SegoeUI-Semibold) after, withpage.get_text()unchanged (817 characters);Type0×6 (Segoe UI regular, semibold and bold; Georgia, Georgia Bold and Georgia Italic), the same 2,193 characters. In VectorCraft it went from 0 text objects and 3,830 objects to 178 text objects and 2,373 objects.Text::FontsandText::Outlinesmatch: no pixel differs by more than 64 levels and the ink is the same. The text reads back too, including 地図 日本語. Subsetter makes CID equal the subset's GID for both kinds.Tests:
pdf::embed::tests::text_in_fonts_is_its_face_embedded: a layout text and a map label (in a group, the second slanted as a synthetic italic) come out as Type 0 overCIDFontType2withCIDToGIDMap /Identityand no Type 3. The subset is a valid font and a quarter of the file's size or less. The ToUnicode map reads backA ç ã o, and the content sets two-byte CIDs.Text::Outlinesgives exactlypdf::write's bytes.a_cff_face_is_a_cid_font_type0: a CFF face of the test's own (crates/render/testdata/test-cff.otf, 712 bytes, made with fontTools by the script intestdata/README.md, so no third-party font is redistributed) comes out as aCIDFontType0over aFontFile3 /OpenTypewith noCIDToGIDMap, in PDF 1.6. Each CID draws its character's glyph (same advance and outline in the subset), and/Wholds its width. The TrueType test checks the same through a shared helper.a_face_that_forbids_embedding_is_set_in_outlines: fsType patched to 2 gives Type 3 and oneOutlined { face: "Ubuntu Light", why: "its licence forbids embedding" }.only_the_face_as_drawn_is_embedded: a static face is embedded; another face's glyph doesn't count as drawing alike; past the room left,TooLargewith its message.embedding_a_scrambled_font_file_never_panics: 64 files, cut short and scrambled in glyf, the table directory and hmtx, that ab_glyph still parses: embedding and naming each never panics.a_layout_pdf_sets_its_text_in_its_fonts:layout.exportwith a text and labelled countries gives Type 0 fonts and no Type 3, says nothing, and has the title'sO ç ãin its maps."outlines"gives Type 3 only;"fonts"matches the default byte for byte;{"text": "curves"},"outlines"(not an object),{"text": 1}and the misspelled{"txt": …}are refused, the last naming the keys"pdf"takes (layers,text). The test's PDF is removed however the test ends.layouts_compose_export_and_round_tripnow expects Type 0 in the default export.cargo fmt,cargo clippy --workspace --all-targets -D warnings, and the render and engine tests pass locally (Windows), except two tests that fail on this PC onmaintoo:gdal_formats_openneeds GDAL 3.8 (3.7.1 here), andreload::wrong_geometrygets a Windows message in Portuguese.Size
About 480 lines of non-test code with doc comments (
pdf/embed.rs180,pdf/fonts.rs130,pdf.rs90,layout.export65) and 185 lines of tests. That is over the 300–400 line target. Gathering, deciding, writing and the option only work together: the content's codes depend on the decision made before any page is written, so this part can't be split further without leaving a PDF writer that can't use what it embeds.Not in this PR
mainsince feat(render): layers in vector PDFs (#1815, layers) #1834.)variable-fontsfeature.🤖 Generated with Claude Code
Summary by CodeRabbit