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/psfaddGlyphDemo.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 | examples/psfaddGlyphDemo.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/examples/psfaddGlyphDemo.py b/examples/psfaddGlyphDemo.py new file mode 100755 index 0000000..d933c65 --- /dev/null +++ b/examples/psfaddGlyphDemo.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +'''Demo script for UFOlib to add a glyph to a UFO 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__ = 'David Raymond' + +from silfont.core import execute +import silfont.ufo as ufo +from xml.etree import cElementTree as ET + +suffix = '_addGlyph' +argspec = [ + ('ifont',{'help': 'Input font file'}, {'type': 'infont'}), + ('ofont',{'help': 'Output font file','nargs': '?' }, {'type': 'outfont'}), + ('-l','--log',{'help': 'Log file'}, {'type': 'outfile', 'def': suffix+'log'})] + +def doit(args) : + ''' This will add the following glyph to the font + + <?xml version="1.0" encoding="UTF-8"?> + <glyph name="Test" format="1"> + <unicode hex="007D"/> + <outline> + <contour> + <point x="275" y="1582" type="line"/> + <point x="275" y="-493" type="line"/> + </contour> + </outline> + </glyph> + ''' + + font = args.ifont + + # Create basic glyph + newglyph = ufo.Uglif(layer = font.deflayer, name = "Test") + newglyph.add("unicode", {"hex": "007D"}) + # Add an outline + newglyph.add("outline") + # Create a contour and add to outline + element = ET.Element("contour") + ET.SubElement(element, "point", {"x": "275", "y": "1582", "type": "line"}) + ET.SubElement(element, "point", {"x": "275", "y": "-493", "type": "line"}) + contour =ufo.Ucontour(newglyph["outline"],element) + newglyph["outline"].appendobject(contour, "contour") + + font.deflayer.addGlyph(newglyph) + + return args.ifont + +def cmd() : execute("UFO",doit,argspec) +if __name__ == "__main__": cmd() + |