diff --git a/Lib/fontTools/designspaceLib/__init__.py b/Lib/fontTools/designspaceLib/__init__.py
index 6490a47c3..4c5be8b43 100644
--- a/Lib/fontTools/designspaceLib/__init__.py
+++ b/Lib/fontTools/designspaceLib/__init__.py
@@ -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):
diff --git a/Tests/designspaceLib/data/test.designspace b/Tests/designspaceLib/data/test.designspace
index 9f97ab57c..901a0ee06 100644
--- a/Tests/designspaceLib/data/test.designspace
+++ b/Tests/designspaceLib/data/test.designspace
@@ -5,9 +5,10 @@
Wéíght
قطر
-
+
Chasse
+
diff --git a/Tests/designspaceLib/designspace_test.py b/Tests/designspaceLib/designspace_test.py
index ffa5a69b1..2d01c6598 100644
--- a/Tests/designspaceLib/designspace_test.py
+++ b/Tests/designspaceLib/designspace_test.py
@@ -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 = """\
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ """
+ designspace = DesignSpaceDocument.fromstring(designspace_string)
+ assert designspace.findDefault().filename == "Font-Italic.ufo"