Skip to content

Commit

Permalink
Merge pull request #3408 from miloush/main
Browse files Browse the repository at this point in the history
Merge tool improvements
  • Loading branch information
behdad committed Jan 8, 2024
2 parents 62d54b0 + 549ce73 commit 1722dab
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
54 changes: 46 additions & 8 deletions Lib/fontTools/merge/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def mergeObjects(self, returnTable, logic, tables):
*(vars(table).keys() for table in tables if table is not NotImplemented),
)
for key in allKeys:
log.info(" %s", key)
try:
mergeLogic = logic[key]
except KeyError:
Expand Down Expand Up @@ -181,17 +182,50 @@ def main(args=None):
args = sys.argv[1:]

options = Options()
args = options.parse_opts(args, ignore_unknown=["output-file"])
outfile = "merged.ttf"
args = options.parse_opts(args)
fontfiles = []
if options.input_file:
with open(options.input_file) as inputfile:
fontfiles = [
line.strip()
for line in inputfile.readlines()
if not line.lstrip().startswith("#")
]
for g in args:
if g.startswith("--output-file="):
outfile = g[14:]
continue
fontfiles.append(g)

if len(args) < 1:
print("usage: pyftmerge font...", file=sys.stderr)
if len(fontfiles) < 1:
print(
"usage: pyftmerge [font1 ... fontN] [--input-file=filelist.txt] [--output-file=merged.ttf] [--import-file=tables.ttx]",
file=sys.stderr,
)
print(
" [--drop-tables=tags] [--verbose] [--timing]",
file=sys.stderr,
)
print("", file=sys.stderr)
print(" font1 ... fontN Files to merge.", file=sys.stderr)
print(
" --input-file=<filename> Read files to merge from a text file, each path new line. # Comment lines allowed.",
file=sys.stderr,
)
print(
" --output-file=<filename> Specify output file name (default: merged.ttf).",
file=sys.stderr,
)
print(
" --import-file=<filename> TTX file to import after merging. This can be used to set metadata.",
file=sys.stderr,
)
print(
" --drop-tables=<table tags> Comma separated list of table tags to skip, case sensitive.",
file=sys.stderr,
)
print(
" --verbose Output progress information.",
file=sys.stderr,
)
print(" --timing Output progress timing.", file=sys.stderr)
return 1

configLogger(level=logging.INFO if options.verbose else logging.WARNING)
Expand All @@ -202,8 +236,12 @@ def main(args=None):

merger = Merger(options=options)
font = merger.merge(fontfiles)

if options.import_file:
font.importXML(options.import_file)

with timer("compile and save font"):
font.save(outfile)
font.save(options.output_file)


if __name__ == "__main__":
Expand Down
3 changes: 3 additions & 0 deletions Lib/fontTools/merge/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ def __init__(self, **kwargs):
self.verbose = False
self.timing = False
self.drop_tables = []
self.input_file = None
self.output_file = "merged.ttf"
self.import_file = None

self.set(**kwargs)

Expand Down

0 comments on commit 1722dab

Please sign in to comment.