Skip to content

Commit 376040c

Browse files
committed
testing
1 parent 0ee2d58 commit 376040c

File tree

1 file changed

+120
-10
lines changed

1 file changed

+120
-10
lines changed

lib/pathins/overlap.py

Lines changed: 120 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pathops # type: ignore
55
from fontTools.ttLib import TTFont # type: ignore
66

7-
from .bridge import ttfont_glyph_to_skia_path
7+
from .bridge import skia_path_to_ttfont_glyph, ttfont_glyph_to_skia_path
88
from .stringbuilder import overlap_result
99
from .validators import validate_fontpath, validate_glyph_in_font
1010

@@ -26,15 +26,126 @@
2626
"uni03A8",
2727
]
2828

29+
FLAG_ON_CURVE = 0x01
2930

30-
def has_overlap(skia_path_pre: pathops.Path) -> bool:
31+
32+
def temp_test(coords1, coords2, endpoints1, endpoints2, flags1, flags2):
33+
coordset1 = set()
34+
coordset2 = set()
35+
# fill with pre simplified glyph coordinates
36+
for coord in coords1:
37+
coordset1.add(coord)
38+
# fill with post simplified glyph coordinates
39+
for coord in coords2:
40+
coordset2.add(coord)
41+
42+
print(flags1)
43+
print(endpoints1)
44+
# endpoints is a list of the *index* (in coordinates) of endpoint
45+
# for *each contour*!
46+
i = endpoints1[0]
47+
print(f"endpoint: {coords1[i]}")
48+
49+
# print on/off curve status (0 = off curve, 1 = on curve)
50+
for x, coord in enumerate(coords1):
51+
print(coord, flags1[x] & FLAG_ON_CURVE)
52+
53+
sys.exit()
54+
55+
# empty segment check
56+
# TODO: add check that simplified path has fewer
57+
# coordinates and does not contain the empty segments
58+
for x, first_test_coord in enumerate(coords1):
59+
if x + 2 <= len(coords1):
60+
second_test_coord = coords1[x + 1]
61+
if first_test_coord == second_test_coord:
62+
print("Empty segment:")
63+
print(first_test_coord, second_test_coord)
64+
65+
# collinear vector check
66+
# TODO: add check that simplified path does not contain
67+
# the collinear coordinates
68+
for x, begin_test_coord in enumerate(coords1):
69+
if x + 4 <= len(coords1):
70+
second_test_coord = coords1[x + 1]
71+
third_test_coord = coords1[x + 2]
72+
end_test_coord = coords1[x + 3]
73+
if (
74+
begin_test_coord[0]
75+
== second_test_coord[0]
76+
== third_test_coord[0]
77+
== end_test_coord[0]
78+
):
79+
print("x-axis:")
80+
print(
81+
begin_test_coord,
82+
second_test_coord,
83+
third_test_coord,
84+
end_test_coord,
85+
)
86+
if (
87+
begin_test_coord[1]
88+
== second_test_coord[1]
89+
== third_test_coord[1]
90+
== end_test_coord[1]
91+
):
92+
print("y-axis:")
93+
print(
94+
begin_test_coord,
95+
second_test_coord,
96+
third_test_coord,
97+
end_test_coord,
98+
)
99+
print(len(coordset1) > len(coordset2))
100+
print(coordset1.difference(coordset2))
101+
102+
103+
def has_overlap(skia_path_pre: pathops.Path, glyf_table) -> bool:
31104
# if there are no contours, then there are no overlaps
32105
# skip pathops.simplify and diff check
33106
if len(list(skia_path_pre.contours)) == 0:
34107
return False
35108
# analyze skia simplified outline diff
36109
skia_path_post = pathops.simplify(skia_path_pre, clockwise=skia_path_pre.clockwise)
37-
return skia_path_pre != skia_path_post
110+
111+
if skia_path_pre != skia_path_post:
112+
# simplified skia paths do not match
113+
# let's confirm that this is not simply a
114+
# change in starting points
115+
ttglyph_pre = skia_path_to_ttfont_glyph(skia_path_pre)
116+
coords1, endpoints1, flags1 = ttglyph_pre.getCoordinates(glyf_table)
117+
ttglyph_post = skia_path_to_ttfont_glyph(skia_path_post)
118+
coords2, endpoints2, flags2 = ttglyph_post.getCoordinates(glyf_table)
119+
coordset1 = set()
120+
coordset2 = set()
121+
# fill with pre simplified glyph coordinates
122+
for coord in coords1:
123+
coordset1.add(coord)
124+
# fill with post simplified glyph coordinates
125+
for coord in coords2:
126+
coordset2.add(coord)
127+
128+
#
129+
#
130+
# TESTING
131+
#
132+
#
133+
temp_test(coords1, coords2, endpoints1, endpoints2, flags1, flags2)
134+
135+
#
136+
#
137+
# END TESTING
138+
#
139+
#
140+
141+
if (len(coords1) == len(coords2)) and len(
142+
coordset1.symmetric_difference(coordset2)
143+
) == 0:
144+
return False
145+
else:
146+
return True
147+
else:
148+
return False
38149

39150

40151
def overlap_run(args: argparse.Namespace) -> None:
@@ -48,9 +159,6 @@ def overlap_run(args: argparse.Namespace) -> None:
48159

49160
tt = TTFont(fontpath)
50161

51-
skia_path_pre: pathops.Path
52-
skia_path_post: pathops.Path
53-
54162
# --check option implementation
55163
if args.check:
56164
# start with probable overlap list and fail early
@@ -59,7 +167,7 @@ def overlap_run(args: argparse.Namespace) -> None:
59167
# confirm that the glyph is in the font
60168
tt["glyf"][probable_glyphname] # type: ignore
61169
skia_path_pre = ttfont_glyph_to_skia_path(glyphname, tt)
62-
if has_overlap(skia_path_pre):
170+
if has_overlap(skia_path_pre, tt["glyf"]):
63171
print(f"{fontpath}: overlapping paths are present")
64172
sys.exit(1)
65173
# if the glyph is not present in the font
@@ -76,7 +184,7 @@ def overlap_run(args: argparse.Namespace) -> None:
76184
skia_path_pre = ttfont_glyph_to_skia_path(
77185
local_glyphname, tt # type: ignore
78186
)
79-
if has_overlap(skia_path_pre):
187+
if has_overlap(skia_path_pre, tt["glyf"]):
80188
print(f"{fontpath}: overlapping paths are present")
81189
sys.exit(1)
82190

@@ -90,7 +198,9 @@ def overlap_run(args: argparse.Namespace) -> None:
90198
validate_glyph_in_font(glyphname, tt)
91199
skia_path_pre = ttfont_glyph_to_skia_path(glyphname, tt)
92200
print(
93-
overlap_result(glyphname, has_overlap(skia_path_pre), nocolor=args.nocolor)
201+
overlap_result(
202+
glyphname, has_overlap(skia_path_pre, tt["glyf"]), nocolor=args.nocolor
203+
)
94204
)
95205
else:
96206
glyph_names = tt.getGlyphOrder()
@@ -99,7 +209,7 @@ def overlap_run(args: argparse.Namespace) -> None:
99209
print(
100210
overlap_result(
101211
str(local_glyphname),
102-
has_overlap(skia_path_pre),
212+
has_overlap(skia_path_pre, tt["glyf"]),
103213
nocolor=args.nocolor,
104214
)
105215
)

0 commit comments

Comments
 (0)