Skip to content

Commit 4f4b23e

Browse files
committed
Update script
1 parent 422d273 commit 4f4b23e

5 files changed

Lines changed: 55 additions & 29 deletions

File tree

scripts/update-overhang-fea.py

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import uharfbuzz as hb
2020

2121
THRESHOLD = 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):
92100
def 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"\tpos {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"\tpos {match}' {adj} {lookahead}';"
146+
if rule not in rules:
147+
rules.append(rule)
126148
if not found:
127149
break
128150
i += 1

sources/Raqq-overhang.fea

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
lookup overhang {
44
lookupflag IgnoreMarks;
55
pos @beh.init' 410 hah-ar.fina.alt';
6-
pos seen-ar.init' 90 hah-ar.fina';
7-
pos fehDotless-ar.init.hah' 140 hah-ar.fina';
8-
pos heh-ar.init' 100 hah-ar.fina';
9-
pos @beh.init' 210 _c.seen.beh' @beh.medi' hah-ar.fina';
10-
pos @beh.init' 110 _c.seen.beh' ain-ar.medi' hah-ar.fina';
11-
pos @beh.init' 80 _c.seen.beh' @beh.medi' _c.seen.beh' @beh.medi' hah-ar.fina';
6+
pos seen-ar.init' 90 @hah.fina';
7+
pos fehDotless-ar.init.hah' 140 @hah.fina';
8+
pos heh-ar.init' 100 @hah.fina';
9+
pos @beh.init' 210 _c.seen.beh' @beh.medi' @hah.fina';
10+
pos @beh.init' 110 _c.seen.beh' ain-ar.medi' @hah.fina';
11+
pos @beh.init' 80 _c.seen.beh' @beh.medi' _c.seen.beh' @beh.medi' @hah.fina';
1212
pos @beh.init' 410 @hah.medi';
1313
pos seen-ar.init' 90 @hah.medi';
1414
pos fehDotless-ar.init.hah' 140 @hah.medi';

sources/Raqq.glyphspackage/fontinfo.plist

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
.appVersion = "3430";
2+
.appVersion = "3434";
33
.formatVersion = 3;
44
axes = (
55
{
@@ -1041,6 +1041,8 @@ code = "lookup spacing {
10411041
@hah.init = [$[name MATCHES \"hah-ar.init.*\"]];
10421042
@hah.medi = [$[name MATCHES \"hah-ar.medi.*\"]];
10431043
@seen.medi = [$[name MATCHES \"seen-ar.medi.*\"]];
1044+
@yeh.fina = [alefMaksura-ar.fina alefMaksura-ar.fina.salt];
1045+
@hah.fina = [hah-ar.fina];
10441046
10451047
include(Raqq-overhang.fea)
10461048
";

sources/RaqqSura-overhang.fea

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
lookup overhang {
44
lookupflag IgnoreMarks;
55
pos @beh.init' 410 hah-ar.fina.alt';
6-
pos seen-ar.init' 120 hah-ar.fina';
7-
pos fehDotless-ar.init.hah' 140 hah-ar.fina';
8-
pos meem-ar.init' 70 hah-ar.fina';
9-
pos heh-ar.init' 90 hah-ar.fina';
10-
pos @beh.init' 260 @beh.medi' hah-ar.fina';
11-
pos @beh.init' 160 ain-ar.medi' hah-ar.fina';
12-
pos @beh.init' 160 @beh.medi' @beh.medi' hah-ar.fina';
13-
pos @beh.init' 60 @beh.medi' ain-ar.medi' hah-ar.fina';
14-
pos @beh.init' 60 ain-ar.medi' @beh.medi' hah-ar.fina';
15-
pos @beh.init' 60 @beh.medi' @beh.medi' @beh.medi' hah-ar.fina';
6+
pos seen-ar.init' 120 @hah.fina';
7+
pos fehDotless-ar.init.hah' 140 @hah.fina';
8+
pos meem-ar.init' 70 @hah.fina';
9+
pos heh-ar.init' 90 @hah.fina';
10+
pos @beh.init' 260 @beh.medi' @hah.fina';
11+
pos @beh.init' 160 ain-ar.medi' @hah.fina';
12+
pos @beh.init' 160 @beh.medi' @beh.medi' @hah.fina';
13+
pos @beh.init' 60 @beh.medi' ain-ar.medi' @hah.fina';
14+
pos @beh.init' 60 ain-ar.medi' @beh.medi' @hah.fina';
15+
pos @beh.init' 60 @beh.medi' @beh.medi' @beh.medi' @hah.fina';
1616
pos @beh.init' 410 @hah.medi';
1717
pos seen-ar.init' 120 @hah.medi';
1818
pos fehDotless-ar.init.hah' 140 @hah.medi';

sources/RaqqSura.glyphspackage/fontinfo.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,8 @@ code = "# Automatic Code
10281028
@hah.init = [$[name MATCHES \"hah-ar.init.*\"]];
10291029
@hah.medi = [$[name MATCHES \"hah-ar.medi.*\"]];
10301030
@seen.medi = [$[name MATCHES \"seen-ar.medi.*\"]];
1031+
@yeh.fina = [alefMaksura-ar.fina alefMaksura-ar.fina.salt];
1032+
@hah.fina = [hah-ar.fina];
10311033
10321034
include(RaqqSura-overhang.fea)
10331035
";

0 commit comments

Comments
 (0)