From 24b45b6326c46d6b4c97b351beee7e015a82278c Mon Sep 17 00:00:00 2001 From: justvanrossum Date: Wed, 6 Mar 2019 17:20:40 +0100 Subject: [PATCH 01/23] fix embedded license URL in name tables of test fonts --- Tests/ttLib/data/TestOTF-Regular.otx | 4 ++-- Tests/ttLib/data/TestTTF-Regular.ttx | 4 ++-- Tests/ttx/data/TestOTF.ttx | 4 ++-- Tests/ttx/data/TestTTF.ttx | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Tests/ttLib/data/TestOTF-Regular.otx b/Tests/ttLib/data/TestOTF-Regular.otx index bceaf4ab7..92e0b2f60 100644 --- a/Tests/ttLib/data/TestOTF-Regular.otx +++ b/Tests/ttLib/data/TestOTF-Regular.otx @@ -148,7 +148,7 @@ https://github.com/fonttools/fonttools - https://github.com/fonttools/fonttools/blob/master/LICENSE.txt + https://github.com/fonttools/fonttools/blob/master/LICENSE Test TTF @@ -190,7 +190,7 @@ https://github.com/fonttools/fonttools - https://github.com/fonttools/fonttools/blob/master/LICENSE.txt + https://github.com/fonttools/fonttools/blob/master/LICENSE diff --git a/Tests/ttLib/data/TestTTF-Regular.ttx b/Tests/ttLib/data/TestTTF-Regular.ttx index b4928ef48..1f1dd2b49 100644 --- a/Tests/ttLib/data/TestTTF-Regular.ttx +++ b/Tests/ttLib/data/TestTTF-Regular.ttx @@ -468,7 +468,7 @@ https://github.com/fonttools/fonttools - https://github.com/fonttools/fonttools/blob/master/LICENSE.txt + https://github.com/fonttools/fonttools/blob/master/LICENSE Test TTF @@ -510,7 +510,7 @@ https://github.com/fonttools/fonttools - https://github.com/fonttools/fonttools/blob/master/LICENSE.txt + https://github.com/fonttools/fonttools/blob/master/LICENSE diff --git a/Tests/ttx/data/TestOTF.ttx b/Tests/ttx/data/TestOTF.ttx index 1d84b5932..96f184497 100644 --- a/Tests/ttx/data/TestOTF.ttx +++ b/Tests/ttx/data/TestOTF.ttx @@ -148,7 +148,7 @@ https://github.com/fonttools/fonttools - https://github.com/fonttools/fonttools/blob/master/LICENSE.txt + https://github.com/fonttools/fonttools/blob/master/LICENSE Test TTF @@ -190,7 +190,7 @@ https://github.com/fonttools/fonttools - https://github.com/fonttools/fonttools/blob/master/LICENSE.txt + https://github.com/fonttools/fonttools/blob/master/LICENSE diff --git a/Tests/ttx/data/TestTTF.ttx b/Tests/ttx/data/TestTTF.ttx index 38c78d5dc..66caf6ce8 100644 --- a/Tests/ttx/data/TestTTF.ttx +++ b/Tests/ttx/data/TestTTF.ttx @@ -468,7 +468,7 @@ https://github.com/fonttools/fonttools - https://github.com/fonttools/fonttools/blob/master/LICENSE.txt + https://github.com/fonttools/fonttools/blob/master/LICENSE Test TTF @@ -510,7 +510,7 @@ https://github.com/fonttools/fonttools - https://github.com/fonttools/fonttools/blob/master/LICENSE.txt + https://github.com/fonttools/fonttools/blob/master/LICENSE From c4899330c552fb9a7db0d05a50074004d6fa2805 Mon Sep 17 00:00:00 2001 From: Nikolaus Waxweiler Date: Sun, 10 Mar 2019 22:12:06 +0000 Subject: [PATCH 02/23] designspaceLib, findDefault: consider axis mapping --- Lib/fontTools/designspaceLib/__init__.py | 21 +++++++-- Tests/designspaceLib/designspace_test.py | 58 ++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/Lib/fontTools/designspaceLib/__init__.py b/Lib/fontTools/designspaceLib/__init__.py index 6490a47c3..02cc05811 100644 --- a/Lib/fontTools/designspaceLib/__init__.py +++ b/Lib/fontTools/designspaceLib/__init__.py @@ -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): diff --git a/Tests/designspaceLib/designspace_test.py b/Tests/designspaceLib/designspace_test.py index ffa5a69b1..30bbfa0c5 100644 --- a/Tests/designspaceLib/designspace_test.py +++ b/Tests/designspaceLib/designspace_test.py @@ -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" From 5f7afa23b224052a114f83018853746b051c4bf2 Mon Sep 17 00:00:00 2001 From: Nikolaus Waxweiler Date: Sun, 10 Mar 2019 22:20:00 +0000 Subject: [PATCH 03/23] newDefaultLocation: Return location in design space --- Lib/fontTools/designspaceLib/__init__.py | 5 ++++- Tests/designspaceLib/data/test.designspace | 3 ++- Tests/designspaceLib/designspace_test.py | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Lib/fontTools/designspaceLib/__init__.py b/Lib/fontTools/designspaceLib/__init__.py index 02cc05811..57c0c0b06 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): 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 قطر -