From ad8130e1a425cc7a72f1e887278488b987ea8ba2 Mon Sep 17 00:00:00 2001 From: ReadRoberts Date: Thu, 29 Nov 2018 15:07:08 -0800 Subject: [PATCH] [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 --- Lib/fontTools/cffLib/cff2mergePen.py | 124 ------------------ .../data/master_cff2/TestCFF2_Black.otf | Bin 2088 -> 2272 bytes .../data/master_cff2/TestCFF2_ExtraLight.otf | Bin 2112 -> 2300 bytes .../data/master_cff2/TestCFF2_Regular.otf | Bin 2092 -> 2280 bytes .../data/test_results/BuildTestCFF2.ttx | 111 ++++++++-------- 5 files changed, 57 insertions(+), 178 deletions(-) diff --git a/Lib/fontTools/cffLib/cff2mergePen.py b/Lib/fontTools/cffLib/cff2mergePen.py index 2d2ddfe1c..709566085 100644 --- a/Lib/fontTools/cffLib/cff2mergePen.py +++ b/Lib/fontTools/cffLib/cff2mergePen.py @@ -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. diff --git a/Tests/varLib/data/master_cff2/TestCFF2_Black.otf b/Tests/varLib/data/master_cff2/TestCFF2_Black.otf index b928e00d707f7ff5dcf0c00e403c4368fc3c5fd6..b4249e1079ffb20a6ebff29c4f588843650f0314 100644 GIT binary patch delta 778 zcmXw1eMr+$6n)#g`J!A2{wgs{%Tg4y{FsVHu8plEb2&BpfHbwl5DkkaDeL18iwm|I zIu~iFSW?MED~3r6jVQ`A5iHCU+8?2rLDbuL6M94XkJqz)F4(fcOj`*d zI*m>jq05_kK}dj;5QR=_+^-kDj1X!OO!bCbqx0}Viu`%0qPvU)*{rMhSE4_M3_yLW>_X5cSE{hC8ET%2$O6a>~HUUwvSSgYPRoh z-)+yKlYAUlHUcm5h66A27t7(mB3Zb^#>F-)6u6&xC@5K_NXinz(*!Kn-;4s^Gk-H` zMf;k>C1UFJe7F%uDBf#paUdPW{)?_NbaoL6%`TlI7AcR!Bt34U$PH}R zhI)z@OqWj~J&5^tH3L-5DZDTERs9jEiN{JT**g!>HsHz2^RQ$FWdv*Om$I?C1H4P2r6n9M&uq{Z%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*nWo5uBsQ(j~_!WIHL^NBgFcPN21-ub8&A z!Et@>v2HceP&}Z+y%eQb<}jnQhhma8Cm5+3Q+o@o^lTN_ia!)OkS0kXB2&4RptJ!b z)!Gtt)q|gcU2PWAu;^ayAbork$`+yizP_OjX)Rv7bgh<})Niv_kvj0}5HdN%_vP=T zZKJf>01^5p1uxM~(eY+r2I&Yss_o06#r=U+%LEcm4V0aJTBhX4Qo delta 601 zcmew(ctBu+SUvj(1_lN1H~B`7&t6|G>3bDfAEg* zV^0_u*mnT=X70hEPCLFGU;*+=fP5GKV11*A+7M=-76%|dAvrg(fMEht4bVIwmtjXn zYGR6@XT)P5`wkGBWdH@(j2NpK#2FYxfC4HRxg`}$9~j;M4a@-Yc_yy0P`R_K?QA^1 z%~u9y<`+OQhU;%RtKhWJ{|QWLOdlq5FzWLHof*KuzzUROW{TMC!g!LIpXJA{pDnE4 z7w~^yDR}h9%gHjV*X!LF${E@jZZjI)7yIGzQ{#^d+wQ*{q94Dzoc_w%&vsJr{cji6 z->`WIx+t%f;@?t-s6tQIJ^6_PgPy25UasZ>c{vqThEe|Gkrqum1Z6vDH6$ zzSk}P(~9wMt9v^-w|J~>Jv+VCmQs<9se{g+maq4!t`SV#fCdI8blh&{e zHJ1Nv_5IoM-v&~y!I3Ivo*UOD%T<=LrtY|s{7l;Qx0>j8qn{sg`+pn#{lJRPOlzVI zt^9FHbme!gT(-Y4EWb5Ye%D~1{Dj>|Y&j3lS{~jXZ$ucFA{as#jDRqWA#Jh@N6q9d O93C9N;0Hzo0|NlHcIk`& diff --git a/Tests/varLib/data/master_cff2/TestCFF2_Regular.otf b/Tests/varLib/data/master_cff2/TestCFF2_Regular.otf index 85ff86cc914d5b8c89b73f82345c0cec51feeb40..c87342e418d5b5e4d78b9483305788fe2ed204ca 100644 GIT binary patch delta 793 zcmX|-Hff{0>;N@7TwR_6SmnNT2Y4INW%D+9dffHF1&E6!dT#c@HbH^m$*k}BRlW?XV{+`4j)0g83@TDgs()YNa@iD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x index 3462bac67..a4e859f14 100644 --- a/Tests/varLib/data/test_results/BuildTestCFF2.ttx +++ b/Tests/varLib/data/test_results/BuildTestCFF2.ttx @@ -1,5 +1,5 @@ - + @@ -91,12 +91,6 @@ - - - - - - @@ -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 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 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 - 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 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