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 --- lib/silfont/scripts/psfexportmarkcolors.py | 55 ++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 lib/silfont/scripts/psfexportmarkcolors.py (limited to 'lib/silfont/scripts/psfexportmarkcolors.py') diff --git a/lib/silfont/scripts/psfexportmarkcolors.py b/lib/silfont/scripts/psfexportmarkcolors.py new file mode 100755 index 0000000..98beae1 --- /dev/null +++ b/lib/silfont/scripts/psfexportmarkcolors.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python +__doc__ = '''Write mapping of glyph name to cell mark color to a csv file +- csv format glyphname,colordef''' +__url__ = 'http://github.com/silnrsi/pysilfont' +__copyright__ = 'Copyright (c) 2019 SIL International (http://www.sil.org)' +__license__ = 'Released under the MIT License (http://opensource.org/licenses/MIT)' +__author__ = 'Victor Gaultney' + +from silfont.core import execute +from silfont.util import parsecolors, colortoname +import datetime + +suffix = "_colormap" +argspec = [ + ('ifont',{'help': 'Input font file'}, {'type': 'infont'}), + ('-o','--output',{'help': 'Output csv file'}, {'type': 'outfile', 'def': suffix+'.csv'}), + ('-c','--color',{'help': 'Export list of glyphs that match color'},{}), + ('-n','--names',{'help': 'Export colors as names', 'action': 'store_true', 'default': False},{}), + ('-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) : + font = args.ifont + outfile = args.output + logger = args.logger + color = args.color + + # 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") + + if color : + (colorfilter, colorname, logcolor, splitcolor) = parsecolors(color, single=True) + if colorfilter is None : logger.log(logcolor, "S") # If color not parsed, parsecolors() puts error in logcolor + + glyphlist = font.deflayer.keys() + + for glyphn in sorted(glyphlist) : + glyph = font.deflayer[glyphn] + colordefraw = "" + colordef = "" + if glyph["lib"] : + lib = glyph["lib"] + if "public.markColor" in lib : + colordefraw = lib["public.markColor"][1].text + colordef = '"' + colordefraw + '"' + if args.names : colordef = colortoname(colordefraw, colordef) + if color : + if colorfilter == colordefraw : outfile.write(glyphn + "\n") + if not color : outfile.write(glyphn + "," + colordef + "\n") + return + +def cmd() : execute("UFO",doit,argspec) +if __name__ == "__main__": cmd() -- cgit v1.2.3