Files
pdfcraft/docs/editing-existing-text.md
T
6d843a8e8b Preserve source fonts in text editing and resize clipped artwork (#1116)
* M0: remove upstream trademark artwork from contributor fork

Use the existing document icon and a plain project label. Remove trademark
asset entries and regenerate attribution as required for modified forks.

Co-authored-by: OpenAI Codex <codex@openai.com>

* M7: group compatible PDF words and hide source text during editing

Join compatible words across text objects and subset-font spaces, recognize
component colours, and reuse subset fonts with numeric space positioning.
Render a read-only background with the selected glyphs removed while the
inline editor is open. Keep one frame and source line breaks, and reset
the layout width when switching paragraphs. Expose the same preview through page_render.

Add synthetic extraction, save/reopen, preview and UI regressions. Record
the remaining mixed-style paragraph and installed-font limitations.

Co-authored-by: OpenAI Codex <codex@openai.com>

* M7: preserve rich PDF regions and preview text edits in place

Group mixed source runs into complete visual regions, retain run styles and source encodings, and use validated embedded source faces in the inline editor. Preserve source baselines and show a single live frame as text grows or shrinks, backed by a read-only draft geometry tool.

Validation: strict workspace Clippy, workspace tests, all 30 WASM crates, asset and parity gates, licensed synthetic edit/save/reopen and desktop checks, and an opt-in four-page private-document regression.

Co-authored-by: OpenAI Codex <codex@openai.com>

* M7: keep cropped artwork from blocking text editing

Track page/path clipping separately from full image placement, use visible selection bounds, and prioritize text hit testing over overlapping artwork. Preserve fixed clips during image transformations and expose visible bounds through the headless tools.

Validation: strict workspace Clippy, workspace tests, 30 WASM crates, asset/parity gates, synthetic engine/tool/UI and native desktop checks, both private-document UI regressions, and all-page local edit/save/reopen/undo on a four-page cropped-artwork PDF.

Co-authored-by: OpenAI Codex <codex@openai.com>

* M7: resize cropped images with their clipping paths

Keep the visible frame and image pixels under the same transform. Preserve the
opposite corner and respond to diagonal, horizontal-only and vertical-only
corner drags without jumping from an off-centre grip. Refuse shared clipping
scopes that would move unrelated content.

Add synthetic engine/tool/UI regressions and opt-in private-file coverage
for 80 corner gestures and 10 grow/shrink save/reopen/undo render checks.

Co-authored-by: OpenAI Codex <codex@openai.com>

* M7: complete source font subsets and preserve clipped editing

Add explicit document fonts, CFF embedding, range formatting and bounded contextual shaping; isolate shared image clips and verify private Chinese edits on all pages.

Co-authored-by: OpenAI Codex <codex@openai.com>

* Revert "M0: remove upstream trademark artwork from contributor fork"

This reverts commit 3aa539b5b6.

* Test: give the text layer up to 4 s before copying (it flaked on a loaded machine)

---------

Co-authored-by: Kamoliddin Fatkhullaev <komoliddinfatxullayev@MacBook-Pro-Komoliddin.local>
Co-authored-by: OpenAI Codex <codex@openai.com>
Co-authored-by: Brandon Thomas <echelon@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 20:27:55 -04:00

3.7 KiB

Editing existing text and source subsets

Click a text region in Edit a PDF → Edit text and images. One editor contains its source rows and mixed styles. Embedded TrueType and OpenType/CFF faces are used in memory; source font programs, colour, size and baseline anchors stay intact. A textless preview prevents a second copy underneath. The frame shows the live extent as text grows or shrinks.

A subset font contains only some of the original face's glyphs. A new character cannot be reconstructed from a glyph the PDF does not contain. Load font… imports an openly licensed, embeddable standalone .ttf or .otf face. Installed fonts… discovers eligible user-installed faces on request, off the UI thread; the document-font menu selects resources already on the page. Select Keep source fonts to preserve each run's original face. A matching full face completes its subsets automatically, including new Chinese characters. Choosing another face is explicit. Fonts with restricted embedding, unsupported collections, excluded families or no open-licence declaration are refused. Interface fallback fonts are never exported.

The full selected program, glyph mappings, widths and Unicode text are embedded in the PDF. Saving and reopening therefore needs no locally installed font. Original subset bytes are preserved. Optional matching faces from CRAFT_FONTS_DIR can also complete source subsets; this works only when that build input actually contains the full face. This change does not add a font binary or change the release font pin. Fonts shared by releases belong in storytold/craft-fonts under the repository's asset rules.

Select text within the editor before changing size, colour, font, underline or spacing to format that selection. Automation supports up to 1024 disjoint UTF-8 byte ranges with the same properties; invalid or overlapping ranges fail atomically. Untouched source formatting survives. OpenType shaping uses the selected/source face's substitution and positioning rules, preserves marks and ligatures, and applies Unicode bidi ordering for a single face. Logical text remains available after save/reopen through ToUnicode and ActualText.

For headless editing, use text_font_files → text_font_import → text_fonts and pass a resource to text_edit.font_resource. text_edit.ranges holds selected range formatting. text_edit_layout accepts resource/ranges too and measures a draft without applying it. All file inputs respect CLI root confinement; importing a font and applying text are undoable.

Explicit marked paragraph/heading scopes prevent unrelated tagged regions from merging. Compatible geometry groups untagged content, including runs split across content streams or equivalent graphics transforms. Geometry cannot infer author intent in every untagged PDF. Semantic structure-tree preservation, legacy Type 1/Type 3 inline font preview, font collections/variable-font instances, mixed-font/style contextual runs and complete rotated layout fidelity still need broader coverage. Do not interpret the passing real-file checks as a guarantee for every PDF.

Private acceptance tests are opt-in and keep inputs unmodified. They exercise actual Chinese keyboard insertion/deletion on all four pages, source-face/baseline checks and identical in-memory renders before and after saving/reopening. Synthetic tests cover full TrueType mapping, OpenType/CFF, Arabic marks/ligatures/mixed bidi, repeated edits, disjoint styles, invalid ranges, font selection and root confinement. CLI acceptance repeats insertion/deletion and two saves/reopens on four pages; independent PDFium checks extraction and rendering. No private document, font or screenshot is included in the repository.