Debian Codegraph @

tests/test_math_device_table.py

raw symbols SCIP
1 #Needs: fonts/Ambrosia.sfd
2
3 #Test MATH device table access
4 import sys, fontforge
5
6 ambrosia = sys.argv[1]
7 font = fontforge.open(ambrosia)
8
9 assert font.math.MathLeadingDeviceTable == {}
10
11 # Assign various adjustment sets
12 for adjustments in [
13 {9: -1, 10: -1, 12: -1}, # set non-empty
14 {9: -1, 10: -1, 12: -1}, # set previous
15 {9: -1, 10: -1}, # reduce
16 {9: -1, 10: -1, 14: -1, 18: -1}, # increase
17 {9: 1, 10: -2, 12: 0, 18: -3}, # change values
18 {9: 1, 12: 0, 18: -3, 10: -2}, # change order
19 {}, # set empty
20 {} # set previous
21 ]:
22 font.math.MathLeadingDeviceTable = adjustments
23 # Filter out zero entries, they are not stored
24 non_zero_adjustments = {k:v for (k,v) in adjustments.items() if v != 0}
25 assert font.math.MathLeadingDeviceTable == non_zero_adjustments
26 assert len(font.math.MathLeadingDeviceTable) == len(non_zero_adjustments)
27
28 # Set table to None
29 font.math.AxisHeightDeviceTable = {10: -1}
30 # Check that None assignment removes all data from table
31 font.math.AxisHeightDeviceTable = None
32 assert font.math.AxisHeightDeviceTable == {}
33
34 # Set element to None
35 font.math.AxisHeightDeviceTable = {10: 3, 11:-1}
36 assert font.math.AxisHeightDeviceTable[11] == -1
37 font.math.AxisHeightDeviceTable[11] = None
38 assert font.math.AxisHeightDeviceTable[11] == 0
39
40 # Directly assign value to a table entry
41 font.math.MathLeadingDeviceTable[9] = -1
42 font.math.MathLeadingDeviceTable[10] = 0
43 font.math.MathLeadingDeviceTable[12] = 2
44
45 # Verify all non-zero values were assigned
46 assert font.math.MathLeadingDeviceTable == {9: -1, 12: 2}
47 assert len(font.math.MathLeadingDeviceTable) == 2
48
49 # Verify access by pixel size
50 assert font.math.MathLeadingDeviceTable[3] == 0
51 assert font.math.MathLeadingDeviceTable[9] == -1
52 assert font.math.MathLeadingDeviceTable[11] == 0
53 assert font.math.MathLeadingDeviceTable[12] == 2
54 assert font.math.MathLeadingDeviceTable[20] == 0
55
56 # Copy device table to another entry
57 assert font.math.SpaceAfterScriptDeviceTable == {}
58 font.math.SpaceAfterScriptDeviceTable = font.math.MathLeadingDeviceTable
59 assert font.math.SpaceAfterScriptDeviceTable == {9: -1, 12: 2}
60
61 # Check comparison
62 assert not font.math.SpaceAfterScriptDeviceTable == {12: 2}
63 assert font.math.SpaceAfterScriptDeviceTable != {12: 2}
64
65 # Iterate device table
66 tbl = font.math.MathLeadingDeviceTable
67 output = []
68 for px in tbl:
69 output.append(px)
70 assert tbl[px] != 0
71
72 assert len(output) == len(tbl)