featureVars.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. """Module to build FeatureVariation tables:
  2. https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#featurevariations-table
  3. NOTE: The API is experimental and subject to change.
  4. """
  5. from fontTools.misc.dictTools import hashdict
  6. from fontTools.misc.intTools import bit_count
  7. from fontTools.ttLib import newTable
  8. from fontTools.ttLib.tables import otTables as ot
  9. from fontTools.ttLib.ttVisitor import TTVisitor
  10. from fontTools.otlLib.builder import buildLookup, buildSingleSubstSubtable
  11. from collections import OrderedDict
  12. from .errors import VarLibError, VarLibValidationError
  13. def addFeatureVariations(font, conditionalSubstitutions, featureTag="rvrn"):
  14. """Add conditional substitutions to a Variable Font.
  15. The `conditionalSubstitutions` argument is a list of (Region, Substitutions)
  16. tuples.
  17. A Region is a list of Boxes. A Box is a dict mapping axisTags to
  18. (minValue, maxValue) tuples. Irrelevant axes may be omitted and they are
  19. interpretted as extending to end of axis in each direction. A Box represents
  20. an orthogonal 'rectangular' subset of an N-dimensional design space.
  21. A Region represents a more complex subset of an N-dimensional design space,
  22. ie. the union of all the Boxes in the Region.
  23. For efficiency, Boxes within a Region should ideally not overlap, but
  24. functionality is not compromised if they do.
  25. The minimum and maximum values are expressed in normalized coordinates.
  26. A Substitution is a dict mapping source glyph names to substitute glyph names.
  27. Example:
  28. # >>> f = TTFont(srcPath)
  29. # >>> condSubst = [
  30. # ... # A list of (Region, Substitution) tuples.
  31. # ... ([{"wdth": (0.5, 1.0)}], {"cent": "cent.rvrn"}),
  32. # ... ([{"wght": (0.5, 1.0)}], {"dollar": "dollar.rvrn"}),
  33. # ... ]
  34. # >>> addFeatureVariations(f, condSubst)
  35. # >>> f.save(dstPath)
  36. """
  37. processLast = featureTag != "rvrn"
  38. _checkSubstitutionGlyphsExist(
  39. glyphNames=set(font.getGlyphOrder()),
  40. substitutions=conditionalSubstitutions,
  41. )
  42. substitutions = overlayFeatureVariations(conditionalSubstitutions)
  43. # turn substitution dicts into tuples of tuples, so they are hashable
  44. conditionalSubstitutions, allSubstitutions = makeSubstitutionsHashable(
  45. substitutions
  46. )
  47. if "GSUB" not in font:
  48. font["GSUB"] = buildGSUB()
  49. # setup lookups
  50. lookupMap = buildSubstitutionLookups(
  51. font["GSUB"].table, allSubstitutions, processLast
  52. )
  53. # addFeatureVariationsRaw takes a list of
  54. # ( {condition}, [ lookup indices ] )
  55. # so rearrange our lookups to match
  56. conditionsAndLookups = []
  57. for conditionSet, substitutions in conditionalSubstitutions:
  58. conditionsAndLookups.append(
  59. (conditionSet, [lookupMap[s] for s in substitutions])
  60. )
  61. addFeatureVariationsRaw(font, font["GSUB"].table, conditionsAndLookups, featureTag)
  62. def _checkSubstitutionGlyphsExist(glyphNames, substitutions):
  63. referencedGlyphNames = set()
  64. for _, substitution in substitutions:
  65. referencedGlyphNames |= substitution.keys()
  66. referencedGlyphNames |= set(substitution.values())
  67. missing = referencedGlyphNames - glyphNames
  68. if missing:
  69. raise VarLibValidationError(
  70. "Missing glyphs are referenced in conditional substitution rules:"
  71. f" {', '.join(missing)}"
  72. )
  73. def overlayFeatureVariations(conditionalSubstitutions):
  74. """Compute overlaps between all conditional substitutions.
  75. The `conditionalSubstitutions` argument is a list of (Region, Substitutions)
  76. tuples.
  77. A Region is a list of Boxes. A Box is a dict mapping axisTags to
  78. (minValue, maxValue) tuples. Irrelevant axes may be omitted and they are
  79. interpretted as extending to end of axis in each direction. A Box represents
  80. an orthogonal 'rectangular' subset of an N-dimensional design space.
  81. A Region represents a more complex subset of an N-dimensional design space,
  82. ie. the union of all the Boxes in the Region.
  83. For efficiency, Boxes within a Region should ideally not overlap, but
  84. functionality is not compromised if they do.
  85. The minimum and maximum values are expressed in normalized coordinates.
  86. A Substitution is a dict mapping source glyph names to substitute glyph names.
  87. Returns data is in similar but different format. Overlaps of distinct
  88. substitution Boxes (*not* Regions) are explicitly listed as distinct rules,
  89. and rules with the same Box merged. The more specific rules appear earlier
  90. in the resulting list. Moreover, instead of just a dictionary of substitutions,
  91. a list of dictionaries is returned for substitutions corresponding to each
  92. unique space, with each dictionary being identical to one of the input
  93. substitution dictionaries. These dictionaries are not merged to allow data
  94. sharing when they are converted into font tables.
  95. Example::
  96. >>> condSubst = [
  97. ... # A list of (Region, Substitution) tuples.
  98. ... ([{"wght": (0.5, 1.0)}], {"dollar": "dollar.rvrn"}),
  99. ... ([{"wght": (0.5, 1.0)}], {"dollar": "dollar.rvrn"}),
  100. ... ([{"wdth": (0.5, 1.0)}], {"cent": "cent.rvrn"}),
  101. ... ([{"wght": (0.5, 1.0), "wdth": (-1, 1.0)}], {"dollar": "dollar.rvrn"}),
  102. ... ]
  103. >>> from pprint import pprint
  104. >>> pprint(overlayFeatureVariations(condSubst))
  105. [({'wdth': (0.5, 1.0), 'wght': (0.5, 1.0)},
  106. [{'dollar': 'dollar.rvrn'}, {'cent': 'cent.rvrn'}]),
  107. ({'wdth': (0.5, 1.0)}, [{'cent': 'cent.rvrn'}]),
  108. ({'wght': (0.5, 1.0)}, [{'dollar': 'dollar.rvrn'}])]
  109. """
  110. # Merge same-substitutions rules, as this creates fewer number oflookups.
  111. merged = OrderedDict()
  112. for value, key in conditionalSubstitutions:
  113. key = hashdict(key)
  114. if key in merged:
  115. merged[key].extend(value)
  116. else:
  117. merged[key] = value
  118. conditionalSubstitutions = [(v, dict(k)) for k, v in merged.items()]
  119. del merged
  120. # Merge same-region rules, as this is cheaper.
  121. # Also convert boxes to hashdict()
  122. #
  123. # Reversing is such that earlier entries win in case of conflicting substitution
  124. # rules for the same region.
  125. merged = OrderedDict()
  126. for key, value in reversed(conditionalSubstitutions):
  127. key = tuple(
  128. sorted(
  129. (hashdict(cleanupBox(k)) for k in key),
  130. key=lambda d: tuple(sorted(d.items())),
  131. )
  132. )
  133. if key in merged:
  134. merged[key].update(value)
  135. else:
  136. merged[key] = dict(value)
  137. conditionalSubstitutions = list(reversed(merged.items()))
  138. del merged
  139. # Overlay
  140. #
  141. # Rank is the bit-set of the index of all contributing layers.
  142. initMapInit = ((hashdict(), 0),) # Initializer representing the entire space
  143. boxMap = OrderedDict(initMapInit) # Map from Box to Rank
  144. for i, (currRegion, _) in enumerate(conditionalSubstitutions):
  145. newMap = OrderedDict(initMapInit)
  146. currRank = 1 << i
  147. for box, rank in boxMap.items():
  148. for currBox in currRegion:
  149. intersection, remainder = overlayBox(currBox, box)
  150. if intersection is not None:
  151. intersection = hashdict(intersection)
  152. newMap[intersection] = newMap.get(intersection, 0) | rank | currRank
  153. if remainder is not None:
  154. remainder = hashdict(remainder)
  155. newMap[remainder] = newMap.get(remainder, 0) | rank
  156. boxMap = newMap
  157. # Generate output
  158. items = []
  159. for box, rank in sorted(
  160. boxMap.items(), key=(lambda BoxAndRank: -bit_count(BoxAndRank[1]))
  161. ):
  162. # Skip any box that doesn't have any substitution.
  163. if rank == 0:
  164. continue
  165. substsList = []
  166. i = 0
  167. while rank:
  168. if rank & 1:
  169. substsList.append(conditionalSubstitutions[i][1])
  170. rank >>= 1
  171. i += 1
  172. items.append((dict(box), substsList))
  173. return items
  174. #
  175. # Terminology:
  176. #
  177. # A 'Box' is a dict representing an orthogonal "rectangular" bit of N-dimensional space.
  178. # The keys in the dict are axis tags, the values are (minValue, maxValue) tuples.
  179. # Missing dimensions (keys) are substituted by the default min and max values
  180. # from the corresponding axes.
  181. #
  182. def overlayBox(top, bot):
  183. """Overlays ``top`` box on top of ``bot`` box.
  184. Returns two items:
  185. * Box for intersection of ``top`` and ``bot``, or None if they don't intersect.
  186. * Box for remainder of ``bot``. Remainder box might not be exact (since the
  187. remainder might not be a simple box), but is inclusive of the exact
  188. remainder.
  189. """
  190. # Intersection
  191. intersection = {}
  192. intersection.update(top)
  193. intersection.update(bot)
  194. for axisTag in set(top) & set(bot):
  195. min1, max1 = top[axisTag]
  196. min2, max2 = bot[axisTag]
  197. minimum = max(min1, min2)
  198. maximum = min(max1, max2)
  199. if not minimum < maximum:
  200. return None, bot # Do not intersect
  201. intersection[axisTag] = minimum, maximum
  202. # Remainder
  203. #
  204. # Remainder is empty if bot's each axis range lies within that of intersection.
  205. #
  206. # Remainder is shrank if bot's each, except for exactly one, axis range lies
  207. # within that of intersection, and that one axis, it extrudes out of the
  208. # intersection only on one side.
  209. #
  210. # Bot is returned in full as remainder otherwise, as true remainder is not
  211. # representable as a single box.
  212. remainder = dict(bot)
  213. extruding = False
  214. fullyInside = True
  215. for axisTag in top:
  216. if axisTag in bot:
  217. continue
  218. extruding = True
  219. fullyInside = False
  220. break
  221. for axisTag in bot:
  222. if axisTag not in top:
  223. continue # Axis range lies fully within
  224. min1, max1 = intersection[axisTag]
  225. min2, max2 = bot[axisTag]
  226. if min1 <= min2 and max2 <= max1:
  227. continue # Axis range lies fully within
  228. # Bot's range doesn't fully lie within that of top's for this axis.
  229. # We know they intersect, so it cannot lie fully without either; so they
  230. # overlap.
  231. # If we have had an overlapping axis before, remainder is not
  232. # representable as a box, so return full bottom and go home.
  233. if extruding:
  234. return intersection, bot
  235. extruding = True
  236. fullyInside = False
  237. # Otherwise, cut remainder on this axis and continue.
  238. if min1 <= min2:
  239. # Right side survives.
  240. minimum = max(max1, min2)
  241. maximum = max2
  242. elif max2 <= max1:
  243. # Left side survives.
  244. minimum = min2
  245. maximum = min(min1, max2)
  246. else:
  247. # Remainder leaks out from both sides. Can't cut either.
  248. return intersection, bot
  249. remainder[axisTag] = minimum, maximum
  250. if fullyInside:
  251. # bot is fully within intersection. Remainder is empty.
  252. return intersection, None
  253. return intersection, remainder
  254. def cleanupBox(box):
  255. """Return a sparse copy of `box`, without redundant (default) values.
  256. >>> cleanupBox({})
  257. {}
  258. >>> cleanupBox({'wdth': (0.0, 1.0)})
  259. {'wdth': (0.0, 1.0)}
  260. >>> cleanupBox({'wdth': (-1.0, 1.0)})
  261. {}
  262. """
  263. return {tag: limit for tag, limit in box.items() if limit != (-1.0, 1.0)}
  264. #
  265. # Low level implementation
  266. #
  267. def addFeatureVariationsRaw(font, table, conditionalSubstitutions, featureTag="rvrn"):
  268. """Low level implementation of addFeatureVariations that directly
  269. models the possibilities of the FeatureVariations table."""
  270. processLast = featureTag != "rvrn"
  271. #
  272. # if there is no <featureTag> feature:
  273. # make empty <featureTag> feature
  274. # sort features, get <featureTag> feature index
  275. # add <featureTag> feature to all scripts
  276. # make lookups
  277. # add feature variations
  278. #
  279. if table.Version < 0x00010001:
  280. table.Version = 0x00010001 # allow table.FeatureVariations
  281. table.FeatureVariations = None # delete any existing FeatureVariations
  282. varFeatureIndices = []
  283. for index, feature in enumerate(table.FeatureList.FeatureRecord):
  284. if feature.FeatureTag == featureTag:
  285. varFeatureIndices.append(index)
  286. if not varFeatureIndices:
  287. varFeature = buildFeatureRecord(featureTag, [])
  288. table.FeatureList.FeatureRecord.append(varFeature)
  289. table.FeatureList.FeatureCount = len(table.FeatureList.FeatureRecord)
  290. sortFeatureList(table)
  291. varFeatureIndex = table.FeatureList.FeatureRecord.index(varFeature)
  292. for scriptRecord in table.ScriptList.ScriptRecord:
  293. if scriptRecord.Script.DefaultLangSys is None:
  294. raise VarLibError(
  295. "Feature variations require that the script "
  296. f"'{scriptRecord.ScriptTag}' defines a default language system."
  297. )
  298. langSystems = [lsr.LangSys for lsr in scriptRecord.Script.LangSysRecord]
  299. for langSys in [scriptRecord.Script.DefaultLangSys] + langSystems:
  300. langSys.FeatureIndex.append(varFeatureIndex)
  301. langSys.FeatureCount = len(langSys.FeatureIndex)
  302. varFeatureIndices = [varFeatureIndex]
  303. axisIndices = {
  304. axis.axisTag: axisIndex for axisIndex, axis in enumerate(font["fvar"].axes)
  305. }
  306. featureVariationRecords = []
  307. for conditionSet, lookupIndices in conditionalSubstitutions:
  308. conditionTable = []
  309. for axisTag, (minValue, maxValue) in sorted(conditionSet.items()):
  310. if minValue > maxValue:
  311. raise VarLibValidationError(
  312. "A condition set has a minimum value above the maximum value."
  313. )
  314. ct = buildConditionTable(axisIndices[axisTag], minValue, maxValue)
  315. conditionTable.append(ct)
  316. records = []
  317. for varFeatureIndex in varFeatureIndices:
  318. existingLookupIndices = table.FeatureList.FeatureRecord[
  319. varFeatureIndex
  320. ].Feature.LookupListIndex
  321. combinedLookupIndices = (
  322. existingLookupIndices + lookupIndices
  323. if processLast
  324. else lookupIndices + existingLookupIndices
  325. )
  326. records.append(
  327. buildFeatureTableSubstitutionRecord(
  328. varFeatureIndex, combinedLookupIndices
  329. )
  330. )
  331. featureVariationRecords.append(
  332. buildFeatureVariationRecord(conditionTable, records)
  333. )
  334. table.FeatureVariations = buildFeatureVariations(featureVariationRecords)
  335. #
  336. # Building GSUB/FeatureVariations internals
  337. #
  338. def buildGSUB():
  339. """Build a GSUB table from scratch."""
  340. fontTable = newTable("GSUB")
  341. gsub = fontTable.table = ot.GSUB()
  342. gsub.Version = 0x00010001 # allow gsub.FeatureVariations
  343. gsub.ScriptList = ot.ScriptList()
  344. gsub.ScriptList.ScriptRecord = []
  345. gsub.FeatureList = ot.FeatureList()
  346. gsub.FeatureList.FeatureRecord = []
  347. gsub.LookupList = ot.LookupList()
  348. gsub.LookupList.Lookup = []
  349. srec = ot.ScriptRecord()
  350. srec.ScriptTag = "DFLT"
  351. srec.Script = ot.Script()
  352. srec.Script.DefaultLangSys = None
  353. srec.Script.LangSysRecord = []
  354. srec.Script.LangSysCount = 0
  355. langrec = ot.LangSysRecord()
  356. langrec.LangSys = ot.LangSys()
  357. langrec.LangSys.ReqFeatureIndex = 0xFFFF
  358. langrec.LangSys.FeatureIndex = []
  359. srec.Script.DefaultLangSys = langrec.LangSys
  360. gsub.ScriptList.ScriptRecord.append(srec)
  361. gsub.ScriptList.ScriptCount = 1
  362. gsub.FeatureVariations = None
  363. return fontTable
  364. def makeSubstitutionsHashable(conditionalSubstitutions):
  365. """Turn all the substitution dictionaries in sorted tuples of tuples so
  366. they are hashable, to detect duplicates so we don't write out redundant
  367. data."""
  368. allSubstitutions = set()
  369. condSubst = []
  370. for conditionSet, substitutionMaps in conditionalSubstitutions:
  371. substitutions = []
  372. for substitutionMap in substitutionMaps:
  373. subst = tuple(sorted(substitutionMap.items()))
  374. substitutions.append(subst)
  375. allSubstitutions.add(subst)
  376. condSubst.append((conditionSet, substitutions))
  377. return condSubst, sorted(allSubstitutions)
  378. class ShifterVisitor(TTVisitor):
  379. def __init__(self, shift):
  380. self.shift = shift
  381. @ShifterVisitor.register_attr(ot.Feature, "LookupListIndex") # GSUB/GPOS
  382. def visit(visitor, obj, attr, value):
  383. shift = visitor.shift
  384. value = [l + shift for l in value]
  385. setattr(obj, attr, value)
  386. @ShifterVisitor.register_attr(
  387. (ot.SubstLookupRecord, ot.PosLookupRecord), "LookupListIndex"
  388. )
  389. def visit(visitor, obj, attr, value):
  390. setattr(obj, attr, visitor.shift + value)
  391. def buildSubstitutionLookups(gsub, allSubstitutions, processLast=False):
  392. """Build the lookups for the glyph substitutions, return a dict mapping
  393. the substitution to lookup indices."""
  394. # Insert lookups at the beginning of the lookup vector
  395. # https://github.com/googlefonts/fontmake/issues/950
  396. firstIndex = len(gsub.LookupList.Lookup) if processLast else 0
  397. lookupMap = {}
  398. for i, substitutionMap in enumerate(allSubstitutions):
  399. lookupMap[substitutionMap] = firstIndex + i
  400. if not processLast:
  401. # Shift all lookup indices in gsub by len(allSubstitutions)
  402. shift = len(allSubstitutions)
  403. visitor = ShifterVisitor(shift)
  404. visitor.visit(gsub.FeatureList.FeatureRecord)
  405. visitor.visit(gsub.LookupList.Lookup)
  406. for i, subst in enumerate(allSubstitutions):
  407. substMap = dict(subst)
  408. lookup = buildLookup([buildSingleSubstSubtable(substMap)])
  409. if processLast:
  410. gsub.LookupList.Lookup.append(lookup)
  411. else:
  412. gsub.LookupList.Lookup.insert(i, lookup)
  413. assert gsub.LookupList.Lookup[lookupMap[subst]] is lookup
  414. gsub.LookupList.LookupCount = len(gsub.LookupList.Lookup)
  415. return lookupMap
  416. def buildFeatureVariations(featureVariationRecords):
  417. """Build the FeatureVariations subtable."""
  418. fv = ot.FeatureVariations()
  419. fv.Version = 0x00010000
  420. fv.FeatureVariationRecord = featureVariationRecords
  421. fv.FeatureVariationCount = len(featureVariationRecords)
  422. return fv
  423. def buildFeatureRecord(featureTag, lookupListIndices):
  424. """Build a FeatureRecord."""
  425. fr = ot.FeatureRecord()
  426. fr.FeatureTag = featureTag
  427. fr.Feature = ot.Feature()
  428. fr.Feature.LookupListIndex = lookupListIndices
  429. fr.Feature.populateDefaults()
  430. return fr
  431. def buildFeatureVariationRecord(conditionTable, substitutionRecords):
  432. """Build a FeatureVariationRecord."""
  433. fvr = ot.FeatureVariationRecord()
  434. fvr.ConditionSet = ot.ConditionSet()
  435. fvr.ConditionSet.ConditionTable = conditionTable
  436. fvr.ConditionSet.ConditionCount = len(conditionTable)
  437. fvr.FeatureTableSubstitution = ot.FeatureTableSubstitution()
  438. fvr.FeatureTableSubstitution.Version = 0x00010000
  439. fvr.FeatureTableSubstitution.SubstitutionRecord = substitutionRecords
  440. fvr.FeatureTableSubstitution.SubstitutionCount = len(substitutionRecords)
  441. return fvr
  442. def buildFeatureTableSubstitutionRecord(featureIndex, lookupListIndices):
  443. """Build a FeatureTableSubstitutionRecord."""
  444. ftsr = ot.FeatureTableSubstitutionRecord()
  445. ftsr.FeatureIndex = featureIndex
  446. ftsr.Feature = ot.Feature()
  447. ftsr.Feature.LookupListIndex = lookupListIndices
  448. ftsr.Feature.LookupCount = len(lookupListIndices)
  449. return ftsr
  450. def buildConditionTable(axisIndex, filterRangeMinValue, filterRangeMaxValue):
  451. """Build a ConditionTable."""
  452. ct = ot.ConditionTable()
  453. ct.Format = 1
  454. ct.AxisIndex = axisIndex
  455. ct.FilterRangeMinValue = filterRangeMinValue
  456. ct.FilterRangeMaxValue = filterRangeMaxValue
  457. return ct
  458. def sortFeatureList(table):
  459. """Sort the feature list by feature tag, and remap the feature indices
  460. elsewhere. This is needed after the feature list has been modified.
  461. """
  462. # decorate, sort, undecorate, because we need to make an index remapping table
  463. tagIndexFea = [
  464. (fea.FeatureTag, index, fea)
  465. for index, fea in enumerate(table.FeatureList.FeatureRecord)
  466. ]
  467. tagIndexFea.sort()
  468. table.FeatureList.FeatureRecord = [fea for tag, index, fea in tagIndexFea]
  469. featureRemap = dict(
  470. zip([index for tag, index, fea in tagIndexFea], range(len(tagIndexFea)))
  471. )
  472. # Remap the feature indices
  473. remapFeatures(table, featureRemap)
  474. def remapFeatures(table, featureRemap):
  475. """Go through the scripts list, and remap feature indices."""
  476. for scriptIndex, script in enumerate(table.ScriptList.ScriptRecord):
  477. defaultLangSys = script.Script.DefaultLangSys
  478. if defaultLangSys is not None:
  479. _remapLangSys(defaultLangSys, featureRemap)
  480. for langSysRecordIndex, langSysRec in enumerate(script.Script.LangSysRecord):
  481. langSys = langSysRec.LangSys
  482. _remapLangSys(langSys, featureRemap)
  483. if hasattr(table, "FeatureVariations") and table.FeatureVariations is not None:
  484. for fvr in table.FeatureVariations.FeatureVariationRecord:
  485. for ftsr in fvr.FeatureTableSubstitution.SubstitutionRecord:
  486. ftsr.FeatureIndex = featureRemap[ftsr.FeatureIndex]
  487. def _remapLangSys(langSys, featureRemap):
  488. if langSys.ReqFeatureIndex != 0xFFFF:
  489. langSys.ReqFeatureIndex = featureRemap[langSys.ReqFeatureIndex]
  490. langSys.FeatureIndex = [featureRemap[index] for index in langSys.FeatureIndex]
  491. if __name__ == "__main__":
  492. import doctest, sys
  493. sys.exit(doctest.testmod().failed)