Merge pull request #1535 from fonttools/designspaceLib-find-bent-master
designspaceLib, findDefault: consider axis mapping
This commit is contained in:
commit
1765e59f86
@ -1128,11 +1128,14 @@ class DesignSpaceDocument(LogMixin, AsDictMixin):
|
||||
self.rules.append(ruleDescriptor)
|
||||
|
||||
def newDefaultLocation(self):
|
||||
"""Return default location in design space."""
|
||||
# Without OrderedDict, output XML would be non-deterministic.
|
||||
# https://github.com/LettError/designSpaceDocument/issues/10
|
||||
loc = collections.OrderedDict()
|
||||
for axisDescriptor in self.axes:
|
||||
loc[axisDescriptor.name] = axisDescriptor.default
|
||||
loc[axisDescriptor.name] = axisDescriptor.map_forward(
|
||||
axisDescriptor.default
|
||||
)
|
||||
return loc
|
||||
|
||||
def updateFilenameFromPath(self, masters=True, instances=True, force=False):
|
||||
@ -1176,15 +1179,25 @@ 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).
|
||||
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):
|
||||
|
@ -5,9 +5,10 @@
|
||||
<labelname xml:lang="en">Wéíght</labelname>
|
||||
<labelname xml:lang="fa-IR">قطر</labelname>
|
||||
</axis>
|
||||
<axis tag="wdth" name="width" minimum="0" maximum="1000" default="20" hidden="1">
|
||||
<axis tag="wdth" name="width" minimum="0" maximum="1000" default="15" hidden="1">
|
||||
<labelname xml:lang="fr">Chasse</labelname>
|
||||
<map input="0" output="10"/>
|
||||
<map input="15" output="20"/>
|
||||
<map input="401" output="66"/>
|
||||
<map input="1000" output="990"/>
|
||||
</axis>
|
||||
|
@ -66,10 +66,10 @@ def test_fill_document(tmpdir):
|
||||
a2 = AxisDescriptor()
|
||||
a2.minimum = 0
|
||||
a2.maximum = 1000
|
||||
a2.default = 20
|
||||
a2.default = 15
|
||||
a2.name = "width"
|
||||
a2.tag = "wdth"
|
||||
a2.map = [(0.0, 10.0), (401.0, 66.0), (1000.0, 990.0)]
|
||||
a2.map = [(0.0, 10.0), (15.0, 20.0), (401.0, 66.0), (1000.0, 990.0)]
|
||||
a2.hidden = True
|
||||
a2.labelNames[u'fr'] = u"Chasse"
|
||||
doc.addAxis(a2)
|
||||
@ -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