26
26
SPARSE_TTF_MASTER_TABLES ,
27
27
USE_PRODUCTION_NAMES ,
28
28
)
29
+ from ufo2ft .errors import InvalidFontData
29
30
from ufo2ft .fontInfoData import intListToNum
30
31
from ufo2ft .outlineCompiler import OutlineOTFCompiler , OutlineTTFCompiler
31
32
@@ -1406,9 +1407,10 @@ def test_achVendId_space_padded_if_less_than_4_chars(
1406
1407
assert font ["OS/2" ].achVendID == expected
1407
1408
1408
1409
1409
- def test_MATH_table (FontClass ):
1410
+ @pytest .mark .parametrize ("compile" , [compileTTF , compileOTF ])
1411
+ def test_MATH_table (FontClass , compile ):
1410
1412
ufo = FontClass (getpath ("TestMathFont-Regular.ufo" ))
1411
- result = compileTTF (ufo )
1413
+ result = compile (ufo )
1412
1414
assert "MATH" in result
1413
1415
1414
1416
math = result ["MATH" ].table
@@ -1427,6 +1429,53 @@ def test_MATH_table(FontClass):
1427
1429
1428
1430
assert set (math .MathGlyphInfo .ExtendedShapeCoverage .glyphs ) == extendedShapes
1429
1431
1432
+ assert set (math .MathVariants .VertGlyphCoverage .glyphs ) == {
1433
+ "parenright" ,
1434
+ "parenleft" ,
1435
+ }
1436
+ assert math .MathVariants .VertGlyphConstruction
1437
+ assert len (math .MathVariants .VertGlyphConstruction ) == 2
1438
+ assert (
1439
+ math .MathVariants .VertGlyphConstruction [0 ].GlyphAssembly .ItalicsCorrection .Value
1440
+ == 0
1441
+ )
1442
+ assert (
1443
+ len (math .MathVariants .VertGlyphConstruction [0 ].GlyphAssembly .PartRecords ) == 3
1444
+ )
1445
+
1446
+ assert not math .MathVariants .HorizGlyphCoverage
1447
+ assert not math .MathVariants .HorizGlyphConstruction
1448
+
1449
+
1450
+ @pytest .mark .parametrize ("compile" , [compileTTF , compileOTF ])
1451
+ @pytest .mark .parametrize (
1452
+ "attribute" ,
1453
+ [
1454
+ "vAssembly" ,
1455
+ "hAssembly" ,
1456
+ "vVariants" ,
1457
+ "hVariants" ,
1458
+ ],
1459
+ )
1460
+ def test_MATH_table_ignore_empty (FontClass , compile , attribute ):
1461
+ # Should not raise becaise of empty assembly/variants
1462
+ ufo = FontClass (getpath ("TestMathFont-Regular.ufo" ))
1463
+ ufo ["parenright" ].lib [GLYPHS_MATH_VARIANTS_KEY ][attribute ] = []
1464
+ compile (ufo )
1465
+
1466
+
1467
+ @pytest .mark .parametrize ("compile" , [compileTTF , compileOTF ])
1468
+ @pytest .mark .parametrize ("attribute" , ["vAssembly" , "hAssembly" ])
1469
+ def test_MATH_table_invalid (FontClass , compile , attribute ):
1470
+ ufo = FontClass (getpath ("TestMathFont-Regular.ufo" ))
1471
+ ufo ["parenright" ].lib [GLYPHS_MATH_VARIANTS_KEY ][attribute ] = [
1472
+ ["parenright.top" , 0 , 0 ],
1473
+ ["parenright.ext" , 1 , 100 , 100 ],
1474
+ ["parenright.bot" , 0 , 100 , 0 ],
1475
+ ]
1476
+ with pytest .raises (InvalidFontData , match = "Invalid assembly" ):
1477
+ compile (ufo )
1478
+
1430
1479
1431
1480
if __name__ == "__main__" :
1432
1481
import sys
0 commit comments