Skip to content

Commit 6c6f549

Browse files
committed
Fix extracting multiple anchor classes from same lookup
Fixes #75
1 parent 96f025c commit 6c6f549

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

Lib/extractor/formats/opentype.py

+24-8
Original file line numberDiff line numberDiff line change
@@ -1168,18 +1168,20 @@ def _gatherAnchorsForLookup(gpos, lookupIndex):
11681168
if (lookup.LookupType == 9):
11691169
subtable = subtable.ExtSubTable
11701170
subtableAnchors = _handleAnchorLookupType4Format1(subtable)
1171-
allAnchorGroups.append(subtableAnchors)
1171+
allAnchorGroups = allAnchorGroups + subtableAnchors
11721172
return allAnchorGroups
11731173

11741174

11751175
def _handleAnchorLookupType4Format1(subtable):
11761176
"""
11771177
Extract anchors from a Lookup Type 4 Format 1.
1178+
Returns a list of anchor group data dicts in the following format:
1179+
{
1180+
"baseAnchors": {"A": {"x": 672, "y": 1600}, "B": {"x": 624, "y": 1600}},
1181+
"markAnchors": {'gravecomb': {'x': -400, 'y': 1500}, 'acutecomb': {'x': -630, 'y': 1500}},
1182+
}
11781183
"""
1179-
anchors = {
1180-
"baseAnchors": {},
1181-
"markAnchors": {},
1182-
}
1184+
anchors = []
11831185

11841186
if subtable.LookupType not in (4, 6):
11851187
print(f" Skipping Anchor lookup subtable with unsupported LookupType {subtable.LookupType}.")
@@ -1191,12 +1193,26 @@ def _handleAnchorLookupType4Format1(subtable):
11911193
markCoverage = subtable.MarkCoverage.glyphs if subtableIsType4 else subtable.Mark1Coverage.glyphs
11921194

11931195
for baseRecordIndex, baseRecord in enumerate(subtable.BaseArray.BaseRecord if subtableIsType4 else subtable.Mark2Array.Mark2Record):
1194-
baseAnchor = baseRecord.BaseAnchor[0] if subtableIsType4 else baseRecord.Mark2Anchor[0]
1195-
anchors["baseAnchors"].update({baseCoverage[baseRecordIndex]: {"x": baseAnchor.XCoordinate, "y": baseAnchor.YCoordinate}})
1196+
for baseAnchorIndex, baseAnchor in enumerate(baseRecord.BaseAnchor if subtableIsType4 else baseRecord.Mark2Anchor):
1197+
for i in range(len(anchors), baseAnchorIndex + 1):
1198+
anchors.append ({
1199+
"baseAnchors": {},
1200+
"markAnchors": {},
1201+
})
1202+
if baseAnchor:
1203+
anchors[baseAnchorIndex]["baseAnchors"].update({baseCoverage[baseRecordIndex]: {"x": baseAnchor.XCoordinate, "y": baseAnchor.YCoordinate}})
11961204

11971205
for markRecordIndex, markRecord in enumerate(subtable.MarkArray.MarkRecord if subtableIsType4 else subtable.Mark1Array.MarkRecord):
1206+
for i in range(len(anchors), markRecord.Class + 1):
1207+
anchors.append({
1208+
"baseAnchors": {},
1209+
"markAnchors": {},
1210+
})
11981211
markAnchor = markRecord.MarkAnchor
1199-
anchors["markAnchors"].update({markCoverage[markRecordIndex]: {"x": markAnchor.XCoordinate, "y": markAnchor.YCoordinate}})
1212+
if (markAnchor.Format != 1):
1213+
print(f" Unexpected markAnchor format {markAnchor.Format}.")
1214+
continue
1215+
anchors[markRecord.Class]["markAnchors"].update({markCoverage[markRecordIndex]: {"x": markAnchor.XCoordinate, "y": markAnchor.YCoordinate}})
12001216

12011217
return anchors
12021218

0 commit comments

Comments
 (0)