Skip to content

Commit

Permalink
[designspace] Hack to read avar2 mapping
Browse files Browse the repository at this point in the history
This just uses list of list of dictionaries. Should use proper objects.

#3049

https://github.com/harfbuzz/boring-expansion-spec/blob/main/avar2-in-designspace.md
  • Loading branch information
behdad committed May 25, 2023
1 parent 77a35fe commit 044054a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Lib/fontTools/designspaceLib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2005,6 +2005,24 @@ def readAxes(self):
self.documentObject.axes.append(axisObject)
self.axisDefaults[axisObject.name] = axisObject.default

mappingElement = self.root.find(".axes/mapping")
self.documentObject.mapping = []
if mappingElement is not None:
for regionElement in mappingElement.findall("region"):
inputElement = regionElement.find("input")
outputElement = regionElement.find("output")
inputLoc = {}
outputLoc = {}

Check warning on line 2015 in Lib/fontTools/designspaceLib/__init__.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/designspaceLib/__init__.py#L2012-L2015

Added lines #L2012 - L2015 were not covered by tests
for dimElement in inputElement.findall(".dimension"):
tag = dimElement.attrib["tag"]
value = float(dimElement.attrib["xvalue"])
inputLoc[tag] = value

Check warning on line 2019 in Lib/fontTools/designspaceLib/__init__.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/designspaceLib/__init__.py#L2017-L2019

Added lines #L2017 - L2019 were not covered by tests
for dimElement in outputElement.findall(".dimension"):
tag = dimElement.attrib["tag"]
value = float(dimElement.attrib["xvalue"])
outputLoc[tag] = value
self.documentObject.mapping.append([inputLoc, outputLoc])

Check warning on line 2024 in Lib/fontTools/designspaceLib/__init__.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/designspaceLib/__init__.py#L2021-L2024

Added lines #L2021 - L2024 were not covered by tests

def readAxisLabel(self, element: ET.Element):
xml_attrs = {
"userminimum",
Expand Down

0 comments on commit 044054a

Please sign in to comment.