blob: c072117a792dbf82468c23ef1b62a108f15ac9a6 [file] [log] [blame]
#!/usr/bin/env python3
import argparse
import logging
import os
import sys
from fontTools.ttLib import TTFont
def ProcessTable(table):
found = set()
for rec in table.ScriptList.ScriptRecord:
if rec.ScriptTag == "DFLT" and rec.Script.LangSysCount != 0:
tags = [r.LangSysTag for r in rec.Script.LangSysRecord]"Removing %d extraneous LangSys records: %s",
rec.Script.LangSysCount, " ".join(tags))
rec.Script.LangSysRecord = []
rec.Script.LangSysCount = 0
if not found:"All fine")
return False
for rec in table.ScriptList.ScriptRecord:
tags = set([r.LangSysTag for r in rec.Script.LangSysRecord])
found -= tags
if found:
logging.warning("Records are missing from non-DFLT scripts: %s",
" ".join(found))
return True
def ProcessFont(font):
found = False
for tag in ("GSUB", "GPOS"):
if tag in font:"Processing %s table", tag)
if ProcessTable(font[tag].table):
found = True
# Unmark the table as loaded so that it is read from disk when
# writing the font, to avoid any unnecessary changes caused by
# decompiling then recompiling again.
del font.tables[tag]
return found
def ProcessFiles(filenames):
for filename in filenames:"Processing %s", filename)
font = TTFont(filename)
name, ext = os.path.splitext(filename)
fixedname = name + ".fixed" + ext
if ProcessFont(font):"Saving fixed font to %s\n", fixedname)
else:"Font file is fine, nothing to fix\n")
def main():
parser = argparse.ArgumentParser(
description="Fix LangSys records for DFLT script")
parser.add_argument("files", metavar="FILE", type=str, nargs="+",
help="input font to process")
parser.add_argument("-s", "--silent", action='store_true',
help="suppress normal messages")
args = parser.parse_args()
logformat = "%(levelname)s: %(message)s"
if args.silent:
logging.basicConfig(format=logformat, level=logging.DEBUG)
logging.basicConfig(format=logformat, level=logging.INFO)
if __name__ == "__main__":