otTables: try to fix MarkBasePos subtable overflows
Fixes https://github.com/googlei18n/fontmake/issues/450
This commit is contained in:
parent
2798bf6d1f
commit
6e8e431dee
@ -1281,6 +1281,67 @@ def splitPairPos(oldSubTable, newSubTable, overflowRecord):
|
||||
return ok
|
||||
|
||||
|
||||
def splitMarkBasePos(oldSubTable, newSubTable, overflowRecord):
|
||||
# split half of the mark classes to the new subtable
|
||||
classCount = oldSubTable.ClassCount
|
||||
if classCount < 2:
|
||||
# oh well, not much left to split...
|
||||
return False
|
||||
|
||||
oldClassCount = classCount // 2
|
||||
newClassCount = classCount - oldClassCount
|
||||
|
||||
oldMarkCoverage, oldMarkRecords = [], []
|
||||
newMarkCoverage, newMarkRecords = [], []
|
||||
for glyphName, markRecord in zip(
|
||||
oldSubTable.MarkCoverage.glyphs,
|
||||
oldSubTable.MarkArray.MarkRecord
|
||||
):
|
||||
if markRecord.Class < oldClassCount:
|
||||
oldMarkCoverage.append(glyphName)
|
||||
oldMarkRecords.append(markRecord)
|
||||
else:
|
||||
newMarkCoverage.append(glyphName)
|
||||
newMarkRecords.append(markRecord)
|
||||
|
||||
oldBaseRecords, newBaseRecords = [], []
|
||||
for rec in oldSubTable.BaseArray.BaseRecord:
|
||||
oldBaseRecord, newBaseRecord = rec.__class__(), rec.__class__()
|
||||
oldBaseRecord.BaseAnchor = rec.BaseAnchor[:oldClassCount]
|
||||
newBaseRecord.BaseAnchor = rec.BaseAnchor[oldClassCount:]
|
||||
oldBaseRecords.append(oldBaseRecord)
|
||||
newBaseRecords.append(newBaseRecord)
|
||||
|
||||
newSubTable.Format = oldSubTable.Format
|
||||
|
||||
oldSubTable.MarkCoverage.glyphs = oldMarkCoverage
|
||||
newSubTable.MarkCoverage = oldSubTable.MarkCoverage.__class__()
|
||||
newSubTable.MarkCoverage.Format = oldSubTable.MarkCoverage.Format
|
||||
newSubTable.MarkCoverage.glyphs = newMarkCoverage
|
||||
|
||||
# share the same BaseCoverage in both halves
|
||||
newSubTable.BaseCoverage = oldSubTable.BaseCoverage
|
||||
|
||||
oldSubTable.ClassCount = oldClassCount
|
||||
newSubTable.ClassCount = newClassCount
|
||||
|
||||
oldSubTable.MarkArray.MarkRecord = oldMarkRecords
|
||||
newSubTable.MarkArray = oldSubTable.MarkArray.__class__()
|
||||
newSubTable.MarkArray.MarkRecord = newMarkRecords
|
||||
|
||||
oldSubTable.MarkArray.MarkCount = len(oldMarkRecords)
|
||||
newSubTable.MarkArray.MarkCount = len(newMarkRecords)
|
||||
|
||||
oldSubTable.BaseArray.BaseRecord = oldBaseRecords
|
||||
newSubTable.BaseArray = oldSubTable.BaseArray.__class__()
|
||||
newSubTable.BaseArray.BaseRecord = newBaseRecords
|
||||
|
||||
oldSubTable.BaseArray.BaseCount = len(oldBaseRecords)
|
||||
newSubTable.BaseArray.BaseCount = len(newBaseRecords)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
splitTable = { 'GSUB': {
|
||||
# 1: splitSingleSubst,
|
||||
# 2: splitMultipleSubst,
|
||||
@ -1295,7 +1356,7 @@ splitTable = { 'GSUB': {
|
||||
# 1: splitSinglePos,
|
||||
2: splitPairPos,
|
||||
# 3: splitCursivePos,
|
||||
# 4: splitMarkBasePos,
|
||||
4: splitMarkBasePos,
|
||||
# 5: splitMarkLigPos,
|
||||
# 6: splitMarkMarkPos,
|
||||
# 7: splitContextPos,
|
||||
|
Loading…
x
Reference in New Issue
Block a user