Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | #!/usr/bin/python |
michael@0 | 2 | # vim: set shiftwidth=4 tabstop=8 autoindent expandtab: |
michael@0 | 3 | # This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | # License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 6 | |
michael@0 | 7 | # For general fontforge documentation, see: |
michael@0 | 8 | # http://fontforge.sourceforge.net/ |
michael@0 | 9 | # For fontforge scripting documentation, see: |
michael@0 | 10 | # http://fontforge.sourceforge.net/scripting-tutorial.html |
michael@0 | 11 | # http://fontforge.sourceforge.net/scripting.html |
michael@0 | 12 | # and most importantly: |
michael@0 | 13 | # http://fontforge.sourceforge.net/python.html |
michael@0 | 14 | |
michael@0 | 15 | # To install what you need, on Ubuntu, |
michael@0 | 16 | # sudo apt-get install python-fontforge |
michael@0 | 17 | |
michael@0 | 18 | from __future__ import print_function |
michael@0 | 19 | import fontforge |
michael@0 | 20 | |
michael@0 | 21 | em = 1000 |
michael@0 | 22 | |
michael@0 | 23 | def newMathFont(aName): |
michael@0 | 24 | print("Generating %s.otf..." % aName, end="") |
michael@0 | 25 | mathFont = fontforge.font() |
michael@0 | 26 | mathFont.fontname = aName |
michael@0 | 27 | mathFont.familyname = aName |
michael@0 | 28 | mathFont.fullname = aName |
michael@0 | 29 | mathFont.copyright = "Copyright (c) 2014 Mozilla Corporation" |
michael@0 | 30 | mathFont.encoding = "UnicodeFull" |
michael@0 | 31 | |
michael@0 | 32 | # Create a space character. Also force the creation of some MATH subtables |
michael@0 | 33 | # so that OTS will not reject the MATH table. |
michael@0 | 34 | g = mathFont.createChar(ord(" "), "space") |
michael@0 | 35 | g.width = em |
michael@0 | 36 | g.italicCorrection = 0 |
michael@0 | 37 | g.topaccent = 0 |
michael@0 | 38 | g.mathKern.bottomLeft = tuple([(0,0)]) |
michael@0 | 39 | g.mathKern.bottomRight = tuple([(0,0)]) |
michael@0 | 40 | g.mathKern.topLeft = tuple([(0,0)]) |
michael@0 | 41 | g.mathKern.topRight = tuple([(0,0)]) |
michael@0 | 42 | mathFont[ord(" ")].horizontalVariants = "space" |
michael@0 | 43 | mathFont[ord(" ")].verticalVariants = "space" |
michael@0 | 44 | return mathFont |
michael@0 | 45 | |
michael@0 | 46 | def saveMathFont(aFont): |
michael@0 | 47 | aFont.em = em |
michael@0 | 48 | aFont.ascent = aFont.descent = em/2 |
michael@0 | 49 | aFont.hhea_ascent = aFont.os2_typoascent = aFont.os2_winascent = em/2 |
michael@0 | 50 | aFont.descent = aFont.hhea_descent = em/2 |
michael@0 | 51 | aFont.os2_typodescent = aFont.os2_windescent = em/2 |
michael@0 | 52 | aFont.hhea_ascent_add = aFont.hhea_descent_add = 0 |
michael@0 | 53 | aFont.os2_typoascent_add = aFont.os2_typodescent_add = 0 |
michael@0 | 54 | aFont.os2_winascent_add = aFont.os2_windescent_add = 0 |
michael@0 | 55 | aFont.os2_use_typo_metrics = True |
michael@0 | 56 | aFont.generate(aFont.fontname + ".otf") |
michael@0 | 57 | print(" done.") |
michael@0 | 58 | |
michael@0 | 59 | ################################################################################ |
michael@0 | 60 | # Glyph variants and constructions |
michael@0 | 61 | f = newMathFont("stretchy") |
michael@0 | 62 | nvariants = 3 |
michael@0 | 63 | |
michael@0 | 64 | # Draw boxes for the size variants and glues |
michael@0 | 65 | for i in range(0, nvariants): |
michael@0 | 66 | s = em * (i + 1) |
michael@0 | 67 | |
michael@0 | 68 | g = f.createChar(-1, "h%d" % i) |
michael@0 | 69 | p = g.glyphPen() |
michael@0 | 70 | p.moveTo(0, -em) |
michael@0 | 71 | p.lineTo(0, em) |
michael@0 | 72 | p.lineTo(s, em) |
michael@0 | 73 | p.lineTo(s, -em) |
michael@0 | 74 | p.closePath() |
michael@0 | 75 | g.width = s |
michael@0 | 76 | |
michael@0 | 77 | g = f.createChar(-1, "v%d" % i) |
michael@0 | 78 | p = g.glyphPen() |
michael@0 | 79 | p.moveTo(0, 0) |
michael@0 | 80 | p.lineTo(0, s) |
michael@0 | 81 | p.lineTo(2 * em, s) |
michael@0 | 82 | p.lineTo(2 * em, 0) |
michael@0 | 83 | p.closePath(); |
michael@0 | 84 | g.width = 2 * em |
michael@0 | 85 | |
michael@0 | 86 | # Draw some pieces for stretchy operators |
michael@0 | 87 | s = em * nvariants |
michael@0 | 88 | |
michael@0 | 89 | g = f.createChar(-1, "left") |
michael@0 | 90 | p = g.glyphPen() |
michael@0 | 91 | p.moveTo(0, -2 * em) |
michael@0 | 92 | p.lineTo(0, 2 * em) |
michael@0 | 93 | p.lineTo(s, em) |
michael@0 | 94 | p.lineTo(s, -em) |
michael@0 | 95 | p.closePath(); |
michael@0 | 96 | g.width = s |
michael@0 | 97 | |
michael@0 | 98 | g = f.createChar(-1, "right") |
michael@0 | 99 | p = g.glyphPen() |
michael@0 | 100 | p.moveTo(0, -em) |
michael@0 | 101 | p.lineTo(0, em) |
michael@0 | 102 | p.lineTo(s, 2 * em) |
michael@0 | 103 | p.lineTo(s, -2 * em) |
michael@0 | 104 | p.closePath(); |
michael@0 | 105 | g.width = s |
michael@0 | 106 | |
michael@0 | 107 | g = f.createChar(-1, "hmid") |
michael@0 | 108 | p = g.glyphPen() |
michael@0 | 109 | p.moveTo(0, -em) |
michael@0 | 110 | p.lineTo(0, em) |
michael@0 | 111 | p.lineTo(s, 2 * em) |
michael@0 | 112 | p.lineTo(2 * s, em) |
michael@0 | 113 | p.lineTo(2 * s, -em) |
michael@0 | 114 | p.lineTo(s, -2 * em) |
michael@0 | 115 | p.closePath(); |
michael@0 | 116 | g.width = 2 * s |
michael@0 | 117 | |
michael@0 | 118 | g = f.createChar(-1, "bottom") |
michael@0 | 119 | p = g.glyphPen() |
michael@0 | 120 | p.moveTo(0, 0) |
michael@0 | 121 | p.lineTo(0, s) |
michael@0 | 122 | p.lineTo(2 * em, s) |
michael@0 | 123 | p.lineTo(4 * em, 0) |
michael@0 | 124 | p.closePath(); |
michael@0 | 125 | g.width = 4 * em |
michael@0 | 126 | |
michael@0 | 127 | g = f.createChar(-1, "top") |
michael@0 | 128 | p = g.glyphPen() |
michael@0 | 129 | p.moveTo(0, 0) |
michael@0 | 130 | p.lineTo(4 * em, 0) |
michael@0 | 131 | p.lineTo(2 * em, -s) |
michael@0 | 132 | p.lineTo(0, -s) |
michael@0 | 133 | p.closePath(); |
michael@0 | 134 | g.width = 4 * em |
michael@0 | 135 | |
michael@0 | 136 | g = f.createChar(-1, "vmid") |
michael@0 | 137 | p = g.glyphPen() |
michael@0 | 138 | p.moveTo(0, s) |
michael@0 | 139 | p.lineTo(2 * em, s) |
michael@0 | 140 | p.lineTo(4 * em, 0) |
michael@0 | 141 | p.lineTo(2 * em, -s) |
michael@0 | 142 | p.lineTo(0, -s) |
michael@0 | 143 | p.closePath(); |
michael@0 | 144 | g.width = 3 * em |
michael@0 | 145 | |
michael@0 | 146 | # Create small rectangle of various size for some exotic arrows that are |
michael@0 | 147 | # unlikely to be stretchable with standard fonts. |
michael@0 | 148 | hstretchy = [ |
michael@0 | 149 | 0x219C, # leftwards wave arrow |
michael@0 | 150 | 0x219D, # rightwards wave arrow |
michael@0 | 151 | 0x219E, # leftwards two headed arrow |
michael@0 | 152 | 0x21A0, # rightwards two headed arrow |
michael@0 | 153 | 0x21A2 # leftwards arrow with tail |
michael@0 | 154 | ] |
michael@0 | 155 | vstretchy = [ |
michael@0 | 156 | 0x219F, # upwards two headed arrow |
michael@0 | 157 | 0x21A1, # downwards two headed arrow |
michael@0 | 158 | 0x21A5, # upwards arrow from bar |
michael@0 | 159 | 0x21A7, # downwards arrow from bar |
michael@0 | 160 | 0x21A8 # up down arrow with base |
michael@0 | 161 | ] |
michael@0 | 162 | for i in range(0, 1 + nvariants + 1): |
michael@0 | 163 | s = (i + 1) * em/10 |
michael@0 | 164 | |
michael@0 | 165 | g = f.createChar(hstretchy[i]) |
michael@0 | 166 | p = g.glyphPen() |
michael@0 | 167 | p.moveTo(0, -em/10) |
michael@0 | 168 | p.lineTo(0, em/10) |
michael@0 | 169 | p.lineTo(s, em/10) |
michael@0 | 170 | p.lineTo(s, -em/10) |
michael@0 | 171 | p.closePath() |
michael@0 | 172 | g.width = s |
michael@0 | 173 | |
michael@0 | 174 | g = f.createChar(vstretchy[i]) |
michael@0 | 175 | p = g.glyphPen() |
michael@0 | 176 | p.moveTo(0, 0) |
michael@0 | 177 | p.lineTo(0, s) |
michael@0 | 178 | p.lineTo(2 * em/10, s) |
michael@0 | 179 | p.lineTo(2 * em/10, 0) |
michael@0 | 180 | p.closePath(); |
michael@0 | 181 | g.width = 2 * em/10 |
michael@0 | 182 | |
michael@0 | 183 | # hstretchy[0] and vstretchy[0] have all the variants and the components. The others only have one of them. |
michael@0 | 184 | s = em * nvariants |
michael@0 | 185 | |
michael@0 | 186 | f[hstretchy[0]].horizontalVariants = "uni219C h0 h1 h2" |
michael@0 | 187 | f[hstretchy[0]].horizontalComponents = (("left", False, 0, 0, s), \ |
michael@0 | 188 | ("h2", True, 0, 0, s), ("hmid", False, 0, 0, 2 * s), ("h2", True, 0, 0, s), \ |
michael@0 | 189 | ("right", False, 0, 0, s)) |
michael@0 | 190 | |
michael@0 | 191 | f[hstretchy[1]].horizontalVariants = "uni219D h0" |
michael@0 | 192 | f[hstretchy[2]].horizontalVariants = "uni219E h1" |
michael@0 | 193 | f[hstretchy[3]].horizontalVariants = "uni21A0 h2" |
michael@0 | 194 | f[hstretchy[4]].horizontalVariants = "uni21A2 h2" |
michael@0 | 195 | f[hstretchy[4]].horizontalComponents = f[hstretchy[0]].horizontalComponents |
michael@0 | 196 | |
michael@0 | 197 | f[vstretchy[0]].verticalVariants = "uni219F v0 v1 v2" |
michael@0 | 198 | f[vstretchy[0]].verticalComponents = (("bottom", False, 0, 0, s), \ |
michael@0 | 199 | ("v2", True, 0, 0, s), ("vmid", False, 0, 0, 2 * s), ("v2", True, 0, 0, s), \ |
michael@0 | 200 | ("top", False, 0, 0, s)) |
michael@0 | 201 | |
michael@0 | 202 | f[vstretchy[1]].verticalVariants = "uni21A1 v0" |
michael@0 | 203 | f[vstretchy[2]].verticalVariants = "uni21A5 v1" |
michael@0 | 204 | f[vstretchy[3]].verticalVariants = "uni21A7 v2" |
michael@0 | 205 | f[vstretchy[4]].verticalVariants = "uni21A8" |
michael@0 | 206 | f[vstretchy[4]].verticalComponents = f[vstretchy[0]].verticalComponents |
michael@0 | 207 | |
michael@0 | 208 | ################################################################################ |
michael@0 | 209 | # Testing DisplayOperatorMinHeight |
michael@0 | 210 | f.math.DisplayOperatorMinHeight = 8 * em |
michael@0 | 211 | largeop = [0x2A1B, 0x2A1C] # integral with overbar/underbar |
michael@0 | 212 | |
michael@0 | 213 | # Draw boxes of size 1, 2, 7, 8, 9em. |
michael@0 | 214 | for i in [1, 2, 7, 8, 9]: |
michael@0 | 215 | s = em * i |
michael@0 | 216 | if i == 1 or i == 2: |
michael@0 | 217 | g = f.createChar(largeop[i-1]) |
michael@0 | 218 | else: |
michael@0 | 219 | g = f.createChar(-1, "L%d" % i) |
michael@0 | 220 | p = g.glyphPen() |
michael@0 | 221 | p.moveTo(0, 0) |
michael@0 | 222 | p.lineTo(0, s) |
michael@0 | 223 | p.lineTo(s, s) |
michael@0 | 224 | p.lineTo(s, 0) |
michael@0 | 225 | p.closePath(); |
michael@0 | 226 | g.width = s |
michael@0 | 227 | |
michael@0 | 228 | f[largeop[0]].verticalVariants = "uni2A1B L7 L8 L9" |
michael@0 | 229 | f[largeop[1]].verticalVariants = "uni2A1C L8" |
michael@0 | 230 | |
michael@0 | 231 | saveMathFont(f) |