Repository navigation
Conversation
The built-in encoding lookup used the original character code while encodeText() maps some characters to a different byte, so U+20AC and U+0080 both wrote byte 80 but measured differently in ZapfDingbats. Agent: claude
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.
What kind of change does this PR introduce?
Bug fix. Fixes #580.
widthOfString()returns 0 for the letters ofSymbol(such asA) and for almost everyZapfDingbatscharacter (such as!and the euro sign), so wrapping and alignment are wrong with them.AFMFont#characterToGlyph(lib/font/afm.js:178) looks every character up in the Roman WinAnsi name table (AbecomesA). These two fonts use their own built-in encoding, markedEncodingScheme FontSpecific(lib/font/data/Symbol.afm:18,lib/font/data/ZapfDingbats.afm:18), where code 65 isAlpha(lib/font/data/Symbol.afm:55), notA. So the lookup misses their glyphs.The converter (
tools/afm-converter.js) now reads the character code of each glyph. ForFontSpecificfonts it keeps every glyph with a code from 0 to 255 (tools/afm-converter.js:125-129) and writes aglyphCodesarray next toglyphNames(tools/afm-converter.js:173).AFMFontuses that map incharacterToGlyphwhen it is present (lib/font/afm.js:181-183), after the same byte mappingencodeText()uses (outputCode,lib/font/afm.js:37), so one output byte has one width. The Roman fonts' generated files are unchanged.Symbol.jsandZapfDingbats.jswere regenerated astools/README.mddescribes.Checklist:
tools/README.mdschema)Ran live on c39a34d: built the branch and ran
d.font(f).widthOfString('ABGDEZHQIKLMNXOPRSTUFCYW')-> Symbol 195.276, ZapfDingbats 228.36, Helvetica 197.352 (Symbol and ZapfDingbats were 0 on master); the ZapfDingbats euro sign and\u0080, both written as byte 80, both measure 4.68 at the default size.Callers checked: lib/font/afm.js, lib/font/standard.js, tools/afm-converter.js, tests/tools/afm-converter.spec.js, tests/unit/afm.spec.js
AI disclosure: AI-assisted writing and checking, including automated tests and live checks; I take responsibility for it.