Exemple #1
0
def createSizeVariants(aFont):
    for size in (0, 1, 2, 3):
        g = aFont.createChar(-1, "v%d" % size)
        mathfont.drawRectangleGlyph(g, mathfont.em, (size + 1) * mathfont.em,
                                    0)
        g = aFont.createChar(-1, "h%d" % size)
        mathfont.drawRectangleGlyph(g, (size + 1) * mathfont.em, mathfont.em,
                                    0)
def createStretchyRadical(aFont):
    radicalCodePoint = 0x221a
    mathfont.createSquareGlyph(aFont, radicalCodePoint)
    g = aFont.createChar(-1, "size1")
    mathfont.drawRectangleGlyph(g, mathfont.em, 2 * mathfont.em, 0)
    g = aFont.createChar(-1, "size2")
    mathfont.drawRectangleGlyph(g, mathfont.em, 3 * mathfont.em, 0)
    g = aFont.createChar(-1, "size3")
    mathfont.drawRectangleGlyph(g, mathfont.em, 4 * mathfont.em, 0)
    overlap = mathfont.em / 2
    aFont[radicalCodePoint].verticalVariants = "radical size1 size2 size3"
    aFont[radicalCodePoint].verticalComponents = \
        (("size2", False, 0, mathfont.em, 3 * mathfont.em), \
         ("size1", True, mathfont.em, mathfont.em, 2 * mathfont.em))
Exemple #3
0
def createStretchyRadical(aFont):
    radicalCodePoint = 0x221a
    mathfont.createSquareGlyph(aFont, radicalCodePoint)
    g = aFont.createChar(-1, "size1")
    mathfont.drawRectangleGlyph(g, mathfont.em, 2 * mathfont.em, 0)
    g = aFont.createChar(-1, "size2")
    mathfont.drawRectangleGlyph(g, mathfont.em, 3 * mathfont.em, 0)
    g = aFont.createChar(-1, "size3")
    mathfont.drawRectangleGlyph(g, mathfont.em, 4 * mathfont.em, 0)
    aFont[radicalCodePoint].verticalVariants = "radical size1 size2 size3"
    # Part: (glyphName, isExtender, startConnector, endConnector, fullAdvance)
    aFont.math.MinConnectorOverlap = 0
    aFont[radicalCodePoint].verticalComponents = \
        (("size2", False, 0, mathfont.em, 3 * mathfont.em), \
         ("size1", True, mathfont.em, mathfont.em, 2 * mathfont.em))
Exemple #4
0
# Set parameters for accent tests so that we only have large gap when
# overscript is an accent.
font.math.UpperLimitBaselineRiseMin = 0
font.math.StretchStackTopShiftUp = 0
font.math.AccentBaseHeight = 2 * mathfont.em
font.math.OverbarVerticalGap = 0

createSizeVariants(font)
for key in operatorDictionary:
    value = operatorDictionary[key]
    for c in value["characters"]:
        if c in font:
            continue
        if c == NonBreakingSpace:
            g = font.createChar(c)
            mathfont.drawRectangleGlyph(g, mathfont.em, mathfont.em / 3, 0)
        else:
            mathfont.createSquareGlyph(font, c)
        createStretchy(font, c, c in inlineAxisOperators)
mathfont.save(font)

# Generate the python file.
for key in operatorDictionary:
    del operatorDictionary[key]["characters"]  # Remove this temporary value.
JSON = {
    "comment":
    "This file was automatically generated by operator-dictionary.py. Do not edit.",
    "dictionary": operatorDictionary
}
with open('../support/operator-dictionary.json', 'w') as fp:
    json.dump(JSON, fp, sort_keys=True, ensure_ascii=True)
Exemple #5
0
#!/usr/bin/python

from utils import mathfont
import fontforge

nAryWhiteVerticalBarCodePoint = 0x2AFF
v1 = 5 * mathfont.em
f = mathfont.create("largeop-displayoperatorminheight%d" % v1,
                    "Copyright (c) 2016 MathML Association")
f.math.DisplayOperatorMinHeight = v1
mathfont.createSquareGlyph(f, nAryWhiteVerticalBarCodePoint)
g = f.createChar(-1, "uni2AFF.display")
mathfont.drawRectangleGlyph(g, mathfont.em, v1, 0)
f[nAryWhiteVerticalBarCodePoint].verticalVariants = "uni2AFF uni2AFF.display"
mathfont.save(f)

v1 = 2 * mathfont.em
v2 = 3 * mathfont.em
f = mathfont.create(
    "largeop-displayoperatorminheight%d-2AFF-italiccorrection%d" % (v1, v2),
    "Copyright (c) 2018 Igalia S.L.")
f.math.DisplayOperatorMinHeight = v1
mathfont.createSquareGlyph(f, nAryWhiteVerticalBarCodePoint)
g = f.createChar(-1, "uni2AFF.display")
p = g.glyphPen()
p.moveTo(0, 0)
p.lineTo(v2, v1)
p.lineTo(v2 + mathfont.em, v1)
p.lineTo(mathfont.em, 0)
p.closePath()
g.width = mathfont.em + v2
Exemple #6
0
#!/usr/bin/python

from utils import mathfont
import fontforge

nAryWhiteVerticalBarCodePoint = 0x2AFF
v1 = 5 * mathfont.em
f = mathfont.create("largeop-displayoperatorminheight%d" % v1)
f.math.DisplayOperatorMinHeight = v1
mathfont.createSquareGlyph(f, nAryWhiteVerticalBarCodePoint)
g = f.createChar(-1, "uni2AFF.display")
mathfont.drawRectangleGlyph(g, mathfont.em, v1, 0)
f[nAryWhiteVerticalBarCodePoint].verticalVariants = "uni2AFF uni2AFF.display"
mathfont.save(f)

v1 = 2 * mathfont.em
v2 = 3 * mathfont.em
f = mathfont.create("largeop-displayoperatorminheight%d-2AFF-italiccorrection%d" % (v1, v2))
f.copyright = "Copyright (c) 2018 Igalia S.L."
f.math.DisplayOperatorMinHeight = v1
mathfont.createSquareGlyph(f, nAryWhiteVerticalBarCodePoint)
g = f.createChar(-1, "uni2AFF.display")
p = g.glyphPen()
p.moveTo(0, 0)
p.lineTo(v2, v1)
p.lineTo(v2 + mathfont.em, v1)
p.lineTo(mathfont.em, 0)
p.closePath();
g.width = mathfont.em + v2
g.italicCorrection = v2
f[nAryWhiteVerticalBarCodePoint].verticalVariants = "uni2AFF uni2AFF.display"
Exemple #7
0
#!/usr/bin/env python3

from utils import mathfont
import fontforge

verticalArrowCodePoint = 0x21A8
v1 = 5 * mathfont.em
v2 = 14 * mathfont.em
f = mathfont.create("axisheight%d-verticalarrow%d" % (v1, v2),
                    "Copyright (c) 2016 MathML Association")
f.math.AxisHeight = v1
f.math.MinConnectorOverlap = 0
mathfont.createSquareGlyph(f, verticalArrowCodePoint)
g = f.createChar(-1, "size1")
mathfont.drawRectangleGlyph(g, mathfont.em, v2 / 2, 0)
g = f.createChar(-1, "size2")
mathfont.drawRectangleGlyph(g, mathfont.em, v2, 0)
g = f.createChar(-1, "bot")
mathfont.drawRectangleGlyph(g, mathfont.em, v2 + v1, 0)
g = f.createChar(-1, "ext")
mathfont.drawRectangleGlyph(g, mathfont.em, mathfont.em, 0)
f[verticalArrowCodePoint].verticalVariants = "uni21A8 size1 size2"
# Part: (glyphName, isExtender, startConnector, endConnector, fullAdvance)
f[verticalArrowCodePoint].verticalComponents = \
  (("bot", False, 0, mathfont.em, v2 + v1), ("ext", True, mathfont.em, mathfont.em, mathfont.em))
mathfont.save(f)
Exemple #8
0
#!/usr/bin/python

from utils import mathfont
import fontforge

verticalArrowCodePoint = 0x21A8
v1 = 5 * mathfont.em
v2 = 14 * mathfont.em
f = mathfont.create("axisheight%d-verticalarrow%d" % (v1, v2))
f.math.AxisHeight = v1
mathfont.createSquareGlyph(f, verticalArrowCodePoint)
g = f.createChar(-1, "size1")
mathfont.drawRectangleGlyph(g, mathfont.em, v2 / 2, 0)
g = f.createChar(-1, "size2")
mathfont.drawRectangleGlyph(g, mathfont.em, v2, 0)
g = f.createChar(-1, "bot")
mathfont.drawRectangleGlyph(g, mathfont.em, v2 + v1, 0)
g = f.createChar(-1, "ext")
mathfont.drawRectangleGlyph(g, mathfont.em, mathfont.em, 0)
f[verticalArrowCodePoint].verticalVariants = "uni21A8 size1 size2"
f[verticalArrowCodePoint].verticalComponents = \
  (("bot", False, 0, 0, mathfont.em), ("ext", True, 0, 0, mathfont.em));
mathfont.save(f)
# Convert the Python structure into JSON
jsonFileName = "../relations/css-styling/mathvariant-transforms.json"
print("Generating %s..." % jsonFileName, end="")
jsonFile = open(jsonFileName, "w")
jsonFile.write(json.dumps(mathvariantTransforms,sort_keys=True, indent=4))
jsonFile.close()
print(" done.")

# Encode each transformed
font = mathfont.create("mathvariant-transforms")

transformedCharIndex = 1  # Index of the transformedChar.
numberOfBits = 11 # Number of bits to encode transformedCharIndex.
glyphWidth = 2 * mathfont.em # width of the mathvariant glyphs
rectangleWidth = glyphWidth / numberOfBits
assert rectangleWidth > 100

for mathvariant in mathvariantTransforms:
    for baseChar in mathvariantTransforms[mathvariant]:
        if baseChar not in font:
            g = font.createChar(baseChar)
            mathfont.drawRectangleGlyph(g, glyphWidth, mathfont.em, 0)
        transformedChar = mathvariantTransforms[mathvariant][baseChar]
        mathfont.createGlyphFromValue(font,
                                      transformedChar,
                                      glyphWidth,
                                      transformedCharIndex,
                                      numberOfBits)
        transformedCharIndex += 1
mathfont.save(font)