From da875fcb62c801b8d19b3d4d984ad963574fb356 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 2 Mar 2023 21:01:10 +0100 Subject: Adding upstream version 1.6.0. Signed-off-by: Daniel Baumann --- examples/FFmapGdlNames2.py | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 examples/FFmapGdlNames2.py (limited to 'examples/FFmapGdlNames2.py') diff --git a/examples/FFmapGdlNames2.py b/examples/FFmapGdlNames2.py new file mode 100755 index 0000000..13f1356 --- /dev/null +++ b/examples/FFmapGdlNames2.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python +'''Write mapping of graphite names to new graphite names based on: + - an original ttf font + - the gdl file produced by makeGdl when original font was produced + - a csv mapping glyph names used in original ttf to those in the new font + - pysilfont's gdl library - so assumes pysilfonts makeGdl will be used with new font''' +__url__ = 'http://github.com/silnrsi/pysilfont' +__copyright__ = 'Copyright (c) 2016 SIL International (http://www.sil.org)' +__license__ = 'Released under the MIT License (http://opensource.org/licenses/MIT)' +__author__ = 'David Raymond' + +from silfont.core import execute +import silfont.gdl.psnames as ps +import datetime + +suffix = "_mapGDLnames" +argspec = [ + ('ifont',{'help': 'Input ttf font file'}, {'type': 'infont'}), + ('-g','--gdl',{'help': 'Input gdl file'}, {'type': 'infile', 'def': '.gdl'}), + ('-m','--mapping',{'help': 'Mapping csv file'}, {'type': 'incsv', 'def': '_map.csv'}), + ('-o','--output',{'help': 'Ouput csv file'}, {'type': 'outfile', 'def': suffix+'.csv'}), + ('-l','--log',{'help': 'Log file'}, {'type': 'outfile', 'def': suffix+'.log'}), + ('--nocomments',{'help': 'No comments in output files', 'action': 'store_true', 'default': False},{})] + +def doit(args) : + logger = args.paramsobj.logger + # Check input font is a ttf + fontfile = args.cmdlineargs[1] + if fontfile[-3:] != "ttf" : + logger.log("Input font needs to be a ttf file", "S") + + font = args.ifont + gdlfile = args.gdl + mapping = args.mapping + outfile = args.output + + # Add initial comments to outfile + if not args.nocomments : + outfile.write("# " + datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S ") + args.cmdlineargs[0] + "\n") + outfile.write("# "+" ".join(args.cmdlineargs[1:])+"\n\n") + + # Process gdl file + oldgrnames = {} + for line in args.gdl : + # Look for lines of format = glyphid(nnn)... + pos = line.find(" = glyphid(") + if pos == -1 : continue + grname = line[0:pos] + gid = line[pos+11:line.find(")")] + oldgrnames[int(gid)]=grname + + # Create map from AGL name to new graphite name + newgrnames = {} + mapping.numfields = 2 + for line in mapping : + AGLname = line[1] + SILname = line[0] + grname = ps.Name(SILname).GDL() + newgrnames[AGLname] = grname + + # Find glyph names in ttf font + for glyph in font.glyphs(): + gid = glyph.originalgid + gname = glyph.glyphname + oldgrname = oldgrnames[gid] if gid in oldgrnames else None + newgrname = newgrnames[gname] if gname in newgrnames else None + outfile.write(oldgrname + "," + newgrname+"\n") + + outfile.close() + return + +execute("FF",doit, argspec) -- cgit v1.2.3