Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken accent stacking behavior for partially precomposed characters with leaning anchors (#2492). #2493

Merged
merged 2 commits into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/31.6.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix broken accent stacking behavior for partially precomposed characters with leaning anchors (#2492).
60 changes: 45 additions & 15 deletions packages/font-glyphs/src/auto-build/accents.ptl
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,22 @@ glyph-block AutoBuild-Accents : begin
return amended

# Here, we build a simplified substitution builder that does the mark substitutions
define [substParts parts ignore backtrack input loookAhead production] : begin
# This is similar to GSUB lookup type 6 but with more flexibility
define flex-params [substParts] : begin
local-parameter : parts
local-parameter : ignore -- MatchUtil.never
local-parameter : backtrack -- {}
local-parameter : input
local-parameter : lookAhead -- {}
local-parameter : replace
local igl 0
while (igl < parts.length) : begin
local m : substMatch parts igl ignore backtrack input loookAhead
local m : substMatch parts igl ignore backtrack input lookAhead
if [not m]
: then : inc igl
: else : begin
local inputGlyphs : ArrayUtil.mapIndexToItems parts m
local producedGlyphs : production.apply null inputGlyphs
local producedGlyphs : replace.apply null inputGlyphs
foreach i [range (m.length - 1) downtill 0] : begin
parts.splice m.(i) 1
ArrayUtil.insertSliceAt parts m.0 producedGlyphs
Expand Down Expand Up @@ -78,24 +85,22 @@ glyph-block AutoBuild-Accents : begin

return m

# Match/replace directives
define [dotless g] : begin
local gDotless : query-glyph : Dotless.get g
if [not gDotless] : return null
return {gDotless}

define [isMark k] : function [g] : begin
return : g && g.markAnchors && g.markAnchors.(k)
define [isMarkExcluding k] : function [g] : begin
return : g && g.markAnchors && [Object.keys g.markAnchors].length && !g.markAnchors.(k)
define [hasBaseAnchor k] : function [g] : begin
return : g && g.baseAnchors && g.baseAnchors.(k)
define [isLeaningMark k] : function [g] : begin
return : g && g.markAnchors && g.markAnchors.(k) && [LeaningMark.get g]
define [leaningMarkSplit g] : begin
define [produceLeaningMark gnSuppressAnchor] : function [g] : begin
local spacer : query-glyph : LeaningMarkSpacer.get g
local alternative : query-glyph : LeaningMark.get g
if (spacer && alternative) : return { spacer alternative }
return { g }
return { [query-glyph gnSuppressAnchor] g }

define [markSubst uk] : begin
local mapping : new Map
Expand Down Expand Up @@ -165,23 +170,48 @@ glyph-block AutoBuild-Accents : begin
### Keep the semantics here synchronized with `ccmp` feature

# Handle dotless form
substParts parts [isMarkExcluding 'above'] {} {dotless} {[isMark 'above']} dotless
substParts parts
ignore -- [isMarkExcluding 'above']
input -- {dotless}
lookAhead -- {[isMark 'above']}
replace -- dotless

# Handle iota subscript
substParts parts iotaLF.ignore {[hasBaseAnchor 'lf']} {iotaLF.matcher} {} iotaLF.production
substParts parts
ignore -- iotaLF.ignore
backtrack -- {[hasBaseAnchor 'lf']}
input -- {iotaLF.matcher}
replace -- iotaLF.production

# Handle ogonek
substParts parts ogonek.ignore {[hasBaseAnchor 'trailing']} {ogonek.matcher} {} ogonek.production
substParts parts
ignore -- ogonek.ignore
backtrack -- {[hasBaseAnchor 'trailing']}
input -- {ogonek.matcher}
replace -- ogonek.production

# Handle mark combinations (Greek)
substParts parts MatchUtil.never {} { markComposition.matchFirst markComposition.matchSecond } {} markComposition.production
substParts parts
input -- { markComposition.matchFirst markComposition.matchSecond }
replace -- markComposition.production

# Handle upper Greek Tonos marks
substParts parts MatchUtil.never {[hasBaseAnchor 'grekUpperTonos']} {upperTonos.matcher} {} upperTonos.production
substParts parts
backtrack -- {[hasBaseAnchor 'grekUpperTonos']}
input -- {upperTonos.matcher}
replace -- upperTonos.production

# Handle leaning marks
substParts parts [isMarkExcluding 'above'] {[MatchUtil.either [hasBaseAnchor 'leaningAbove'] [isMark 'leaningAbove']]} {[isLeaningMark 'above']} {} leaningMarkSplit
substParts parts [isMarkExcluding 'below'] {[MatchUtil.either [hasBaseAnchor 'leaningBelow'] [isMark 'leaningBelow']]} {[isLeaningMark 'below']} {} leaningMarkSplit
substParts parts
ignore -- [isMarkExcluding 'above']
backtrack -- {[MatchUtil.either [hasBaseAnchor 'leaningAbove'] [isMark 'leaningAbove']]}
input -- {[isMark 'above']}
replace -- [produceLeaningMark 'mark/suppressLeaningAboveAnchor']
substParts parts
ignore -- [isMarkExcluding 'below']
backtrack -- {[MatchUtil.either [hasBaseAnchor 'leaningBelow'] [isMark 'leaningBelow']]}
input -- {[isMark 'below']}
replace -- [produceLeaningMark 'mark/suppressLeaningBelowAnchor']

define [pad _s n] : begin
local s _s
Expand Down