tottfgpos: Fix needless warning about 16-bit field#5136
Merged
jtanx merged 1 commit intofontforge:masterfrom Dec 31, 2022
Merged
tottfgpos: Fix needless warning about 16-bit field#5136jtanx merged 1 commit intofontforge:masterfrom
jtanx merged 1 commit intofontforge:masterfrom
Conversation
When a single substitution table (format 1) is to be written and the substitution offset is very big and backwards (i.e. to lower numbers) a warning is issued although the encoded font is correct. For example codepoint 65342 is to be replaced by 1683. The offset is -63659 in this case (old codepoint + offset = new codepoint). The warning in putshort() triggers: if(sval < -32768 || sval > 65535) ... [how] The offset is calculated with signed ints, so we have the result above. The actual calculations 'in the font' are done with uint16_t. According to specs "Addition of deltaGlyphID is modulo 65536" [1]. So we simply need to drop all the bits outside uint16_t and still have the correct calculation. With the new offset value of -63659 & 0xFFFF = 1877 the calculation is 65342 + 1877 = 67219 == 1683 (assuming unit16_t arithmetic) [1] https://learn.microsoft.com/en-us/typography/opentype/spec/gsub#11-single-substitution-format-1 Fixes: fontforge#3009 Reported-by: Thayne McCombs <tmccombs> Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>
3 tasks
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.
[why]
When a single substitution table (format 1) is to be written and the substitution offset is very big and backwards (i.e. to lower numbers) a warning is issued although the encoded font is correct.
For example codepoint 65342 is to be replaced by 1683. The offset is -63659 in this case (old codepoint + offset = new codepoint).
The warning in putshort() triggers:
if(sval < -32768 || sval > 65535) ...[how]
The offset is calculated with signed ints, so we have the result above. The actual calculations 'in the font' are done with uint16_t. According to specs "Addition of deltaGlyphID is modulo 65536" [1]. So we simply need to drop all the bits outside uint16_t and still have the correct calculation.
With the new offset value of -63659 & 0xFFFF = 1877 the calculation is
65342 + 1877 = 67219 == 1683 (assuming unit16_t arithmetic)
[1] https://learn.microsoft.com/en-us/typography/opentype/spec/gsub#11-single-substitution-format-1
Fixes: #3009
Reported-by: Thayne McCombs @tmccombs
Signed-off-by: Fini Jastrow ulf.fini.jastrow@desy.de
Type of change
Reproduction / Test
Font to try:
Repo link https://github.com/googlefonts/noto-cjk/releases/tag/Sans2.004
Zip link https://github.com/googlefonts/noto-cjk/releases/download/Sans2.004/06_NotoSansCJKjp.zip
Font file in zip
NotoSansCJKjp-Bold.otfAffected lookup: CID -> CID font info -> Lookups -> 31 ('hist')
Just open and immediately re-generate new CID font.
See comments in #3009.