Skip to content

Commit

Permalink
Merge pull request googlefonts#239 from moyogo/postscriptWeightName
Browse files Browse the repository at this point in the history
CFF topDict Weight is optional, fallback to None
  • Loading branch information
moyogo authored Mar 30, 2018
2 parents 8ba91ce + 6a979a9 commit 5c13d7f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 40 deletions.
42 changes: 2 additions & 40 deletions Lib/ufo2ft/fontInfoData.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import unicodedata
import os

from fontTools.misc.py23 import tobytes, tostr, tounicode, unichr, round, round2
from fontTools.misc.py23 import tobytes, tostr, tounicode, unichr, round
from fontTools.misc.textTools import binary2num
import ufoLib

Expand Down Expand Up @@ -245,44 +245,6 @@ def postscriptUnderlinePositionFallback(info):
'Underline position not set in UFO, defaulting to UPM * -0.075')
return info.unitsPerEm * -0.075

_postscriptWeightNameOptions = {
100 : "Thin",
200 : "Extra-light",
300 : "Light",
400 : "Normal",
500 : "Medium",
600 : "Semi-bold",
700 : "Bold",
800 : "Extra-bold",
900 : "Black"
}

def postscriptWeightNameFallback(info):
"""
Fallback to the closest match of the *openTypeOS2WeightClass*
in this table:
=== ===========
100 Thin
200 Extra-light
300 Light
400 Normal
500 Medium
600 Semi-bold
700 Bold
800 Extra-bold
900 Black
=== ===========
"""
value = getAttrWithFallback(info, "openTypeOS2WeightClass")
value = int(round2(value, -2))
if value < 100:
value = 100
elif value > 900:
value = 900
name = _postscriptWeightNameOptions[value]
return name

def postscriptBlueScaleFallback(info):
"""
Fallback to a calculated value: 3/(4 * *maxZoneHeight*)
Expand Down Expand Up @@ -368,6 +330,7 @@ def postscriptBlueScaleFallback(info):
openTypeVheaCaretOffset=None,

postscriptUniqueID=None,
postscriptWeightName=None,
postscriptIsFixedPitch=False,
postscriptBlueValues=[],
postscriptOtherBlues=[],
Expand Down Expand Up @@ -414,7 +377,6 @@ def postscriptBlueScaleFallback(info):
postscriptSlantAngle=postscriptSlantAngleFallback,
postscriptUnderlineThickness=postscriptUnderlineThicknessFallback,
postscriptUnderlinePosition=postscriptUnderlinePositionFallback,
postscriptWeightName=postscriptWeightNameFallback,
postscriptBlueScale=postscriptBlueScaleFallback
)

Expand Down
8 changes: 8 additions & 0 deletions tests/fontInfoData_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ def test_redundant_metadata(self):
"1.001;NONE;FamilyName-StyleName")

self.assertEqual(getAttrWithFallback(info, "postscriptSlantAngle"), 0)

def test_unecessary_metadata(self):
info = TestInfoObject()

self.assertEqual(
getAttrWithFallback(info, "postscriptWeightName"),
None)
info.postscriptWeightName = "Normal"
self.assertEqual(
getAttrWithFallback(info, "postscriptWeightName"),
"Normal")
Expand Down

0 comments on commit 5c13d7f

Please sign in to comment.