summaryrefslogtreecommitdiff
path: root/misc/pylib/robofab/test/test_psHints.py
blob: 991e9d9cc0c42577f2606263f53cf990807b1096 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
def test():
	"""
		# some tests for the ps Hints operations
		>>> from robofab.world import RFont, RGlyph
		>>> g = RGlyph()
		>>> g.psHints.isEmpty()
		True

		>>> h = RGlyph()
		>>> i = g + h
		>>> i.psHints.isEmpty()
		True
		
		>>> i = g - h
		>>> i.psHints.isEmpty()
		True
		
		>>> i = g * 2
		>>> i.psHints.isEmpty()
		True
		
		>>> i = g / 2
		>>> i.psHints.isEmpty()
		True
		
		>>> g.psHints.vHints = [(100, 50), (200, 50)]
		>>> g.psHints.hHints = [(100, 50), (200, 5)]

		>>> not g.psHints.isEmpty()
		True
		
		>>> gc = g.copy()
		>>> gc.psHints.asDict() == g.psHints.asDict()
		True
		
		# multiplication
		>>> v = g.psHints * 2
		>>> v.asDict() == {'vHints': [[200, 100], [400, 100]], 'hHints': [[200, 100], [400, 10]]}
		True

		# division
		>>> v = g.psHints / 2
		>>> v.asDict() == {'vHints': [[50.0, 25.0], [100.0, 25.0]], 'hHints': [[50.0, 25.0], [100.0, 2.5]]}
		True

		# multiplication with x, y, factor
		# vertically oriented values should respond different
		>>> v = g.psHints * (.5, 10)
		>>> v.asDict() == {'vHints': [[1000, 500], [2000, 500]], 'hHints': [[50.0, 25.0], [100.0, 2.5]]}
		True

		# division with x, y, factor
		# vertically oriented values should respond different
		>>> v = g.psHints / (.5, 10)
		>>> v.asDict() == {'vHints': [[10.0, 5.0], [20.0, 5.0]], 'hHints': [[200.0, 100.0], [400.0, 10.0]]}
		True

		# rounding to integer
		>>> v = g.psHints / 2
		>>> v.round()
		>>> v.asDict() == {'vHints': [(50, 25), (100, 25)], 'hHints': [(50, 25), (100, 3)]}
		True

		# "ps hint values calculating with a glyph"
		# ps hint values as part of glyphmath operations.
		# multiplication
		>>> h = g * 10
		>>> h.psHints.asDict() == {'vHints': [[1000, 500], [2000, 500]], 'hHints': [[1000, 500], [2000, 50]]}
		True

		# division
		>>> h = g / 2
		>>> h.psHints.asDict() == {'vHints': [[50.0, 25.0], [100.0, 25.0]], 'hHints': [[50.0, 25.0], [100.0, 2.5]]}
		True

		# x, y factor multiplication
		>>> h = g * (.5, 10)
		>>> h.psHints.asDict() == {'vHints': [[1000, 500], [2000, 500]], 'hHints': [[50.0, 25.0], [100.0, 2.5]]}
		True

		# x, y factor division
		>>> h = g / (.5, 10)
		>>> h.psHints.asDict() == {'vHints': [[10.0, 5.0], [20.0, 5.0]], 'hHints': [[200.0, 100.0], [400.0, 10.0]]}
		True

		# "font ps hint values"
		>>> f = RFont()
		>>> f.psHints.isEmpty()
		True

		>>> f.psHints.blueScale = .5
		>>> f.psHints.blueShift = 1
		>>> f.psHints.blueFuzz = 1
		>>> f.psHints.forceBold = True
		>>> f.psHints.hStems = (100, 90)
		>>> f.psHints.vStems = (500, 10)

		>>> not f.psHints.isEmpty()
		True

		>>> f.insertGlyph(g, name="new")
		<RGlyph for None.new>
		>>> f["new"].psHints.asDict() == g.psHints.asDict()
		True
	"""

if __name__ == "__main__":
	import doctest
	doctest.testmod()