Skip to content

Let Edit mode replace text that Folio can't read - #121

Open
stozo04 wants to merge 1 commit into
Forward-Future:mainfrom
stozo04:fix/edit-unreadable-text
Open

stozo04 wants to merge 1 commit into
Forward-Future:mainfrom
stozo04:fix/edit-unreadable-text

Conversation

@stozo04

@stozo04 stozo04 commented Nov 30, 2026 •

Copy link
Copy Markdown

Problem

In PDFs whose fonts have no usable Unicode map, Edit mode fills the box with invisible control codes that cover the original. Typing then fails with "Enter a single line of text.", and replacing the whole box fails with "This font can't display all of those characters." Steps and cause are in #120.

Change

For lines whose text contains control characters (tabs excluded):

  • The box starts empty below the original, which stays visible, and Folio says the font will change.
  • The replacement is drawn in the bundled DejaVu Sans, the way Arabic lines are redrawn. A blank or spaces-only box changes nothing. Version history shows the old text as "Unreadable text".
  • It is centered where the original was, including on later edits and after saving and reopening. A new FolioCenteredLine mark records this, so other redrawn lines keep their current placement.
  • If a font's nominal size is much smaller than its glyphs (possible with Type 3 fonts), the size comes from the glyph height, measured along the line so tilted text isn't inflated.

Two related changes:

  • PDFium reports a hyphen that splits a word across lines as a control code. These are now read as "-", so such lines aren't mistaken for unreadable ones. This affects readable hyphenated lines: the edit box now gets a normal hyphen.
  • The font loading error no longer mentions Arabic.

Issue or approval

Fixes #120. No maintainer has replied yet. The replacement font and centered placement are open questions there; I'm happy to change either.

Centering suits short values such as amounts, but it moves the left edge of left-aligned lines when their length changes.

How I checked it

macOS only. Windows and Linux are untested apart from whatever CI reports.

  • npx tsc --noEmit and npm run build pass. npm test: 264 tests pass.
  • npm run smoke passed twice on the final code. The new check uses a synthetic Type 3 PDF with no ToUnicode table. It covers blank input, centering, repeat edits, save and reopen, a small nominal font size, tilted text and a word split by a hyphen. An earlier version of the check, run on unchanged main, failed because the edit box held control codes.
  • The link history check (checkLinkHistory, scroll position after Back) failed intermittently during development: about 3 of 21 smoke runs with versions of this change, and 0 of 7 on main. Six alternating runs each, before the last review fixes, all passed. I don't know the cause, and I haven't shown that it happens without this change.
  • I also tried an earlier version on the private billing statement that showed the bug: replacing and re-editing an amount worked. I couldn't recheck that file after adding the hyphen, blank input and font size fixes. A separate PDFium probe with Type 3 inline-image glyphs showed their size stays below the resize threshold.
  • Not checked: how the "Unreadable text" entry looks in version history, or opening a saved copy in another PDF viewer.
  • Unreadable text made only of printable characters behaves as before.

Screenshots use a synthetic PDF.

Before:
unreadable-before

While:
unreadable-edit

After:
unreadable-edit-after

Written by Claude Sonnet 5.5 in Claude Code.

🤖 Generated with Claude Code

Fonts without a usable character map extract as control codes, so the edit
box held invisible characters that could not be saved. These lines now start
with an empty box, are redrawn in the bundled font and stay centered where the
original was.

Fixes Forward-Future#120

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@stozo04
stozo04 marked this pull request as ready for review November 30, 2026 19:14

This branch has not been deployed

No deployments
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.

Edit mode can't edit text in PDFs whose fonts have no usable Unicode map

1 participant