Created
April 17, 2015 08:49
-
-
Save typemytype/915ba9e00103c7e949d6 to your computer and use it in GitHub Desktop.
fix Strikeout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from fontTools.ttLib import TTFont | |
from mojo.events import addObserver | |
from ufo2fdk.fontInfoData import getAttrWithFallback | |
from ufo2fdk.outlineOTF import _roundInt | |
class FixBinaryOutput(object): | |
def __init__(self): | |
addObserver(self, "fixit", "fontDidGenerate") | |
def fixit(self, notification): | |
# get the path | |
path = notification["path"] | |
# get the font | |
font = notification["font"] | |
# load the binary font | |
binaryFont = TTFont(path) | |
# get the table | |
os2 = binaryFont["OS/2"] | |
# set correct values strikeout | |
v = getAttrWithFallback(font.info, "openTypeOS2StrikeoutSize") | |
if v is None: | |
v = 0 | |
os2.yStrikeoutSize = _roundInt(v) | |
v = getAttrWithFallback(font.info, "openTypeOS2StrikeoutPosition") | |
if v is None: | |
v = 0 | |
os2.yStrikeoutPosition = _roundInt(v) | |
# set up a temp path | |
filePath, ext = os.path.splitext(path) | |
tempPath = filePath + "_fix" + ext | |
# save the font to the temp path | |
binaryFont.save(tempPath) | |
# remove the original file | |
os.remove(filePath) | |
# rename the file back | |
os.rename(tempPath, filePath) | |
FixBinaryOutput() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment