diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-03-02 20:01:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-03-02 20:01:10 +0000 |
commit | da875fcb62c801b8d19b3d4d984ad963574fb356 (patch) | |
tree | 3d85503747c56c2a387b291524442946f4bebb73 /lib/silfont/scripts/psfexportmarkcolors.py | |
parent | Initial commit. (diff) | |
download | pysilfont-1f9ed76662986bf6e3802e9fb3080d61e5797532.tar.xz pysilfont-1f9ed76662986bf6e3802e9fb3080d61e5797532.zip |
Adding upstream version 1.6.0.upstream/1.6.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rwxr-xr-x | lib/silfont/scripts/psfexportmarkcolors.py | 55 |
1 files changed, 55 insertions, 0 deletions
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() |