Skip to content

PDF: map each glyph to its shaping cluster's text in ToUnicode (#164) - #178

Merged
h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
MarekSpodBiedry:issue-164
Oct 14, 2026
Merged

h-a-n-a-s-h-i merged 1 commit into
storytold:mainfrom
MarekSpodBiedry:issue-164

Conversation

@MarekSpodBiedry

Copy link
Copy Markdown
Contributor

Fixes #164.

The PDF text layer gave each glyph its text range by position. That worked only when a run had exactly one glyph per character. When a run had fewer or more glyphs than characters (for example a ligature such as "fl"), glyph 0 got the whole run's text and every other glyph got nothing. The ToUnicode CMap then mapped one glyph to a whole sentence and left codes like <0002> with no mapping. poppler rejected the long entries, and text extraction came out garbled.

The cluster data the issue asks for is already available: GlyphRun.cells holds, for each glyph, the paragraph character that heads its shaping cluster. The new helper glyph_text_ranges uses it:

  • A cluster runs from its head to the next cluster head in the run, or to the end of the run. A ligature glyph therefore maps to all of its characters ("fl" maps to f and l), and every other glyph maps to its own character.
  • All glyphs of one cluster (for example a base letter and a combining mark, or kashida fill) share the cluster's range. krilla treats glyphs with the same range as one cluster and writes the text only once.
  • Ranges are computed from cluster heads, not from glyph order, so right-to-left runs (glyphs in visual order) get the correct characters too. krilla then marks them as reversed.
  • A glyph with no cell gets an empty range, the same as the old code gave it. Every range stays inside the run's text, so krilla's text[range] cannot panic.

Rendering does not change, because the text layer is invisible.

Test: glyph_ranges_follow_shaping_clusters in crates/pdf/src/tests.rs covers an "fl" ligature, a two-glyph cluster, and a right-to-left run that starts mid-paragraph and uses multi-byte characters. With the old logic, the ligature case maps the whole word to glyph 0.

@MarekSpodBiedry
MarekSpodBiedry marked this pull request as ready for review October 11, 2026 21:46
@h-a-n-a-s-h-i
h-a-n-a-s-h-i merged commit 31390e5 into storytold:main Oct 14, 2026
1 check passed
h-a-n-a-s-h-i pushed a commit that referenced this pull request Oct 14, 2026
- #178: ToUnicode ranges looked up without indexing
- #465: frame_num gaps are concealed (bounded) even when the SPS forbids them; cut streams keep playing
- #471: control request lines up to 256 MB so picture/media inserts still fit
- #473: a merge that loses its only row or column is removed, with regression tests
- #521: AutoCorrect no longer rewrites real words (cant, wont, im)
- #654: inherit_placeholder_geometry's doc comment back on its function

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@echelon

echelon commented Oct 14, 2026

Copy link
Copy Markdown
Member

Thank you for this contribution, @MarekSpodBiedry! It has landed on main and will ship in the next DeckCraft release.

If you haven't already, please come join us on Discord: https://discord.gg/artcraft

itrycodinganditsbad added a commit to itrycodinganditsbad/deckcraft that referenced this pull request Oct 15, 2026
The start screen is now the File tab (New, Open › Browse, Recent), so the
build and open guides use those labels. The FXC (storytold#176), transition
duration (storytold#149), PDF text (storytold#178) and PPTX round-trip fixes are merged but
not in 0.7.0, so the pages say that instead of "open". Every page is now
verified: 0.7.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anishguduru pushed a commit to anishguduru/deckcraft that referenced this pull request Oct 16, 2026
storytold#178)

* storytold#163: allow replacing saved signatures and render long names fully

Add saved signature and initials previews with change/remove/add controls in
Fill & Sign. Preserve placed annotations and saved values on cancellation.
Use bounded line outlines for long names and fit typed placements to 150 pt.

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

* cargo fmt after the rename

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Brandon Thomas <echelon@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

0.5.0: PDF ToUnicode maps a run's first glyph to the whole run when glyph count != char count (poppler warns, extraction garbles)

3 participants