Correct parsing of negative values in fvar table - #59
Open
softmarshmallow wants to merge 1 commit into
Open
Conversation
Owner
|
This was already fixed in my local versoin of Typr.js, so I just uploaded it here to GitHub. |
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.
Here's a description you can copy-paste for your PR:
Fix: Correct parsing of negative values in fvar table
Problem
The
readFixedfunction in Typr.js was incorrectly parsing negative values in the fvar table. Variable fonts like Roboto Flex use negative values for design axes (e.g.,slntaxis with min: -10,GRADaxis with min: -200), but these were being interpreted as very large positive numbers (65526, 65336, etc.).Root Cause
The original
readFixedimplementation treated the 32-bit fixed-point numbers as unsigned integers:This approach treated the high 16 bits as unsigned, causing negative values to be interpreted as large positive numbers due to two's complement representation.
Solution
Fixed the
readFixedfunction to properly handle signed 32-bit integers:Why 65536?
In OpenType fonts, fixed-point numbers are stored as 32-bit integers where:
65536 = 2^16is the scale factor that converts between the integer representation and the actual floating-point valuesBy using the existing
readIntfunction (which properly handles signed integers) and dividing by 65536, we correctly convert the fixed-point format to floating-point values while preserving negative values.Impact
This fix ensures that variable font axes with negative values (like
slnt,GRAD,YTDEin Roboto Flex) are parsed correctly, enabling proper support for design axes that use negative ranges.