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/psfdupglyphs.py | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 lib/silfont/scripts/psfdupglyphs.py (limited to 'lib/silfont/scripts/psfdupglyphs.py') diff --git a/lib/silfont/scripts/psfdupglyphs.py b/lib/silfont/scripts/psfdupglyphs.py new file mode 100644 index 0000000..1b68bee --- /dev/null +++ b/lib/silfont/scripts/psfdupglyphs.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python3 +'''Duplicates glyphs in a UFO based on a csv definition: source,target. +Duplicates everything except unicodes.''' +__url__ = 'http://github.com/silnrsi/pysilfont' +__copyright__ = 'Copyright (c) 2018 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 + +argspec = [ + ('ifont', {'help': 'Input font filename'}, {'type': 'infont'}), + ('ofont',{'help': 'Output font file','nargs': '?' }, {'type': 'outfont'}), + ('-i','--input',{'help': 'Input csv file'}, {'type': 'incsv', 'def': 'duplicates.csv'}), + ('-l','--log',{'help': 'Set log file name'}, {'type': 'outfile', 'def': '_duplicates.log'})] + +def doit(args) : + font = args.ifont + logger = args.logger + + # Process duplicates csv file into a dictionary structure + args.input.numfields = 2 + duplicates = {} + for line in args.input : + duplicates[line[0]] = line[1] + + # Iterate through dictionary (unsorted) + for source, target in duplicates.items() : + # Check if source glyph is in font + if source in font.keys() : + # Give warning if target is already in font, but overwrite anyway + if target in font.keys() : + logger.log("Warning: " + target + " already in font and will be replaced") + sourceglyph = font[source] + # Make a copy of source into a new glyph object + newglyph = sourceglyph.copy() + # Modify that glyph object + newglyph.unicodes = [] + # Add the new glyph object to the font with name target + font.__setitem__(target,newglyph) + logger.log(source + " duplicated to " + target) + else : + logger.log("Warning: " + source + " not in font") + + return font + +def cmd() : execute("FP",doit,argspec) +if __name__ == "__main__": cmd() -- cgit v1.2.3