Repository navigation
Look up the space glyph in ToUnicode by string in Font.spaceWidth - #22474
Open
jayhemnani9910 wants to merge 1 commit into
Open
jayhemnani9910 wants to merge 1 commit into
jayhemnani9910 wants to merge 1 commit into
Conversation
ToUnicodeMap.charCodeOf expects a string, but spaceWidth passed the code point as a number, so the lookup never matched and the width came from widths[32] or defaultWidth instead of the font's space glyph. With a wrong space width the word-space threshold is too small, and letter-spaced text such as LibreOffice headings comes out as "T R A C K".
jayhemnani9910
force-pushed
the
fix-spacewidth-tounicode-lookup
branch
from
November 8, 2026 18:25
214f8ae to
f9c734a
Compare
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Font.spaceWidthlooks up the code of the space glyph withthis.toUnicode.charCodeOf(glyphUnicode), whereglyphUnicodeis a number.ToUnicodeMapstores strings, so the lookup never matches and the width comes fromwidths[32]ordefaultWidthinstead of the font's own space glyph.encodeStringin the same file already converts withString.fromCodePoint(and passes the number through forIdentityToUnicodeMap); this does the same.Since the word-space detection now uses
spaceWidth, the wrong value shows up in text content. A heading exported from LibreOffice withletter-spacing: 2pt(simple font, space mapped throughDifferencesand ToUnicode) extracts asT R A C K E D H E A D I N G T E X T; pdftotext givesTRACKED HEADING TEXT.Added
tounicode_space_width.pdf(hand-written, Helvetica with/Differences [1 /T /R /A /C /K /space], ToUnicode, TJ with -165 between glyphs) and a unit test inapi_spec.js. It fails before the change (T R A C K T A C K) and passes after.gulp linton the changed files passes; the unit tests pass except the 20 specs that need linked PDFs, which could not be downloaded here.