#!/usr/bin/python

from utils import mathfont
import fontforge

v = mathfont.em / 2
f = mathfont.create("xheight%d" % v)
g = f.createChar(ord('x'))
mathfont.drawRectangleGlyph(g, mathfont.em, v, 0)
assert f.xHeight == v, "Bad x-height value!"
mathfont.save(f)
Exemple #2
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 #3
0
#!/usr/bin/python

from utils import mathfont
import fontforge

nArySumCodePoint = 0x2211 # largeop operator

v = 3 * mathfont.em
f = mathfont.create("limits-lowerlimitbaselinedropmin%d" % v)
mathfont.createSquareGlyph(f, nArySumCodePoint)
f.math.LowerLimitBaselineDropMin = v
f.math.LowerLimitGapMin = 0
f.math.OverbarExtraAscender = 0
f.math.OverbarVerticalGap = 0
f.math.StretchStackBottomShiftDown = 0
f.math.StretchStackGapAboveMin = 0
f.math.StretchStackGapBelowMin = 0
f.math.StretchStackTopShiftUp = 0
f.math.UnderbarExtraDescender = 0
f.math.UnderbarVerticalGap = 0
f.math.UpperLimitBaselineRiseMin = 0
f.math.UpperLimitGapMin = 0
mathfont.save(f)

v = 11 * mathfont.em
f = mathfont.create("limits-lowerlimitgapmin%d" % v)
mathfont.createSquareGlyph(f, nArySumCodePoint)
f.math.LowerLimitBaselineDropMin = 0
f.math.LowerLimitGapMin = v
f.math.OverbarExtraAscender = 0
f.math.OverbarVerticalGap = 0
Exemple #4
0
#!/usr/bin/python

from utils import mathfont
import fontforge

v1 = 7 * mathfont.em
v2 = 1 * mathfont.em
f = mathfont.create("fraction-axisheight%d-rulethickness%d" % (v1, v2))
f.math.AxisHeight = v1
f.math.FractionDenominatorDisplayStyleGapMin = 0
f.math.FractionDenominatorDisplayStyleShiftDown = 0
f.math.FractionDenominatorGapMin = 0
f.math.FractionDenominatorShiftDown = 0
f.math.FractionNumeratorDisplayStyleGapMin = 0
f.math.FractionNumeratorDisplayStyleShiftUp = 0
f.math.FractionNumeratorGapMin = 0
f.math.FractionNumeratorShiftUp = 0
f.math.FractionRuleThickness = v2
mathfont.save(f)

v1 = 5 * mathfont.em
v2 = 1 * mathfont.em
f = mathfont.create("fraction-denominatordisplaystylegapmin%d-rulethickness%d" % (v1, v2))
f.math.AxisHeight = 0
f.math.FractionDenominatorDisplayStyleGapMin = v1
f.math.FractionDenominatorDisplayStyleShiftDown = 0
f.math.FractionDenominatorGapMin = 0
f.math.FractionDenominatorShiftDown = 0
f.math.FractionNumeratorDisplayStyleGapMin = 0
f.math.FractionNumeratorDisplayStyleShiftUp = 0
f.math.FractionNumeratorGapMin = 0
Exemple #5
0
#!/usr/bin/python

from utils import mathfont
import fontforge

breveCodePoint = 0x2D8 # accent operator
degreeCodePoint = 0xB0 # nonaccent operator
accentBaseHeight = 4 * mathfont.em

v = 3 * mathfont.em
f = mathfont.create("underover-accentbaseheight%d-overbarextraascender%d" % (accentBaseHeight, v))
mathfont.createSquareGlyph(f, breveCodePoint)
mathfont.createSquareGlyph(f, degreeCodePoint)
f.math.AccentBaseHeight = accentBaseHeight
f.math.LowerLimitBaselineDropMin = 0
f.math.LowerLimitGapMin = 0
f.math.OverbarExtraAscender = v
f.math.OverbarVerticalGap = 0
f.math.StretchStackBottomShiftDown = 0
f.math.StretchStackGapAboveMin = 0
f.math.StretchStackGapBelowMin = 0
f.math.StretchStackTopShiftUp = 0
f.math.UnderbarExtraDescender = 0
f.math.UnderbarVerticalGap = 0
f.math.UpperLimitBaselineRiseMin = 0
f.math.UpperLimitGapMin = 0
mathfont.save(f)

v = 11 * mathfont.em
f = mathfont.create("underover-accentbaseheight%d-overbarverticalgap%d" % (accentBaseHeight, v))
mathfont.createSquareGlyph(f, breveCodePoint)
Exemple #6
0
#!/usr/bin/env python3

from utils import mathfont
import fontforge

v = mathfont.em / 2
f = mathfont.create("xheight%d" % v, "Copyright (c) 2016 MathML Association")
g = f.createChar(ord('x'))
mathfont.drawRectangleGlyph(g, mathfont.em, v, 0)
assert f.xHeight == v, "Bad x-height value!"
mathfont.save(f)
Exemple #7
0
#!/usr/bin/env python3

from utils import mathfont
import fontforge

# Create a WOFF font with glyphs for all the operator strings.
font = mathfont.create("stretchy", "Copyright (c) 2021 Igalia S.L.")

# Set parameters for stretchy tests.
font.math.MinConnectorOverlap = mathfont.em // 2

# Make sure that underover parameters don't add extra spacing.
font.math.LowerLimitBaselineDropMin = 0
font.math.LowerLimitGapMin = 0
font.math.StretchStackBottomShiftDown = 0
font.math.StretchStackGapAboveMin = 0
font.math.UnderbarVerticalGap = 0
font.math.UnderbarExtraDescender = 0
font.math.UpperLimitBaselineRiseMin = 0
font.math.UpperLimitGapMin = 0
font.math.StretchStackTopShiftUp = 0
font.math.StretchStackGapBelowMin = 0
font.math.OverbarVerticalGap = 0
font.math.AccentBaseHeight = 0
font.math.OverbarExtraAscender = 0

# These two characters will be stretchable in both directions.
horizontalArrow = 0x295A  # LEFTWARDS HARPOON WITH BARB UP FROM BAR
verticalArrow = 0x295C  # UPWARDS HARPOON WITH BARB RIGHT FROM BAR

mathfont.createSizeVariants(font)
        mathvariantTransforms[mathvariant] = {}
    mathvariantTransforms[mathvariant][baseChar] = transformedChar

# There is no "isolated" mathvariant.
del mathvariantTransforms["isolated"]

# 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,
Exemple #9
0
#!/usr/bin/python

from utils import mathfont
import fontforge

nArySumCodePoint = 0x2211  # largeop operator

v = 3 * mathfont.em
f = mathfont.create("limits-lowerlimitbaselinedropmin%d" % v,
                    "Copyright (c) 2016 MathML Association")
mathfont.createSquareGlyph(f, nArySumCodePoint)
f.math.LowerLimitBaselineDropMin = v
f.math.LowerLimitGapMin = 0
f.math.OverbarExtraAscender = 0
f.math.OverbarVerticalGap = 0
f.math.StretchStackBottomShiftDown = 0
f.math.StretchStackGapAboveMin = 0
f.math.StretchStackGapBelowMin = 0
f.math.StretchStackTopShiftUp = 0
f.math.UnderbarExtraDescender = 0
f.math.UnderbarVerticalGap = 0
f.math.UpperLimitBaselineRiseMin = 0
f.math.UpperLimitGapMin = 0
mathfont.save(f)

v = 11 * mathfont.em
f = mathfont.create("limits-lowerlimitgapmin%d" % v,
                    "Copyright (c) 2016 MathML Association")
mathfont.createSquareGlyph(f, nArySumCodePoint)
f.math.LowerLimitBaselineDropMin = 0
f.math.LowerLimitGapMin = v
Exemple #10
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
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 #11
0
#!/usr/bin/python

from utils import mathfont
import fontforge

v1 = 80
v2 = 40
f = mathfont.create("scriptpercentscaledown%d-scriptscriptpercentscaledown%d" %
                    (v1, v2))
f.math.ScriptPercentScaleDown = v1
f.math.ScriptScriptPercentScaleDown = v2
mathfont.save(f)

f = mathfont.create("scriptpercentscaledown0-scriptscriptpercentscaledown%d" %
                    v2)
f.math.ScriptPercentScaleDown = 0
f.math.ScriptScriptPercentScaleDown = v2
mathfont.save(f)

f = mathfont.create("scriptpercentscaledown%d-scriptscriptpercentscaledown0" %
                    v1)
f.math.ScriptPercentScaleDown = v1
f.math.ScriptScriptPercentScaleDown = 0
mathfont.save(f)
#!/usr/bin/env python3

from utils import mathfont
import fontforge

v1 = 80
v2 = 40
f = mathfont.create("scriptpercentscaledown%d-scriptscriptpercentscaledown%d" % (v1, v2),
                    "Copyright (c) 2019 Igalia S.L.")
f.math.ScriptPercentScaleDown = v1
f.math.ScriptScriptPercentScaleDown = v2
mathfont.save(f)

f = mathfont.create("scriptpercentscaledown0-scriptscriptpercentscaledown%d" % v2,
                    "Copyright (c) 2019 Igalia S.L.")
f.math.ScriptPercentScaleDown = 0
f.math.ScriptScriptPercentScaleDown = v2
mathfont.save(f)

f = mathfont.create("scriptpercentscaledown%d-scriptscriptpercentscaledown0" % v1,
                    "Copyright (c) 2019 Igalia S.L.")
f.math.ScriptPercentScaleDown = v1
f.math.ScriptScriptPercentScaleDown = 0
mathfont.save(f)
Exemple #13
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)
Exemple #14
0
    if mathvariant not in mathvariantTransforms:
        mathvariantTransforms[mathvariant] = {}
    mathvariantTransforms[mathvariant][baseChar] = transformedChar

# There is no "isolated" mathvariant.
del mathvariantTransforms["isolated"]

# Automatic mathvariant uses the same transform as italic.
# It is handled specially (see below).
mathvariantTransforms["auto"] = mathvariantTransforms["italic"]

# Create a WOFF font for each mathvariant.
for mathvariant in mathvariantTransforms:
    if mathvariant == "auto":
        continue
    font = mathfont.create("mathvariant-%s" % mathvariant,
                           "Copyright (c) 2016 MathML Association")
    for baseChar in mathvariantTransforms[mathvariant]:
        if baseChar not in font:
            mathfont.createGlyphFromValue(font, baseChar)
        transformedChar = mathvariantTransforms[mathvariant][baseChar]
        mathfont.createGlyphFromValue(font, transformedChar)
    mathfont.save(font)

# Create a MathML and CSS test for each mathvariant.
for mathvariant in mathvariantTransforms:
    print("Generating tests for %s..." % mathvariant, end="")
    reftest = open(
        "../relations/css-styling/mathvariant-%s.html" % mathvariant, "w")
    reftestReference = open(
        "../relations/css-styling/mathvariant-%s-ref.html" % mathvariant, "w")
    CSSreftest = open(
Exemple #15
0
#!/usr/bin/python

from utils import mathfont
import fontforge

arrowCodePoint = 0x2192 # horizontal stretch operator

v = 3 * mathfont.em
f = mathfont.create("stretchstack-bottomshiftdown%d" % v,
                    "Copyright (c) 2016 MathML Association")
mathfont.createSquareGlyph(f, arrowCodePoint)
f.math.LowerLimitBaselineDropMin = 0
f.math.LowerLimitGapMin = 0
f.math.OverbarExtraAscender = 0
f.math.OverbarVerticalGap = 0
f.math.StretchStackBottomShiftDown = v
f.math.StretchStackGapAboveMin = 0
f.math.StretchStackGapBelowMin = 0
f.math.StretchStackTopShiftUp = 0
f.math.UnderbarExtraDescender = 0
f.math.UnderbarVerticalGap = 0
f.math.UpperLimitBaselineRiseMin = 0
f.math.UpperLimitGapMin = 0
mathfont.save(f)

v = 11 * mathfont.em
f = mathfont.create("stretchstack-gapbelowmin%d" % v,
                    "Copyright (c) 2016 MathML Association")
mathfont.createSquareGlyph(f, arrowCodePoint)
f.math.LowerLimitBaselineDropMin = 0
f.math.LowerLimitGapMin = 0
Exemple #16
0
#!/usr/bin/env python3

from utils import mathfont
import fontforge

v1 = 5 * mathfont.em
v2 = 1 * mathfont.em
f = mathfont.create(
    "stack-bottomdisplaystyleshiftdown%d-axisheight%d" % (v1, v2),
    "Copyright (c) 2016 MathML Association")
f.math.AxisHeight = v2
f.math.StackBottomDisplayStyleShiftDown = v1
f.math.StackBottomShiftDown = 0
f.math.StackDisplayStyleGapMin = 0
f.math.StackGapMin = 0
f.math.StackTopDisplayStyleShiftUp = 0
f.math.StackTopShiftUp = 0
mathfont.save(f)

v1 = 6 * mathfont.em
v2 = 1 * mathfont.em
f = mathfont.create("stack-bottomshiftdown%d-axisheight%d" % (v1, v2),
                    "Copyright (c) 2016 MathML Association")
f.math.AxisHeight = v2
f.math.StackBottomDisplayStyleShiftDown = 0
f.math.StackBottomShiftDown = v1
f.math.StackDisplayStyleGapMin = 0
f.math.StackGapMin = 0
f.math.StackTopDisplayStyleShiftUp = 0
f.math.StackTopShiftUp = 0
mathfont.save(f)
Exemple #17
0
    # layout, so they are not added to the JSON file.
    parseSpaces(value, entry, ["lspace", "rspace"])
    parseProperties(value, entry, ["stretchy", "symmetric", "largeop",
                                   "movablelimits", "accent"])
    if (len(characters) == 1 and characters[0] in inlineAxisOperators):
        value["horizontal"] = True
    operatorDictionary[key] = value

# Create entries for the non-breaking space in all forms in order to test the
# default for operators outside the official dictionary.
for form in ["infix", "prefix", "suffix"]:
    key, value = buildKeyAndValueFrom(tuple([NonBreakingSpace]), form)
    operatorDictionary[key] = value

# Create a WOFF font with glyphs for all the operator strings.
font = mathfont.create("operators")

# Set parameters for largeop and stretchy tests.
font.math.DisplayOperatorMinHeight = 2 * mathfont.em
font.math.MinConnectorOverlap = mathfont.em / 2

# 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]
Exemple #18
0
#!/usr/bin/python

from utils import mathfont
import fontforge

v1 = 7 * mathfont.em
v2 = 1 * mathfont.em
f = mathfont.create("fraction-axisheight%d-rulethickness%d" % (v1, v2))
f.math.AxisHeight = v1
f.math.FractionDenominatorDisplayStyleGapMin = 0
f.math.FractionDenominatorDisplayStyleShiftDown = 0
f.math.FractionDenominatorGapMin = 0
f.math.FractionDenominatorShiftDown = 0
f.math.FractionNumeratorDisplayStyleGapMin = 0
f.math.FractionNumeratorDisplayStyleShiftUp = 0
f.math.FractionNumeratorGapMin = 0
f.math.FractionNumeratorShiftUp = 0
f.math.FractionRuleThickness = v2
mathfont.save(f)

v1 = 5 * mathfont.em
v2 = 1 * mathfont.em
f = mathfont.create(
    "fraction-denominatordisplaystylegapmin%d-rulethickness%d" % (v1, v2))
f.math.AxisHeight = 0
f.math.FractionDenominatorDisplayStyleGapMin = v1
f.math.FractionDenominatorDisplayStyleShiftDown = 0
f.math.FractionDenominatorGapMin = 0
f.math.FractionDenominatorShiftDown = 0
f.math.FractionNumeratorDisplayStyleGapMin = 0
f.math.FractionNumeratorDisplayStyleShiftUp = 0
Exemple #19
0
#!/usr/bin/python

from utils import mathfont
import fontforge

v = 3 * mathfont.em
f = mathfont.create("scripts-spaceafterscript%d" % v)
f.math.SpaceAfterScript = v
f.math.SubSuperscriptGapMin = 0
f.math.SubscriptBaselineDropMin = 0
f.math.SubscriptShiftDown = 0
f.math.SubscriptTopMax = 0
f.math.SuperscriptBaselineDropMax = 0
f.math.SuperscriptBottomMaxWithSubscript = 0
f.math.SuperscriptBottomMin = 0
f.math.SuperscriptShiftUp = 0
f.math.SuperscriptShiftUpCramped = 0
mathfont.save(f)

v = 7 * mathfont.em
f = mathfont.create("scripts-superscriptshiftup%d" % v)
f.math.SpaceAfterScript = 0
f.math.SubSuperscriptGapMin = 0
f.math.SubscriptBaselineDropMin = 0
f.math.SubscriptShiftDown = 0
f.math.SubscriptTopMax = 0
f.math.SuperscriptBaselineDropMax = 0
f.math.SuperscriptBottomMaxWithSubscript = 0
f.math.SuperscriptBottomMin = 0
f.math.SuperscriptShiftUp = v
f.math.SuperscriptShiftUpCramped = 0
Exemple #20
0
#!/usr/bin/python

from utils import mathfont
import fontforge

arrowCodePoint = 0x2192  # horizontal stretch operator

v = 3 * mathfont.em
f = mathfont.create("stretchstack-bottomshiftdown%d" % v)
mathfont.createSquareGlyph(f, arrowCodePoint)
f.math.LowerLimitBaselineDropMin = 0
f.math.LowerLimitGapMin = 0
f.math.OverbarExtraAscender = 0
f.math.OverbarVerticalGap = 0
f.math.StretchStackBottomShiftDown = v
f.math.StretchStackGapAboveMin = 0
f.math.StretchStackGapBelowMin = 0
f.math.StretchStackTopShiftUp = 0
f.math.UnderbarExtraDescender = 0
f.math.UnderbarVerticalGap = 0
f.math.UpperLimitBaselineRiseMin = 0
f.math.UpperLimitGapMin = 0
mathfont.save(f)

v = 11 * mathfont.em
f = mathfont.create("stretchstack-gapbelowmin%d" % v)
mathfont.createSquareGlyph(f, arrowCodePoint)
f.math.LowerLimitBaselineDropMin = 0
f.math.LowerLimitGapMin = 0
f.math.OverbarExtraAscender = 0
f.math.OverbarVerticalGap = 0
Exemple #21
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)
def parseCodePoint(aHexaString):
    return int("0x%s" % aHexaString[1:], 16)
for entry in root:
    mathvariant = entry.get("mathvariant")
    baseChar = parseCodePoint(entry.get("baseChar"))
    transformedChar = parseCodePoint(entry.get("transformedChar"))
    if mathvariant not in mathvariantTransforms:
        mathvariantTransforms[mathvariant] = {}
    mathvariantTransforms[mathvariant][baseChar] = transformedChar

# There is no "isolated" mathvariant.
del mathvariantTransforms["isolated"]

# Create a WOFF font for each mathvariant.
for mathvariant in mathvariantTransforms:
    font = mathfont.create("mathvariant-%s" % mathvariant)
    for baseChar in mathvariantTransforms[mathvariant]:
        if baseChar not in font:
            mathfont.createGlyphFromValue(font, baseChar)
        transformedChar = mathvariantTransforms[mathvariant][baseChar]
        mathfont.createGlyphFromValue(font, transformedChar)
    mathfont.save(font)

# Create a test font for each mathvariant.
for mathvariant in mathvariantTransforms:
    print("Generating test for %s..." % mathvariant, end="")
    reftest = open("../relations/css-styling/mathvariant-%s.html" % mathvariant, "w")
    reftestReference = open("../relations/css-styling/mathvariant-%s-ref.html" % mathvariant, "w")
    source = '\
<!DOCTYPE html>\n\
<html>\n\
Exemple #23
0
#!/usr/bin/python

from utils import mathfont
import fontforge

v = 3 * mathfont.em
f = mathfont.create("scripts-spaceafterscript%d" % v)
f.math.SpaceAfterScript = v
f.math.SubSuperscriptGapMin = 0
f.math.SubscriptBaselineDropMin = 0
f.math.SubscriptShiftDown = 0
f.math.SubscriptTopMax = 0
f.math.SuperscriptBaselineDropMax = 0
f.math.SuperscriptBottomMaxWithSubscript = 0
f.math.SuperscriptBottomMin = 0
f.math.SuperscriptShiftUp = 0
f.math.SuperscriptShiftUpCramped = 0
mathfont.save(f)

v = 7 * mathfont.em
f = mathfont.create("scripts-superscriptshiftup%d" % v)
f.math.SpaceAfterScript = 0
f.math.SubSuperscriptGapMin = 0
f.math.SubscriptBaselineDropMin = 0
f.math.SubscriptShiftDown = 0
f.math.SubscriptTopMax = 0
f.math.SuperscriptBaselineDropMax = 0
f.math.SuperscriptBottomMaxWithSubscript = 0
f.math.SuperscriptBottomMin = 0
f.math.SuperscriptShiftUp = v
f.math.SuperscriptShiftUpCramped = 0
Exemple #24
0
#!/usr/bin/python

from utils import mathfont
import fontforge

v = 7 * mathfont.em
f = mathfont.create("stack-axisheight%d" % v)
f.math.AxisHeight = v
f.math.StackBottomDisplayStyleShiftDown = 0
f.math.StackBottomShiftDown = 0
f.math.StackDisplayStyleGapMin = 0
f.math.StackGapMin = 0
f.math.StackTopDisplayStyleShiftUp = 0
f.math.StackTopShiftUp = 0
mathfont.save(f)

v = 5 * mathfont.em
f = mathfont.create("stack-bottomdisplaystyleshiftdown%d" % v)
f.math.AxisHeight = 0
f.math.StackBottomDisplayStyleShiftDown = v
f.math.StackBottomShiftDown = 0
f.math.StackDisplayStyleGapMin = 0
f.math.StackGapMin = 0
f.math.StackTopDisplayStyleShiftUp = 0
f.math.StackTopShiftUp = 0
mathfont.save(f)

v = 6 * mathfont.em
f = mathfont.create("stack-bottomshiftdown%d" % v)
f.math.AxisHeight = 0
f.math.StackBottomDisplayStyleShiftDown = 0
Exemple #25
0
#!/usr/bin/python

from utils import mathfont
import fontforge

v1 = 7 * mathfont.em
v2 = 1 * mathfont.em
f = mathfont.create("fraction-axisheight%d-rulethickness%d" % (v1, v2),
                    "Copyright (c) 2016 MathML Association")
f.math.AxisHeight = v1
f.math.FractionDenominatorDisplayStyleGapMin = 0
f.math.FractionDenominatorDisplayStyleShiftDown = 0
f.math.FractionDenominatorGapMin = 0
f.math.FractionDenominatorShiftDown = 0
f.math.FractionNumeratorDisplayStyleGapMin = 0
f.math.FractionNumeratorDisplayStyleShiftUp = 0
f.math.FractionNumeratorGapMin = 0
f.math.FractionNumeratorShiftUp = 0
f.math.FractionRuleThickness = v2
mathfont.save(f)

v1 = 5 * mathfont.em
v2 = 1 * mathfont.em
f = mathfont.create("fraction-denominatordisplaystylegapmin%d-rulethickness%d" % (v1, v2),
                    "Copyright (c) 2016 MathML Association")
f.math.AxisHeight = 0
f.math.FractionDenominatorDisplayStyleGapMin = v1
f.math.FractionDenominatorDisplayStyleShiftDown = 0
f.math.FractionDenominatorGapMin = 0
f.math.FractionDenominatorShiftDown = 0
f.math.FractionNumeratorDisplayStyleGapMin = 0
Exemple #26
0
    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))

v1 = 25
v2 = 1 * mathfont.em
f = mathfont.create("radical-degreebottomraisepercent%d-rulethickness%d" % (v1, v2),
                    "Copyright (c) 2016 MathML Association")
createStretchyRadical(f)
f.math.RadicalDegreeBottomRaisePercent = v1
f.math.RadicalDisplayStyleVerticalGap = 0
f.math.RadicalExtraAscender = 0
f.math.RadicalKernAfterDegree = 0
f.math.RadicalKernBeforeDegree = 0
f.math.RadicalRuleThickness = v2
f.math.RadicalVerticalGap = 0
mathfont.save(f)

v1 = 7 * mathfont.em
v2 = 1 * mathfont.em
f = mathfont.create("radical-displaystyleverticalgap%d-rulethickness%d" % (v1, v2),
                    "Copyright (c) 2016 MathML Association")
createStretchyRadical(f)
Exemple #27
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 #28
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 #29
0
#!/usr/bin/env python3

from utils import mathfont
import fontforge

breveCodePoint = 0x2D8 # accent operator
degreeCodePoint = 0xB0 # nonaccent operator
accentBaseHeight = 4 * mathfont.em

v = 3 * mathfont.em
f = mathfont.create("underover-accentbaseheight%d-overbarextraascender%d" % (accentBaseHeight, v),
                    "Copyright (c) 2016 MathML Association")
mathfont.createSquareGlyph(f, breveCodePoint)
mathfont.createSquareGlyph(f, degreeCodePoint)
f.math.AccentBaseHeight = accentBaseHeight
f.math.LowerLimitBaselineDropMin = 0
f.math.LowerLimitGapMin = 0
f.math.OverbarExtraAscender = v
f.math.OverbarVerticalGap = 0
f.math.StretchStackBottomShiftDown = 0
f.math.StretchStackGapAboveMin = 0
f.math.StretchStackGapBelowMin = 0
f.math.StretchStackTopShiftUp = 0
f.math.UnderbarExtraDescender = 0
f.math.UnderbarVerticalGap = 0
f.math.UpperLimitBaselineRiseMin = 0
f.math.UpperLimitGapMin = 0
mathfont.save(f)

v = 11 * mathfont.em
f = mathfont.create("underover-accentbaseheight%d-overbarverticalgap%d" % (accentBaseHeight, v),
    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))

v1 = 25
v2 = 1 * mathfont.em
f = mathfont.create("radical-degreebottomraisepercent%d-rulethickness%d" % (v1, v2))
createStretchyRadical(f)
f.math.RadicalDegreeBottomRaisePercent = v1
f.math.RadicalDisplayStyleVerticalGap = 0
f.math.RadicalExtraAscender = 0
f.math.RadicalKernAfterDegree = 0
f.math.RadicalKernBeforeDegree = 0
f.math.RadicalRuleThickness = v2
f.math.RadicalVerticalGap = 0
mathfont.save(f)

v1 = 7 * mathfont.em
v2 = 1 * mathfont.em
f = mathfont.create("radical-displaystyleverticalgap%d-rulethickness%d" % (v1, v2))
createStretchyRadical(f)
f.math.RadicalDegreeBottomRaisePercent = 0
Exemple #31
0
    if mathvariant not in mathvariantTransforms:
        mathvariantTransforms[mathvariant] = {}
    mathvariantTransforms[mathvariant][baseChar] = transformedChar

# There is no "isolated" mathvariant.
del mathvariantTransforms["isolated"]

# Automatic mathvariant uses the same transform as italic.
# It is handled specially (see below).
mathvariantTransforms["auto"] = mathvariantTransforms["italic"]

# Create a WOFF font for each mathvariant.
for mathvariant in mathvariantTransforms:
    if mathvariant == "auto":
        continue
    font = mathfont.create("mathvariant-%s" % mathvariant)
    for baseChar in mathvariantTransforms[mathvariant]:
        if baseChar not in font:
            mathfont.createGlyphFromValue(font, baseChar)
        transformedChar = mathvariantTransforms[mathvariant][baseChar]
        mathfont.createGlyphFromValue(font, transformedChar)
    mathfont.save(font)

# Create a MathML and CSS test for each mathvariant.
for mathvariant in mathvariantTransforms:
    print("Generating tests for %s..." % mathvariant, end="")
    reftest = open(
        "../relations/css-styling/mathvariant-%s.html" % mathvariant, "w")
    reftestReference = open(
        "../relations/css-styling/mathvariant-%s-ref.html" % mathvariant, "w")
    CSSreftest = open(
Exemple #32
0
#!/usr/bin/env python3

from utils import mathfont
import fontforge

v = 3 * mathfont.em
f = mathfont.create("scripts-spaceafterscript%d" % v,
                    "Copyright (c) 2016 MathML Association")
f.math.SpaceAfterScript = v
f.math.SubSuperscriptGapMin = 0
f.math.SubscriptBaselineDropMin = 0
f.math.SubscriptShiftDown = 0
f.math.SubscriptTopMax = 0
f.math.SuperscriptBaselineDropMax = 0
f.math.SuperscriptBottomMaxWithSubscript = 0
f.math.SuperscriptBottomMin = 0
f.math.SuperscriptShiftUp = 0
f.math.SuperscriptShiftUpCramped = 0
mathfont.save(f)

v = 7 * mathfont.em
f = mathfont.create("scripts-superscriptshiftup%d" % v,
                    "Copyright (c) 2016 MathML Association")
f.math.SpaceAfterScript = 0
f.math.SubSuperscriptGapMin = 0
f.math.SubscriptBaselineDropMin = 0
f.math.SubscriptShiftDown = 0
f.math.SubscriptTopMax = 0
f.math.SuperscriptBaselineDropMax = 0
f.math.SuperscriptBottomMaxWithSubscript = 0
f.math.SuperscriptBottomMin = 0
Exemple #33
0
#!/usr/bin/python

from utils import mathfont
import fontforge

breveCodePoint = 0x2D8  # accent operator
degreeCodePoint = 0xB0  # nonaccent operator
accentBaseHeight = 4 * mathfont.em

v = 3 * mathfont.em
f = mathfont.create("underover-accentbaseheight%d-overbarextraascender%d" %
                    (accentBaseHeight, v))
mathfont.createSquareGlyph(f, breveCodePoint)
mathfont.createSquareGlyph(f, degreeCodePoint)
f.math.AccentBaseHeight = accentBaseHeight
f.math.LowerLimitBaselineDropMin = 0
f.math.LowerLimitGapMin = 0
f.math.OverbarExtraAscender = v
f.math.OverbarVerticalGap = 0
f.math.StretchStackBottomShiftDown = 0
f.math.StretchStackGapAboveMin = 0
f.math.StretchStackGapBelowMin = 0
f.math.StretchStackTopShiftUp = 0
f.math.UnderbarExtraDescender = 0
f.math.UnderbarVerticalGap = 0
f.math.UpperLimitBaselineRiseMin = 0
f.math.UpperLimitGapMin = 0
mathfont.save(f)

v = 11 * mathfont.em
f = mathfont.create("underover-accentbaseheight%d-overbarverticalgap%d" %
Exemple #34
0
    parseSpaces(value, entry, ["lspace", "rspace"])
    parseProperties(
        value, entry,
        ["stretchy", "symmetric", "largeop", "movablelimits", "accent"])
    if (len(characters) == 1 and characters[0] in inlineAxisOperators):
        value["horizontal"] = True
    operatorDictionary[key] = value

# Create entries for the non-breaking space in all forms in order to test the
# default for operators outside the official dictionary.
for form in ["infix", "prefix", "suffix"]:
    key, value = buildKeyAndValueFrom(tuple([NonBreakingSpace]), form)
    operatorDictionary[key] = value

# Create a WOFF font with glyphs for all the operator strings.
font = mathfont.create("operators", "Copyright (c) 2019 Igalia S.L.")

# Set parameters for largeop and stretchy tests.
font.math.DisplayOperatorMinHeight = 2 * mathfont.em
font.math.MinConnectorOverlap = mathfont.em / 2

# 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]
#!/usr/bin/python

from utils import mathfont
import fontforge

arrowCodePoint = 0x2192 # horizontal stretch operator

v = 3 * mathfont.em
f = mathfont.create("stretchstack-bottomshiftdown%d" % v)
mathfont.createSquareGlyph(f, arrowCodePoint)
f.math.LowerLimitBaselineDropMin = 0
f.math.LowerLimitGapMin = 0
f.math.OverbarExtraAscender = 0
f.math.OverbarVerticalGap = 0
f.math.StretchStackBottomShiftDown = v
f.math.StretchStackGapAboveMin = 0
f.math.StretchStackGapBelowMin = 0
f.math.StretchStackTopShiftUp = 0
f.math.UnderbarExtraDescender = 0
f.math.UnderbarVerticalGap = 0
f.math.UpperLimitBaselineRiseMin = 0
f.math.UpperLimitGapMin = 0
mathfont.save(f)

v = 11 * mathfont.em
f = mathfont.create("stretchstack-gapbelowmin%d" % v)
mathfont.createSquareGlyph(f, arrowCodePoint)
f.math.LowerLimitBaselineDropMin = 0
f.math.LowerLimitGapMin = 0
f.math.OverbarExtraAscender = 0
f.math.OverbarVerticalGap = 0