anchorstoadd.add( (name,x,y) ) else: infont.logger.log("Incomplete information for anchor '" + name + "' for glyph " + gname, "E") # compare sets if anchorstoadd == anchorsinfont: if len(anchorstoadd) > 0: infont.logger.log("Anchors in file already in font for glyph " + gname + ": " + str(anchorstoadd), "V") else: infont.logger.log("No anchors in file or in font for glyph " + gname, "V") else: infont.logger.log("Anchors in file for glyph " + gname + ": " + str(anchorstoadd), "I") infont.logger.log("Anchors in font for glyph " + gname + ": " + str(anchorsinfont), "I") for name,x,y in anchorstoadd: # if anchor being added exists in font already, delete it first ancnames = [a.element.get('name') for a in glyph['anchor']] infont.logger.log(str(ancnames), "V") ### if name in ancnames: infont.logger.log("removing anchor " + name + ", index " + str(ancnames.index(name)), "V") ### glyph.remove('anchor', ancnames.index(name)) infont.logger.log("adding anchor " + name + ": (" + x + ", " + y + ")", "V") ### glyph.add('anchor', {'name': name, 'x': x, 'y': y}) # If analysis only, return without writing output font if args.analysis: return # Return changed font and let execute() write it out return infont except ET.ParseError as mess: infont.logger.log("Error parsing XML input file: " + str(mess), "S") return # but really should terminate after logging Severe error above execute("PSFU", doit, argspec)
#!/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' __version__ = '0.0.1' from silfont.genlib 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() execute("FF",doit, argspec)
cgobj.CDline=line cgobj.CDelement=None try: cgobj.parsefromCDline() if cgobj.CDelement != None: f.append(cgobj.CDelement) elementcount += 1 except ValueError, e: lfile.write("Line "+str(filelinecount)+": "+str(e)+'\n') if linecount != elementcount: lfile.write("Lines read from input file: " + str(filelinecount)+'\n') lfile.write("Lines parsed (excluding blank and comment lines): " + str(linecount)+'\n') lfile.write("Valid glyphs found: " + str(elementcount)+'\n') # instead of simple serialization with: ofile.write(ET.tostring(f)) # create ETWriter object and specify indentation and attribute order to get normalized output indentFirst = " " indentIncr = " " attOrder = "PSName,UID,with,at,x,y" for k in args.params: if k == 'indentIncr': indentIncr = args.params['indentIncr'] elif k == 'indentFirst': indentFirst = args.params['indentFirst'] elif k == 'attOrder': attOrder = args.params['attOrder'] x = attOrder.split(',') attributeOrder = dict(zip(x,range(len(x)))) etwobj=ETWriter(f, indentFirst=indentFirst, indentIncr=indentIncr, attributeOrder=attributeOrder) etwobj.serialize_xml(ofile.write) return execute(None,doit,argspec)