Honour user alternateNumber in GSUB Type 3 substitutions#371
Open
lehni wants to merge 1 commit into
Open
Conversation
- Type 3 hardcoded USER_INDEX = 0; `nalt: 2` silently rendered as alt #1 - Thread user features through ShapingPlan so GSUB reads the 1-based index - Don't mutate caller's features in OTLayoutEngine.setup; overlay instead
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.
fontkit's GSUB Type 3 (Alternate Substitution) hardcodes the alternate index to 0, so user-supplied alternateNumber values (e.g.
font.layout(text, { aalt: 2 })) are silently ignored and every aalt/nalt/etc. request resolves to the first alternate. This makes Type 3 features effectively read-only from a caller's perspective.This PR:
ShapingPlanso processors can read per-feature integer values without losing them to the shaper plan'strue/falsenormalisation.OTLayoutEngine.setupto overlay the user's original values onto the chosen-features map without mutating the caller's input object.GSUBProcessorType 3 now readsuserFeatures[currentFeature]as a 1-based alternate index, falls back to the first alternate when no value is given or the requested index is out of range.Test: FiraSans's aalt lookup carries multiple alternates per coverage entry. For 'A' (glyph 3) the alternate set is
[1078 'ordfeminine', 764 'a.sc']. The added test shapes 'A' with{ aalt: true }and{ aalt: 2 }and asserts the correct glyph ID for each — matching what HarfBuzz produces for--features='aalt=1'vs--features='aalt=2'.