michael@0: #!/usr/bin/python michael@0: # vim: set shiftwidth=4 tabstop=8 autoindent expandtab: michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: michael@0: # For general fontforge documentation, see: michael@0: # http://fontforge.sourceforge.net/ michael@0: # For fontforge scripting documentation, see: michael@0: # http://fontforge.sourceforge.net/scripting-tutorial.html michael@0: # http://fontforge.sourceforge.net/scripting.html michael@0: # and most importantly: michael@0: # http://fontforge.sourceforge.net/python.html michael@0: michael@0: # To install what you need, on Ubuntu, michael@0: # sudo apt-get install python-fontforge michael@0: michael@0: import fontforge michael@0: michael@0: # generate a set of fonts, each with our special glyph at one codepoint, michael@0: # and nothing else michael@0: for codepoint in range(ord("A"), ord("D") + 1): michael@0: for (mark, width) in [("", 1500), ("2", 1800)]: michael@0: charname = chr(codepoint) michael@0: f = fontforge.font() michael@0: n = "Mark" + mark + charname michael@0: f.fontname = n michael@0: f.familyname = n michael@0: f.fullname = n michael@0: f.copyright = "Copyright (c) 2008 Mozilla Corporation" michael@0: michael@0: g = f.createChar(codepoint, charname) michael@0: g.importOutlines("mark" + mark + "-glyph.svg") michael@0: g.width = width michael@0: michael@0: f.generate("mark" + mark + charname + ".ttf") michael@0: f.generate("mark" + mark + charname + ".otf") michael@0: michael@0: michael@0: for codepoint in range(ord("A"), ord("A") + 1): michael@0: for (mark, width) in [("", 1500), ("2", 1800)]: michael@0: for (uposname, upos) in [("low", -350), ("high", -50)]: michael@0: charname = chr(codepoint) michael@0: f = fontforge.font() michael@0: n = "Mark" + mark + charname michael@0: f.fontname = n michael@0: f.familyname = n michael@0: f.fullname = n michael@0: f.descent = 400 michael@0: f.upos = upos michael@0: f.uwidth = 100 michael@0: f.copyright = "Copyright (c) 2008 Mozilla Corporation" michael@0: michael@0: g = f.createChar(codepoint, charname) michael@0: g.importOutlines("mark" + mark + "-glyph.svg") michael@0: g.width = width michael@0: michael@0: f.generate("mark" + mark + charname + "-" + uposname + michael@0: "underline.ttf") michael@0: michael@0: # font with a ligature involving a space michael@0: michael@0: f = fontforge.font() michael@0: n = "MarkAB-spaceliga" michael@0: f.fontname = n michael@0: f.familyname = n michael@0: f.fullname = n michael@0: f.copyright = "Copyright (c) 2008-2011 Mozilla Corporation" michael@0: michael@0: g = f.createChar(ord(" "), "space") michael@0: g.width = 1000 michael@0: for charname in ["A", "B"]: michael@0: g = f.createChar(ord(charname), charname) michael@0: g.importOutlines("mark-glyph.svg") michael@0: g.width = 1500 michael@0: michael@0: f.addLookup("liga-table", "gsub_ligature", (), (("liga",(("latn",("dflt")),)),)) michael@0: f.addLookupSubtable("liga-table", "liga-subtable") michael@0: g = f.createChar(-1, "spaceA") michael@0: g.glyphclass = "baseligature"; michael@0: g.addPosSub("liga-subtable", ("space", "A")) michael@0: g.importOutlines("mark2-glyph.svg") michael@0: g.width = 1800 michael@0: michael@0: f.generate("markAB-spaceliga.otf") michael@0: michael@0: # font with a known line-height (which is greater than winascent + windescent). michael@0: michael@0: f = fontforge.font() michael@0: lineheight = 1500 michael@0: n = "MarkA-lineheight" + str(lineheight) michael@0: f.fontname = n michael@0: f.familyname = n michael@0: f.fullname = n michael@0: f.copyright = "Copyright (c) 2008-2011 Mozilla Corporation" michael@0: michael@0: g = f.createChar(ord(" "), "space") michael@0: g.width = 1000 michael@0: g = f.createChar(ord("A"), "A") michael@0: g.importOutlines("mark-glyph.svg") michael@0: g.width = 1500 michael@0: michael@0: f.os2_typoascent_add = False michael@0: f.os2_typoascent = 800 michael@0: f.os2_typodescent_add = False michael@0: f.os2_typodescent = -200 michael@0: f.os2_use_typo_metrics = True michael@0: f.os2_typolinegap = lineheight - (f.os2_typoascent - f.os2_typodescent) michael@0: # glyph height is 800 (hhea ascender - descender) michael@0: f.hhea_linegap = lineheight - 800 michael@0: michael@0: f.generate("markA-lineheight" + str(lineheight) + ".ttf")