mark-generate.py (4902B)
1 #!/usr/bin/python 2 # vim: set shiftwidth=4 tabstop=8 autoindent expandtab: 3 # This Source Code Form is subject to the terms of the Mozilla Public 4 # License, v. 2.0. If a copy of the MPL was not distributed with this 5 # file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 7 # For general fontforge documentation, see: 8 # http://fontforge.sourceforge.net/ 9 # For fontforge scripting documentation, see: 10 # http://fontforge.sourceforge.net/scripting-tutorial.html 11 # http://fontforge.sourceforge.net/scripting.html 12 # and most importantly: 13 # http://fontforge.sourceforge.net/python.html 14 15 # To install what you need, on Ubuntu, 16 # sudo apt-get install python-fontforge 17 18 import fontforge 19 20 # generate a set of fonts, each with our special glyph at one codepoint, 21 # and nothing else 22 for codepoint in range(ord("A"), ord("D") + 1): 23 for mark, width in [("", 1500), ("2", 1800)]: 24 charname = chr(codepoint) 25 f = fontforge.font() 26 n = "Mark" + mark + charname 27 f.fontname = n 28 f.familyname = n 29 f.fullname = n 30 f.copyright = "Copyright (c) 2008-2020 Mozilla Corporation" 31 32 g = f.createChar(ord(" "), "space") 33 g.width = 1000 34 35 g = f.createChar(codepoint, charname) 36 g.importOutlines("mark" + mark + "-glyph.svg") 37 g.width = width 38 39 f.generate("mark" + mark + charname + ".ttf") 40 f.generate("mark" + mark + charname + ".otf") 41 42 43 for codepoint in range(ord("A"), ord("A") + 1): 44 for mark, width in [("", 1500), ("2", 1800)]: 45 for uposname, upos in [("low", -350), ("high", -50)]: 46 charname = chr(codepoint) 47 f = fontforge.font() 48 n = "Mark" + mark + charname 49 f.fontname = n 50 f.familyname = n 51 f.fullname = n 52 f.descent = 400 53 f.upos = upos 54 f.uwidth = 100 55 f.copyright = "Copyright (c) 2008-2020 Mozilla Corporation" 56 57 g = f.createChar(ord(" "), "space") 58 g.width = 1000 59 60 g = f.createChar(codepoint, charname) 61 g.importOutlines("mark" + mark + "-glyph.svg") 62 g.width = width 63 64 f.generate("mark" + mark + charname + "-" + uposname + "underline.ttf") 65 66 # font with a ligature involving a space 67 68 f = fontforge.font() 69 n = "MarkAB-spaceliga" 70 f.fontname = n 71 f.familyname = n 72 f.fullname = n 73 f.copyright = "Copyright (c) 2008-2011 Mozilla Corporation" 74 75 g = f.createChar(ord(" "), "space") 76 g.width = 1000 77 for charname in ["A", "B"]: 78 g = f.createChar(ord(charname), charname) 79 g.importOutlines("mark-glyph.svg") 80 g.width = 1500 81 82 f.addLookup("liga-table", "gsub_ligature", (), (("liga", (("latn", ("dflt")),)),)) 83 f.addLookupSubtable("liga-table", "liga-subtable") 84 g = f.createChar(-1, "spaceA") 85 g.glyphclass = "baseligature" 86 g.addPosSub("liga-subtable", ("space", "A")) 87 g.importOutlines("mark2-glyph.svg") 88 g.width = 1800 89 90 f.generate("markAB-spaceliga.otf") 91 92 # font with a known line-height (which is greater than winascent + windescent). 93 94 f = fontforge.font() 95 lineheight = 1500 96 n = "MarkA-lineheight" + str(lineheight) 97 f.fontname = n 98 f.familyname = n 99 f.fullname = n 100 f.copyright = "Copyright (c) 2008-2011 Mozilla Corporation" 101 102 g = f.createChar(ord(" "), "space") 103 g.width = 1000 104 g = f.createChar(ord("A"), "A") 105 g.importOutlines("mark-glyph.svg") 106 g.width = 1500 107 108 f.os2_typoascent_add = False 109 f.os2_typoascent = 800 110 f.os2_typodescent_add = False 111 f.os2_typodescent = -200 112 f.os2_use_typo_metrics = True 113 f.os2_typolinegap = lineheight - (f.os2_typoascent - f.os2_typodescent) 114 # glyph height is 800 (hhea ascender - descender) 115 f.hhea_linegap = lineheight - 800 116 117 f.generate("markA-lineheight" + str(lineheight) + ".ttf") 118 119 # Fonts with known winHeight and typoLineHeight such that winHeight is much 120 # larger than typoLineHeight. 121 f = fontforge.font() 122 typoLineHeight = 2700 123 winHeight = 6000 124 n = "MarkA-lineheight" + str(winHeight) 125 n = n + "-typolineheight" + str(typoLineHeight) 126 f.fontname = n 127 f.familyname = n 128 f.fullname = n 129 f.copyright = "Copyright (c) 2008-2015 Mozilla Corporation" 130 131 g = f.createChar(ord(" "), "space") 132 g.width = 1000 133 g = f.createChar(ord("A"), "A") 134 g.importOutlines("mark-glyph.svg") 135 g.width = 1500 136 137 f.os2_typoascent_add = False 138 f.os2_typoascent = 800 139 f.os2_typodescent_add = False 140 f.os2_typodescent = -200 141 f.os2_typolinegap = typoLineHeight - (f.os2_typoascent - f.os2_typodescent) 142 143 f.hhea_ascent = winHeight / 2 144 f.hhea_ascent_add = False 145 f.hhea_descent = winHeight / 2 146 f.hhea_descent_add = False 147 f.hhea_linegap = 0 148 149 f.os2_winascent = winHeight / 2 150 f.os2_winascent_add = False 151 f.os2_windescent = winHeight / 2 152 f.os2_windescent_add = False 153 154 f.os2_use_typo_metrics = True 155 f.generate( 156 "markA-lineheight" 157 + str(winHeight) 158 + "-typolineheight" 159 + str(typoLineHeight) 160 + ".otf" 161 ) 162 f.generate( 163 "markA-lineheight" 164 + str(winHeight) 165 + "-typolineheight" 166 + str(typoLineHeight) 167 + ".ttf" 168 )