designspaceLib, findDefault: consider axis mapping
This commit is contained in:
parent
9efbb0e74e
commit
c4899330c5
@ -1176,15 +1176,26 @@ class DesignSpaceDocument(LogMixin, AsDictMixin):
|
||||
return None
|
||||
|
||||
def findDefault(self):
|
||||
# new default finder
|
||||
# take the sourcedescriptor with the location at all the defaults
|
||||
# if we can't find it, return None, let someone else figure it out
|
||||
"""Set and return SourceDescriptor at the default location or None.
|
||||
|
||||
The default location is the set of all `default` values in user space
|
||||
of all axes.
|
||||
"""
|
||||
self.default = None
|
||||
|
||||
# Convert the default location from user space to design space before comparing
|
||||
# it against the SourceDescriptor locations (always in design space).
|
||||
# Note: given no map, piecewiseLinearMap will simply return the value.
|
||||
default_location_design = {
|
||||
axis.name: axis.map_forward(self.defaultLoc[axis.name])
|
||||
for axis in self.axes
|
||||
}
|
||||
|
||||
for sourceDescriptor in self.sources:
|
||||
if sourceDescriptor.location == self.defaultLoc:
|
||||
# we choose you!
|
||||
if sourceDescriptor.location == default_location_design:
|
||||
self.default = sourceDescriptor
|
||||
return sourceDescriptor
|
||||
|
||||
return None
|
||||
|
||||
def normalizeLocation(self, location):
|
||||
|
@ -847,3 +847,61 @@ def test_with_with_path_object(tmpdir):
|
||||
doc = DesignSpaceDocument()
|
||||
doc.write(dest)
|
||||
assert dest.exists()
|
||||
|
||||
|
||||
def test_findDefault_axis_mapping():
|
||||
designspace_string = """\
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<designspace format="4.0">
|
||||
<axes>
|
||||
<axis tag="wght" name="Weight" minimum="100" maximum="800" default="400">
|
||||
<map input="100" output="20"/>
|
||||
<map input="300" output="40"/>
|
||||
<map input="400" output="80"/>
|
||||
<map input="700" output="126"/>
|
||||
<map input="800" output="170"/>
|
||||
</axis>
|
||||
<axis tag="ital" name="Italic" minimum="0" maximum="1" default="1"/>
|
||||
</axes>
|
||||
<sources>
|
||||
<source filename="Font-Light.ufo">
|
||||
<location>
|
||||
<dimension name="Weight" xvalue="20"/>
|
||||
<dimension name="Italic" xvalue="0"/>
|
||||
</location>
|
||||
</source>
|
||||
<source filename="Font-Regular.ufo">
|
||||
<location>
|
||||
<dimension name="Weight" xvalue="80"/>
|
||||
<dimension name="Italic" xvalue="0"/>
|
||||
</location>
|
||||
</source>
|
||||
<source filename="Font-Bold.ufo">
|
||||
<location>
|
||||
<dimension name="Weight" xvalue="170"/>
|
||||
<dimension name="Italic" xvalue="0"/>
|
||||
</location>
|
||||
</source>
|
||||
<source filename="Font-LightItalic.ufo">
|
||||
<location>
|
||||
<dimension name="Weight" xvalue="20"/>
|
||||
<dimension name="Italic" xvalue="1"/>
|
||||
</location>
|
||||
</source>
|
||||
<source filename="Font-Italic.ufo">
|
||||
<location>
|
||||
<dimension name="Weight" xvalue="80"/>
|
||||
<dimension name="Italic" xvalue="1"/>
|
||||
</location>
|
||||
</source>
|
||||
<source filename="Font-BoldItalic.ufo">
|
||||
<location>
|
||||
<dimension name="Weight" xvalue="170"/>
|
||||
<dimension name="Italic" xvalue="1"/>
|
||||
</location>
|
||||
</source>
|
||||
</sources>
|
||||
</designspace>
|
||||
"""
|
||||
designspace = DesignSpaceDocument.fromstring(designspace_string)
|
||||
assert designspace.findDefault().filename == "Font-Italic.ufo"
|
||||
|
Loading…
x
Reference in New Issue
Block a user