layout/reftests/fonts/mark-generate.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/reftests/fonts/mark-generate.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,112 @@
     1.4 +#!/usr/bin/python
     1.5 +# vim: set shiftwidth=4 tabstop=8 autoindent expandtab:
     1.6 +# This Source Code Form is subject to the terms of the Mozilla Public
     1.7 +# License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 +# file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.9 +
    1.10 +# For general fontforge documentation, see:
    1.11 +#   http://fontforge.sourceforge.net/
    1.12 +# For fontforge scripting documentation, see:
    1.13 +#   http://fontforge.sourceforge.net/scripting-tutorial.html
    1.14 +#   http://fontforge.sourceforge.net/scripting.html
    1.15 +# and most importantly:
    1.16 +#   http://fontforge.sourceforge.net/python.html
    1.17 +
    1.18 +# To install what you need, on Ubuntu,
    1.19 +#   sudo apt-get install python-fontforge
    1.20 +
    1.21 +import fontforge
    1.22 +
    1.23 +# generate a set of fonts, each with our special glyph at one codepoint,
    1.24 +# and nothing else
    1.25 +for codepoint in range(ord("A"), ord("D") + 1):
    1.26 +    for (mark, width) in [("", 1500), ("2", 1800)]:
    1.27 +        charname = chr(codepoint)
    1.28 +        f = fontforge.font()
    1.29 +        n = "Mark" + mark + charname
    1.30 +        f.fontname = n
    1.31 +        f.familyname = n
    1.32 +        f.fullname = n
    1.33 +        f.copyright = "Copyright (c) 2008 Mozilla Corporation"
    1.34 +
    1.35 +        g = f.createChar(codepoint, charname)
    1.36 +        g.importOutlines("mark" + mark + "-glyph.svg")
    1.37 +        g.width = width
    1.38 +
    1.39 +        f.generate("mark" + mark + charname + ".ttf")
    1.40 +        f.generate("mark" + mark + charname + ".otf")
    1.41 +
    1.42 +
    1.43 +for codepoint in range(ord("A"), ord("A") + 1):
    1.44 +    for (mark, width) in [("", 1500), ("2", 1800)]:
    1.45 +        for (uposname, upos) in [("low", -350), ("high", -50)]:
    1.46 +            charname = chr(codepoint)
    1.47 +            f = fontforge.font()
    1.48 +            n = "Mark" + mark + charname
    1.49 +            f.fontname = n
    1.50 +            f.familyname = n
    1.51 +            f.fullname = n
    1.52 +            f.descent = 400
    1.53 +            f.upos = upos
    1.54 +            f.uwidth = 100
    1.55 +            f.copyright = "Copyright (c) 2008 Mozilla Corporation"
    1.56 +    
    1.57 +            g = f.createChar(codepoint, charname)
    1.58 +            g.importOutlines("mark" + mark + "-glyph.svg")
    1.59 +            g.width = width
    1.60 +    
    1.61 +            f.generate("mark" + mark + charname + "-" + uposname +
    1.62 +                       "underline.ttf")
    1.63 +
    1.64 +# font with a ligature involving a space
    1.65 +
    1.66 +f = fontforge.font()
    1.67 +n = "MarkAB-spaceliga"
    1.68 +f.fontname = n
    1.69 +f.familyname = n
    1.70 +f.fullname = n
    1.71 +f.copyright = "Copyright (c) 2008-2011 Mozilla Corporation"
    1.72 +
    1.73 +g = f.createChar(ord(" "), "space")
    1.74 +g.width = 1000
    1.75 +for charname in ["A", "B"]:
    1.76 +    g = f.createChar(ord(charname), charname)
    1.77 +    g.importOutlines("mark-glyph.svg")
    1.78 +    g.width = 1500
    1.79 +
    1.80 +f.addLookup("liga-table", "gsub_ligature", (), (("liga",(("latn",("dflt")),)),))
    1.81 +f.addLookupSubtable("liga-table", "liga-subtable")
    1.82 +g = f.createChar(-1, "spaceA")
    1.83 +g.glyphclass = "baseligature";
    1.84 +g.addPosSub("liga-subtable", ("space", "A"))
    1.85 +g.importOutlines("mark2-glyph.svg")
    1.86 +g.width = 1800
    1.87 +
    1.88 +f.generate("markAB-spaceliga.otf")
    1.89 +
    1.90 +# font with a known line-height (which is greater than winascent + windescent).
    1.91 +
    1.92 +f = fontforge.font()
    1.93 +lineheight = 1500
    1.94 +n = "MarkA-lineheight" + str(lineheight)
    1.95 +f.fontname = n
    1.96 +f.familyname = n
    1.97 +f.fullname = n
    1.98 +f.copyright = "Copyright (c) 2008-2011 Mozilla Corporation"
    1.99 +
   1.100 +g = f.createChar(ord(" "), "space")
   1.101 +g.width = 1000
   1.102 +g = f.createChar(ord("A"), "A")
   1.103 +g.importOutlines("mark-glyph.svg")
   1.104 +g.width = 1500
   1.105 +
   1.106 +f.os2_typoascent_add = False
   1.107 +f.os2_typoascent = 800
   1.108 +f.os2_typodescent_add = False
   1.109 +f.os2_typodescent = -200
   1.110 +f.os2_use_typo_metrics = True
   1.111 +f.os2_typolinegap = lineheight - (f.os2_typoascent - f.os2_typodescent)
   1.112 +# glyph height is 800 (hhea ascender - descender)
   1.113 +f.hhea_linegap = lineheight - 800
   1.114 +
   1.115 +f.generate("markA-lineheight" + str(lineheight) + ".ttf")

mercurial