Skip to content

Commit

Permalink
Merge pull request #137 from anthrotype/fix-use-my-metrics
Browse files Browse the repository at this point in the history
Fix autoUseMyMetrics when convertCubics=True
  • Loading branch information
Cosimo Lupo authored May 23, 2017
2 parents 2091f38 + 6f12c87 commit 412408c
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Lib/ufo2ft/outlineCompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,8 @@ def setupTable_glyf(self):
glyph.draw(Cu2QuPen(
newGlyph.getPen(), self.cubicConversionError,
reverse_direction=True))
# the width is needed for autoUseMyMetrics method below
newGlyph.width = glyph.width
allGlyphs[name] = newGlyph

self.otf["loca"] = newTable("loca")
Expand Down
42 changes: 42 additions & 0 deletions tests/data/UseMyMetrics.ufo/fontinfo.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ascender</key>
<real>2146.0</real>
<key>capHeight</key>
<real>1456.0</real>
<key>copyright</key>
<string>Copyright 2011 Google Inc. All Rights Reserved.</string>
<key>descender</key>
<real>-555.0</real>
<key>familyName</key>
<string>Roboto</string>
<key>italicAngle</key>
<integer>0</integer>
<key>openTypeNameDesigner</key>
<string>Christian Robertson</string>
<key>openTypeNameDesignerURL</key>
<string>Google.com</string>
<key>openTypeNameLicense</key>
<string>Licensed under the Apache License, Version 2.0</string>
<key>openTypeNameLicenseURL</key>
<string>http://www.apache.org/licenses/LICENSE-2.0</string>
<key>openTypeNameManufacturer</key>
<string>Google</string>
<key>openTypeNameManufacturerURL</key>
<string>Google.com</string>
<key>styleName</key>
<string>Regular</string>
<key>trademark</key>
<string>Roboto is a trademark of Google.</string>
<key>unitsPerEm</key>
<real>2048.0</real>
<key>versionMajor</key>
<integer>0</integer>
<key>versionMinor</key>
<integer>0</integer>
<key>xHeight</key>
<real>1082.0</real>
</dict>
</plist>
13 changes: 13 additions & 0 deletions tests/data/UseMyMetrics.ufo/glyphs/I_.glif
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<glyph name="I" format="2">
<advance width="557"/>
<unicode hex="0049"/>
<outline>
<contour>
<point x="376" y="1456" type="line"/>
<point x="183" y="1456" type="line"/>
<point x="183" y="0" type="line"/>
<point x="376" y="0" type="line"/>
</contour>
</outline>
</glyph>
9 changes: 9 additions & 0 deletions tests/data/UseMyMetrics.ufo/glyphs/I_acute.glif
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<glyph name="Iacute" format="2">
<advance width="557"/>
<unicode hex="00CD"/>
<outline>
<component base="acute" xOffset="81" yOffset="325"/>
<component base="I"/>
</outline>
</glyph>
13 changes: 13 additions & 0 deletions tests/data/UseMyMetrics.ufo/glyphs/acute.glif
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<glyph name="acute" format="2">
<advance width="642"/>
<unicode hex="00B4"/>
<outline>
<contour>
<point x="123" y="1242" type="line"/>
<point x="272" y="1242" type="line"/>
<point x="540" y="1536" type="line"/>
<point x="317" y="1536" type="line"/>
</contour>
</outline>
</glyph>
14 changes: 14 additions & 0 deletions tests/data/UseMyMetrics.ufo/glyphs/contents.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>I</key>
<string>I_.glif</string>
<key>Iacute</key>
<string>I_acute.glif</string>
<key>acute</key>
<string>acute.glif</string>
<key>romanthree</key>
<string>romanthree.glif</string>
</dict>
</plist>
10 changes: 10 additions & 0 deletions tests/data/UseMyMetrics.ufo/glyphs/romanthree.glif
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<glyph name="romanthree" format="2">
<advance width="1593"/>
<unicode hex="2162"/>
<outline>
<component base="I"/>
<component base="I" xOffset="517"/>
<component base="I" xOffset="1034"/>
</outline>
</glyph>
10 changes: 10 additions & 0 deletions tests/data/UseMyMetrics.ufo/layercontents.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<array>
<string>foreground</string>
<string>glyphs</string>
</array>
</array>
</plist>
10 changes: 10 additions & 0 deletions tests/data/UseMyMetrics.ufo/metainfo.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>creator</key>
<string>org.robofab.ufoLib</string>
<key>formatVersion</key>
<integer>3</integer>
</dict>
</plist>
34 changes: 32 additions & 2 deletions tests/outlineCompiler_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
from fontTools.misc.py23 import basestring
from defcon import Font
from ufo2ft.outlineCompiler import OutlineTTFCompiler, OutlineOTFCompiler
from fontTools.ttLib.tables._g_l_y_f import USE_MY_METRICS
from ufo2ft import compileTTF
import unittest
import os


def getTestUFO():
def getTestUFO(name='TestFont'):
dirname = os.path.dirname(__file__)
return Font(os.path.join(dirname, 'data', 'TestFont.ufo'))
return Font(os.path.join(dirname, 'data', name+'.ufo'))


class OutlineTTFCompilerTest(unittest.TestCase):
Expand Down Expand Up @@ -56,6 +57,35 @@ def test_makeGlyphsBoundingBoxes(self):
self.assertEqual(compiler.glyphBoundingBoxes['d'],
(90, 77, 211, 197))

def test_autoUseMyMetrics(self):
# make sure we get the same USE_MY_METRICS flags with both values of
# 'convertCubics': https://github.com/googlei18n/ufo2ft/issues/136
ufo = getTestUFO('UseMyMetrics')
for convertCubics in (False, True):
compiler = OutlineTTFCompiler(ufo, convertCubics=convertCubics)
ttf = compiler.compile()
# the first component in the 'Iacute' composite glyph ('acute')
# does _not_ have the USE_MY_METRICS flag
self.assertFalse(
ttf['glyf']['Iacute'].components[0].flags & USE_MY_METRICS)
# the second component in the 'Iacute' composite glyph ('I')
# has the USE_MY_METRICS flag set
self.assertTrue(
ttf['glyf']['Iacute'].components[1].flags & USE_MY_METRICS)
# none of the 'I' components of the 'romanthree' glyph has
# the USE_MY_METRICS flag set, because the composite glyph has a
# different width
for component in ttf['glyf']['romanthree'].components:
self.assertFalse(component.flags & USE_MY_METRICS)

def test_autoUseMyMetrics_None(self):
ufo = getTestUFO('UseMyMetrics')
compiler = OutlineTTFCompiler(ufo)
# setting 'autoUseMyMetrics' attribute to None disables the feature
compiler.autoUseMyMetrics = None
ttf = compiler.compile()
self.assertFalse(ttf['glyf']['Iacute'].components[1].flags & USE_MY_METRICS)


class OutlineOTFCompilerTest(unittest.TestCase):

Expand Down

0 comments on commit 412408c

Please sign in to comment.