diff --git a/Lib/fontTools/misc/psCharStrings.py b/Lib/fontTools/misc/psCharStrings.py index a75b43330..1ade9c01f 100644 --- a/Lib/fontTools/misc/psCharStrings.py +++ b/Lib/fontTools/misc/psCharStrings.py @@ -642,19 +642,57 @@ class SimpleT2Decompiler(object): def op_roll(self, index): raise NotImplementedError -class T2OutlineExtractor(SimpleT2Decompiler): - def __init__(self, pen, localSubrs, globalSubrs, nominalWidthX, defaultWidthX): +class T2WidthExtractor(SimpleT2Decompiler): + + def __init__(self, localSubrs, globalSubrs, nominalWidthX, defaultWidthX): SimpleT2Decompiler.__init__(self, localSubrs, globalSubrs) - self.pen = pen self.nominalWidthX = nominalWidthX self.defaultWidthX = defaultWidthX def reset(self): SimpleT2Decompiler.reset(self) - self.hints = [] self.gotWidth = 0 self.width = 0 + + def popallWidth(self, evenOdd=0): + args = self.popall() + if not self.gotWidth: + if evenOdd ^ (len(args) % 2): + self.width = self.nominalWidthX + args[0] + args = args[1:] + else: + self.width = self.defaultWidthX + self.gotWidth = 1 + return args + + def countHints(self): + args = self.popallWidth() + self.hintCount = self.hintCount + len(args) // 2 + + def op_rmoveto(self, index): + self.popallWidth() + + def op_hmoveto(self, index): + self.popallWidth(1) + + def op_vmoveto(self, index): + self.popallWidth(1) + + def op_endchar(self, index): + self.popallWidth() + + +class T2OutlineExtractor(T2WidthExtractor): + + def __init__(self, pen, localSubrs, globalSubrs, nominalWidthX, defaultWidthX): + T2WidthExtractor.__init__( + self, localSubrs, globalSubrs, nominalWidthX, defaultWidthX) + self.pen = pen + + def reset(self): + T2WidthExtractor.reset(self) + self.hints = [] # XXX this attribute seems to be unused self.currentPoint = (0, 0) self.sawMoveTo = 0 @@ -689,21 +727,6 @@ class T2OutlineExtractor(SimpleT2Decompiler): # finishing a sub path. self.closePath() - def popallWidth(self, evenOdd=0): - args = self.popall() - if not self.gotWidth: - if evenOdd ^ (len(args) % 2): - self.width = self.nominalWidthX + args[0] - args = args[1:] - else: - self.width = self.defaultWidthX - self.gotWidth = 1 - return args - - def countHints(self): - args = self.popallWidth() - self.hintCount = self.hintCount + len(args) // 2 - # # hint operators # diff --git a/Lib/fontTools/subset/__init__.py b/Lib/fontTools/subset/__init__.py index b7e402af9..7f8859b9b 100644 --- a/Lib/fontTools/subset/__init__.py +++ b/Lib/fontTools/subset/__init__.py @@ -7,7 +7,7 @@ from fontTools.misc.py23 import * from fontTools import ttLib from fontTools.ttLib.tables import otTables from fontTools.misc import psCharStrings -from fontTools.pens.boundsPen import BoundsPen +from fontTools.pens.basePen import NullPen from fontTools.misc.loggingTools import Timer import sys import struct @@ -1851,8 +1851,8 @@ def prune_pre_subset(self, font, options): private = font.Private dfltWdX = private.defaultWidthX nmnlWdX = private.nominalWidthX - pen = BoundsPen(None) - c.draw(pen) # this will set the charstring's width + pen = NullPen() + c.draw(pen) # this will set the charstring's width if c.width != dfltWdX: c.program = [c.width - nmnlWdX, 'endchar'] else: @@ -1964,7 +1964,7 @@ class _MarkingT2Decompiler(psCharStrings.SimpleT2Decompiler): self.globalSubrs._used.add(self.operandStack[-1]+self.globalBias) psCharStrings.SimpleT2Decompiler.op_callgsubr(self, index) -class _DehintingT2Decompiler(psCharStrings.SimpleT2Decompiler): +class _DehintingT2Decompiler(psCharStrings.T2WidthExtractor): class Hints(object): def __init__(self): @@ -1985,17 +1985,16 @@ class _DehintingT2Decompiler(psCharStrings.SimpleT2Decompiler): self.has_hintmask = False pass - def __init__(self, css, localSubrs, globalSubrs): + def __init__(self, css, localSubrs, globalSubrs, nominalWidthX, defaultWidthX): self._css = css - psCharStrings.SimpleT2Decompiler.__init__(self, - localSubrs, - globalSubrs) + psCharStrings.T2WidthExtractor.__init__( + self, localSubrs, globalSubrs, nominalWidthX, defaultWidthX) def execute(self, charString): old_hints = charString._hints if hasattr(charString, '_hints') else None charString._hints = self.Hints() - psCharStrings.SimpleT2Decompiler.execute(self, charString) + psCharStrings.T2WidthExtractor.execute(self, charString) hints = charString._hints @@ -2017,38 +2016,38 @@ class _DehintingT2Decompiler(psCharStrings.SimpleT2Decompiler): def op_callsubr(self, index): subr = self.localSubrs[self.operandStack[-1]+self.localBias] - psCharStrings.SimpleT2Decompiler.op_callsubr(self, index) + psCharStrings.T2WidthExtractor.op_callsubr(self, index) self.processSubr(index, subr) def op_callgsubr(self, index): subr = self.globalSubrs[self.operandStack[-1]+self.globalBias] - psCharStrings.SimpleT2Decompiler.op_callgsubr(self, index) + psCharStrings.T2WidthExtractor.op_callgsubr(self, index) self.processSubr(index, subr) def op_hstem(self, index): - psCharStrings.SimpleT2Decompiler.op_hstem(self, index) + psCharStrings.T2WidthExtractor.op_hstem(self, index) self.processHint(index) def op_vstem(self, index): - psCharStrings.SimpleT2Decompiler.op_vstem(self, index) + psCharStrings.T2WidthExtractor.op_vstem(self, index) self.processHint(index) def op_hstemhm(self, index): - psCharStrings.SimpleT2Decompiler.op_hstemhm(self, index) + psCharStrings.T2WidthExtractor.op_hstemhm(self, index) self.processHint(index) def op_vstemhm(self, index): - psCharStrings.SimpleT2Decompiler.op_vstemhm(self, index) + psCharStrings.T2WidthExtractor.op_vstemhm(self, index) self.processHint(index) def op_hintmask(self, index): - psCharStrings.SimpleT2Decompiler.op_hintmask(self, index) + psCharStrings.T2WidthExtractor.op_hintmask(self, index) self.processHintmask(index) def op_cntrmask(self, index): - psCharStrings.SimpleT2Decompiler.op_cntrmask(self, index) + psCharStrings.T2WidthExtractor.op_cntrmask(self, index) self.processHintmask(index) def processHintmask(self, index): cs = self.callingStack[-1] hints = cs._hints hints.has_hintmask = True - if hints.status != 2 and hints.has_hint: + if hints.status != 2: # Check from last_check, see if we may be an implicit vstem for i in range(hints.last_checked, index - 1): if isinstance(cs.program[i], str): @@ -2056,6 +2055,7 @@ class _DehintingT2Decompiler(psCharStrings.SimpleT2Decompiler): break if hints.status != 2: # We are an implicit vstem + hints.has_hint = True hints.last_hint = index + 1 hints.status = 0 hints.last_checked = index + 1 @@ -2209,8 +2209,11 @@ def prune_post_subset(self, options): c,sel = cs.getItemAndSelector(g) c.decompile() subrs = getattr(c.private, "Subrs", []) - decompiler = _DehintingT2Decompiler(css, subrs, c.globalSubrs) + decompiler = _DehintingT2Decompiler(css, subrs, c.globalSubrs, + c.private.nominalWidthX, + c.private.defaultWidthX) decompiler.execute(c) + c.width = decompiler.width for charstring in css: charstring.drop_hints() del css diff --git a/Tests/subset/data/Lobster.subset.ttx b/Tests/subset/data/Lobster.subset.ttx new file mode 100644 index 000000000..62e33fd86 --- /dev/null +++ b/Tests/subset/data/Lobster.subset.ttx @@ -0,0 +1,649 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Copyright (c) 2010 by Pablo Impallari. www.impallari.com. All rights reserved. + + + Lobster 1.4 + + + Regular + + + PabloImpallari.www.impallari.com: Lobster 1.4: 2010 + + + Lobster1.4 + + + Version 1.4 + + + Lobster1.4 + + + Lobster 1.4 is a trademark of Pablo Impallari. www.impallari.com. + + + Pablo Impallari. www.impallari.com + + + Pablo Impallari + + + Copyright (c) 2010 by Pablo Impallari. All rights reserved. + + + www.impallari.com + + + www.impallari.com + + + Copyright (c) 2010, Pablo Impallari (www.impallari.com|impallari@gmail.com), +with Reserved Font Name Lobster. +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is available with a FAQ at: http://scripts.sil.org/OFL + + + http://scripts.sil.org/OFL + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 397 748 rmoveto + 1 -13 -13 1 -14 hhcurveto + -106 callsubr + 53 75 87 36 vhcurveto + -145 -679 rlineto + return + + + -167 -184 -127 -133 -72 38 -25 69 hvcurveto + -1 9 -13 8 51 vvcurveto + 107 return + + + 119 hintmask 01111100 + 230 636 rmoveto + -136 -636 rlineto + 144 hlineto + return + + + -67 41 -25 66 vhcurveto + -1 9 -13 8 51 vvcurveto + return + + + + + + -63 endchar + + + 220 -93 -21 114 -20 297 181 -59 59 292 -20 hstemhm + 9 118 -43 120 hintmask 11101100 + 535 hmoveto + 157 736 rlineto + 10 -24 -32 4 -23 hhcurveto + -117 -130 -135 -160 -101 hvcurveto + 2 -21 -17 1 -14 hhcurveto + -118 -86 -55 -68 -39 28 -19 34 31 25 15 24 14 -8 17 -5 hvcurveto + hintmask 11011010 + 13 34 42 14 62 4 rrcurveto + -87 -153 -60 -164 -90 vvcurveto + -104 80 -2 54 vhcurveto + -6 9 -8 15 32 vvcurveto + 104 55 190 75 163 vhcurveto + 44 -4 39 -9 51 -23 -77 -363 rcurveline + 86 407 rmoveto + -39 16 -43 11 -40 8 56 112 64 93 60 32 rrcurveto + endchar + + + 142 -92 -21 113 -20 386 52 333 -20 hstem + 8 120 vstem + 459 hmoveto + 157 736 rlineto + 12 -30 -26 3 -24 hhcurveto + -238 -290 -563 -189 -106 65 -2 69 -4 hvcurveto + -1 9 -13 -4 51 vvcurveto + 97 42 172 64 154 vhcurveto + 158 hlineto + -77 -366 rlineto + -59 418 rmoveto + 58 126 72 106 73 32 -56 -264 rcurveline + endchar + + + 187 -17 96 -79 -20 406 48 270 46 hstemhm + 6 93 362 139 -119 101 -101 -105 callsubr + 82 383 rlineto + 2 18 20 1 8 hhcurveto + 73 22 -57 -70 hvcurveto + hintmask 10111001 + -76 -26 -104 -73 -23 -19 10 26 -25 vhcurveto + -9 -23 -4 -19 -16 vvcurveto + -61 56 -13 43 167 52 192 96 75 -33 69 -85 17 vhcurveto + hintmask 10111010 + 65 37 35 63 59 vvcurveto + 82 -66 77 -147 -189 -174 -127 -138 -104 callsubr + 165 133 78 117 95 37 -51 -57 -75 -64 -87 -80 vhcurveto + -6 hlineto + 47 222 rlineto + endchar + + + 185 -28 92 -64 -20 413 41 270 46 hstemhm + 6 93 350 149 -119 105 -105 -105 callsubr + 6 30 rlineto + hintmask 10111001 + -41 39 41 -17 39 hhcurveto + 125 110 175 136 72 -32 62 -82 15 hvcurveto + hintmask 10111010 + 64 38 36 61 58 vvcurveto + 83 -74 78 -144 -183 -177 -126 -139 -104 callsubr + 152 116 91 138 101 25 -49 -53 -81 -59 -87 -83 vhcurveto + -6 hlineto + 47 222 rlineto + -59 -592 rmoveto + -20 -21 8 21 -20 hvcurveto + 62 290 rlineto + 2 18 20 1 7 hhcurveto + hintmask 10111100 + 63 21 -49 -57 -96 -58 -120 -72 hvcurveto + endchar + + + -73 21 -21 750 -20 hstem + 6 93 vstem + -107 callsubr + 144 hlineto + endchar + + + 215 -207 50 157 -20 770 -20 hstemhm + 6 93 13 84 -84 205 hintmask 11111000 + -107 callsubr + 34 hlineto + -11 -20 -5 -23 -27 vvcurveto + -79 48 -58 113 155 66 109 138 29 vhcurveto + 150 710 -150 -33 -164 -751 rlineto + -100 -22 -30 -23 -40 hhcurveto + -44 -27 29 39 40 29 33 36 16 17 -7 -16 16 hvcurveto + hintmask 11110100 + 4 11 3 11 11 vvcurveto + 34 -26 24 -41 6 vhcurveto + endchar + + + 88 -207 50 144 81 682 -20 hstemhm + 17 84 -84 220 -50 93 hintmask 11110100 + 538 750 rmoveto + -106 callsubr + 54 76 87 36 vhcurveto + -157 -714 rlineto + -103 -23 -27 -20 -45 hhcurveto + -29 -39 18 52 37 24 37 46 20 15 -5 -21 25 hvcurveto + hintmask 11101000 + 4 15 2 14 11 vvcurveto + 64 -58 3 -40 -79 -43 -66 -68 -83 53 -58 95 164 67 94 153 32 vhcurveto + 150 710 rlineto + endchar + + + -131 21 -21 624 46 78 -20 hstem + 324 748 rmoveto + -72 -121 -78 -6 -55 hhcurveto + -12 -46 rlineto + 95 hlineto + -132 -624 rlineto + 144 hlineto + endchar + + + 66 -5 65 197 51 204 237 -54 54 hstemhm + 6 111 -12 110 117 155 -117 117 hintmask 11101001 + 205 257 rmoveto + 38 -8 -33 13 -37 hhcurveto + -80 -41 -60 -83 -154 141 -16 58 171 111 136 121 71 -38 65 -88 29 hvcurveto + 92 46 45 74 66 vvcurveto + 78 -63 68 -123 vhcurveto + hintmask 11100110 + -116 -91 -61 -91 -54 32 -31 40 24 27 11 23 25 hvcurveto + -28 8 -10 36 27 vvcurveto + hintmask 11011001 + 47 31 31 48 51 25 -36 -46 -70 -58 -94 -113 -31 vhcurveto + hintmask 11101010 + 93 -33 40 -80 -76 vvcurveto + -87 -53 -82 -86 -37 -39 13 76 40 10 62 78 6 vhcurveto + endchar + + + 44 -11 125 -89 89 -89 107 380 237 -54 54 hstemhm + 66 110 142 119 -119 144 hintmask 00110101 + 111 132 rmoveto + -5 hlineto + 83 135 273 98 223 vvcurveto + 97 -53 64 -137 -151 -55 -79 -68 -58 31 -32 41 24 26 11 23 26 vhcurveto + -28 8 -10 37 23 vvcurveto + hintmask 01001110 + 50 14 31 67 29 32 -33 -49 vhcurveto + -266 -329 -98 -219 vvcurveto + -11 0 -11 2 -11 vhcurveto + 7 20 36 21 23 hhcurveto + hintmask 10010110 + 102 37 -36 109 hhcurveto + 99 20 52 98 14 0 14 -1 16 hvcurveto + -44 -47 -17 -25 -70 hhcurveto + hintmask 00110110 + -75 -57 18 -59 hhcurveto + endchar + + + 98 -9 84 623 52 hstem + 30 158 236 131 vstem + 377 750 rmoveto + -215 -132 -223 -273 -166 35 -97 172 205 113 299 199 168 -53 93 -125 hvcurveto + -189 -425 rmoveto + 225 17 105 148 60 hhcurveto + 47 7 -63 -82 -232 -68 -246 -114 -48 -11 77 74 37 3 35 2 27 hvcurveto + endchar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/subset/data/expect_desubroutinize_CFF.ttx b/Tests/subset/data/expect_desubroutinize_CFF.ttx new file mode 100644 index 000000000..494d0ce89 --- /dev/null +++ b/Tests/subset/data/expect_desubroutinize_CFF.ttx @@ -0,0 +1,240 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -63 endchar + + + 220 -93 -21 114 -20 297 181 -59 59 292 -20 hstemhm + 9 118 -43 120 hintmask 11101100 + 535 hmoveto + 157 736 rlineto + 10 -24 -32 4 -23 hhcurveto + -117 -130 -135 -160 -101 hvcurveto + 2 -21 -17 1 -14 hhcurveto + -118 -86 -55 -68 -39 28 -19 34 31 25 15 24 14 -8 17 -5 hvcurveto + hintmask 11011010 + 13 34 42 14 62 4 rrcurveto + -87 -153 -60 -164 -90 vvcurveto + -104 80 -2 54 vhcurveto + -6 9 -8 15 32 vvcurveto + 104 55 190 75 163 vhcurveto + 44 -4 39 -9 51 -23 -77 -363 rcurveline + 86 407 rmoveto + -39 16 -43 11 -40 8 56 112 64 93 60 32 rrcurveto + endchar + + + 142 -92 -21 113 -20 386 52 333 -20 hstem + 8 120 vstem + 459 hmoveto + 157 736 rlineto + 12 -30 -26 3 -24 hhcurveto + -238 -290 -563 -189 -106 65 -2 69 -4 hvcurveto + -1 9 -13 -4 51 vvcurveto + 97 42 172 64 154 vhcurveto + 158 hlineto + -77 -366 rlineto + -59 418 rmoveto + 58 126 72 106 73 32 -56 -264 rcurveline + endchar + + + 187 -17 96 -79 -20 406 48 270 46 hstemhm + 6 93 362 139 -119 101 -101 119 hintmask 01111100 + 230 636 rmoveto + -136 -636 rlineto + 144 hlineto + 82 383 rlineto + 2 18 20 1 8 hhcurveto + 73 22 -57 -70 hvcurveto + hintmask 10111001 + -76 -26 -104 -73 -23 -19 10 26 -25 vhcurveto + -9 -23 -4 -19 -16 vvcurveto + -61 56 -13 43 167 52 192 96 75 -33 69 -85 17 vhcurveto + hintmask 10111010 + 65 37 35 63 59 vvcurveto + 82 -66 77 -147 -189 -174 -127 -138 -67 41 -25 66 vhcurveto + -1 9 -13 8 51 vvcurveto + 165 133 78 117 95 37 -51 -57 -75 -64 -87 -80 vhcurveto + -6 hlineto + 47 222 rlineto + endchar + + + 185 -28 92 -64 -20 413 41 270 46 hstemhm + 6 93 350 149 -119 105 -105 119 hintmask 01111100 + 230 636 rmoveto + -136 -636 rlineto + 144 hlineto + 6 30 rlineto + hintmask 10111001 + -41 39 41 -17 39 hhcurveto + 125 110 175 136 72 -32 62 -82 15 hvcurveto + hintmask 10111010 + 64 38 36 61 58 vvcurveto + 83 -74 78 -144 -183 -177 -126 -139 -67 41 -25 66 vhcurveto + -1 9 -13 8 51 vvcurveto + 152 116 91 138 101 25 -49 -53 -81 -59 -87 -83 vhcurveto + -6 hlineto + 47 222 rlineto + -59 -592 rmoveto + -20 -21 8 21 -20 hvcurveto + 62 290 rlineto + 2 18 20 1 7 hhcurveto + hintmask 10111100 + 63 21 -49 -57 -96 -58 -120 -72 hvcurveto + endchar + + + -73 21 -21 750 -20 hstem + 6 93 vstem + 397 748 rmoveto + 1 -13 -13 1 -14 hhcurveto + -167 -184 -127 -133 -72 38 -25 69 hvcurveto + -1 9 -13 8 51 vvcurveto + 107 53 75 87 36 vhcurveto + -145 -679 rlineto + 144 hlineto + endchar + + + 215 -207 50 157 -20 770 -20 hstemhm + 6 93 13 84 -84 205 hintmask 11111000 + 397 748 rmoveto + 1 -13 -13 1 -14 hhcurveto + -167 -184 -127 -133 -72 38 -25 69 hvcurveto + -1 9 -13 8 51 vvcurveto + 107 53 75 87 36 vhcurveto + -145 -679 rlineto + 34 hlineto + -11 -20 -5 -23 -27 vvcurveto + -79 48 -58 113 155 66 109 138 29 vhcurveto + 150 710 -150 -33 -164 -751 rlineto + -100 -22 -30 -23 -40 hhcurveto + -44 -27 29 39 40 29 33 36 16 17 -7 -16 16 hvcurveto + hintmask 11110100 + 4 11 3 11 11 vvcurveto + 34 -26 24 -41 6 vhcurveto + endchar + + + 88 -207 50 144 81 682 -20 hstemhm + 17 84 -84 220 -50 93 hintmask 11110100 + 538 750 rmoveto + -167 -184 -127 -133 -72 38 -25 69 hvcurveto + -1 9 -13 8 51 vvcurveto + 107 54 76 87 36 vhcurveto + -157 -714 rlineto + -103 -23 -27 -20 -45 hhcurveto + -29 -39 18 52 37 24 37 46 20 15 -5 -21 25 hvcurveto + hintmask 11101000 + 4 15 2 14 11 vvcurveto + 64 -58 3 -40 -79 -43 -66 -68 -83 53 -58 95 164 67 94 153 32 vhcurveto + 150 710 rlineto + endchar + + + -131 21 -21 624 46 78 -20 hstem + 324 748 rmoveto + -72 -121 -78 -6 -55 hhcurveto + -12 -46 rlineto + 95 hlineto + -132 -624 rlineto + 144 hlineto + endchar + + + 66 -5 65 197 51 204 237 -54 54 hstemhm + 6 111 -12 110 117 155 -117 117 hintmask 11101001 + 205 257 rmoveto + 38 -8 -33 13 -37 hhcurveto + -80 -41 -60 -83 -154 141 -16 58 171 111 136 121 71 -38 65 -88 29 hvcurveto + 92 46 45 74 66 vvcurveto + 78 -63 68 -123 vhcurveto + hintmask 11100110 + -116 -91 -61 -91 -54 32 -31 40 24 27 11 23 25 hvcurveto + -28 8 -10 36 27 vvcurveto + hintmask 11011001 + 47 31 31 48 51 25 -36 -46 -70 -58 -94 -113 -31 vhcurveto + hintmask 11101010 + 93 -33 40 -80 -76 vvcurveto + -87 -53 -82 -86 -37 -39 13 76 40 10 62 78 6 vhcurveto + endchar + + + 44 -11 125 -89 89 -89 107 380 237 -54 54 hstemhm + 66 110 142 119 -119 144 hintmask 00110101 + 111 132 rmoveto + -5 hlineto + 83 135 273 98 223 vvcurveto + 97 -53 64 -137 -151 -55 -79 -68 -58 31 -32 41 24 26 11 23 26 vhcurveto + -28 8 -10 37 23 vvcurveto + hintmask 01001110 + 50 14 31 67 29 32 -33 -49 vhcurveto + -266 -329 -98 -219 vvcurveto + -11 0 -11 2 -11 vhcurveto + 7 20 36 21 23 hhcurveto + hintmask 10010110 + 102 37 -36 109 hhcurveto + 99 20 52 98 14 0 14 -1 16 hvcurveto + -44 -47 -17 -25 -70 hhcurveto + hintmask 00110110 + -75 -57 18 -59 hhcurveto + endchar + + + 98 -9 84 623 52 hstem + 30 158 236 131 vstem + 377 750 rmoveto + -215 -132 -223 -273 -166 35 -97 172 205 113 299 199 168 -53 93 -125 hvcurveto + -189 -425 rmoveto + 225 17 105 148 60 hhcurveto + 47 7 -63 -82 -232 -68 -246 -114 -48 -11 77 74 37 3 35 2 27 hvcurveto + endchar + + + + + + + + + + diff --git a/Tests/subset/data/expect_no_hinting_CFF.ttx b/Tests/subset/data/expect_no_hinting_CFF.ttx new file mode 100644 index 000000000..7031c9741 --- /dev/null +++ b/Tests/subset/data/expect_no_hinting_CFF.ttx @@ -0,0 +1,211 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 397 748 rmoveto + 1 -13 -13 1 -14 hhcurveto + -106 callsubr + 53 75 87 36 vhcurveto + -145 -679 rlineto + return + + + -167 -184 -127 -133 -72 38 -25 69 hvcurveto + -1 9 -13 8 51 vvcurveto + 107 return + + + 230 636 rmoveto + -136 -636 rlineto + 144 hlineto + return + + + -67 41 -25 66 vhcurveto + -1 9 -13 8 51 vvcurveto + return + + + + + + -63 endchar + + + 220 535 hmoveto + 157 736 rlineto + 10 -24 -32 4 -23 hhcurveto + -117 -130 -135 -160 -101 hvcurveto + 2 -21 -17 1 -14 hhcurveto + -118 -86 -55 -68 -39 28 -19 34 31 25 15 24 14 -8 17 -5 hvcurveto + 13 34 42 14 62 4 rrcurveto + -87 -153 -60 -164 -90 vvcurveto + -104 80 -2 54 vhcurveto + -6 9 -8 15 32 vvcurveto + 104 55 190 75 163 vhcurveto + 44 -4 39 -9 51 -23 -77 -363 rcurveline + 86 407 rmoveto + -39 16 -43 11 -40 8 56 112 64 93 60 32 rrcurveto + endchar + + + 142 459 hmoveto + 157 736 rlineto + 12 -30 -26 3 -24 hhcurveto + -238 -290 -563 -189 -106 65 -2 69 -4 hvcurveto + -1 9 -13 -4 51 vvcurveto + 97 42 172 64 154 vhcurveto + 158 hlineto + -77 -366 rlineto + -59 418 rmoveto + 58 126 72 106 73 32 -56 -264 rcurveline + endchar + + + 187 -105 callsubr + 82 383 rlineto + 2 18 20 1 8 hhcurveto + 73 22 -57 -70 hvcurveto + -76 -26 -104 -73 -23 -19 10 26 -25 vhcurveto + -9 -23 -4 -19 -16 vvcurveto + -61 56 -13 43 167 52 192 96 75 -33 69 -85 17 vhcurveto + 65 37 35 63 59 vvcurveto + 82 -66 77 -147 -189 -174 -127 -138 -104 callsubr + 165 133 78 117 95 37 -51 -57 -75 -64 -87 -80 vhcurveto + -6 hlineto + 47 222 rlineto + endchar + + + 185 -105 callsubr + 6 30 rlineto + -41 39 41 -17 39 hhcurveto + 125 110 175 136 72 -32 62 -82 15 hvcurveto + 64 38 36 61 58 vvcurveto + 83 -74 78 -144 -183 -177 -126 -139 -104 callsubr + 152 116 91 138 101 25 -49 -53 -81 -59 -87 -83 vhcurveto + -6 hlineto + 47 222 rlineto + -59 -592 rmoveto + -20 -21 8 21 -20 hvcurveto + 62 290 rlineto + 2 18 20 1 7 hhcurveto + 63 21 -49 -57 -96 -58 -120 -72 hvcurveto + endchar + + + -73 -107 callsubr + 144 hlineto + endchar + + + 215 -107 callsubr + 34 hlineto + -11 -20 -5 -23 -27 vvcurveto + -79 48 -58 113 155 66 109 138 29 vhcurveto + 150 710 -150 -33 -164 -751 rlineto + -100 -22 -30 -23 -40 hhcurveto + -44 -27 29 39 40 29 33 36 16 17 -7 -16 16 hvcurveto + 4 11 3 11 11 vvcurveto + 34 -26 24 -41 6 vhcurveto + endchar + + + 88 538 750 rmoveto + -106 callsubr + 54 76 87 36 vhcurveto + -157 -714 rlineto + -103 -23 -27 -20 -45 hhcurveto + -29 -39 18 52 37 24 37 46 20 15 -5 -21 25 hvcurveto + 4 15 2 14 11 vvcurveto + 64 -58 3 -40 -79 -43 -66 -68 -83 53 -58 95 164 67 94 153 32 vhcurveto + 150 710 rlineto + endchar + + + -131 324 748 rmoveto + -72 -121 -78 -6 -55 hhcurveto + -12 -46 rlineto + 95 hlineto + -132 -624 rlineto + 144 hlineto + endchar + + + 66 205 257 rmoveto + 38 -8 -33 13 -37 hhcurveto + -80 -41 -60 -83 -154 141 -16 58 171 111 136 121 71 -38 65 -88 29 hvcurveto + 92 46 45 74 66 vvcurveto + 78 -63 68 -123 vhcurveto + -116 -91 -61 -91 -54 32 -31 40 24 27 11 23 25 hvcurveto + -28 8 -10 36 27 vvcurveto + 47 31 31 48 51 25 -36 -46 -70 -58 -94 -113 -31 vhcurveto + 93 -33 40 -80 -76 vvcurveto + -87 -53 -82 -86 -37 -39 13 76 40 10 62 78 6 vhcurveto + endchar + + + 44 111 132 rmoveto + -5 hlineto + 83 135 273 98 223 vvcurveto + 97 -53 64 -137 -151 -55 -79 -68 -58 31 -32 41 24 26 11 23 26 vhcurveto + -28 8 -10 37 23 vvcurveto + 50 14 31 67 29 32 -33 -49 vhcurveto + -266 -329 -98 -219 vvcurveto + -11 0 -11 2 -11 vhcurveto + 7 20 36 21 23 hhcurveto + 102 37 -36 109 hhcurveto + 99 20 52 98 14 0 14 -1 16 hvcurveto + -44 -47 -17 -25 -70 hhcurveto + -75 -57 18 -59 hhcurveto + endchar + + + 98 377 750 rmoveto + -215 -132 -223 -273 -166 35 -97 172 205 113 299 199 168 -53 93 -125 hvcurveto + -189 -425 rmoveto + 225 17 105 148 60 hhcurveto + 47 7 -63 -82 -232 -68 -246 -114 -48 -11 77 74 37 3 35 2 27 hvcurveto + endchar + + + + + + + + + + diff --git a/Tests/subset/data/expect_no_hinting_TTF.ttx b/Tests/subset/data/expect_no_hinting_TTF.ttx new file mode 100644 index 000000000..4c2e55b99 --- /dev/null +++ b/Tests/subset/data/expect_no_hinting_TTF.ttx @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/subset/data/expect_no_hinting_desubroutinize_CFF.ttx b/Tests/subset/data/expect_no_hinting_desubroutinize_CFF.ttx new file mode 100644 index 000000000..7dae4e734 --- /dev/null +++ b/Tests/subset/data/expect_no_hinting_desubroutinize_CFF.ttx @@ -0,0 +1,204 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -63 endchar + + + 220 535 hmoveto + 157 736 rlineto + 10 -24 -32 4 -23 hhcurveto + -117 -130 -135 -160 -101 hvcurveto + 2 -21 -17 1 -14 hhcurveto + -118 -86 -55 -68 -39 28 -19 34 31 25 15 24 14 -8 17 -5 hvcurveto + 13 34 42 14 62 4 rrcurveto + -87 -153 -60 -164 -90 vvcurveto + -104 80 -2 54 vhcurveto + -6 9 -8 15 32 vvcurveto + 104 55 190 75 163 vhcurveto + 44 -4 39 -9 51 -23 -77 -363 rcurveline + 86 407 rmoveto + -39 16 -43 11 -40 8 56 112 64 93 60 32 rrcurveto + endchar + + + 142 459 hmoveto + 157 736 rlineto + 12 -30 -26 3 -24 hhcurveto + -238 -290 -563 -189 -106 65 -2 69 -4 hvcurveto + -1 9 -13 -4 51 vvcurveto + 97 42 172 64 154 vhcurveto + 158 hlineto + -77 -366 rlineto + -59 418 rmoveto + 58 126 72 106 73 32 -56 -264 rcurveline + endchar + + + 187 230 636 rmoveto + -136 -636 rlineto + 144 hlineto + 82 383 rlineto + 2 18 20 1 8 hhcurveto + 73 22 -57 -70 hvcurveto + -76 -26 -104 -73 -23 -19 10 26 -25 vhcurveto + -9 -23 -4 -19 -16 vvcurveto + -61 56 -13 43 167 52 192 96 75 -33 69 -85 17 vhcurveto + 65 37 35 63 59 vvcurveto + 82 -66 77 -147 -189 -174 -127 -138 -67 41 -25 66 vhcurveto + -1 9 -13 8 51 vvcurveto + 165 133 78 117 95 37 -51 -57 -75 -64 -87 -80 vhcurveto + -6 hlineto + 47 222 rlineto + endchar + + + 185 230 636 rmoveto + -136 -636 rlineto + 144 hlineto + 6 30 rlineto + -41 39 41 -17 39 hhcurveto + 125 110 175 136 72 -32 62 -82 15 hvcurveto + 64 38 36 61 58 vvcurveto + 83 -74 78 -144 -183 -177 -126 -139 -67 41 -25 66 vhcurveto + -1 9 -13 8 51 vvcurveto + 152 116 91 138 101 25 -49 -53 -81 -59 -87 -83 vhcurveto + -6 hlineto + 47 222 rlineto + -59 -592 rmoveto + -20 -21 8 21 -20 hvcurveto + 62 290 rlineto + 2 18 20 1 7 hhcurveto + 63 21 -49 -57 -96 -58 -120 -72 hvcurveto + endchar + + + -73 397 748 rmoveto + 1 -13 -13 1 -14 hhcurveto + -167 -184 -127 -133 -72 38 -25 69 hvcurveto + -1 9 -13 8 51 vvcurveto + 107 53 75 87 36 vhcurveto + -145 -679 rlineto + 144 hlineto + endchar + + + 215 397 748 rmoveto + 1 -13 -13 1 -14 hhcurveto + -167 -184 -127 -133 -72 38 -25 69 hvcurveto + -1 9 -13 8 51 vvcurveto + 107 53 75 87 36 vhcurveto + -145 -679 rlineto + 34 hlineto + -11 -20 -5 -23 -27 vvcurveto + -79 48 -58 113 155 66 109 138 29 vhcurveto + 150 710 -150 -33 -164 -751 rlineto + -100 -22 -30 -23 -40 hhcurveto + -44 -27 29 39 40 29 33 36 16 17 -7 -16 16 hvcurveto + 4 11 3 11 11 vvcurveto + 34 -26 24 -41 6 vhcurveto + endchar + + + 88 538 750 rmoveto + -167 -184 -127 -133 -72 38 -25 69 hvcurveto + -1 9 -13 8 51 vvcurveto + 107 54 76 87 36 vhcurveto + -157 -714 rlineto + -103 -23 -27 -20 -45 hhcurveto + -29 -39 18 52 37 24 37 46 20 15 -5 -21 25 hvcurveto + 4 15 2 14 11 vvcurveto + 64 -58 3 -40 -79 -43 -66 -68 -83 53 -58 95 164 67 94 153 32 vhcurveto + 150 710 rlineto + endchar + + + -131 324 748 rmoveto + -72 -121 -78 -6 -55 hhcurveto + -12 -46 rlineto + 95 hlineto + -132 -624 rlineto + 144 hlineto + endchar + + + 66 205 257 rmoveto + 38 -8 -33 13 -37 hhcurveto + -80 -41 -60 -83 -154 141 -16 58 171 111 136 121 71 -38 65 -88 29 hvcurveto + 92 46 45 74 66 vvcurveto + 78 -63 68 -123 vhcurveto + -116 -91 -61 -91 -54 32 -31 40 24 27 11 23 25 hvcurveto + -28 8 -10 36 27 vvcurveto + 47 31 31 48 51 25 -36 -46 -70 -58 -94 -113 -31 vhcurveto + 93 -33 40 -80 -76 vvcurveto + -87 -53 -82 -86 -37 -39 13 76 40 10 62 78 6 vhcurveto + endchar + + + 44 111 132 rmoveto + -5 hlineto + 83 135 273 98 223 vvcurveto + 97 -53 64 -137 -151 -55 -79 -68 -58 31 -32 41 24 26 11 23 26 vhcurveto + -28 8 -10 37 23 vvcurveto + 50 14 31 67 29 32 -33 -49 vhcurveto + -266 -329 -98 -219 vvcurveto + -11 0 -11 2 -11 vhcurveto + 7 20 36 21 23 hhcurveto + 102 37 -36 109 hhcurveto + 99 20 52 98 14 0 14 -1 16 hvcurveto + -44 -47 -17 -25 -70 hhcurveto + -75 -57 18 -59 hhcurveto + endchar + + + 98 377 750 rmoveto + -215 -132 -223 -273 -166 35 -97 172 205 113 299 199 168 -53 93 -125 hvcurveto + -189 -425 rmoveto + 225 17 105 148 60 hhcurveto + 47 7 -63 -82 -232 -68 -246 -114 -48 -11 77 74 37 3 35 2 27 hvcurveto + endchar + + + + + + + + + + diff --git a/Tests/subset/subset_test.py b/Tests/subset/subset_test.py index c9dab4693..3e12be8cd 100644 --- a/Tests/subset/subset_test.py +++ b/Tests/subset/subset_test.py @@ -224,6 +224,47 @@ class SubsetTest(unittest.TestCase): self.assertEqual(subsetfont['maxp'].numGlyphs, 3) self.assertEqual(subsetfont.getGlyphOrder(), ['.notdef', 'A', 'u1F6D2']) + def test_no_hinting_CFF(self): + ttxpath = self.getpath("Lobster.subset.ttx") + _, fontpath = self.compile_font(ttxpath, ".otf") + subsetpath = self.temp_path(".otf") + subset.main([fontpath, "--no-hinting", "--notdef-outline", + "--output-file=%s" % subsetpath, "*"]) + subsetfont = TTFont(subsetpath) + self.expect_ttx(subsetfont, self.getpath( + "expect_no_hinting_CFF.ttx"), ["CFF "]) + + def test_desubroutinize_CFF(self): + ttxpath = self.getpath("Lobster.subset.ttx") + _, fontpath = self.compile_font(ttxpath, ".otf") + subsetpath = self.temp_path(".otf") + subset.main([fontpath, "--desubroutinize", "--notdef-outline", + "--output-file=%s" % subsetpath, "*"]) + subsetfont = TTFont(subsetpath) + self.expect_ttx(subsetfont, self.getpath( + "expect_desubroutinize_CFF.ttx"), ["CFF "]) + + def test_no_hinting_desubroutinize_CFF(self): + ttxpath = self.getpath("Lobster.subset.ttx") + _, fontpath = self.compile_font(ttxpath, ".otf") + subsetpath = self.temp_path(".otf") + subset.main([fontpath, "--no-hinting", "--desubroutinize", "--notdef-outline", + "--output-file=%s" % subsetpath, "*"]) + subsetfont = TTFont(subsetpath) + self.expect_ttx(subsetfont, self.getpath( + "expect_no_hinting_desubroutinize_CFF.ttx"), ["CFF "]) + + def test_no_hinting_TTF(self): + _, fontpath = self.compile_font(self.getpath("TestTTF-Regular.ttx"), ".ttf") + subsetpath = self.temp_path(".ttf") + subset.main([fontpath, "--no-hinting", "--notdef-outline", + "--output-file=%s" % subsetpath, "*"]) + subsetfont = TTFont(subsetpath) + self.expect_ttx(subsetfont, self.getpath( + "expect_no_hinting_TTF.ttx"), ["glyf", "maxp"]) + for tag in subset.Options().hinting_tables: + self.assertTrue(tag not in subsetfont) + if __name__ == "__main__": sys.exit(unittest.main())