Skip to content

Instantly share code, notes, and snippets.

@typemytype
Created April 17, 2015 08:49
Show Gist options
  • Save typemytype/915ba9e00103c7e949d6 to your computer and use it in GitHub Desktop.
Save typemytype/915ba9e00103c7e949d6 to your computer and use it in GitHub Desktop.
fix Strikeout
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