[varlib] Remove path compatiblization logic from CFF2CharStringMergePen

Agreed that paths glyphs form source fonts shoudl be fully compatible before varLib.build is called.

Updated test files
This commit is contained in:
ReadRoberts 2018-11-29 15:07:08 -08:00
parent c5def97cd8
commit ad8130e1a4
5 changed files with 57 additions and 178 deletions

View File

@ -60,129 +60,6 @@ class CFF2CharStringMergePen(T2CharStringPen):
self._p0 = pt
return list(self._p0)
def make_flat_curve(self, prev_coords, cur_coords):
# Convert line coords to curve coords.
dx = self.roundNumber((cur_coords[0] - prev_coords[0])/3.0)
dy = self.roundNumber((cur_coords[1] - prev_coords[1])/3.0)
new_coords = [prev_coords[0] + dx,
prev_coords[1] + dy,
prev_coords[0] + 2*dx,
prev_coords[1] + 2*dy
] + cur_coords
return new_coords
def make_curve_coords(self, coords, is_default):
# Convert line coords to curve coords.
prev_cmd = self._commands[self.pt_index-1]
if is_default:
new_coords = []
for i, cur_coords in enumerate(coords):
prev_coords = prev_cmd[1][i]
master_coords = self.make_flat_curve(prev_coords[:2],
cur_coords)
new_coords.append(master_coords)
else:
cur_coords = coords
prev_coords = prev_cmd[1][-1]
new_coords = self.make_flat_curve(prev_coords[:2], cur_coords)
return new_coords
def check_and_fix_flat_curve(self, cmd, point_type, pt_coords):
if (point_type == 'rlineto') and (cmd[0] == 'rrcurveto'):
is_default = False
pt_coords = self.make_curve_coords(pt_coords, is_default)
success = True
elif (point_type == 'rrcurveto') and (cmd[0] == 'rlineto'):
is_default = True
expanded_coords = self.make_curve_coords(cmd[1], is_default)
cmd[1] = expanded_coords
cmd[0] = point_type
success = True
else:
success = False
return success, pt_coords
def check_and_fix_closepath(self, cmd, point_type, pt_coords):
""" Some workflows drop a lineto which closes a path.
Also, if the last segment is a curve in one master,
and a flat curve in another, the flat curve can get
converted to a closing lineto, and then dropped.
Test if:
1) one master op is a moveto,
2) the previous op for this master does not close the path
3) in the other master the current op is not a moveto
4) the current op in the otehr master closes the current path
If the default font is missing the closing lineto, insert it,
then proceed with merging the current op and pt_coords.
If the current region is missing the closing lineto
and therefore the current op is a moveto,
then add closing coordinates to self._commands,
and increment self.pt_index.
Note that if this may insert a point in the default font list,
so after using it, 'cmd' needs to be reset.
return True if we can fix this issue.
"""
if point_type == 'rmoveto':
# If this is the case, we know that cmd[0] != 'rmoveto'
# The previous op must not close the path for this region font.
prev_moveto_coords = self._commands[self.prev_move_idx][1][-1]
prv_coords = self._commands[self.pt_index-1][1][-1]
if prev_moveto_coords == prv_coords[-2:]:
return False
# The current op must close the path for the default font.
prev_moveto_coords2 = self._commands[self.prev_move_idx][1][0]
prv_coords = self._commands[self.pt_index][1][0]
if prev_moveto_coords2 != prv_coords[-2:]:
return False
# Add the closing line coords for this region
# so self._commands, then increment self.pt_index
# so that the current region op will get merged
# with the next default font moveto.
if cmd[0] == 'rrcurveto':
new_coords = self.make_curve_coords(prev_moveto_coords, False)
cmd[1].append(new_coords)
self.pt_index += 1
return True
if cmd[0] == 'rmoveto':
# The previous op must not close the path for the default font.
prev_moveto_coords = self._commands[self.prev_move_idx][1][0]
prv_coords = self._commands[self.pt_index-1][1][0]
if prev_moveto_coords == prv_coords[-2:]:
return False
# The current op must close the path for this region font.
prev_moveto_coords2 = self._commands[self.prev_move_idx][1][-1]
if prev_moveto_coords2 != pt_coords[-2:]:
return False
# Insert the close path segment in the default font.
# We omit the last coords from the previous moveto
# is it will be supplied by the current region point.
# after this function returns.
new_cmd = [point_type, None]
prev_move_coords = self._commands[self.prev_move_idx][1][:-1]
# Note that we omit the last region's coord from prev_move_coords,
# as that is from the current region, and we will add the
# current pts' coords from the current region in its place.
if point_type == 'rlineto':
new_cmd[1] = prev_move_coords
else:
# We omit the last set of coords from the
# previous moveto, as it will be supplied by the coords
# for the current region pt.
new_cmd[1] = self.make_curve_coords(prev_move_coords, True)
self._commands.insert(self.pt_index, new_cmd)
return True
return False
def add_point(self, point_type, pt_coords):
if self.m_index == 0:
self._commands.append([point_type, [pt_coords]])
@ -211,7 +88,6 @@ class CFF2CharStringMergePen(T2CharStringPen):
def _moveTo(self, pt):
pt_coords = self._p(pt)
self.prev_move_abs_coords = self.roundPoint(self._p0)
self.add_point('rmoveto', pt_coords)
# I set prev_move_idx here because add_point()
# can change self.pt_index.

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ttFont sfntVersion="OTTO" ttLibVersion="3.31">
<ttFont sfntVersion="OTTO" ttLibVersion="3.32">
<fvar>
@ -91,12 +91,6 @@
<StdVW>
<blend value="85 -51.0 87.0"/>
</StdVW>
<StemSnapH>
<blend value="67 -39 67"/>
</StemSnapH>
<StemSnapV>
<blend value="85 -51 87"/>
</StemSnapV>
</Private>
</FontDict>
</FDArray>
@ -106,29 +100,31 @@
hmoveto
476 -44 76 1 blend
660 -476 44 -76 1 blend
hlineto
109 -601 -61 103 -27 45 2 blend
-660 hlineto
109 59 -61 103 -27 45 2 blend
rmoveto
73 131 54 102 29 -47 45 -75 10 -18 4 -6 4 blend
4 0 52 -102 73 -131 10 -16 -4 6 27 -47 -45 75 4 blend
rlineto
-300 52 -42 72 -10 16 2 blend
-256 -76 128 1 blend
hlineto
-44 52 34 -56 -10 16 2 blend
rmoveto
461 75 -125 1 blend
vlineto
127 -232 27 -45 -38 64 2 blend
127 -232 -127 -229 27 -45 -38 64 -27 45 -37 61 4 blend
rlineto
44 48 -22 36 -22 36 2 blend
171 277 5 -9 15 -25 2 blend
rmoveto
-50 93 -66 119 234 -6 10 -1 3 -28 48 49 -83 68 -114 5 blend
0 -65 -119 -49 -93 -29 47 -49 83 -5 9 1 -3 4 blend
rlineto
44 -48 -22 36 22 -36 2 blend
-4 hlineto
48 -48 -22 36 22 -36 2 blend
rmoveto
126 232 26 -44 38 -64 2 blend
0 -461 -126 229 -75 125 -26 44 37 -61 3 blend
rlineto
-461 -75 125 1 blend
vlineto
</CharString>
<CharString name="A">
31 19 -31 1 blend
@ -141,58 +137,65 @@
20 -76 22 -72 23 -73 4 -6 -6 10 2 -3 4 -6 5 -9 -7 11 6 blend
rrcurveto
113 -366 90 25 -40 -30 50 -56 92 3 blend
0 -221 656 -15 25 4 -6 2 blend
0 -221 656 -96 -15 25 4 -6 68 -112 3 blend
0 -221 -656 -15 25 -4 6 2 blend
rlineto
-96 68 -112 1 blend
hlineto
-104 -457 -30 49 33 -55 2 blend
117 199 -15 24 37 -61 2 blend
rmoveto
301 68 -301 -8 15 -40 65 8 -15 3 blend
301 68 -301 -68 -8 15 -40 65 8 -15 40 -65 4 blend
hlineto
</CharString>
<CharString name="T">
258 26 -44 1 blend
hmoveto
84 585 217 71 -518 -71 217 -52 88 47 -79 17 -30 -43 73 18 -28 43 -73 17 -30 7 blend
84 585 217 71 -518 -71 217 -585 -52 88 47 -79 17 -30 -43 73 18 -28 43 -73 17 -30 -47 79 8 blend
hlineto
</CharString>
<CharString name="dollar">
304 7 -12 1 blend
34 rmoveto
125 86 65 96 -22 38 2 -3 -9 15 -2 4 4 blend
hvcurveto
183 -324 -21 110 1 -1 -14 22 -11 17 32 -54 4 blend
vvcurveto
50 42 32 67 68 36 -21 -36 47 18 -29 15 -24 12 -21 18 -31 8 -13 -2 3 -3 5 -2 4 -3 5 9 blend
vhcurveto
44 49 -24 40 -29 49 2 blend
rlineto
44 -46 -54 33 -89 -6 8 5 -7 9 -15 -1 3 4 -8 5 blend
hhcurveto
-115 -81 -59 -94 16 -26 3 -7 5 -9 6 -10 4 blend
hvcurveto
-174 324 22 -124 8 -14 14 -22 6 -10 -32 56 4 blend
vvcurveto
-51 -42 -35 -78 -76 -62 31 37 -52 -19 31 -14 23 -15 25 -25 41 -9 15 -4 7 7 -11 -3 3 12 -20 9 blend
vhcurveto
-39 -58 73 -26 73 -26 73 -27 21 -35 36 -58 -28 -8 -12 -28 0 28 -14 -2 18 -3 27 27 8 blend
rlinecurve
-24 566 6 -21 0 -34 2 blend
248 35 -3 12 -28 4 2 blend
rmoveto
56 -26 56 1 blend
hlineto
50 0 9 1 blend
0 50 50 0 9 0 10 2 blend
-39 -45 5 18 -46 -26 -26 6 17 10 6 32 6 0 -3 5 blend
hvcurveto
53 -36 -17 76 -17 36 -12 -17 -11 2 24 13 4 blend
rlineto
53 -12 -22 13 -24 -37 -1 8 3 10 0 -9 5 13 -19 5 blend
hhcurveto
-22 -14 -11 -20 -9 8 -4 6 -13 4 -3 6 -18 8 -5 5 blend
hvcurveto
-87 4 81 -59 107 2 -3 20 -4 -20 -10 8 5 0 32 5 blend
hhcurveto
136 82 76 107 82 -41 65 -135 47 -45 27 8 17 -23 8 4 10 -12 16 15 -17 1 3 1 -7 10 -2 9 blend
hvcurveto
-38 13 19 5 -5 -3 2 blend
rlineto
-71 23 -40 35 64 -22 -1 16 -1 -2 16 14 -11 4 -15 5 blend
vvcurveto
-56 26 -56 1 blend
hlineto
-50 0 -9 1 blend
0 -50 -50 0 -9 0 -10 2 blend
75 57 37 74 30 36 -5 -17 42 16 -14 3 -10 11 -14 14 -7 26 12 -1 -9 -9 1 -33 -7 2 10 9 blend
vhcurveto
-52 36 17 -76 14 -33 11 11 11 -7 -24 9 4 blend
rlineto
-52 12 25 -14 22 37 -23 -6 -1 -15 12 9 0 -11 17 5 blend
hhcurveto
19 17 10 21 8 -5 7 -9 12 -3 5 -7 20 -7 -3 5 blend
hvcurveto
86 -6 -80 60 -101 2 2 -18 -2 13 4 -12 -12 17 -20 5 blend
hhcurveto
-115 -83 -80 -102 -100 62 -54 105 -37 23 -43 1 -2 29 0 -6 -13 20 7 -17 4 1 -15 -13 16 -5 -2 9 blend
hvcurveto
37 -13 0 -5 -4 2 2 blend
rlineto
85 -30 36 -30 -63 29 -5 -22 2 -10 -13 -16 11 -2 10 5 blend
vvcurveto
-562 0 102 1 blend
vmoveto
-148 56 148 0 -68 -26 56 0 68 3 blend
-74 -53 -42 -82 -18 19 -12 10 -12 3 -8 10 4 blend
vhcurveto
31 287 -13 33 40 -12 2 blend
rmoveto
428 -40 -428 40 0 -11 18 -31 0 11 -18 31 4 blend
vlineto
-41 -437 19 -38 -12 8 2 blend
rmoveto
40 437 -40 -437 -18 31 12 -8 18 -31 -12 8 4 blend
hlineto
</CharString>
<CharString name="glyph00003">
304 7 -12 1 blend
@ -219,7 +222,7 @@
hhcurveto
-51 -147 -19 32 1 -3 2 blend
rmoveto
159 857 -56 7 -159 -858 -1 1 3 -3 26 -44 -3 5 1 -1 -2 4 6 blend
159 857 -56 7 -159 -858 56 -6 -1 1 3 -3 26 -44 -3 5 1 -1 -2 4 -26 44 2 -6 8 blend
rlineto
</CharString>
</CharStrings>