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 /examples/fontforge-old | |
parent | Initial commit. (diff) | |
download | pysilfont-upstream.tar.xz pysilfont-upstream.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 | examples/fontforge-old/FFaddPUA.py | 31 | ||||
-rwxr-xr-x | examples/fontforge-old/FFcheckDupUSV.py | 62 | ||||
-rwxr-xr-x | examples/fontforge-old/FFcolourGlyphs.py | 51 | ||||
-rwxr-xr-x | examples/fontforge-old/FFcompareFonts.py | 44 | ||||
-rwxr-xr-x | examples/fontforge-old/FFdblEncode.py | 48 | ||||
-rwxr-xr-x | examples/fontforge-old/FFfromAP.py | 74 | ||||
-rwxr-xr-x | examples/fontforge-old/FFlistAPNum.py | 38 | ||||
-rwxr-xr-x | examples/fontforge-old/FFlistGlyphNames.py | 22 | ||||
-rwxr-xr-x | examples/fontforge-old/FFlistGlyphinfo.py | 61 | ||||
-rwxr-xr-x | examples/fontforge-old/FFlistRefNum.py | 33 | ||||
-rwxr-xr-x | examples/fontforge-old/FFnameSearchNReplace.py | 38 | ||||
-rwxr-xr-x | examples/fontforge-old/FFundblEncode.py | 50 | ||||
-rwxr-xr-x | examples/fontforge-old/demoAddToMenu.py | 38 | ||||
-rwxr-xr-x | examples/fontforge-old/demoExecuteScript.py | 29 | ||||
-rwxr-xr-x | examples/fontforge-old/demoFunctions.py | 90 |
15 files changed, 709 insertions, 0 deletions
diff --git a/examples/fontforge-old/FFaddPUA.py b/examples/fontforge-old/FFaddPUA.py new file mode 100755 index 0000000..6bd4a96 --- /dev/null +++ b/examples/fontforge-old/FFaddPUA.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python +'''FontForge: Add cmap entries for all glyphs in the 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__ = 'Martin Hosken' + +from silfont.core import execute + +argspec = [ + ('ifont',{'help': 'Input font file'}, {'type': 'infont'}), + ('ofont',{'help': 'Output font file','nargs': '?' }, {'type': 'outfont', 'def': 'new'}) +] + +def nextpua(p) : + if p == 0 : return 0xE000 + if p == 0xF8FF : return 0xF0000 + return p + 1 + +def doit(args) : + p = nextpua(0) + font = args.ifont + for n in font : + g = font[n] + if g.unicode == -1 : + g.unicode = p + p = nextpua(p) + return font + +def cmd() : execute("FF",doit,argspec) +if __name__ == "__main__": cmd() diff --git a/examples/fontforge-old/FFcheckDupUSV.py b/examples/fontforge-old/FFcheckDupUSV.py new file mode 100755 index 0000000..d6d948c --- /dev/null +++ b/examples/fontforge-old/FFcheckDupUSV.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +'FontForge: Check for duplicate USVs in unicode or altuni fields' +__url__ = 'http://github.com/silnrsi/pysilfont' +__copyright__ = 'Copyright (c) 2015 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 + +argspec = [ + ('ifont',{'help': 'Input font file'}, {'type': 'infont'}), + ('-o','--output',{'help': 'Output text file'}, {'type': 'outfile', 'def': 'DupUSV.txt'})] + +def doit(args) : + font = args.ifont + outf = args.output + + # Process unicode and altunicode for all glyphs + usvs={} + for glyph in font: + g = font[glyph] + if g.unicode != -1: + usv=UniStr(g.unicode) + AddUSV(usvs,usv,glyph) + # Check any alternate usvs + altuni=g.altuni + if altuni != None: + for au in altuni: + usv=UniStr(au[0]) # (may need to check variant flag) + AddUSV(usvs,usv,glyph + ' (alt)') + + items = usvs.items() + items = filter(lambda x: len(x[1]) > 1, items) + items.sort() + + for i in items: + usv = i[0] + print usv + ' has duplicates' + gl = i[1] + glyphs = gl[0] + for j in range(1,len(gl)): + glyphs = glyphs + ', ' + gl[j] + + outf.write('%s: %s\n' % (usv,glyphs)) + + outf.close() + print "Done!" + +def UniStr(u): + if u: + return "U+{0:04X}".format(u) + else: + return "No USV" #length same as above + +def AddUSV(usvs,usv,glyph): + if not usvs.has_key(usv): + usvs[usv] = [glyph] + else: + usvs[usv].append(glyph) + +def cmd() : execute("FF",doit,argspec) +if __name__ == "__main__": cmd() diff --git a/examples/fontforge-old/FFcolourGlyphs.py b/examples/fontforge-old/FFcolourGlyphs.py new file mode 100755 index 0000000..e49594b --- /dev/null +++ b/examples/fontforge-old/FFcolourGlyphs.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +'Set Glyph colours based on a csv file - format glyphname,colour' +__url__ = 'http://github.com/silnrsi/pysilfont' +__copyright__ = 'Copyright (c) 2015 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 + +argspec = [ + ('ifont',{'help': 'Input font file'}, {'type': 'infont'}), + ('ofont',{'help': 'Output font file','nargs': '?' }, {'type': 'outfont', 'def': 'new'}), + ('-i','--input',{'help': 'Input csv file'}, {'type': 'infile', 'def': 'colourGlyphs.csv'}), + ('-l','--log',{'help': 'Log file'}, {'type': 'outfile', 'def': 'colourGlyphs.log'})] + +def doit(args) : + font=args.ifont + inpf = args.input + logf = args.log +# define colours + colours = { + 'black' :0x000000, + 'red' :0xFF0000, + 'green' :0x00FF00, + 'blue' :0x0000FF, + 'cyan' :0x00FFFF, + 'magenta':0xFF00FF, + 'yellow' :0xFFFF00, + 'white' :0xFFFFFF } + +# Change colour of Glyphs + for line in inpf.readlines() : + glyphn, colour = line.strip().split(",") # will exception if not 2 elements + colour=colour.lower() + if glyphn[0] in '"\'' : glyphn = glyphn[1:-1] # slice off quote marks, if present + if glyphn not in font: + logf.write("Glyph %s not in font\n" % (glyphn)) + print "Glyph %s not in font" % (glyphn) + continue + g = font[glyphn] + if colour in colours.keys(): + g.color=colours[colour] + else: + logf.write("Glyph: %s - non-standard colour %s\n" % (glyphn,colour)) + print "Glyph: %s - non-standard colour %s" % (glyphn,colour) + + logf.close() + return font + +def cmd() : execute("FF",doit,argspec) +if __name__ == "__main__": cmd() diff --git a/examples/fontforge-old/FFcompareFonts.py b/examples/fontforge-old/FFcompareFonts.py new file mode 100755 index 0000000..66f2079 --- /dev/null +++ b/examples/fontforge-old/FFcompareFonts.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +'Compare two fonts based on specified criteria and report differences' +__url__ = 'http://github.com/silnrsi/pysilfont' +__copyright__ = 'Copyright (c) 2015 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 + +argspec = [ + ('ifont',{'help': 'Input font file'}, {'type': 'infont'}), + ('ifont2',{'help': 'Input font file 2'}, {'type': 'infont', 'def': 'new'}), + ('-l','--log',{'help': 'Log file'}, {'type': 'outfile', 'def': 'compareFonts.log'}), + ('-o','--options',{'help': 'Options', 'choices': ['c'], 'nargs': '*'}, {}) + ] + +def doit(args) : + font1=args.ifont + font2=args.ifont2 + logf = args.log + options = args.options + logf.write("Comparing fonts: \n %s (%s)\n %s (%s)\n" % (font1.path,font1.fontname,font2.path,font2.fontname)) + if options != None : logf.write('with options: %s\n' % (options)) + logf.write("\n") + compare(font1,font2,logf,options) + compare(font2,font1,logf,None) # Compare again the other way around, just looking for missing Glyphs + logf.close() + return + +def compare(fonta,fontb,logf,options) : + for glyph in fonta : + if glyph in fontb : + if options != None : # Do extra checks based on options supplied + ga=fonta[glyph] + gb=fontb[glyph] + for opt in options : + if opt == "c" : + if len(ga.references) != len(gb.references) : + logf.write("Glyph %s: number of components is different - %s v %s\n" % (glyph,len(ga.references),len(gb.references))) + else : + logf.write("Glyph %s missing from %s\n" % (glyph,fonta.path)) + +def cmd() : execute("FF",doit,argspec) +if __name__ == "__main__": cmd() diff --git a/examples/fontforge-old/FFdblEncode.py b/examples/fontforge-old/FFdblEncode.py new file mode 100755 index 0000000..781267b --- /dev/null +++ b/examples/fontforge-old/FFdblEncode.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python +'''FontForge: Double encode glyphs based on double encoding data in a file +Lines in file should look like: "LtnSmARetrHook",U+F236,U+1D8F''' +__url__ = 'http://github.com/silnrsi/pysilfont' +__copyright__ = 'Copyright (c) 2015 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 + +argspec = [ + ('ifont',{'help': 'Input font file'}, {'type': 'infont'}), + ('ofont',{'help': 'Output font file','nargs': '?' }, {'type': 'outfont', 'def': 'new'}), + ('-i','--input',{'help': 'Input csv text file'}, {'type': 'infile', 'def': 'DblEnc.txt'}), + ('-l','--log',{'help': 'Log file'}, {'type': 'outfile', 'def': 'DblEnc.log'})] + +def doit(args) : + font = args.ifont + inpf = args.input + logf = args.log +#Create dbl_encode list from the input file + dbl_encode = {} + for line in inpf.readlines() : + glyphn, pua_usv_str, std_usv_str = line.strip().split(",") # will exception if not 3 elements + if glyphn[0] in '"\'' : glyphn = glyphn[1:-1] # slice off quote marks, if present + pua_usv, std_usv = int(pua_usv_str[2:], 16), int(std_usv_str[2:], 16) + dbl_encode[glyphn] = [std_usv, pua_usv] + inpf.close() + + for glyph in sorted(dbl_encode.keys()) : + if glyph not in font: + logf.write("Glyph %s not in font\n" % (glyph)) + continue + g = font[glyph] + ousvs=[g.unicode] + oalt=g.altuni + if oalt != None: + for au in oalt: + ousvs.append(au[0]) # (may need to check variant flag) + dbl = dbl_encode[glyph] + g.unicode = dbl[0] + g.altuni = ((dbl[1],),) + logf.write("encoding for %s changed: %s -> %s\n" % (glyph, ousvs, dbl)) + logf.close() + return font + +def cmd() : execute("FF",doit,argspec) +if __name__ == "__main__": cmd() diff --git a/examples/fontforge-old/FFfromAP.py b/examples/fontforge-old/FFfromAP.py new file mode 100755 index 0000000..ab66a29 --- /dev/null +++ b/examples/fontforge-old/FFfromAP.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python +'''Import Attachment Point database into a fontforge font''' +__url__ = 'http://github.com/silnrsi/pysilfont' +__copyright__ = 'Copyright (c) 2015 SIL International (http://www.sil.org)' +__license__ = 'Released under the MIT License (http://opensource.org/licenses/MIT)' +__author__ = 'Martin Hosken' + +from silfont.core import execute + +argspec = [ + ('ifont', {'help': 'Input font file'}, {'type': 'infont'}), + ('ofont', {'help': 'Output font file'}, {'type': 'outfont'}), + ('-a','--ap', {'nargs' : 1, 'help': 'Input AP database (required)'}, {}) +] + +def assign(varlist, expr) : + """passes a variable to be assigned as a list and returns the value""" + varlist[0] = expr + return expr + +def getuidenc(e, f) : + if 'UID' in e.attrib : + u = int(e.get('UID'), 16) + return f.findEncodingSlot(u) + else : + return -1 + +def getgid(e, f) : + if 'GID' in e.attrib : + return int(e.get('GID')) + else : + return -1 + +def doit(args) : + from xml.etree.ElementTree import parse + + f = args.ifont + g = None + etree = parse(args.ap) + u = [] + for e in etree.getroot().iterfind("glyph") : + name = e.get('PSName') + if name in f : + g = f[name] + elif assign(u, getuidenc(e, f)) != -1 : + g = f[u[0]] + elif assign(u, getgid(e, f)) != -1 : + g = f[u[0]] + elif g is not None : # assume a rename so just take next glyph + g = f[g.encoding + 1] + else : + g = f[0] + g.name = name + g.anchorPoints = () + for p in e.iterfind('point') : + pname = p.get('type') + l = p[0] + x = int(l.get('x')) + y = int(l.get('y')) + if pname.startswith('_') : + ptype = 'mark' + pname = pname[1:] + else : + ptype = 'base' + g.addAnchorPoint(pname, ptype, float(x), float(y)) + comment = [] + for p in e.iterfind('property') : + comment.append("{}: {}".format(e.get('name'), e.get('value'))) + for p in e.iterfind('note') : + comment.append(e.text.strip()) + g.comment = "\n".join(comment) + +def cmd() : execute("FF",doit,argspec) +if __name__ == "__main__": cmd() diff --git a/examples/fontforge-old/FFlistAPNum.py b/examples/fontforge-old/FFlistAPNum.py new file mode 100755 index 0000000..ebba84b --- /dev/null +++ b/examples/fontforge-old/FFlistAPNum.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +'FontForge: Report Glyph name, number of anchors - sorted by number of anchors' +__url__ = 'http://github.com/silnrsi/pysilfont' +__copyright__ = 'Copyright (c) 2015 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 + +argspec = [ + ('ifont',{'help': 'Input font file'}, {'type': 'infont'}), + ('-o','--output',{'help': 'Output text file'}, {'type': 'outfile', 'def': 'APnum.txt'})] + +def doit(args) : + font = args.ifont + outf = args.output + + # Make a list of glyphs and number of anchor points + AP_lst = [] + for glyph in font: + AP_lst.append( [glyph, len(font[glyph].anchorPoints)] ) + # Sort by numb of APs then glyphname + AP_lst.sort(AP_cmp) + for AP in AP_lst: + outf.write("%s,%s\n" % (AP[0], AP[1])) + + outf.close() + print "done" + +def AP_cmp(a, b): # Comparison to sort first by number of attachment points) then by Glyph name + c = cmp(a[1], b[1]) + if c != 0: + return c + else: + return cmp(a[0], b[0]) + +def cmd() : execute("FF",doit,argspec) +if __name__ == "__main__": cmd() diff --git a/examples/fontforge-old/FFlistGlyphNames.py b/examples/fontforge-old/FFlistGlyphNames.py new file mode 100755 index 0000000..3967df0 --- /dev/null +++ b/examples/fontforge-old/FFlistGlyphNames.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +'FontForge: List all gyphs with encoding and name' +__url__ = 'http://github.com/silnrsi/pysilfont' +__copyright__ = 'Copyright (c) 2015 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 + +argspec = [ + ('ifont',{'help': 'Input font file'}, {'type': 'infont'}), + ('-o','--output',{'help': 'Output text file'}, {'type': 'outfile', 'def': 'Gnames.txt'})] + +def doit(args) : + outf = args.output + for glyph in args.ifont: + g = args.ifont[glyph] + outf.write('%s: %s, %s\n' % (glyph, g.encoding, g.glyphname)) + outf.close() + +def cmd() : execute("FF",doit,argspec) +if __name__ == "__main__": cmd() diff --git a/examples/fontforge-old/FFlistGlyphinfo.py b/examples/fontforge-old/FFlistGlyphinfo.py new file mode 100755 index 0000000..00736b8 --- /dev/null +++ b/examples/fontforge-old/FFlistGlyphinfo.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python +'FontForge: List all the data in a glyph object in key, value pairs' +__url__ = 'http://github.com/silnrsi/pysilfont' +__copyright__ = 'Copyright (c) 2015 SIL International (http://www.sil.org)' +__license__ = 'Released under the MIT License (http://opensource.org/licenses/MIT)' +__author__ = 'David Raymond' + +import fontforge, types, sys +from silfont.core import execute + +argspec = [ + ('font',{'help': 'Input font file'}, {'type': 'infont'}), + ('-o','--output',{'help': 'Output text file'}, {'type': 'outfile', 'def': 'glyphinfo.txt'})] + + +def doit(args) : + font=args.font + outf = args.output + + glyphn = raw_input("Glyph name or number: ") + + while glyphn: + + isglyph=True + if not(glyphn in font): + try: + glyphn=int(glyphn) + except ValueError: + isglyph=False + else: + if not(glyphn in font): + isglyph=False + + if isglyph: + g=font[glyphn] + outf.write("\n%s\n\n" % glyphn) + # Write to file all normal key,value pairs - exclude __ and built in functions + for k in dir(g): + if k[0:2] == "__": continue + attrk=getattr(g,k) + if attrk is None: continue + tk=type(attrk) + if tk == types.BuiltinFunctionType: continue + if k == "ttinstrs": # ttinstr values are not printable characters + outf.write("%s,%s\n" % (k,"<has values>")) + else: + outf.write("%s,%s\n" % (k,attrk)) + # Write out all normal keys where value is none + for k in dir(g): + attrk=getattr(g,k) + if attrk is None: + outf.write("%s,%s\n" % (k,attrk)) + else: + print "Invalid glyph" + + glyphn = raw_input("Glyph name or number: ") + print "done" + outf.close + +def cmd() : execute("FF",doit,argspec) +if __name__ == "__main__": cmd() diff --git a/examples/fontforge-old/FFlistRefNum.py b/examples/fontforge-old/FFlistRefNum.py new file mode 100755 index 0000000..e709781 --- /dev/null +++ b/examples/fontforge-old/FFlistRefNum.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +'FontForge: Report Glyph name, Number of references (components)' +__url__ = 'http://github.com/silnrsi/pysilfont' +__copyright__ = 'Copyright (c) 2015 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 + +argspec = [ + ('ifont',{'help': 'Input font file'}, {'type': 'infont'}), + ('-o','--output',{'help': 'Output text file'}, {'type': 'outfile', 'def': 'RefNum.txt'})] + +def doit(args) : + font = args.ifont + outf = args.output + + outf.write("# glyphs with number of components\n\n") + for glyph in font: + gname=font[glyph].glyphname + ref = font[glyph].references + if ref is None: + n=0 + else: + n=len(ref) + outf.write("%s %i\n" % (gname,n)) + + outf.close() + + print "Done!" + +def cmd() : execute("FF",doit,argspec) +if __name__ == "__main__": cmd() diff --git a/examples/fontforge-old/FFnameSearchNReplace.py b/examples/fontforge-old/FFnameSearchNReplace.py new file mode 100755 index 0000000..ce6fb7e --- /dev/null +++ b/examples/fontforge-old/FFnameSearchNReplace.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +'Search and replace strings in Glyph names. Strings can be regular expressions' +__url__ = 'http://github.com/silnrsi/pysilfont' +__copyright__ = 'Copyright (c) 2015 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 re + +argspec = [ + ('ifont',{'help': 'Input font file'}, {'type': 'infont'}), + ('ofont',{'help': 'Output font file','nargs': '?' }, {'type': 'outfont', 'def': 'new'}), + ('search',{'help': 'Expression to search for'}, {}), + ('replace',{'help': 'Expression to replace with'}, {}), + ('-l','--log',{'help': 'Log file'}, {'type': 'outfile', 'def': 'searchNReplace.log'})] + +def doit(args) : + font=args.ifont + search=args.search + replace=args.replace + logf = args.log + + changes=False + for glyph in font : + newname = re.sub(search, replace, glyph) + if newname != glyph : + font[glyph].glyphname=newname + changes=True + logf.write('Glyph %s renamed to %s\n' % (glyph,newname)) + logf.close() + if changes : + return font + else : + return + +def cmd() : execute("FF",doit,argspec) +if __name__ == "__main__": cmd() diff --git a/examples/fontforge-old/FFundblEncode.py b/examples/fontforge-old/FFundblEncode.py new file mode 100755 index 0000000..651a7e3 --- /dev/null +++ b/examples/fontforge-old/FFundblEncode.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python +'''FontForge: Re-encode double-encoded glyphs based on double encoding data in a file +Lines in file should look like: "LtnSmARetrHook",U+F236,U+1D8F''' +__url__ = 'http://github.com/silnrsi/pysilfont' +__copyright__ = 'Copyright (c) 2015 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 + +argspec = [ + ('ifont',{'help': 'Input font file'}, {'type': 'infont'}), + ('ofont',{'help': 'Output font file','nargs': '?' }, {'type': 'outfont', 'def': 'new'}), + ('-i','--input',{'help': 'Input csv text file'}, {'type': 'infile', 'def': 'DblEnc.txt'}), + ('-l','--log',{'help': 'Log file'}, {'type': 'outfile', 'def': 'unDblEnc.log'})] + +def doit(args) : + font=args.ifont + inpf = args.input + logf = args.log +# Create dbl_encode list from the input file + dbl_encode = {} + for line in inpf.readlines(): + glyphn, pua_usv_str, std_usv_str = line.strip().split(",") # will exception if not 3 elements + if glyphn[0] in '"\'' : glyphn = glyphn[1:-1] # slice off quote marks, if present + pua_usv, std_usv = int(pua_usv_str[2:], 16), int(std_usv_str[2:], 16) + dbl_encode[glyphn] = [std_usv, pua_usv] + inpf.close() + + for glyph in sorted(dbl_encode.keys()): + logf.write (reincode(font,glyph,dbl_encode[glyph][0])) + logf.write (reincode(font,glyph+"Dep",dbl_encode[glyph][1])) + logf.close() + return font + +def reincode(font,glyph,usv): + if glyph not in font: + return ("Glyph %s not in font\n" % (glyph)) + g = font[glyph] + ousvs=[g.unicode] + oalt=g.altuni + if oalt != None: + for au in oalt: + ousvs.append(au[0]) # (may need to check variant flag) + g.unicode = usv + g.altuni = None + return ("encoding for %s changed: %s -> %s\n" % (glyph, ousvs, usv)) + +def cmd() : execute("FF",doit,argspec) +if __name__ == "__main__": cmd() diff --git a/examples/fontforge-old/demoAddToMenu.py b/examples/fontforge-old/demoAddToMenu.py new file mode 100755 index 0000000..6af6580 --- /dev/null +++ b/examples/fontforge-old/demoAddToMenu.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +'FontForge: Demo script to add menu items to FF tools menu' +__url__ = 'http://github.com/silnrsi/pysilfont' +__copyright__ = 'Copyright (c) 2014 SIL International (http://www.sil.org)' +__license__ = 'Released under the MIT License (http://opensource.org/licenses/MIT)' +__author__ = 'David Raymond' + +import sys, os, fontforge +sys.path.append(os.path.join(os.environ['HOME'], 'src/pysilfont/scripts')) +import samples.demoFunctions +from samples.demoFunctions import functionList, callFunctions +#from samples.demoCallFunctions import callFunctions + +def toolMenuFunction(functionGroup,font) : + reload (samples.demoFunctions) + callFunctions(functionGroup,font) + +funcList=functionList() + +for functionGroup in funcList : + menuType = funcList[functionGroup][0] + fontforge.registerMenuItem(toolMenuFunction,None,functionGroup,menuType,None,functionGroup); + print functionGroup, " registered" + +''' This script needs to be called from one of the folders that FontForge looks in for scripts to +run when it is started. With current versions of FontForge, one is Home/.config/fontforge/python. +You may need to turn on showing hidden files (ctrl-H in Nautilus) before you can see the .config +folder. Within there create a one-line python script, say call sampledemo.py containing a call +to this script, eg: + +execfile("/home/david/src/pysilfont/scripts/samples/demoAddToMenu.py") + +Due to the reload(samples.demoFunctions) line above, changes functions defined in demoFunctions.py +are dynamic, ie FontForge does not have to be restarted (as would be the case if the functions were +called directly from the tools menu. Functions can even be added dynamically to the function groups. + +If new function groups are defined, FontForge does have to be restarted to add them to the tools menu. +''' diff --git a/examples/fontforge-old/demoExecuteScript.py b/examples/fontforge-old/demoExecuteScript.py new file mode 100755 index 0000000..22a3094 --- /dev/null +++ b/examples/fontforge-old/demoExecuteScript.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +'FontForge: Demo code to paste into the "Execute Script" dialog' +__url__ = 'http://github.com/silnrsi/pysilfont' +__copyright__ = 'Copyright (c) 2013 SIL International (http://www.sil.org)' +__license__ = 'Released under the MIT License (http://opensource.org/licenses/MIT)' +__author__ = 'David Raymond' + +import sys, os, fontforge +sys.path.append(os.path.join(os.environ['HOME'], 'src/pysilfont/scripts')) +import samples.demoFunctions # Loads demoFunctions.py module from src/pysilfont/scripts/samples +reload (samples.demoFunctions) # Reload the demo module each time you execute the script to pick up any recent edits +samples.demoFunctions.callFunctions("Colour Glyphs",fontforge.activeFont()) + +'''Demo usage: +Open the "Execute Script" dialog (from the FontForge File menu or press ctrl+.), +paste just the code section this (from "import..." to "samples...") into there then +run it (Alt+o) and see how it pops up a dialogue with a choice of 3 functions to run. +Edit demoFunctions.py and alter one of the functions. +Execute the script again and see that that the function's behaviour has changed. + +Additional functions can be added to demoFunctions.py and, if also defined functionList() +become availably immdiately. + +If you want to see the output from print statements, or use commands like input, (eg +for degugging purposes) then start FontForge from a terminal window rather than the +desktop launcher. + +When starting from a terminal window, you can also specify the font to use, +eg $ fontforge /home/david/RFS/GenBasR.sfd'''
\ No newline at end of file diff --git a/examples/fontforge-old/demoFunctions.py b/examples/fontforge-old/demoFunctions.py new file mode 100755 index 0000000..be065a1 --- /dev/null +++ b/examples/fontforge-old/demoFunctions.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python +'FontForge: Sample functions to call from other demo scripts' +__url__ = 'http://github.com/silnrsi/pysilfont' +__copyright__ = 'Copyright (c) 2014 SIL International (http://www.sil.org)' +__license__ = 'Released under the MIT License (http://opensource.org/licenses/MIT)' +__author__ = 'David Raymond' + +import fontforge + +def colLtnAGlyphs(font) : + + #print "Toggling colour of glyphs with LtnCapA in their name" + for glyph in font: + g = font[glyph] + if glyph.find('LtnCapA') >= 0: + if g.color != 0x00FF00: + g.color = 0x00FF00 # Green + else : + g.color = 0xFFFFFF # White + print "LtnCapA glyphs coloured" + +def markOverlaps(font) : + print "Toggling colour of glyphs where contours overlap" + for glyph in font: + g = font[glyph] + if g.selfIntersects() : + if g.color != 0xFF0000: + g.color = 0xFF0000 # Red + else : + g.color = 0xFFFFFF # White + print "Glyphs coloured" + +def markScaled(font) : + print "Toggling colour of glyphs with scaled components" + for glyph in font: + g = font[glyph] + for ref in g.references: + transform=ref[1] + if transform[0] != 1.0 or transform[3] != 1.0 : + if g.color != 0xFF0000: + g.color = 0xFF0000 # Red + else : + g.color = 0xFFFFFF # White + print "Glyphs coloured" + +def clearColours(font) : + for glyph in font : + g = font[glyph] + g.color = 0xFFFFFF + +def functionList() : + ''' Returns a dictionary to be used by callFunctions() and demoAddToMenu.py + The dictionary is indexed by a group name which could be used as Tools menu + entry or to reference the group of functions. For each group there is a tuple + consisting of the Tools menu type (Font or Glyph) then one tuple per function. + For each function the tuple contains: + Function name + Label for the individual function in dialog box called from Tools menu + Actual function object''' + funcList = { + "Colour Glyphs":("Font", + ("colLtnAGlyphs","Colour Latin A Glyphs",colLtnAGlyphs), + ("markOverlaps","Mark Overlaps",markOverlaps), + ("markScaled","Mark Scaled",markScaled), + ("clearColours","Clear all colours",clearColours)), + "Group with single item":("Font", + ("clearColours","Clear all colours",clearColours))} + return funcList + +def callFunctions(functionGroup,font) : + funcList=functionList()[functionGroup] + i=0 + for tuple in funcList : + if i == 0 : + pass # Font/Glyph parameter not relevant here + elif i == 1 : + functionDescs=[tuple[1]] + functions=[tuple[2]] + else : + functionDescs.append(tuple[1]) + functions.append(tuple[2]) + i=i+1 + + if i == 2 : # Only one function in the group, so just call the function + functions[0](font) + else : + functionNum=fontforge.ask(functionGroup,"Please choose the function to run",functionDescs) + functions[functionNum](font) + +
\ No newline at end of file |