| 1 |
|
| 2 |
|
| 3 |
import copy |
| 4 |
import fontforge as f |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
co = f.splineCorner |
| 9 |
|
| 10 |
|
| 11 |
p = f.point((2.3,2.4)) |
| 12 |
if p.x != 2.3 or p.y != 2.4 or not p.on_curve or p.selected: |
| 13 |
raise ValueError("Bad point values" ) |
| 14 |
|
| 15 |
p = f.point((2.3,2.4,False)) |
| 16 |
if p.x != 2.3 or p.y != 2.4 or p.on_curve or p.selected: |
| 17 |
raise ValueError("Bad point values" ) |
| 18 |
|
| 19 |
p = f.point((2.3,2.4),False,co,True) |
| 20 |
if p.x != 2.3 or p.y != 2.4 or p.on_curve or not p.selected: |
| 21 |
raise ValueError("Bad point values" ) |
| 22 |
|
| 23 |
|
| 24 |
p = f.point([2.3,2.4]) |
| 25 |
if p.x != 2.3 or p.y != 2.4 or not p.on_curve or p.selected: |
| 26 |
raise ValueError("Bad point values" ) |
| 27 |
|
| 28 |
p = f.point([2.3,2.4,False]) |
| 29 |
if p.x != 2.3 or p.y != 2.4 or p.on_curve or p.selected: |
| 30 |
raise ValueError("Bad point values" ) |
| 31 |
|
| 32 |
p = f.point([2.3,2.4],False,co,True) |
| 33 |
if p.x != 2.3 or p.y != 2.4 or p.on_curve or not p.selected: |
| 34 |
raise ValueError("Bad point values" ) |
| 35 |
|
| 36 |
|
| 37 |
p = f.point(2.3,2.4) |
| 38 |
if p.x != 2.3 or p.y != 2.4 or not p.on_curve or p.selected: |
| 39 |
raise ValueError("Bad point values" ) |
| 40 |
|
| 41 |
p = f.point(2.3,2.4,False) |
| 42 |
if p.x != 2.3 or p.y != 2.4 or p.on_curve or p.selected: |
| 43 |
raise ValueError("Bad point values" ) |
| 44 |
|
| 45 |
p = f.point(2.3,2.4,False,co,True) |
| 46 |
if p.x != 2.3 or p.y != 2.4 or p.on_curve or not p.selected: |
| 47 |
raise ValueError("Bad point values" ) |
| 48 |
|
| 49 |
|
| 50 |
p.name = 'test' |
| 51 |
p2 = p.dup() |
| 52 |
if p2.x != 2.3 or p2.y != 2.4 or p2.on_curve or not p2.selected or p2.name != 'test': |
| 53 |
raise ValueError("Bad point values" ) |
| 54 |
|
| 55 |
if p2 != (2.3,2.4): |
| 56 |
raise ValueError("Bad point comparison" ) |
| 57 |
|
| 58 |
if p2 != p: |
| 59 |
raise ValueError("Bad point comparison" ) |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
ptl = [(0,0),(1,1,False),(2,2,False),(3,3),(4,4),(5,5,False),(6,6,False),(7,7),(8,8,False),(9,0,False)] |
| 64 |
ptl2 = [(4.2,4.2),(4.5,4.5),(4.7,4.7)] |
| 65 |
|
| 66 |
c = f.contour() |
| 67 |
if len(c) != 0 or c.is_quadratic: |
| 68 |
raise ValueError("Bad contour values" ) |
| 69 |
|
| 70 |
c = f.contour(True) |
| 71 |
if len(c) != 0 or not c.is_quadratic: |
| 72 |
raise ValueError("Bad contour values" ) |
| 73 |
|
| 74 |
c.is_quadratic = False |
| 75 |
if c.is_quadratic: |
| 76 |
raise ValueError("Bad contour values" ) |
| 77 |
|
| 78 |
for pt in ptl: |
| 79 |
c.insertPoint(pt) |
| 80 |
c.closed = True; |
| 81 |
if len(c) != 10: |
| 82 |
raise ValueError("Bad contour length" ) |
| 83 |
|
| 84 |
c2 = f.contour() |
| 85 |
c2[:] = ptl |
| 86 |
c2.closed = True; |
| 87 |
if len(c2) != 10: |
| 88 |
raise ValueError("Bad contour length" ) |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
if list(c2) != list(c): |
| 93 |
raise ValueError("Bad contour comparison" ) |
| 94 |
|
| 95 |
cp = c2[0] |
| 96 |
cp.x = cp.y = -1 |
| 97 |
|
| 98 |
if c2 == c: |
| 99 |
raise ValueError("Bad contour comparison" ) |
| 100 |
|
| 101 |
c2[0] = c[0] |
| 102 |
if list(c2) != list(c): |
| 103 |
raise ValueError("Bad contour comparison" ) |
| 104 |
|
| 105 |
del c2[3] |
| 106 |
if c2[3].x != 4 or len(c2) != 9: |
| 107 |
raise ValueError("Bad contour value after delete" ) |
| 108 |
|
| 109 |
c2.insertPoint(ptl[3], 2) |
| 110 |
if list(c2) != list(c): |
| 111 |
raise ValueError("Bad contour value after delete" ) |
| 112 |
|
| 113 |
del c2[3] |
| 114 |
c2[3:3] = ptl[3:4] |
| 115 |
if list(c2) != list(c): |
| 116 |
raise ValueError("Bad contour value after delete" ) |
| 117 |
|
| 118 |
del c2[3] |
| 119 |
c2.insertPoint(c[3], 2) |
| 120 |
if list(c2) != list(c): |
| 121 |
raise ValueError("Bad contour value after delete" ) |
| 122 |
|
| 123 |
del c2[3] |
| 124 |
c2[3:3] = c[3:4] |
| 125 |
if list(c2) != list(c): |
| 126 |
raise ValueError("Bad contour value after delete" ) |
| 127 |
|
| 128 |
c[:] = ptl |
| 129 |
c += ptl2 |
| 130 |
c2[:] = ptl + ptl2 |
| 131 |
if list(c2) != list(c): |
| 132 |
raise ValueError("Bad contour value after concat" ) |
| 133 |
|
| 134 |
c2[:] = ptl |
| 135 |
c3 = f.contour() |
| 136 |
c3[:] = ptl2 |
| 137 |
if list(c) != list(c2 + c3): |
| 138 |
raise ValueError("Bad contour value from concat" ) |
| 139 |
|
| 140 |
c[:] = ptl |
| 141 |
c2[:] = ptl |
| 142 |
|
| 143 |
try: |
| 144 |
c2.makeFirst(11) |
| 145 |
except TypeError: |
| 146 |
pass |
| 147 |
else: |
| 148 |
raise ValueError("MakeFirst allowed out of bounds") |
| 149 |
|
| 150 |
try: |
| 151 |
c2.makeFirst(1) |
| 152 |
except TypeError: |
| 153 |
pass |
| 154 |
else: |
| 155 |
raise ValueError("MakeFirst allowed on off-curve point") |
| 156 |
|
| 157 |
c2.makeFirst(3) |
| 158 |
if list(c2) != list(c[3:] + c[:3]): |
| 159 |
raise ValueError("MakeFirst corrupted list") |
| 160 |
|
| 161 |
c2.makeFirst(len(c)-3) |
| 162 |
if list(c2) != list(c): |
| 163 |
raise ValueError("MakeFirst corrupted list") |
| 164 |
|
| 165 |
tmpptl = copy.copy(ptl) |
| 166 |
tmpptl[3:7] = ptl2 |
| 167 |
c[:] = tmpptl |
| 168 |
c2[:] = ptl |
| 169 |
c2[3:7] = ptl2 |
| 170 |
if list(c2) != list(c): |
| 171 |
raise ValueError("MakeFirst corrupted list") |
| 172 |
|
| 173 |
tmpptl = copy.copy(ptl) |
| 174 |
tmpptl[8:5:-1] = ptl2 |
| 175 |
c[:] = tmpptl |
| 176 |
c2[:] = ptl |
| 177 |
c2[8:5:-1] = ptl2 |
| 178 |
if list(c2) != list(c): |
| 179 |
raise ValueError("MakeFirst corrupted list") |
| 180 |
|
| 181 |
i = iter(c) |
| 182 |
j = iter(c2) |
| 183 |
k = 0 |
| 184 |
while True: |
| 185 |
try: |
| 186 |
nc = next(i) |
| 187 |
nc2 = next(j) |
| 188 |
except: |
| 189 |
break |
| 190 |
k += 1 |
| 191 |
if nc != nc2: |
| 192 |
raise ValueError("Corrupted contour iterator") |
| 193 |
|
| 194 |
if k != 10: |
| 195 |
raise ValueError("Corrupted contour iterator") |
| 196 |
|
| 197 |
pn = f.point(.5,.5) |
| 198 |
|
| 199 |
if not c2[3] in c or pn in c2 or not (1,1) in c2 or (.5,.5) in c2: |
| 200 |
raise ValueError("Bad contour contains") |
| 201 |
|
| 202 |
l = f.layer() |
| 203 |
if len(l) != 0 or l.is_quadratic: |
| 204 |
raise ValueError("Bad layer values") |
| 205 |
|
| 206 |
l2 = f.layer(True) |
| 207 |
if len(l2) != 0 or not l2.is_quadratic: |
| 208 |
raise ValueError("Bad layer values") |
| 209 |
|
| 210 |
|
| 211 |
try: |
| 212 |
l2 += c |
| 213 |
except: |
| 214 |
pass |
| 215 |
else: |
| 216 |
raise TypeError("Layer accepted contour of wrong type") |
| 217 |
|
| 218 |
l += c |
| 219 |
if len(l) != 1 or list(l[0]) != list(c): |
| 220 |
raise TypeError("Wrong layer values") |
| 221 |
|
| 222 |
c2[:] = ptl[3:6] |
| 223 |
l += c2 |
| 224 |
if len(l) != 2 or list(l[1]) != list(c2): |
| 225 |
raise TypeError("Wrong layer values") |
| 226 |
|
| 227 |
del l[0] |
| 228 |
if len(l) != 1 or list(l[0]) != list(c2): |
| 229 |
raise TypeError("Wrong layer values") |
| 230 |
|
| 231 |
l2 = f.layer() |
| 232 |
c3[:] = ptl2 |
| 233 |
l2 += c3 |
| 234 |
|
| 235 |
l3 = l + l2 |
| 236 |
if len(l3) != 2: |
| 237 |
raise TypeError("Bad layer concat") |