1919import uharfbuzz as hb
2020
2121THRESHOLD = 50
22- OVERHANGERS = ["ح" , "ح\u200D " , "ے" ]
22+ OVERHANGERS = ["ح" , "ح\u200d " , "ے" ]
2323
2424# To decrease lookup size, letters with similar glyph advances are grouped
2525# together, so ل is grouped with ٮ, and ط and ك are grouped with ص.
@@ -45,7 +45,11 @@ def shape(font, text, direction="rtl", script="arab", features=None):
4545
4646 glyphs = []
4747 advance = 0
48+ face = font .face
4849 for info , pos in zip (infos , positions ):
50+ if face .get_layout_glyph_class (info .codepoint ) == hb .OTLayoutGlyphClass .MARK :
51+ assert pos .x_advance == 0
52+ continue
4953 glyph = font .glyph_to_string (info .codepoint )
5054 if glyph .startswith ("behDotless-ar.init" ):
5155 glyph = "@beh.init"
@@ -61,6 +65,10 @@ def shape(font, text, direction="rtl", script="arab", features=None):
6165 glyph = "@hah.medi"
6266 elif glyph .startswith ("seen-ar.medi" ):
6367 glyph = "@seen.medi"
68+ elif glyph in ["alefMaksura-ar.fina" , "alefMaksura-ar.fina.salt" ]:
69+ glyph = "@yeh.fina"
70+ elif glyph in ["hah-ar.fina" , "hah-ar.fina.salt" ]:
71+ glyph = "@hah.fina"
6472 glyphs .append (glyph )
6573 advance += pos .x_advance
6674
@@ -92,6 +100,12 @@ def open_font(path):
92100def main (args ):
93101 font = open_font (args .font )
94102
103+ face = font .face
104+
105+ script_tags = face .get_table_script_tags ("GSUB" )
106+ assert "arab" in script_tags
107+ feature_tags = face .get_language_feature_tags ("GSUB" , script_tags .index ("arab" ))
108+
95109 rules = []
96110 for overhanger in OVERHANGERS :
97111 i = 0
@@ -112,17 +126,25 @@ def main(args):
112126 if text .count ("ح" ) > 1 :
113127 continue
114128
115- glyphs , adj , adj2 = shape (font , text , features = {"kern" : False })
116- if adj < THRESHOLD :
117- continue
118- found = True
119-
120- if adj2 is not None :
121- adj = adj2
122-
123- match = glyphs [0 ]
124- lookahead = "' " .join (glyphs [1 :])
125- rules .append (f"\t pos { match } ' { adj } { lookahead } ';" )
129+ for fea in [None , "hist" , "salt" ]:
130+ features = {"kern" : False }
131+ if fea :
132+ if fea not in feature_tags :
133+ continue
134+ features [fea ] = True
135+ glyphs , adj , adj2 = shape (font , text , features = features )
136+ if adj < THRESHOLD :
137+ continue
138+ found = True
139+
140+ if adj2 is not None :
141+ adj = adj2
142+
143+ match = glyphs [0 ]
144+ lookahead = "' " .join (glyphs [1 :])
145+ rule = f"\t pos { match } ' { adj } { lookahead } ';"
146+ if rule not in rules :
147+ rules .append (rule )
126148 if not found :
127149 break
128150 i += 1
0 commit comments