Skip to content

feat(text-edit): preview committed Type3 text edits in the original font (#723) - #780

Closed
oscar981-op wants to merge 2 commits into
OpenAEC-Foundation:mainfrom
oscar981-op:feat/type3-text-preview-723
Closed

oscar981-op wants to merge 2 commits into
OpenAEC-Foundation:mainfrom
oscar981-op:feat/type3-text-preview-723

Conversation

@oscar981-op

Copy link
Copy Markdown
Contributor

Part of #723. Committed text edits in a Type3 font are now shown on the canvas in the original font. While the text editor box is open it still shows Helvetica, so this PR does not close the issue.

Approach

  • Same code as the saver. applyForPage is split into a read-only analyseerPagina and maakInPlaceResultaat (encodeRun). The preview runs the analysis on the shared pdf-lib document without changing it.
  • Temporary PDF. js/text/type3-voorbeeld.js builds a one-page PDF with the original box. The fonts encodeRun picks are copied in with PDFObjectCopier (CharProcs and the font's Resources included), and the text is drawn with the saver's own tekenTextEdit. Glyph codes, positions, Tc/Tw/Tz, justification, decorations and the Standard-14 fallback are therefore identical to the saved file.
  • Rendering. PDF.js renders only the text area (transparent, at canvas density). The painter in rendering.js draws that bitmap in the page frame, so rotation is handled.
  • Lifecycle:
    • 150 ms debounce on an edit signature
    • stale builds and loads are discarded and their temp documents destroyed, and an in-flight render is cancelled
    • results are cached per run and zoom
    • temp documents are freed on save, undo, reload and close (document-release.js)
    • Helvetica stays as the fallback while the bitmap is pending, on failure, and in print/export
  • Saver fixes found along the way:
    • Type3 widths are now scaled by FontMatrix. Before, the advance was wrong when the matrix ≠ 0.001.
    • A Type3 code only counts as an available glyph if it has a CharProcs entry. Before, an invisible glyph could be saved.

Tests

js/text/type3-voorbeeld.test.mjs (11 tests):

  • temp PDF construction, with show operations identical to the saved file
  • FontMatrix widths
  • missing and mixed glyphs
  • cases that build no preview
  • pixel comparison of the preview bitmap and the saved page (PDF.js + @napi-rs/canvas)
  • scheduling, staleness and cancellation with injected fakes
  • wiring

Full suite: 0 failures. tsc and vite build are clean.

Not yet checked in the running app / limits

  • Not checked: alignment at different zooms, continuous and rotated pages, the cost of the first build on large pages, and the PDF.js worker setup.
  • TeX bitmap fonts without a Unicode mapping still fall back to Helvetica, as in the saver.
  • Not covered: a Type3 font without its own /Resources that relies on the page's resources.

🤖 Generated with Claude Code

…ndation#723)

A replacement in a Type3 font was drawn live in Helvetica because the
painter cannot use a Type3 font as a CSS font. The preview now renders the
edited text through PDF.js from a small temporary PDF built with pdf-lib:
one page with the same box, the page's fonts copied in (CharProcs and
Resources included), and the new text drawn by the saver's own code path,
so the glyph codes, positions and Standard-14 fallback for missing glyphs
are the same as in the saved file.

- text-edit-inplace: split the read-only analysis (analyseerPagina) and
  the encoder (maakInPlaceResultaat) out of applyForPage; Type3 widths are
  scaled by the FontMatrix and a Type3 glyph only counts as present when
  its name has a CharProcs entry.
- text-edits: export tekenTextEdit (draw one edit like the saver).
- type3-voorbeeld: debounced build per edit signature, stale builds and
  renders discarded or cancelled, cache per run and zoom, temp document
  freed when the edit goes away or the document closes; Helvetica preview
  stays while pending or on failure.
- rendering: draw the bitmap in the page frame when available.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The pixel test passed pdf.js a standardFontDataUrl built with path.sep.
On Windows that ends in a backslash, and pdf.js rejects a factory URL
without a trailing slash, so getDocument failed and the preview status
became 'mislukt'. Build the directory with forward slashes instead
(fs.readFile accepts them on Windows).

The preview now keeps the error behind a failed status
(type3VoorbeeldFout), and the test prints it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DutchSailor DutchSailor mentioned this pull request Oct 29, 2026
@DutchSailor

Copy link
Copy Markdown
Collaborator

Thank you, @oscar981-op! This change is included in release 2026.44.1 through the release PR #841, as one squashed commit with you as the author, so this PR is closed rather than merged. During review we added the following on top, with regression tests: pages without Type3 fonts skip the preview work entirely, so text edits on large pages stay fast.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants