| 1 |
"""ttLib.ValueRecord: Converting ValueRecord rules to TrueType.""" |
| 2 |
|
| 3 |
from fontTools.ttLib.tables.otBase import ValueRecord as OTLValueRecord |
| 4 |
from fontTools.feaLib.variableScalar import VariableScalar |
| 5 |
from fontTools.varLib.builder import buildVarDevTable |
| 6 |
|
| 7 |
|
| 8 |
def toOTValueRecord(self, ff, pairPosContext=False): |
| 9 |
"""Converts the ValueRecord to an ``OTLValueRecord`` object. If the |
| 10 |
value record contains any variable scalars, they are saved to the |
| 11 |
GDEF variation store.""" |
| 12 |
otl_value = OTLValueRecord() |
| 13 |
if pairPosContext and not self: |
| 14 |
self.XAdvance = 0 |
| 15 |
for item in ["xPlacement", "yPlacement", "xAdvance", "yAdvance"]: |
| 16 |
itemvalue = getattr(self, item) |
| 17 |
if not itemvalue: |
| 18 |
continue |
| 19 |
item = item[0].upper() + item[1:] |
| 20 |
if isinstance(itemvalue, VariableScalar): |
| 21 |
itemvalue, index = itemvalue.add_to_variation_store(ff.varstorebuilder) |
| 22 |
if index != 0xFFFF: |
| 23 |
setattr(otl_value, item[0:4] + "Device", buildVarDevTable(index)) |
| 24 |
setattr(otl_value, item, itemvalue) |
| 25 |
return otl_value |