| 1 | # Round-trip point selection tests. |
| 2 | |
| 3 | import copy |
| 4 | import fontforge as ff |
| 5 | import pickle |
| 6 | |
| 7 | c0 = [(293.0,48.0,1), (291.0,48.0,1), (271.0,32.0,1), (227.0,-2.0,0), (196.8,-10.0,0), (162.0,-10.0,1), (92.0,-10.0,0), (36.0,16.0,0), (36.0,98.0,1), (36.0,166.0,0), (105.0,219.0,0), (201.0,243.0,1), (287.0,264.0,1), (290.0,265.0,0), (293.0,269.0,0), (293.0,276.0,1), (293.0,389.0,0), (246.0,406.0,0), (212.0,406.0,1), (174.0,406.0,0), (132.0,395.0,0), (132.0,364.0,1), (132.0,353.0,0), (133.0,347.0,0), (134.0,344.0,1), (136.0,340.0,0), (137.0,333.0,0), (137.0,326.0,1), (137.0,313.0,0), (119.0,292.0,0), (90.0,292.0,1), (67.0,292.0,0), (55.0,304.0,0), (55.0,328.0,1), (55.0,385.0,0), (138.0,439.0,0), (220.0,439.0,1), (293.0,439.0,0), (371.0,412.0,0), (371.0,270.0,1), (371.0,123.0,1), (371.0,77.0,0), (372.0,38.0,0), (401.0,38.0,1), (413.7,38.0,0), (430.5,47.8,0), (438.0,54.0,1), (449.3,47.7,0), (453.3,39.3,0), (455.0,27.0,1), (434.3,7.0,0), (398.3,-10.0,0), (360.0,-10.0,1), (309.6,-10.0,0), (299.0,17.0,0)] |
| 8 | |
| 9 | f = ff.font() |
| 10 | |
| 11 | g = f.createMappedChar('a') |
| 12 | |
| 13 | l = ff.layer() |
| 14 | c = ff.contour() |
| 15 | |
| 16 | # Cubic |
| 17 | c[:] = c0 |
| 18 | c.closed = True |
| 19 | l += c |
| 20 | |
| 21 | for (i,p) in enumerate(l[0]): |
| 22 | if i % 5 == 0: |
| 23 | p.selected = True |
| 24 | |
| 25 | g.layers[1] = l |
| 26 | l = g.layers[1] |
| 27 | |
| 28 | for (i,p) in enumerate(l[0]): |
| 29 | if (i % 5 == 0 and not p.selected) or (i % 5 != 0 and p.selected): |
| 30 | raise ValueError("Round trip of layer changed selection status") |
| 31 | |
| 32 | for (i,p) in enumerate(l[0]): |
| 33 | p.selected = True |
| 34 | |
| 35 | g.layers[1] = l |
| 36 | l = g.layers[1] |
| 37 | |
| 38 | for (i,p) in enumerate(l[0]): |
| 39 | if not p.selected: |
| 40 | print(i, p) |
| 41 | raise ValueError("Round trip of layer changed selection status") |
| 42 | |
| 43 | # Quadratic |
| 44 | |
| 45 | f.is_quadratic = True |
| 46 | g.layers[1] = l |
| 47 | l = g.layers[1] |
| 48 | |
| 49 | for (i,p) in enumerate(l[0]): |
| 50 | p.selected = True |
| 51 | |
| 52 | g.layers[1] = l |
| 53 | l = g.layers[1] |
| 54 | |
| 55 | for (i,p) in enumerate(l[0]): |
| 56 | if not p.selected: |
| 57 | print(i, p) |
| 58 | raise ValueError("Round trip of layer changed selection status") |
| 59 | |
| 60 | for (i,p) in enumerate(l[0]): |
| 61 | if i % 3 == 0: |
| 62 | p.selected = True |
| 63 | else: |
| 64 | p.selected = False |
| 65 | |
| 66 | g.layers[1] = l |
| 67 | l = g.layers[1] |
| 68 | |
| 69 | for (i,p) in enumerate(l[0]): |
| 70 | if (i % 3 == 0 and not p.selected) or (i % 3 != 0 and p.selected): |
| 71 | raise ValueError("Round trip of layer changed selection status") |
| 72 | |
| 73 | # Special attention to the tricky quadratic case |
| 74 | |
| 75 | for (i,p) in enumerate(l[0]): |
| 76 | p.selected = False |
| 77 | |
| 78 | pl = l[0][-1] |
| 79 | |
| 80 | if p.on_curve: |
| 81 | raise ValueError("Trailing quadratic contour point should be off-curve") |
| 82 | |
| 83 | pl.selected = True |
| 84 | |
| 85 | g.layers[1] = l |
| 86 | l = g.layers[1] |
| 87 | |
| 88 | lclen = len(l[0]) |
| 89 | |
| 90 | for (i,p) in enumerate(l[0]): |
| 91 | if (i < (lclen-1) and p.selected) or (i == lclen-1 and not p.selected): |
| 92 | raise ValueError("Round trip of layer changed selection status") |
| 93 | |
| 94 | # Point Pickling |
| 95 | |
| 96 | p = ff.point(4.4, 5.5) |
| 97 | pps = pickle.dumps(p) |
| 98 | fpp = pickle.loads(pps) |
| 99 | |
| 100 | if fpp.x != 4.4 or fpp.y != 5.5 or not fpp.on_curve or fpp.selected or fpp.interpolated: |
| 101 | print(fpp, fpp.selected, fpp.interpolated) |
| 102 | raise ValueError("Pickling lost a value") |
| 103 | |
| 104 | p.on_curve = False |
| 105 | p.selected = True |
| 106 | pps = pickle.dumps(p) |
| 107 | fpp = pickle.loads(pps) |
| 108 | |
| 109 | if fpp.x != 4.4 or fpp.y != 5.5 or fpp.on_curve or not fpp.selected or fpp.interpolated: |
| 110 | print(fpp, fpp.selected, fpp.interpolated) |
| 111 | raise ValueError("Pickling lost a value") |
| 112 | |
| 113 | p.selected = False |
| 114 | p.interpolated = True |
| 115 | pps = pickle.dumps(p) |
| 116 | fpp = pickle.loads(pps) |
| 117 | |
| 118 | if fpp.x != 4.4 or fpp.y != 5.5 or fpp.on_curve or fpp.selected or not fpp.interpolated: |
| 119 | print(fpp, fpp.selected, fpp.interpolated) |
| 120 | raise ValueError("Pickling lost a value") |
| 121 |