| 1 |
|
| 2 |
|
| 3 |
import fontforge |
| 4 |
|
| 5 |
font=fontforge.font() |
| 6 |
math = font.math |
| 7 |
|
| 8 |
if math.exists(): |
| 9 |
raise ValueError("Thinks there is a math table in an empty font") |
| 10 |
math.clear() |
| 11 |
|
| 12 |
math.ScriptPercentScaleDown = 3 |
| 13 |
math.SubscriptBaselineDropMin = 6 |
| 14 |
if not math.exists(): |
| 15 |
raise ValueError("Thinks there isn't a math table after we added one") |
| 16 |
if ( math.ScriptPercentScaleDown!=3 or math.SubscriptBaselineDropMin != 6) : |
| 17 |
raise ValueError("Assignment failed") |
| 18 |
|
| 19 |
|
| 20 |
math.clear() |
| 21 |
|
| 22 |
|
| 23 |
accentBaseHeight = font.em * .75 |
| 24 |
g = font.createChar(0x78) |
| 25 |
p = g.glyphPen(); |
| 26 |
p.moveTo(0, 0); |
| 27 |
p.lineTo(accentBaseHeight, 0); |
| 28 |
p.lineTo(accentBaseHeight, accentBaseHeight); |
| 29 |
p.lineTo(0, accentBaseHeight) |
| 30 |
p.closePath(); |
| 31 |
|
| 32 |
|
| 33 |
if ( g.texheight != fontforge.unspecifiedMathValue or |
| 34 |
g.texdepth != fontforge.unspecifiedMathValue or |
| 35 |
g.topaccent != fontforge.unspecifiedMathValue or |
| 36 |
g.italicCorrection != fontforge.unspecifiedMathValue ): |
| 37 |
raise ValueError("Unexpected default value for a glyph constant") |
| 38 |
|
| 39 |
|
| 40 |
axisHeight = font.em * .3 |
| 41 |
g = font.createChar(0x2B) |
| 42 |
p = g.glyphPen(); |
| 43 |
p.moveTo(0, 0); |
| 44 |
p.lineTo(2*axisHeight, 0); |
| 45 |
p.lineTo(2*axisHeight, 2*axisHeight); |
| 46 |
p.lineTo(0, 2*axisHeight) |
| 47 |
p.closePath(); |
| 48 |
|
| 49 |
if ( math.ScriptPercentScaleDown != 80 or |
| 50 |
math.ScriptScriptPercentScaleDown != 60 or |
| 51 |
math.DelimitedSubFormulaMinHeight != int(font.em*1.5) or |
| 52 |
math.AxisHeight != int(axisHeight) or |
| 53 |
math.SubscriptTopMax != int(accentBaseHeight) or |
| 54 |
math.SuperscriptBottomMin != int(accentBaseHeight) or |
| 55 |
math.SubSuperscriptGapMin != int(4*font.uwidth) or |
| 56 |
math.SuperscriptBottomMaxWithSubscript != int(accentBaseHeight) or |
| 57 |
math.SpaceAfterScript != int(font.em/24) or |
| 58 |
math.StackGapMin != int(3*font.uwidth) or |
| 59 |
math.StackDisplayStyleGapMin != int(7*font.uwidth) or |
| 60 |
math.FractionNumeratorGapMin != int(font.uwidth) or |
| 61 |
math.FractionNumeratorDisplayStyleGapMin != int(3*font.uwidth) or |
| 62 |
math.FractionRuleThickness != int(font.uwidth) or |
| 63 |
math.FractionDenominatorGapMin != int(font.uwidth) or |
| 64 |
math.OverbarVerticalGap != int(3*font.uwidth) or |
| 65 |
math.OverbarRuleThickness != int(font.uwidth) or |
| 66 |
math.OverbarExtraAscender != int(font.uwidth) or |
| 67 |
math.UnderbarVerticalGap != int(3*font.uwidth) or |
| 68 |
math.UnderbarRuleThickness != int(font.uwidth) or |
| 69 |
math.UnderbarExtraDescender != int(font.uwidth) or |
| 70 |
math.RadicalVerticalGap != int(font.uwidth) or |
| 71 |
math.RadicalDisplayStyleVerticalGap != int(font.uwidth+.25*accentBaseHeight) or |
| 72 |
math.RadicalRuleThickness != int(font.uwidth) or |
| 73 |
math.RadicalRuleThickness != int(font.uwidth) or |
| 74 |
math.RadicalExtraAscender != int(font.uwidth) or |
| 75 |
math.RadicalKernBeforeDegree != int(5*font.em/18) or |
| 76 |
math.RadicalKernAfterDegree != -int(10*font.em/18) or |
| 77 |
math.RadicalDegreeBottomRaisePercent != 60 ): |
| 78 |
raise ValueError("Unexpected default value for one math constant") |
| 79 |
|
| 80 |
math.clear() |
| 81 |
if math.exists(): |
| 82 |
raise ValueError("Thinks there is a math table in an empty font") |
| 83 |
|
| 84 |
a = font.createChar(65) |
| 85 |
c = font.createChar(67) |
| 86 |
a.horizontalVariants = "B C D" |
| 87 |
a.horizontalComponents = (("a",),("b",1,20,20,200),c) |
| 88 |
a.horizontalComponentItalicCorrection = 10 |
| 89 |
|
| 90 |
a.verticalVariants = "B.v C.v D.v" |
| 91 |
a.verticalComponents = (("a",),("b",1,20,20,200),c) |
| 92 |
a.verticalComponentItalicCorrection = 20 |
| 93 |
|
| 94 |
if a.horizontalVariants != "B C D" or a.horizontalComponentItalicCorrection!=10: |
| 95 |
raise ValueError("Failed to set some glyph horizontal variant/component") |
| 96 |
if a.verticalVariants != "B.v C.v D.v" or a.verticalComponentItalicCorrection!=20: |
| 97 |
raise ValueError("Failed to set some glyph vertical variant/component") |
| 98 |
|
| 99 |
|
| 100 |
font[65].horizontalComponents = (('a',)) |
| 101 |
font[65].verticalComponents = (('a',)) |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|