2015-07-06 21:52:43 +03:00
# This python script finds and replaces the flags="0x0" with flags="0x4" to set the ROUND_XY_TO_GRID bit in a TTF. It then removes any NAME table IDs with a PlatformID="1" attribute
2015-03-20 11:25:08 +03:00
import os
import sys
from fontTools . ttLib import TTFont
from fontTools . ttx import makeOutputFileName
2015-03-11 21:15:29 +03:00
2015-03-20 11:25:08 +03:00
inputTTF = sys . argv [ 1 ]
2015-03-11 21:15:29 +03:00
# open the source file and read it
2015-03-20 11:25:08 +03:00
font = TTFont ( inputTTF )
extension = os . path . splitext ( inputTTF ) [ 1 ]
2015-07-06 21:52:43 +03:00
# Set ROUND_XY_TO_GRID flag
2015-03-20 11:25:08 +03:00
if ' glyf ' in font :
glyf = font [ ' glyf ' ]
for glyphname in glyf . glyphs :
glyph = glyf . glyphs [ glyphname ]
if glyph . isComposite ( ) :
glyph . expand ( glyf )
for component in glyph . components :
2015-03-22 18:07:06 +03:00
component . flags | = 0x4
2015-03-20 11:25:08 +03:00
glyph . compact ( glyf )
2015-07-06 21:52:43 +03:00
# Remove NAME table IDs with a PlatformID="1" attribute
records = [ ]
for record in font [ ' name ' ] . names :
if record . platformID == 1 :
continue
records . append ( record )
font [ ' name ' ] . names = records
2015-03-20 11:25:08 +03:00
outputTTF = makeOutputFileName ( inputTTF , ' ' , extension )
2015-07-06 21:52:43 +03:00
font . save ( outputTTF )