1*e1fe3e4aSElliott Hughesfrom fontTools.cffLib.specializer import ( 2*e1fe3e4aSElliott Hughes programToString, 3*e1fe3e4aSElliott Hughes stringToProgram, 4*e1fe3e4aSElliott Hughes generalizeProgram, 5*e1fe3e4aSElliott Hughes specializeProgram, 6*e1fe3e4aSElliott Hughes programToCommands, 7*e1fe3e4aSElliott Hughes commandsToProgram, 8*e1fe3e4aSElliott Hughes generalizeCommands, 9*e1fe3e4aSElliott Hughes specializeCommands, 10*e1fe3e4aSElliott Hughes) 11*e1fe3e4aSElliott Hughesfrom fontTools.ttLib import TTFont 12*e1fe3e4aSElliott Hughesimport os 13*e1fe3e4aSElliott Hughesimport unittest 14*e1fe3e4aSElliott Hughesfrom fontTools.misc.testTools import parseXML, DataFilesHandler 15*e1fe3e4aSElliott Hughes 16*e1fe3e4aSElliott Hughes# TODO 17*e1fe3e4aSElliott Hughes# https://github.com/fonttools/fonttools/pull/959#commitcomment-22059841 18*e1fe3e4aSElliott Hughes# Maybe we should make these data driven. Each entry will have an input string, 19*e1fe3e4aSElliott Hughes# and a generalized and specialized. For the latter two, if they are None, they 20*e1fe3e4aSElliott Hughes# are considered equal to the input. Then we can do roundtripping tests as well... 21*e1fe3e4aSElliott Hughes# There are a few other places (aosp tests for example) where we generate tests 22*e1fe3e4aSElliott Hughes# from data. 23*e1fe3e4aSElliott Hughes 24*e1fe3e4aSElliott Hughes 25*e1fe3e4aSElliott Hughesdef get_generalized_charstr(charstr, **kwargs): 26*e1fe3e4aSElliott Hughes return programToString(generalizeProgram(stringToProgram(charstr), **kwargs)) 27*e1fe3e4aSElliott Hughes 28*e1fe3e4aSElliott Hughes 29*e1fe3e4aSElliott Hughesdef get_specialized_charstr(charstr, **kwargs): 30*e1fe3e4aSElliott Hughes return programToString(specializeProgram(stringToProgram(charstr), **kwargs)) 31*e1fe3e4aSElliott Hughes 32*e1fe3e4aSElliott Hughes 33*e1fe3e4aSElliott Hughesclass CFFGeneralizeProgramTest(unittest.TestCase): 34*e1fe3e4aSElliott Hughes def __init__(self, methodName): 35*e1fe3e4aSElliott Hughes unittest.TestCase.__init__(self, methodName) 36*e1fe3e4aSElliott Hughes # Python 3 renamed assertRaisesRegexp to assertRaisesRegex, 37*e1fe3e4aSElliott Hughes # and fires deprecation warnings if a program uses the old name. 38*e1fe3e4aSElliott Hughes if not hasattr(self, "assertRaisesRegex"): 39*e1fe3e4aSElliott Hughes self.assertRaisesRegex = self.assertRaisesRegexp 40*e1fe3e4aSElliott Hughes 41*e1fe3e4aSElliott Hughes # no arguments/operands 42*e1fe3e4aSElliott Hughes def test_rmoveto_none(self): 43*e1fe3e4aSElliott Hughes test_charstr = "rmoveto" 44*e1fe3e4aSElliott Hughes with self.assertRaisesRegex(ValueError, r"\[\]"): 45*e1fe3e4aSElliott Hughes get_generalized_charstr(test_charstr) 46*e1fe3e4aSElliott Hughes 47*e1fe3e4aSElliott Hughes def test_hmoveto_none(self): 48*e1fe3e4aSElliott Hughes test_charstr = "hmoveto" 49*e1fe3e4aSElliott Hughes with self.assertRaisesRegex(ValueError, r"\[\]"): 50*e1fe3e4aSElliott Hughes get_generalized_charstr(test_charstr) 51*e1fe3e4aSElliott Hughes 52*e1fe3e4aSElliott Hughes def test_vmoveto_none(self): 53*e1fe3e4aSElliott Hughes test_charstr = "vmoveto" 54*e1fe3e4aSElliott Hughes with self.assertRaisesRegex(ValueError, r"\[\]"): 55*e1fe3e4aSElliott Hughes get_generalized_charstr(test_charstr) 56*e1fe3e4aSElliott Hughes 57*e1fe3e4aSElliott Hughes def test_rlineto_none(self): 58*e1fe3e4aSElliott Hughes test_charstr = "rlineto" 59*e1fe3e4aSElliott Hughes with self.assertRaisesRegex(ValueError, r"\[\]"): 60*e1fe3e4aSElliott Hughes get_generalized_charstr(test_charstr) 61*e1fe3e4aSElliott Hughes 62*e1fe3e4aSElliott Hughes def test_hlineto_none(self): 63*e1fe3e4aSElliott Hughes test_charstr = "hlineto" 64*e1fe3e4aSElliott Hughes with self.assertRaisesRegex(ValueError, r"\[\]"): 65*e1fe3e4aSElliott Hughes get_generalized_charstr(test_charstr) 66*e1fe3e4aSElliott Hughes 67*e1fe3e4aSElliott Hughes def test_vlineto_none(self): 68*e1fe3e4aSElliott Hughes test_charstr = "vlineto" 69*e1fe3e4aSElliott Hughes with self.assertRaisesRegex(ValueError, r"\[\]"): 70*e1fe3e4aSElliott Hughes get_generalized_charstr(test_charstr) 71*e1fe3e4aSElliott Hughes 72*e1fe3e4aSElliott Hughes def test_rrcurveto_none(self): 73*e1fe3e4aSElliott Hughes test_charstr = "rrcurveto" 74*e1fe3e4aSElliott Hughes with self.assertRaisesRegex(ValueError, r"\[\]"): 75*e1fe3e4aSElliott Hughes get_generalized_charstr(test_charstr) 76*e1fe3e4aSElliott Hughes 77*e1fe3e4aSElliott Hughes def test_hhcurveto_none(self): 78*e1fe3e4aSElliott Hughes test_charstr = "hhcurveto" 79*e1fe3e4aSElliott Hughes with self.assertRaisesRegex(ValueError, r"\[\]"): 80*e1fe3e4aSElliott Hughes get_generalized_charstr(test_charstr) 81*e1fe3e4aSElliott Hughes 82*e1fe3e4aSElliott Hughes def test_vvcurveto_none(self): 83*e1fe3e4aSElliott Hughes test_charstr = "vvcurveto" 84*e1fe3e4aSElliott Hughes with self.assertRaisesRegex(ValueError, r"\[\]"): 85*e1fe3e4aSElliott Hughes get_generalized_charstr(test_charstr) 86*e1fe3e4aSElliott Hughes 87*e1fe3e4aSElliott Hughes def test_hvcurveto_none(self): 88*e1fe3e4aSElliott Hughes test_charstr = "hvcurveto" 89*e1fe3e4aSElliott Hughes with self.assertRaisesRegex(ValueError, r"\[\]"): 90*e1fe3e4aSElliott Hughes get_generalized_charstr(test_charstr) 91*e1fe3e4aSElliott Hughes 92*e1fe3e4aSElliott Hughes def test_vhcurveto_none(self): 93*e1fe3e4aSElliott Hughes test_charstr = "vhcurveto" 94*e1fe3e4aSElliott Hughes with self.assertRaisesRegex(ValueError, r"\[\]"): 95*e1fe3e4aSElliott Hughes get_generalized_charstr(test_charstr) 96*e1fe3e4aSElliott Hughes 97*e1fe3e4aSElliott Hughes def test_rcurveline_none(self): 98*e1fe3e4aSElliott Hughes test_charstr = "rcurveline" 99*e1fe3e4aSElliott Hughes with self.assertRaisesRegex(ValueError, r"\[\]"): 100*e1fe3e4aSElliott Hughes get_generalized_charstr(test_charstr) 101*e1fe3e4aSElliott Hughes 102*e1fe3e4aSElliott Hughes def test_rlinecurve_none(self): 103*e1fe3e4aSElliott Hughes test_charstr = "rlinecurve" 104*e1fe3e4aSElliott Hughes with self.assertRaisesRegex(ValueError, r"\[\]"): 105*e1fe3e4aSElliott Hughes get_generalized_charstr(test_charstr) 106*e1fe3e4aSElliott Hughes 107*e1fe3e4aSElliott Hughes # rmoveto 108*e1fe3e4aSElliott Hughes def test_rmoveto_zero(self): 109*e1fe3e4aSElliott Hughes test_charstr = "0 0 rmoveto" 110*e1fe3e4aSElliott Hughes xpct_charstr = test_charstr 111*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 112*e1fe3e4aSElliott Hughes 113*e1fe3e4aSElliott Hughes def test_rmoveto_zero_width(self): 114*e1fe3e4aSElliott Hughes test_charstr = "100 0 0 rmoveto" 115*e1fe3e4aSElliott Hughes xpct_charstr = test_charstr 116*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 117*e1fe3e4aSElliott Hughes 118*e1fe3e4aSElliott Hughes def test_rmoveto(self): 119*e1fe3e4aSElliott Hughes test_charstr = ".55 -.8 rmoveto" 120*e1fe3e4aSElliott Hughes xpct_charstr = "0.55 -0.8 rmoveto" 121*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 122*e1fe3e4aSElliott Hughes 123*e1fe3e4aSElliott Hughes def test_rmoveto_width(self): 124*e1fe3e4aSElliott Hughes test_charstr = "100.5 50 -5.8 rmoveto" 125*e1fe3e4aSElliott Hughes xpct_charstr = test_charstr 126*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 127*e1fe3e4aSElliott Hughes 128*e1fe3e4aSElliott Hughes # hmoveto 129*e1fe3e4aSElliott Hughes def test_hmoveto_zero(self): 130*e1fe3e4aSElliott Hughes test_charstr = "0 hmoveto" 131*e1fe3e4aSElliott Hughes xpct_charstr = "0 0 rmoveto" 132*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 133*e1fe3e4aSElliott Hughes 134*e1fe3e4aSElliott Hughes def test_hmoveto_zero_width(self): 135*e1fe3e4aSElliott Hughes test_charstr = "100 0 hmoveto" 136*e1fe3e4aSElliott Hughes xpct_charstr = "100 0 0 rmoveto" 137*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 138*e1fe3e4aSElliott Hughes 139*e1fe3e4aSElliott Hughes def test_hmoveto(self): 140*e1fe3e4aSElliott Hughes test_charstr = ".67 hmoveto" 141*e1fe3e4aSElliott Hughes xpct_charstr = "0.67 0 rmoveto" 142*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 143*e1fe3e4aSElliott Hughes 144*e1fe3e4aSElliott Hughes def test_hmoveto_width(self): 145*e1fe3e4aSElliott Hughes test_charstr = "100 -70 hmoveto" 146*e1fe3e4aSElliott Hughes xpct_charstr = "100 -70 0 rmoveto" 147*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 148*e1fe3e4aSElliott Hughes 149*e1fe3e4aSElliott Hughes # vmoveto 150*e1fe3e4aSElliott Hughes def test_vmoveto_zero(self): 151*e1fe3e4aSElliott Hughes test_charstr = "0 vmoveto" 152*e1fe3e4aSElliott Hughes xpct_charstr = "0 0 rmoveto" 153*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 154*e1fe3e4aSElliott Hughes 155*e1fe3e4aSElliott Hughes def test_vmoveto_zero_width(self): 156*e1fe3e4aSElliott Hughes test_charstr = "100 0 vmoveto" 157*e1fe3e4aSElliott Hughes xpct_charstr = "100 0 0 rmoveto" 158*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 159*e1fe3e4aSElliott Hughes 160*e1fe3e4aSElliott Hughes def test_vmoveto(self): 161*e1fe3e4aSElliott Hughes test_charstr = "-.24 vmoveto" 162*e1fe3e4aSElliott Hughes xpct_charstr = "0 -0.24 rmoveto" 163*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 164*e1fe3e4aSElliott Hughes 165*e1fe3e4aSElliott Hughes def test_vmoveto_width(self): 166*e1fe3e4aSElliott Hughes test_charstr = "100 44 vmoveto" 167*e1fe3e4aSElliott Hughes xpct_charstr = "100 0 44 rmoveto" 168*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 169*e1fe3e4aSElliott Hughes 170*e1fe3e4aSElliott Hughes # rlineto 171*e1fe3e4aSElliott Hughes def test_rlineto_zero(self): 172*e1fe3e4aSElliott Hughes test_charstr = "0 0 rlineto" 173*e1fe3e4aSElliott Hughes xpct_charstr = test_charstr 174*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 175*e1fe3e4aSElliott Hughes 176*e1fe3e4aSElliott Hughes def test_rlineto_zero_mult(self): 177*e1fe3e4aSElliott Hughes test_charstr = "0 0 0 0 0 0 rlineto" 178*e1fe3e4aSElliott Hughes xpct_charstr = ("0 0 rlineto " * 3).rstrip() 179*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 180*e1fe3e4aSElliott Hughes 181*e1fe3e4aSElliott Hughes def test_rlineto(self): 182*e1fe3e4aSElliott Hughes test_charstr = ".55 -.8 rlineto" 183*e1fe3e4aSElliott Hughes xpct_charstr = "0.55 -0.8 rlineto" 184*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 185*e1fe3e4aSElliott Hughes 186*e1fe3e4aSElliott Hughes def test_rlineto_mult(self): 187*e1fe3e4aSElliott Hughes test_charstr = ".55 -.8 .55 -.8 .55 -.8 rlineto" 188*e1fe3e4aSElliott Hughes xpct_charstr = ("0.55 -0.8 rlineto " * 3).rstrip() 189*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 190*e1fe3e4aSElliott Hughes 191*e1fe3e4aSElliott Hughes # hlineto 192*e1fe3e4aSElliott Hughes def test_hlineto_zero(self): 193*e1fe3e4aSElliott Hughes test_charstr = "0 hlineto" 194*e1fe3e4aSElliott Hughes xpct_charstr = "0 0 rlineto" 195*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 196*e1fe3e4aSElliott Hughes 197*e1fe3e4aSElliott Hughes def test_hlineto_zero_mult(self): 198*e1fe3e4aSElliott Hughes test_charstr = "0 0 0 0 hlineto" 199*e1fe3e4aSElliott Hughes xpct_charstr = ("0 0 rlineto " * 4).rstrip() 200*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 201*e1fe3e4aSElliott Hughes 202*e1fe3e4aSElliott Hughes def test_hlineto(self): 203*e1fe3e4aSElliott Hughes test_charstr = ".67 hlineto" 204*e1fe3e4aSElliott Hughes xpct_charstr = "0.67 0 rlineto" 205*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 206*e1fe3e4aSElliott Hughes 207*e1fe3e4aSElliott Hughes def test_hlineto_mult(self): 208*e1fe3e4aSElliott Hughes test_charstr = ".67 -6.0 .67 hlineto" 209*e1fe3e4aSElliott Hughes xpct_charstr = "0.67 0 rlineto 0 -6.0 rlineto 0.67 0 rlineto" 210*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 211*e1fe3e4aSElliott Hughes 212*e1fe3e4aSElliott Hughes # vlineto 213*e1fe3e4aSElliott Hughes def test_vlineto_zero(self): 214*e1fe3e4aSElliott Hughes test_charstr = "0 vlineto" 215*e1fe3e4aSElliott Hughes xpct_charstr = "0 0 rlineto" 216*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 217*e1fe3e4aSElliott Hughes 218*e1fe3e4aSElliott Hughes def test_vlineto_zero_mult(self): 219*e1fe3e4aSElliott Hughes test_charstr = "0 0 0 vlineto" 220*e1fe3e4aSElliott Hughes xpct_charstr = ("0 0 rlineto " * 3).rstrip() 221*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 222*e1fe3e4aSElliott Hughes 223*e1fe3e4aSElliott Hughes def test_vlineto(self): 224*e1fe3e4aSElliott Hughes test_charstr = "-.24 vlineto" 225*e1fe3e4aSElliott Hughes xpct_charstr = "0 -0.24 rlineto" 226*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 227*e1fe3e4aSElliott Hughes 228*e1fe3e4aSElliott Hughes def test_vlineto_mult(self): 229*e1fe3e4aSElliott Hughes test_charstr = "-.24 +50 30 -4 vlineto" 230*e1fe3e4aSElliott Hughes xpct_charstr = "0 -0.24 rlineto 50 0 rlineto 0 30 rlineto -4 0 rlineto" 231*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 232*e1fe3e4aSElliott Hughes 233*e1fe3e4aSElliott Hughes # rrcurveto 234*e1fe3e4aSElliott Hughes def test_rrcurveto(self): 235*e1fe3e4aSElliott Hughes test_charstr = "-1 56 -2 57 -1 57 rrcurveto" 236*e1fe3e4aSElliott Hughes xpct_charstr = test_charstr 237*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 238*e1fe3e4aSElliott Hughes 239*e1fe3e4aSElliott Hughes def test_rrcurveto_mult(self): 240*e1fe3e4aSElliott Hughes test_charstr = "-30 8 -36 15 -37 22 44 54 31 61 22 68 rrcurveto" 241*e1fe3e4aSElliott Hughes xpct_charstr = "-30 8 -36 15 -37 22 rrcurveto 44 54 31 61 22 68 rrcurveto" 242*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 243*e1fe3e4aSElliott Hughes 244*e1fe3e4aSElliott Hughes def test_rrcurveto_d3947b8(self): 245*e1fe3e4aSElliott Hughes test_charstr = "1 2 3 4 5 0 rrcurveto" 246*e1fe3e4aSElliott Hughes xpct_charstr = test_charstr 247*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 248*e1fe3e4aSElliott Hughes 249*e1fe3e4aSElliott Hughes def test_rrcurveto_v0_0h_h0(self): 250*e1fe3e4aSElliott Hughes test_charstr = "0 10 1 2 0 0 0 0 1 2 0 1 0 1 3 4 0 0 rrcurveto" 251*e1fe3e4aSElliott Hughes xpct_charstr = ( 252*e1fe3e4aSElliott Hughes "0 10 1 2 0 0 rrcurveto 0 0 1 2 0 1 rrcurveto 0 1 3 4 0 0 rrcurveto" 253*e1fe3e4aSElliott Hughes ) 254*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 255*e1fe3e4aSElliott Hughes 256*e1fe3e4aSElliott Hughes def test_rrcurveto_h0_0h_h0(self): 257*e1fe3e4aSElliott Hughes test_charstr = "10 0 1 2 0 0 0 0 1 2 0 1 0 1 3 4 0 0 rrcurveto" 258*e1fe3e4aSElliott Hughes xpct_charstr = ( 259*e1fe3e4aSElliott Hughes "10 0 1 2 0 0 rrcurveto 0 0 1 2 0 1 rrcurveto 0 1 3 4 0 0 rrcurveto" 260*e1fe3e4aSElliott Hughes ) 261*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 262*e1fe3e4aSElliott Hughes 263*e1fe3e4aSElliott Hughes def test_rrcurveto_00_0h_h0(self): 264*e1fe3e4aSElliott Hughes test_charstr = "0 0 1 2 0 0 0 0 1 2 0 1 0 1 3 4 0 0 rrcurveto" 265*e1fe3e4aSElliott Hughes xpct_charstr = ( 266*e1fe3e4aSElliott Hughes "0 0 1 2 0 0 rrcurveto 0 0 1 2 0 1 rrcurveto 0 1 3 4 0 0 rrcurveto" 267*e1fe3e4aSElliott Hughes ) 268*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 269*e1fe3e4aSElliott Hughes 270*e1fe3e4aSElliott Hughes def test_rrcurveto_r0_0h_h0(self): 271*e1fe3e4aSElliott Hughes test_charstr = "10 10 1 2 0 0 0 0 1 2 0 1 0 1 3 4 0 0 rrcurveto" 272*e1fe3e4aSElliott Hughes xpct_charstr = ( 273*e1fe3e4aSElliott Hughes "10 10 1 2 0 0 rrcurveto 0 0 1 2 0 1 rrcurveto 0 1 3 4 0 0 rrcurveto" 274*e1fe3e4aSElliott Hughes ) 275*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 276*e1fe3e4aSElliott Hughes 277*e1fe3e4aSElliott Hughes def test_rrcurveto_v0_0v_v0(self): 278*e1fe3e4aSElliott Hughes test_charstr = "0 10 1 2 0 0 0 0 1 2 1 0 1 0 3 4 0 0 rrcurveto" 279*e1fe3e4aSElliott Hughes xpct_charstr = ( 280*e1fe3e4aSElliott Hughes "0 10 1 2 0 0 rrcurveto 0 0 1 2 1 0 rrcurveto 1 0 3 4 0 0 rrcurveto" 281*e1fe3e4aSElliott Hughes ) 282*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 283*e1fe3e4aSElliott Hughes 284*e1fe3e4aSElliott Hughes def test_rrcurveto_h0_0v_v0(self): 285*e1fe3e4aSElliott Hughes test_charstr = "10 0 1 2 0 0 0 0 1 2 1 0 1 0 3 4 0 0 rrcurveto" 286*e1fe3e4aSElliott Hughes xpct_charstr = ( 287*e1fe3e4aSElliott Hughes "10 0 1 2 0 0 rrcurveto 0 0 1 2 1 0 rrcurveto 1 0 3 4 0 0 rrcurveto" 288*e1fe3e4aSElliott Hughes ) 289*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 290*e1fe3e4aSElliott Hughes 291*e1fe3e4aSElliott Hughes def test_rrcurveto_00_0v_v0(self): 292*e1fe3e4aSElliott Hughes test_charstr = "0 0 1 2 0 0 0 0 1 2 1 0 1 0 3 4 0 0 rrcurveto" 293*e1fe3e4aSElliott Hughes xpct_charstr = ( 294*e1fe3e4aSElliott Hughes "0 0 1 2 0 0 rrcurveto 0 0 1 2 1 0 rrcurveto 1 0 3 4 0 0 rrcurveto" 295*e1fe3e4aSElliott Hughes ) 296*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 297*e1fe3e4aSElliott Hughes 298*e1fe3e4aSElliott Hughes def test_rrcurveto_r0_0v_v0(self): 299*e1fe3e4aSElliott Hughes test_charstr = "10 10 1 2 0 0 0 0 1 2 1 0 1 0 3 4 0 0 rrcurveto" 300*e1fe3e4aSElliott Hughes xpct_charstr = ( 301*e1fe3e4aSElliott Hughes "10 10 1 2 0 0 rrcurveto 0 0 1 2 1 0 rrcurveto 1 0 3 4 0 0 rrcurveto" 302*e1fe3e4aSElliott Hughes ) 303*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 304*e1fe3e4aSElliott Hughes 305*e1fe3e4aSElliott Hughes # hhcurveto 306*e1fe3e4aSElliott Hughes def test_hhcurveto_4(self): 307*e1fe3e4aSElliott Hughes test_charstr = "10 30 0 10 hhcurveto" 308*e1fe3e4aSElliott Hughes xpct_charstr = "10 0 30 0 10 0 rrcurveto" 309*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 310*e1fe3e4aSElliott Hughes 311*e1fe3e4aSElliott Hughes def test_hhcurveto_5(self): 312*e1fe3e4aSElliott Hughes test_charstr = "40 -38 -60 41 -91 hhcurveto" 313*e1fe3e4aSElliott Hughes xpct_charstr = "-38 40 -60 41 -91 0 rrcurveto" 314*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 315*e1fe3e4aSElliott Hughes 316*e1fe3e4aSElliott Hughes def test_hhcurveto_mult_4_4(self): 317*e1fe3e4aSElliott Hughes test_charstr = "43 23 25 18 29 56 42 -84 hhcurveto" 318*e1fe3e4aSElliott Hughes xpct_charstr = "43 0 23 25 18 0 rrcurveto 29 0 56 42 -84 0 rrcurveto" 319*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 320*e1fe3e4aSElliott Hughes 321*e1fe3e4aSElliott Hughes def test_hhcurveto_mult_5_4(self): 322*e1fe3e4aSElliott Hughes test_charstr = "43 23 25 18 29 56 42 -84 79 hhcurveto" 323*e1fe3e4aSElliott Hughes xpct_charstr = "23 43 25 18 29 0 rrcurveto 56 0 42 -84 79 0 rrcurveto" 324*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 325*e1fe3e4aSElliott Hughes 326*e1fe3e4aSElliott Hughes def test_hhcurveto_mult_4_4_4(self): 327*e1fe3e4aSElliott Hughes test_charstr = "1 2 3 4 5 6 7 8 9 10 11 12 hhcurveto" 328*e1fe3e4aSElliott Hughes xpct_charstr = ( 329*e1fe3e4aSElliott Hughes "1 0 2 3 4 0 rrcurveto 5 0 6 7 8 0 rrcurveto 9 0 10 11 12 0 rrcurveto" 330*e1fe3e4aSElliott Hughes ) 331*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 332*e1fe3e4aSElliott Hughes 333*e1fe3e4aSElliott Hughes def test_hhcurveto_mult_5_4_4(self): 334*e1fe3e4aSElliott Hughes test_charstr = "1 2 3 4 5 6 7 8 9 10 11 12 13 hhcurveto" 335*e1fe3e4aSElliott Hughes xpct_charstr = ( 336*e1fe3e4aSElliott Hughes "2 1 3 4 5 0 rrcurveto 6 0 7 8 9 0 rrcurveto 10 0 11 12 13 0 rrcurveto" 337*e1fe3e4aSElliott Hughes ) 338*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 339*e1fe3e4aSElliott Hughes 340*e1fe3e4aSElliott Hughes # vvcurveto 341*e1fe3e4aSElliott Hughes def test_vvcurveto_4(self): 342*e1fe3e4aSElliott Hughes test_charstr = "61 6 52 68 vvcurveto" 343*e1fe3e4aSElliott Hughes xpct_charstr = "0 61 6 52 0 68 rrcurveto" 344*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 345*e1fe3e4aSElliott Hughes 346*e1fe3e4aSElliott Hughes def test_vvcurveto_5(self): 347*e1fe3e4aSElliott Hughes test_charstr = "61 38 35 56 72 vvcurveto" 348*e1fe3e4aSElliott Hughes xpct_charstr = "61 38 35 56 0 72 rrcurveto" 349*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 350*e1fe3e4aSElliott Hughes 351*e1fe3e4aSElliott Hughes def test_vvcurveto_mult_4_4(self): 352*e1fe3e4aSElliott Hughes test_charstr = "-84 -88 -30 -90 -13 19 23 -11 vvcurveto" 353*e1fe3e4aSElliott Hughes xpct_charstr = "0 -84 -88 -30 0 -90 rrcurveto 0 -13 19 23 0 -11 rrcurveto" 354*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 355*e1fe3e4aSElliott Hughes 356*e1fe3e4aSElliott Hughes def test_vvcurveto_mult_5_4(self): 357*e1fe3e4aSElliott Hughes test_charstr = "43 12 17 32 65 68 -6 52 61 vvcurveto" 358*e1fe3e4aSElliott Hughes xpct_charstr = "43 12 17 32 0 65 rrcurveto 0 68 -6 52 0 61 rrcurveto" 359*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 360*e1fe3e4aSElliott Hughes 361*e1fe3e4aSElliott Hughes def test_vvcurveto_mult_4_4_4(self): 362*e1fe3e4aSElliott Hughes test_charstr = "1 2 3 4 5 6 7 8 9 10 11 12 vvcurveto" 363*e1fe3e4aSElliott Hughes xpct_charstr = ( 364*e1fe3e4aSElliott Hughes "0 1 2 3 0 4 rrcurveto 0 5 6 7 0 8 rrcurveto 0 9 10 11 0 12 rrcurveto" 365*e1fe3e4aSElliott Hughes ) 366*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 367*e1fe3e4aSElliott Hughes 368*e1fe3e4aSElliott Hughes def test_vvcurveto_mult_5_4_4(self): 369*e1fe3e4aSElliott Hughes test_charstr = "1 2 3 4 5 6 7 8 9 10 11 12 13 vvcurveto" 370*e1fe3e4aSElliott Hughes xpct_charstr = ( 371*e1fe3e4aSElliott Hughes "1 2 3 4 0 5 rrcurveto 0 6 7 8 0 9 rrcurveto 0 10 11 12 0 13 rrcurveto" 372*e1fe3e4aSElliott Hughes ) 373*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 374*e1fe3e4aSElliott Hughes 375*e1fe3e4aSElliott Hughes # hvcurveto 376*e1fe3e4aSElliott Hughes def test_hvcurveto_4(self): 377*e1fe3e4aSElliott Hughes test_charstr = "1 2 3 4 hvcurveto" 378*e1fe3e4aSElliott Hughes xpct_charstr = "1 0 2 3 0 4 rrcurveto" 379*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 380*e1fe3e4aSElliott Hughes 381*e1fe3e4aSElliott Hughes def test_hvcurveto_5(self): 382*e1fe3e4aSElliott Hughes test_charstr = "57 44 22 40 34 hvcurveto" 383*e1fe3e4aSElliott Hughes xpct_charstr = "57 0 44 22 34 40 rrcurveto" 384*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 385*e1fe3e4aSElliott Hughes 386*e1fe3e4aSElliott Hughes def test_hvcurveto_4_4(self): 387*e1fe3e4aSElliott Hughes test_charstr = "65 33 -19 -45 -45 -29 -25 -71 hvcurveto" 388*e1fe3e4aSElliott Hughes xpct_charstr = "65 0 33 -19 0 -45 rrcurveto 0 -45 -29 -25 -71 0 rrcurveto" 389*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 390*e1fe3e4aSElliott Hughes 391*e1fe3e4aSElliott Hughes def test_hvcurveto_4_5(self): 392*e1fe3e4aSElliott Hughes test_charstr = "97 69 41 86 58 -36 34 -64 11 hvcurveto" 393*e1fe3e4aSElliott Hughes xpct_charstr = "97 0 69 41 0 86 rrcurveto 0 58 -36 34 -64 11 rrcurveto" 394*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 395*e1fe3e4aSElliott Hughes 396*e1fe3e4aSElliott Hughes def test_hvcurveto_4_4_4(self): 397*e1fe3e4aSElliott Hughes test_charstr = "1 2 3 4 5 6 7 8 9 10 11 12 hvcurveto" 398*e1fe3e4aSElliott Hughes xpct_charstr = ( 399*e1fe3e4aSElliott Hughes "1 0 2 3 0 4 rrcurveto 0 5 6 7 8 0 rrcurveto 9 0 10 11 0 12 rrcurveto" 400*e1fe3e4aSElliott Hughes ) 401*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 402*e1fe3e4aSElliott Hughes 403*e1fe3e4aSElliott Hughes def test_hvcurveto_4_4_5(self): 404*e1fe3e4aSElliott Hughes test_charstr = "-124 -79 104 165 163 82 102 124 56 43 -25 -37 35 hvcurveto" 405*e1fe3e4aSElliott Hughes xpct_charstr = "-124 0 -79 104 0 165 rrcurveto 0 163 82 102 124 0 rrcurveto 56 0 43 -25 35 -37 rrcurveto" 406*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 407*e1fe3e4aSElliott Hughes 408*e1fe3e4aSElliott Hughes def test_hvcurveto_4_4_4_4(self): 409*e1fe3e4aSElliott Hughes test_charstr = ( 410*e1fe3e4aSElliott Hughes "32 25 22 32 31 -25 22 -32 -32 -25 -22 -31 -32 25 -22 32 hvcurveto" 411*e1fe3e4aSElliott Hughes ) 412*e1fe3e4aSElliott Hughes xpct_charstr = "32 0 25 22 0 32 rrcurveto 0 31 -25 22 -32 0 rrcurveto -32 0 -25 -22 0 -31 rrcurveto 0 -32 25 -22 32 0 rrcurveto" 413*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 414*e1fe3e4aSElliott Hughes 415*e1fe3e4aSElliott Hughes def test_hvcurveto_4_4_4_4_5(self): 416*e1fe3e4aSElliott Hughes test_charstr = "-170 -128 111 195 234 172 151 178 182 95 -118 -161 -130 -71 -77 -63 -55 -19 38 79 20 hvcurveto" 417*e1fe3e4aSElliott Hughes xpct_charstr = "-170 0 -128 111 0 195 rrcurveto 0 234 172 151 178 0 rrcurveto 182 0 95 -118 0 -161 rrcurveto 0 -130 -71 -77 -63 0 rrcurveto -55 0 -19 38 20 79 rrcurveto" 418*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 419*e1fe3e4aSElliott Hughes 420*e1fe3e4aSElliott Hughes # vhcurveto 421*e1fe3e4aSElliott Hughes def test_vhcurveto_4(self): 422*e1fe3e4aSElliott Hughes test_charstr = "-57 43 -30 53 vhcurveto" 423*e1fe3e4aSElliott Hughes xpct_charstr = "0 -57 43 -30 53 0 rrcurveto" 424*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 425*e1fe3e4aSElliott Hughes 426*e1fe3e4aSElliott Hughes def test_vhcurveto_5(self): 427*e1fe3e4aSElliott Hughes test_charstr = "41 -27 19 -46 11 vhcurveto" 428*e1fe3e4aSElliott Hughes xpct_charstr = "0 41 -27 19 -46 11 rrcurveto" 429*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 430*e1fe3e4aSElliott Hughes 431*e1fe3e4aSElliott Hughes def test_vhcurveto_4_4(self): 432*e1fe3e4aSElliott Hughes test_charstr = "1 2 3 4 5 6 7 8 vhcurveto" 433*e1fe3e4aSElliott Hughes xpct_charstr = "0 1 2 3 4 0 rrcurveto 5 0 6 7 0 8 rrcurveto" 434*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 435*e1fe3e4aSElliott Hughes 436*e1fe3e4aSElliott Hughes def test_vhcurveto_4_5(self): 437*e1fe3e4aSElliott Hughes test_charstr = "-64 -23 -25 -45 -30 -24 14 33 -19 vhcurveto" 438*e1fe3e4aSElliott Hughes xpct_charstr = "0 -64 -23 -25 -45 0 rrcurveto -30 0 -24 14 -19 33 rrcurveto" 439*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 440*e1fe3e4aSElliott Hughes 441*e1fe3e4aSElliott Hughes def test_vhcurveto_4_4_4(self): 442*e1fe3e4aSElliott Hughes test_charstr = "1 2 3 4 5 6 7 8 9 10 11 12 vhcurveto" 443*e1fe3e4aSElliott Hughes xpct_charstr = ( 444*e1fe3e4aSElliott Hughes "0 1 2 3 4 0 rrcurveto 5 0 6 7 0 8 rrcurveto 0 9 10 11 12 0 rrcurveto" 445*e1fe3e4aSElliott Hughes ) 446*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 447*e1fe3e4aSElliott Hughes 448*e1fe3e4aSElliott Hughes def test_vhcurveto_4_4_5(self): 449*e1fe3e4aSElliott Hughes test_charstr = "108 59 81 98 99 59 -81 -108 -100 -46 -66 -63 -47 vhcurveto" 450*e1fe3e4aSElliott Hughes xpct_charstr = "0 108 59 81 98 0 rrcurveto 99 0 59 -81 0 -108 rrcurveto 0 -100 -46 -66 -63 -47 rrcurveto" 451*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 452*e1fe3e4aSElliott Hughes 453*e1fe3e4aSElliott Hughes def test_vhcurveto_4_4_4_5(self): 454*e1fe3e4aSElliott Hughes test_charstr = "60 -26 37 -43 -33 -28 -22 -36 -37 27 -20 32 3 4 0 1 3 vhcurveto" 455*e1fe3e4aSElliott Hughes xpct_charstr = "0 60 -26 37 -43 0 rrcurveto -33 0 -28 -22 0 -36 rrcurveto 0 -37 27 -20 32 0 rrcurveto 3 0 4 0 3 1 rrcurveto" 456*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 457*e1fe3e4aSElliott Hughes 458*e1fe3e4aSElliott Hughes # rcurveline 459*e1fe3e4aSElliott Hughes def test_rcurveline_6_2(self): 460*e1fe3e4aSElliott Hughes test_charstr = "21 -76 21 -72 24 -73 31 -100 rcurveline" 461*e1fe3e4aSElliott Hughes xpct_charstr = "21 -76 21 -72 24 -73 rrcurveto 31 -100 rlineto" 462*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 463*e1fe3e4aSElliott Hughes 464*e1fe3e4aSElliott Hughes def test_rcurveline_6_6_2(self): 465*e1fe3e4aSElliott Hughes test_charstr = "-73 80 -80 121 -49 96 60 65 55 41 54 17 -8 78 rcurveline" 466*e1fe3e4aSElliott Hughes xpct_charstr = ( 467*e1fe3e4aSElliott Hughes "-73 80 -80 121 -49 96 rrcurveto 60 65 55 41 54 17 rrcurveto -8 78 rlineto" 468*e1fe3e4aSElliott Hughes ) 469*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 470*e1fe3e4aSElliott Hughes 471*e1fe3e4aSElliott Hughes def test_rcurveline_6_6_6_2(self): 472*e1fe3e4aSElliott Hughes test_charstr = ( 473*e1fe3e4aSElliott Hughes "1 64 10 51 29 39 15 21 15 20 15 18 47 -89 63 -98 52 -59 91 8 rcurveline" 474*e1fe3e4aSElliott Hughes ) 475*e1fe3e4aSElliott Hughes xpct_charstr = "1 64 10 51 29 39 rrcurveto 15 21 15 20 15 18 rrcurveto 47 -89 63 -98 52 -59 rrcurveto 91 8 rlineto" 476*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 477*e1fe3e4aSElliott Hughes 478*e1fe3e4aSElliott Hughes def test_rcurveline_6_6_6_6_2(self): 479*e1fe3e4aSElliott Hughes test_charstr = "1 64 10 51 29 39 15 21 15 20 15 18 46 -88 63 -97 52 -59 -38 -57 -49 -62 -52 -54 96 -8 rcurveline" 480*e1fe3e4aSElliott Hughes xpct_charstr = "1 64 10 51 29 39 rrcurveto 15 21 15 20 15 18 rrcurveto 46 -88 63 -97 52 -59 rrcurveto -38 -57 -49 -62 -52 -54 rrcurveto 96 -8 rlineto" 481*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 482*e1fe3e4aSElliott Hughes 483*e1fe3e4aSElliott Hughes # rlinecurve 484*e1fe3e4aSElliott Hughes def test_rlinecurve_2_6(self): 485*e1fe3e4aSElliott Hughes test_charstr = "21 -76 21 -72 24 -73 31 -100 rlinecurve" 486*e1fe3e4aSElliott Hughes xpct_charstr = "21 -76 rlineto 21 -72 24 -73 31 -100 rrcurveto" 487*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 488*e1fe3e4aSElliott Hughes 489*e1fe3e4aSElliott Hughes def test_rlinecurve_2_2_6(self): 490*e1fe3e4aSElliott Hughes test_charstr = "-73 80 -80 121 -49 96 60 65 55 41 rlinecurve" 491*e1fe3e4aSElliott Hughes xpct_charstr = "-73 80 rlineto -80 121 rlineto -49 96 60 65 55 41 rrcurveto" 492*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 493*e1fe3e4aSElliott Hughes 494*e1fe3e4aSElliott Hughes def test_rlinecurve_2_2_2_6(self): 495*e1fe3e4aSElliott Hughes test_charstr = "1 64 10 51 29 39 15 21 15 20 15 18 rlinecurve" 496*e1fe3e4aSElliott Hughes xpct_charstr = ( 497*e1fe3e4aSElliott Hughes "1 64 rlineto 10 51 rlineto 29 39 rlineto 15 21 15 20 15 18 rrcurveto" 498*e1fe3e4aSElliott Hughes ) 499*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 500*e1fe3e4aSElliott Hughes 501*e1fe3e4aSElliott Hughes def test_rlinecurve_2_2_2_2_6(self): 502*e1fe3e4aSElliott Hughes test_charstr = "1 64 10 51 29 39 15 21 15 20 15 18 46 -88 rlinecurve" 503*e1fe3e4aSElliott Hughes xpct_charstr = "1 64 rlineto 10 51 rlineto 29 39 rlineto 15 21 rlineto 15 20 15 18 46 -88 rrcurveto" 504*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 505*e1fe3e4aSElliott Hughes 506*e1fe3e4aSElliott Hughes # hstem/vstem 507*e1fe3e4aSElliott Hughes def test_hstem_vstem(self): 508*e1fe3e4aSElliott Hughes test_charstr = "95 0 58 542 60 hstem 89 65 344 67 vstem 89 45 rmoveto" 509*e1fe3e4aSElliott Hughes xpct_charstr = test_charstr 510*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 511*e1fe3e4aSElliott Hughes 512*e1fe3e4aSElliott Hughes # hstemhm/vstemhm 513*e1fe3e4aSElliott Hughes def test_hstemhm_vstemhm(self): 514*e1fe3e4aSElliott Hughes test_charstr = "-16 577 60 24 60 hstemhm 98 55 236 55 vstemhm 343 577 rmoveto" 515*e1fe3e4aSElliott Hughes xpct_charstr = test_charstr 516*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 517*e1fe3e4aSElliott Hughes 518*e1fe3e4aSElliott Hughes # hintmask/cntrmask 519*e1fe3e4aSElliott Hughes def test_hintmask_cntrmask(self): 520*e1fe3e4aSElliott Hughes test_charstr = "52 80 153 61 4 83 -71.5 71.5 hintmask 11011100 94 119 216 119 216 119 cntrmask 1110000 154 -12 rmoveto" 521*e1fe3e4aSElliott Hughes xpct_charstr = test_charstr 522*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 523*e1fe3e4aSElliott Hughes 524*e1fe3e4aSElliott Hughes # endchar 525*e1fe3e4aSElliott Hughes def test_endchar(self): 526*e1fe3e4aSElliott Hughes test_charstr = "-255 319 rmoveto 266 57 rlineto endchar" 527*e1fe3e4aSElliott Hughes xpct_charstr = test_charstr 528*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 529*e1fe3e4aSElliott Hughes 530*e1fe3e4aSElliott Hughes # xtra 531*e1fe3e4aSElliott Hughes def test_xtra(self): 532*e1fe3e4aSElliott Hughes test_charstr = "-255 319 rmoveto 266 57 rlineto xtra 90 34" 533*e1fe3e4aSElliott Hughes xpct_charstr = test_charstr 534*e1fe3e4aSElliott Hughes self.assertEqual(get_generalized_charstr(test_charstr), xpct_charstr) 535*e1fe3e4aSElliott Hughes 536*e1fe3e4aSElliott Hughes 537*e1fe3e4aSElliott Hughesclass CFFSpecializeProgramTest(unittest.TestCase): 538*e1fe3e4aSElliott Hughes def __init__(self, methodName): 539*e1fe3e4aSElliott Hughes unittest.TestCase.__init__(self, methodName) 540*e1fe3e4aSElliott Hughes # Python 3 renamed assertRaisesRegexp to assertRaisesRegex, 541*e1fe3e4aSElliott Hughes # and fires deprecation warnings if a program uses the old name. 542*e1fe3e4aSElliott Hughes if not hasattr(self, "assertRaisesRegex"): 543*e1fe3e4aSElliott Hughes self.assertRaisesRegex = self.assertRaisesRegexp 544*e1fe3e4aSElliott Hughes 545*e1fe3e4aSElliott Hughes # no arguments/operands 546*e1fe3e4aSElliott Hughes def test_rmoveto_none(self): 547*e1fe3e4aSElliott Hughes test_charstr = "rmoveto" 548*e1fe3e4aSElliott Hughes with self.assertRaisesRegex(ValueError, r"\[\]"): 549*e1fe3e4aSElliott Hughes get_specialized_charstr(test_charstr) 550*e1fe3e4aSElliott Hughes 551*e1fe3e4aSElliott Hughes def test_hmoveto_none(self): 552*e1fe3e4aSElliott Hughes test_charstr = "hmoveto" 553*e1fe3e4aSElliott Hughes with self.assertRaisesRegex(ValueError, r"\[\]"): 554*e1fe3e4aSElliott Hughes get_specialized_charstr(test_charstr) 555*e1fe3e4aSElliott Hughes 556*e1fe3e4aSElliott Hughes def test_vmoveto_none(self): 557*e1fe3e4aSElliott Hughes test_charstr = "vmoveto" 558*e1fe3e4aSElliott Hughes with self.assertRaisesRegex(ValueError, r"\[\]"): 559*e1fe3e4aSElliott Hughes get_specialized_charstr(test_charstr) 560*e1fe3e4aSElliott Hughes 561*e1fe3e4aSElliott Hughes def test_rlineto_none(self): 562*e1fe3e4aSElliott Hughes test_charstr = "rlineto" 563*e1fe3e4aSElliott Hughes with self.assertRaisesRegex(ValueError, r"\[\]"): 564*e1fe3e4aSElliott Hughes get_specialized_charstr(test_charstr) 565*e1fe3e4aSElliott Hughes 566*e1fe3e4aSElliott Hughes def test_hlineto_none(self): 567*e1fe3e4aSElliott Hughes test_charstr = "hlineto" 568*e1fe3e4aSElliott Hughes with self.assertRaisesRegex(ValueError, r"\[\]"): 569*e1fe3e4aSElliott Hughes get_specialized_charstr(test_charstr) 570*e1fe3e4aSElliott Hughes 571*e1fe3e4aSElliott Hughes def test_vlineto_none(self): 572*e1fe3e4aSElliott Hughes test_charstr = "vlineto" 573*e1fe3e4aSElliott Hughes with self.assertRaisesRegex(ValueError, r"\[\]"): 574*e1fe3e4aSElliott Hughes get_specialized_charstr(test_charstr) 575*e1fe3e4aSElliott Hughes 576*e1fe3e4aSElliott Hughes def test_rrcurveto_none(self): 577*e1fe3e4aSElliott Hughes test_charstr = "rrcurveto" 578*e1fe3e4aSElliott Hughes with self.assertRaisesRegex(ValueError, r"\[\]"): 579*e1fe3e4aSElliott Hughes get_specialized_charstr(test_charstr) 580*e1fe3e4aSElliott Hughes 581*e1fe3e4aSElliott Hughes def test_hhcurveto_none(self): 582*e1fe3e4aSElliott Hughes test_charstr = "hhcurveto" 583*e1fe3e4aSElliott Hughes with self.assertRaisesRegex(ValueError, r"\[\]"): 584*e1fe3e4aSElliott Hughes get_specialized_charstr(test_charstr) 585*e1fe3e4aSElliott Hughes 586*e1fe3e4aSElliott Hughes def test_vvcurveto_none(self): 587*e1fe3e4aSElliott Hughes test_charstr = "vvcurveto" 588*e1fe3e4aSElliott Hughes with self.assertRaisesRegex(ValueError, r"\[\]"): 589*e1fe3e4aSElliott Hughes get_specialized_charstr(test_charstr) 590*e1fe3e4aSElliott Hughes 591*e1fe3e4aSElliott Hughes def test_hvcurveto_none(self): 592*e1fe3e4aSElliott Hughes test_charstr = "hvcurveto" 593*e1fe3e4aSElliott Hughes with self.assertRaisesRegex(ValueError, r"\[\]"): 594*e1fe3e4aSElliott Hughes get_specialized_charstr(test_charstr) 595*e1fe3e4aSElliott Hughes 596*e1fe3e4aSElliott Hughes def test_vhcurveto_none(self): 597*e1fe3e4aSElliott Hughes test_charstr = "vhcurveto" 598*e1fe3e4aSElliott Hughes with self.assertRaisesRegex(ValueError, r"\[\]"): 599*e1fe3e4aSElliott Hughes get_specialized_charstr(test_charstr) 600*e1fe3e4aSElliott Hughes 601*e1fe3e4aSElliott Hughes def test_rcurveline_none(self): 602*e1fe3e4aSElliott Hughes test_charstr = "rcurveline" 603*e1fe3e4aSElliott Hughes with self.assertRaisesRegex(ValueError, r"\[\]"): 604*e1fe3e4aSElliott Hughes get_specialized_charstr(test_charstr) 605*e1fe3e4aSElliott Hughes 606*e1fe3e4aSElliott Hughes def test_rlinecurve_none(self): 607*e1fe3e4aSElliott Hughes test_charstr = "rlinecurve" 608*e1fe3e4aSElliott Hughes with self.assertRaisesRegex(ValueError, r"\[\]"): 609*e1fe3e4aSElliott Hughes get_specialized_charstr(test_charstr) 610*e1fe3e4aSElliott Hughes 611*e1fe3e4aSElliott Hughes # rmoveto 612*e1fe3e4aSElliott Hughes def test_rmoveto_zero(self): 613*e1fe3e4aSElliott Hughes test_charstr = "0 0 rmoveto" 614*e1fe3e4aSElliott Hughes xpct_charstr = "0 hmoveto" 615*e1fe3e4aSElliott Hughes self.assertEqual( 616*e1fe3e4aSElliott Hughes get_specialized_charstr(test_charstr, generalizeFirst=False), xpct_charstr 617*e1fe3e4aSElliott Hughes ) 618*e1fe3e4aSElliott Hughes 619*e1fe3e4aSElliott Hughes def test_rmoveto_zero_mult(self): 620*e1fe3e4aSElliott Hughes test_charstr = "0 0 rmoveto " * 3 621*e1fe3e4aSElliott Hughes xpct_charstr = "0 hmoveto" 622*e1fe3e4aSElliott Hughes self.assertEqual( 623*e1fe3e4aSElliott Hughes get_specialized_charstr(test_charstr, generalizeFirst=False), xpct_charstr 624*e1fe3e4aSElliott Hughes ) 625*e1fe3e4aSElliott Hughes 626*e1fe3e4aSElliott Hughes def test_rmoveto_zero_width(self): 627*e1fe3e4aSElliott Hughes test_charstr = "100 0 0 rmoveto" 628*e1fe3e4aSElliott Hughes xpct_charstr = "100 0 hmoveto" 629*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 630*e1fe3e4aSElliott Hughes 631*e1fe3e4aSElliott Hughes def test_rmoveto(self): 632*e1fe3e4aSElliott Hughes test_charstr = ".55 -.8 rmoveto" 633*e1fe3e4aSElliott Hughes xpct_charstr = "0.55 -0.8 rmoveto" 634*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 635*e1fe3e4aSElliott Hughes 636*e1fe3e4aSElliott Hughes def test_rmoveto_mult(self): 637*e1fe3e4aSElliott Hughes test_charstr = "55 -8 rmoveto " * 3 638*e1fe3e4aSElliott Hughes xpct_charstr = "165 -24 rmoveto" 639*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 640*e1fe3e4aSElliott Hughes 641*e1fe3e4aSElliott Hughes def test_rmoveto_width(self): 642*e1fe3e4aSElliott Hughes test_charstr = "100.5 50 -5.8 rmoveto" 643*e1fe3e4aSElliott Hughes xpct_charstr = test_charstr 644*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 645*e1fe3e4aSElliott Hughes 646*e1fe3e4aSElliott Hughes # rlineto 647*e1fe3e4aSElliott Hughes def test_rlineto_zero(self): 648*e1fe3e4aSElliott Hughes test_charstr = "0 0 rlineto" 649*e1fe3e4aSElliott Hughes xpct_charstr = "" 650*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 651*e1fe3e4aSElliott Hughes 652*e1fe3e4aSElliott Hughes def test_rlineto_zero_mult(self): 653*e1fe3e4aSElliott Hughes test_charstr = "0 0 rlineto " * 3 654*e1fe3e4aSElliott Hughes xpct_charstr = "" 655*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 656*e1fe3e4aSElliott Hughes 657*e1fe3e4aSElliott Hughes def test_rlineto(self): 658*e1fe3e4aSElliott Hughes test_charstr = ".55 -.8 rlineto" 659*e1fe3e4aSElliott Hughes xpct_charstr = "0.55 -0.8 rlineto" 660*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 661*e1fe3e4aSElliott Hughes 662*e1fe3e4aSElliott Hughes def test_rlineto_mult(self): 663*e1fe3e4aSElliott Hughes test_charstr = ".55 -.8 rlineto " * 3 664*e1fe3e4aSElliott Hughes xpct_charstr = "0.55 -0.8 0.55 -0.8 0.55 -0.8 rlineto" 665*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 666*e1fe3e4aSElliott Hughes 667*e1fe3e4aSElliott Hughes def test_hlineto(self): 668*e1fe3e4aSElliott Hughes test_charstr = ".67 0 rlineto" 669*e1fe3e4aSElliott Hughes xpct_charstr = "0.67 hlineto" 670*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 671*e1fe3e4aSElliott Hughes 672*e1fe3e4aSElliott Hughes def test_hlineto_zero_mult(self): 673*e1fe3e4aSElliott Hughes test_charstr = "62 0 rlineto " * 3 674*e1fe3e4aSElliott Hughes xpct_charstr = "186 hlineto" 675*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 676*e1fe3e4aSElliott Hughes 677*e1fe3e4aSElliott Hughes def test_hlineto_mult(self): 678*e1fe3e4aSElliott Hughes test_charstr = ".67 0 rlineto 0 -6.0 rlineto .67 0 rlineto" 679*e1fe3e4aSElliott Hughes xpct_charstr = "0.67 -6.0 0.67 hlineto" 680*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 681*e1fe3e4aSElliott Hughes 682*e1fe3e4aSElliott Hughes def test_vlineto(self): 683*e1fe3e4aSElliott Hughes test_charstr = "0 -.24 rlineto" 684*e1fe3e4aSElliott Hughes xpct_charstr = "-0.24 vlineto" 685*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 686*e1fe3e4aSElliott Hughes 687*e1fe3e4aSElliott Hughes def test_vlineto_zero_mult(self): 688*e1fe3e4aSElliott Hughes test_charstr = "0 -24 rlineto " * 3 689*e1fe3e4aSElliott Hughes xpct_charstr = "-72 vlineto" 690*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 691*e1fe3e4aSElliott Hughes 692*e1fe3e4aSElliott Hughes def test_vlineto_mult(self): 693*e1fe3e4aSElliott Hughes test_charstr = "0 -.24 rlineto +50 0 rlineto 0 30 rlineto -4 0 rlineto" 694*e1fe3e4aSElliott Hughes xpct_charstr = "-0.24 50 30 -4 vlineto" 695*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 696*e1fe3e4aSElliott Hughes 697*e1fe3e4aSElliott Hughes def test_0lineto_peephole(self): 698*e1fe3e4aSElliott Hughes test_charstr = "1 2 0 0 3 4 rlineto" 699*e1fe3e4aSElliott Hughes xpct_charstr = "1 2 3 4 rlineto" 700*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 701*e1fe3e4aSElliott Hughes 702*e1fe3e4aSElliott Hughes def test_hlineto_peephole(self): 703*e1fe3e4aSElliott Hughes test_charstr = "1 2 5 0 3 4 rlineto" 704*e1fe3e4aSElliott Hughes xpct_charstr = test_charstr 705*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 706*e1fe3e4aSElliott Hughes 707*e1fe3e4aSElliott Hughes def test_vlineto_peephole(self): 708*e1fe3e4aSElliott Hughes test_charstr = "1 2 0 5 3 4 rlineto" 709*e1fe3e4aSElliott Hughes xpct_charstr = test_charstr 710*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 711*e1fe3e4aSElliott Hughes 712*e1fe3e4aSElliott Hughes # rrcurveto 713*e1fe3e4aSElliott Hughes def test_rrcurveto(self): 714*e1fe3e4aSElliott Hughes test_charstr = "-1 56 -2 57 -1 57 rrcurveto" 715*e1fe3e4aSElliott Hughes xpct_charstr = test_charstr 716*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 717*e1fe3e4aSElliott Hughes 718*e1fe3e4aSElliott Hughes def test_rrcurveto_mult(self): 719*e1fe3e4aSElliott Hughes test_charstr = "-30 8 -36 15 -37 22 rrcurveto 44 54 31 61 22 68 rrcurveto" 720*e1fe3e4aSElliott Hughes xpct_charstr = "-30 8 -36 15 -37 22 44 54 31 61 22 68 rrcurveto" 721*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 722*e1fe3e4aSElliott Hughes 723*e1fe3e4aSElliott Hughes def test_rrcurveto_d3947b8(self): 724*e1fe3e4aSElliott Hughes test_charstr = "1 2 3 4 5 0 rrcurveto" 725*e1fe3e4aSElliott Hughes xpct_charstr = "2 1 3 4 5 hhcurveto" 726*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 727*e1fe3e4aSElliott Hughes 728*e1fe3e4aSElliott Hughes def test_hhcurveto_4(self): 729*e1fe3e4aSElliott Hughes test_charstr = "10 0 30 0 10 0 rrcurveto" 730*e1fe3e4aSElliott Hughes xpct_charstr = "10 30 0 10 hhcurveto" 731*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 732*e1fe3e4aSElliott Hughes 733*e1fe3e4aSElliott Hughes def test_hhcurveto_5(self): 734*e1fe3e4aSElliott Hughes test_charstr = "-38 40 -60 41 -91 0 rrcurveto" 735*e1fe3e4aSElliott Hughes xpct_charstr = "40 -38 -60 41 -91 hhcurveto" 736*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 737*e1fe3e4aSElliott Hughes 738*e1fe3e4aSElliott Hughes def test_hhcurveto_mult_4_4(self): 739*e1fe3e4aSElliott Hughes test_charstr = "43 0 23 25 18 0 rrcurveto 29 0 56 42 -84 0 rrcurveto" 740*e1fe3e4aSElliott Hughes xpct_charstr = "43 23 25 18 29 56 42 -84 hhcurveto" 741*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 742*e1fe3e4aSElliott Hughes 743*e1fe3e4aSElliott Hughes def test_hhcurveto_mult_5_4(self): 744*e1fe3e4aSElliott Hughes test_charstr = "23 43 25 18 29 0 rrcurveto 56 0 42 -84 79 0 rrcurveto" 745*e1fe3e4aSElliott Hughes xpct_charstr = "43 23 25 18 29 56 42 -84 79 hhcurveto" 746*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 747*e1fe3e4aSElliott Hughes 748*e1fe3e4aSElliott Hughes def test_hhcurveto_mult_4_4_4(self): 749*e1fe3e4aSElliott Hughes test_charstr = ( 750*e1fe3e4aSElliott Hughes "1 0 2 3 4 0 rrcurveto 5 0 6 7 8 0 rrcurveto 9 0 10 11 12 0 rrcurveto" 751*e1fe3e4aSElliott Hughes ) 752*e1fe3e4aSElliott Hughes xpct_charstr = "1 2 3 4 5 6 7 8 9 10 11 12 hhcurveto" 753*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 754*e1fe3e4aSElliott Hughes 755*e1fe3e4aSElliott Hughes def test_hhcurveto_mult_5_4_4(self): 756*e1fe3e4aSElliott Hughes test_charstr = ( 757*e1fe3e4aSElliott Hughes "2 1 3 4 5 0 rrcurveto 6 0 7 8 9 0 rrcurveto 10 0 11 12 13 0 rrcurveto" 758*e1fe3e4aSElliott Hughes ) 759*e1fe3e4aSElliott Hughes xpct_charstr = "1 2 3 4 5 6 7 8 9 10 11 12 13 hhcurveto" 760*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 761*e1fe3e4aSElliott Hughes 762*e1fe3e4aSElliott Hughes def test_vvcurveto_4(self): 763*e1fe3e4aSElliott Hughes test_charstr = "0 61 6 52 0 68 rrcurveto" 764*e1fe3e4aSElliott Hughes xpct_charstr = "61 6 52 68 vvcurveto" 765*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 766*e1fe3e4aSElliott Hughes 767*e1fe3e4aSElliott Hughes def test_vvcurveto_5(self): 768*e1fe3e4aSElliott Hughes test_charstr = "61 38 35 56 0 72 rrcurveto" 769*e1fe3e4aSElliott Hughes xpct_charstr = "61 38 35 56 72 vvcurveto" 770*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 771*e1fe3e4aSElliott Hughes 772*e1fe3e4aSElliott Hughes def test_vvcurveto_mult_4_4(self): 773*e1fe3e4aSElliott Hughes test_charstr = "0 -84 -88 -30 0 -90 rrcurveto 0 -13 19 23 0 -11 rrcurveto" 774*e1fe3e4aSElliott Hughes xpct_charstr = "-84 -88 -30 -90 -13 19 23 -11 vvcurveto" 775*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 776*e1fe3e4aSElliott Hughes 777*e1fe3e4aSElliott Hughes def test_vvcurveto_mult_5_4(self): 778*e1fe3e4aSElliott Hughes test_charstr = "43 12 17 32 0 65 rrcurveto 0 68 -6 52 0 61 rrcurveto" 779*e1fe3e4aSElliott Hughes xpct_charstr = "43 12 17 32 65 68 -6 52 61 vvcurveto" 780*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 781*e1fe3e4aSElliott Hughes 782*e1fe3e4aSElliott Hughes def test_vvcurveto_mult_4_4_4(self): 783*e1fe3e4aSElliott Hughes test_charstr = ( 784*e1fe3e4aSElliott Hughes "0 1 2 3 0 4 rrcurveto 0 5 6 7 0 8 rrcurveto 0 9 10 11 0 12 rrcurveto" 785*e1fe3e4aSElliott Hughes ) 786*e1fe3e4aSElliott Hughes xpct_charstr = "1 2 3 4 5 6 7 8 9 10 11 12 vvcurveto" 787*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 788*e1fe3e4aSElliott Hughes 789*e1fe3e4aSElliott Hughes def test_vvcurveto_mult_5_4_4(self): 790*e1fe3e4aSElliott Hughes test_charstr = ( 791*e1fe3e4aSElliott Hughes "1 2 3 4 0 5 rrcurveto 0 6 7 8 0 9 rrcurveto 0 10 11 12 0 13 rrcurveto" 792*e1fe3e4aSElliott Hughes ) 793*e1fe3e4aSElliott Hughes xpct_charstr = "1 2 3 4 5 6 7 8 9 10 11 12 13 vvcurveto" 794*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 795*e1fe3e4aSElliott Hughes 796*e1fe3e4aSElliott Hughes def test_hvcurveto_4(self): 797*e1fe3e4aSElliott Hughes test_charstr = "1 0 2 3 0 4 rrcurveto" 798*e1fe3e4aSElliott Hughes xpct_charstr = "1 2 3 4 hvcurveto" 799*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 800*e1fe3e4aSElliott Hughes 801*e1fe3e4aSElliott Hughes def test_hvcurveto_5(self): 802*e1fe3e4aSElliott Hughes test_charstr = "57 0 44 22 34 40 rrcurveto" 803*e1fe3e4aSElliott Hughes xpct_charstr = "57 44 22 40 34 hvcurveto" 804*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 805*e1fe3e4aSElliott Hughes 806*e1fe3e4aSElliott Hughes def test_hvcurveto_4_4(self): 807*e1fe3e4aSElliott Hughes test_charstr = "65 0 33 -19 0 -45 rrcurveto 0 -45 -29 -25 -71 0 rrcurveto" 808*e1fe3e4aSElliott Hughes xpct_charstr = "65 33 -19 -45 -45 -29 -25 -71 hvcurveto" 809*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 810*e1fe3e4aSElliott Hughes 811*e1fe3e4aSElliott Hughes def test_hvcurveto_4_5(self): 812*e1fe3e4aSElliott Hughes test_charstr = "97 0 69 41 0 86 rrcurveto 0 58 -36 34 -64 11 rrcurveto" 813*e1fe3e4aSElliott Hughes xpct_charstr = "97 69 41 86 58 -36 34 -64 11 hvcurveto" 814*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 815*e1fe3e4aSElliott Hughes 816*e1fe3e4aSElliott Hughes def test_hvcurveto_4_4_4(self): 817*e1fe3e4aSElliott Hughes test_charstr = ( 818*e1fe3e4aSElliott Hughes "1 0 2 3 0 4 rrcurveto 0 5 6 7 8 0 rrcurveto 9 0 10 11 0 12 rrcurveto" 819*e1fe3e4aSElliott Hughes ) 820*e1fe3e4aSElliott Hughes xpct_charstr = "1 2 3 4 5 6 7 8 9 10 11 12 hvcurveto" 821*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 822*e1fe3e4aSElliott Hughes 823*e1fe3e4aSElliott Hughes def test_hvcurveto_4_4_5(self): 824*e1fe3e4aSElliott Hughes test_charstr = "-124 0 -79 104 0 165 rrcurveto 0 163 82 102 124 0 rrcurveto 56 0 43 -25 35 -37 rrcurveto" 825*e1fe3e4aSElliott Hughes xpct_charstr = "-124 -79 104 165 163 82 102 124 56 43 -25 -37 35 hvcurveto" 826*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 827*e1fe3e4aSElliott Hughes 828*e1fe3e4aSElliott Hughes def test_hvcurveto_4_4_4_4(self): 829*e1fe3e4aSElliott Hughes test_charstr = "32 0 25 22 0 32 rrcurveto 0 31 -25 22 -32 0 rrcurveto -32 0 -25 -22 0 -31 rrcurveto 0 -32 25 -22 32 0 rrcurveto" 830*e1fe3e4aSElliott Hughes xpct_charstr = ( 831*e1fe3e4aSElliott Hughes "32 25 22 32 31 -25 22 -32 -32 -25 -22 -31 -32 25 -22 32 hvcurveto" 832*e1fe3e4aSElliott Hughes ) 833*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 834*e1fe3e4aSElliott Hughes 835*e1fe3e4aSElliott Hughes def test_hvcurveto_4_4_4_4_5(self): 836*e1fe3e4aSElliott Hughes test_charstr = "-170 0 -128 111 0 195 rrcurveto 0 234 172 151 178 0 rrcurveto 182 0 95 -118 0 -161 rrcurveto 0 -130 -71 -77 -63 0 rrcurveto -55 0 -19 38 20 79 rrcurveto" 837*e1fe3e4aSElliott Hughes xpct_charstr = "-170 -128 111 195 234 172 151 178 182 95 -118 -161 -130 -71 -77 -63 -55 -19 38 79 20 hvcurveto" 838*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 839*e1fe3e4aSElliott Hughes 840*e1fe3e4aSElliott Hughes def test_vhcurveto_4(self): 841*e1fe3e4aSElliott Hughes test_charstr = "0 -57 43 -30 53 0 rrcurveto" 842*e1fe3e4aSElliott Hughes xpct_charstr = "-57 43 -30 53 vhcurveto" 843*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 844*e1fe3e4aSElliott Hughes 845*e1fe3e4aSElliott Hughes def test_vhcurveto_5(self): 846*e1fe3e4aSElliott Hughes test_charstr = "0 41 -27 19 -46 11 rrcurveto" 847*e1fe3e4aSElliott Hughes xpct_charstr = "41 -27 19 -46 11 vhcurveto" 848*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 849*e1fe3e4aSElliott Hughes 850*e1fe3e4aSElliott Hughes def test_vhcurveto_4_4(self): 851*e1fe3e4aSElliott Hughes test_charstr = "0 1 2 3 4 0 rrcurveto 5 0 6 7 0 8 rrcurveto" 852*e1fe3e4aSElliott Hughes xpct_charstr = "1 2 3 4 5 6 7 8 vhcurveto" 853*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 854*e1fe3e4aSElliott Hughes 855*e1fe3e4aSElliott Hughes def test_vhcurveto_4_5(self): 856*e1fe3e4aSElliott Hughes test_charstr = "0 -64 -23 -25 -45 0 rrcurveto -30 0 -24 14 -19 33 rrcurveto" 857*e1fe3e4aSElliott Hughes xpct_charstr = "-64 -23 -25 -45 -30 -24 14 33 -19 vhcurveto" 858*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 859*e1fe3e4aSElliott Hughes 860*e1fe3e4aSElliott Hughes def test_vhcurveto_4_4_4(self): 861*e1fe3e4aSElliott Hughes test_charstr = ( 862*e1fe3e4aSElliott Hughes "0 1 2 3 4 0 rrcurveto 5 0 6 7 0 8 rrcurveto 0 9 10 11 12 0 rrcurveto" 863*e1fe3e4aSElliott Hughes ) 864*e1fe3e4aSElliott Hughes xpct_charstr = "1 2 3 4 5 6 7 8 9 10 11 12 vhcurveto" 865*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 866*e1fe3e4aSElliott Hughes 867*e1fe3e4aSElliott Hughes def test_vhcurveto_4_4_5(self): 868*e1fe3e4aSElliott Hughes test_charstr = "0 108 59 81 98 0 rrcurveto 99 0 59 -81 0 -108 rrcurveto 0 -100 -46 -66 -63 -47 rrcurveto" 869*e1fe3e4aSElliott Hughes xpct_charstr = "108 59 81 98 99 59 -81 -108 -100 -46 -66 -63 -47 vhcurveto" 870*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 871*e1fe3e4aSElliott Hughes 872*e1fe3e4aSElliott Hughes def test_vhcurveto_4_4_4_5(self): 873*e1fe3e4aSElliott Hughes test_charstr = "0 60 -26 37 -43 0 rrcurveto -33 0 -28 -22 0 -36 rrcurveto 0 -37 27 -20 32 0 rrcurveto 3 0 4 0 3 1 rrcurveto" 874*e1fe3e4aSElliott Hughes xpct_charstr = "60 -26 37 -43 -33 -28 -22 -36 -37 27 -20 32 3 4 0 1 3 vhcurveto" 875*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 876*e1fe3e4aSElliott Hughes 877*e1fe3e4aSElliott Hughes def test_rrcurveto_v0_0h_h0(self): 878*e1fe3e4aSElliott Hughes test_charstr = "0 10 1 2 0 0 0 0 1 2 0 1 0 1 3 4 0 0 rrcurveto" 879*e1fe3e4aSElliott Hughes xpct_charstr = "10 1 2 0 0 1 2 1 1 3 4 0 vhcurveto" 880*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 881*e1fe3e4aSElliott Hughes 882*e1fe3e4aSElliott Hughes def test_rrcurveto_h0_0h_h0(self): 883*e1fe3e4aSElliott Hughes test_charstr = "10 0 1 2 0 0 0 0 1 2 0 1 0 1 3 4 0 0 rrcurveto" 884*e1fe3e4aSElliott Hughes xpct_charstr = "10 1 2 0 hhcurveto 0 1 2 1 1 3 4 0 hvcurveto" 885*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 886*e1fe3e4aSElliott Hughes 887*e1fe3e4aSElliott Hughes def test_rrcurveto_00_0h_h0(self): 888*e1fe3e4aSElliott Hughes test_charstr = "0 0 1 2 0 0 0 0 1 2 0 1 0 1 3 4 0 0 rrcurveto" 889*e1fe3e4aSElliott Hughes xpct_charstr = "1 2 rlineto 0 1 2 1 1 3 4 0 hvcurveto" 890*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 891*e1fe3e4aSElliott Hughes 892*e1fe3e4aSElliott Hughes def test_rrcurveto_r0_0h_h0(self): 893*e1fe3e4aSElliott Hughes test_charstr = "10 10 1 2 0 0 0 0 1 2 0 1 0 1 3 4 0 0 rrcurveto" 894*e1fe3e4aSElliott Hughes xpct_charstr = "10 10 1 2 0 0 1 2 1 1 3 4 0 vvcurveto" 895*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 896*e1fe3e4aSElliott Hughes 897*e1fe3e4aSElliott Hughes def test_rrcurveto_v0_0v_v0(self): 898*e1fe3e4aSElliott Hughes test_charstr = "0 10 1 2 0 0 0 0 1 2 1 0 1 0 3 4 0 0 rrcurveto" 899*e1fe3e4aSElliott Hughes xpct_charstr = "10 1 2 0 vhcurveto 0 1 2 1 1 3 4 0 hhcurveto" 900*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 901*e1fe3e4aSElliott Hughes 902*e1fe3e4aSElliott Hughes def test_rrcurveto_h0_0v_v0(self): 903*e1fe3e4aSElliott Hughes test_charstr = "10 0 1 2 0 0 0 0 1 2 1 0 1 0 3 4 0 0 rrcurveto" 904*e1fe3e4aSElliott Hughes xpct_charstr = "10 1 2 0 0 1 2 1 1 3 4 0 hhcurveto" 905*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 906*e1fe3e4aSElliott Hughes 907*e1fe3e4aSElliott Hughes def test_rrcurveto_00_0v_v0(self): 908*e1fe3e4aSElliott Hughes test_charstr = "0 0 1 2 0 0 0 0 1 2 1 0 1 0 3 4 0 0 rrcurveto" 909*e1fe3e4aSElliott Hughes xpct_charstr = "1 2 rlineto 0 1 2 1 1 3 4 0 hhcurveto" 910*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 911*e1fe3e4aSElliott Hughes 912*e1fe3e4aSElliott Hughes def test_rrcurveto_r0_0v_v0(self): 913*e1fe3e4aSElliott Hughes test_charstr = "10 10 1 2 0 0 0 0 1 2 1 0 1 0 3 4 0 0 rrcurveto" 914*e1fe3e4aSElliott Hughes xpct_charstr = "10 10 1 2 0 0 1 2 1 1 3 4 0 hhcurveto" 915*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 916*e1fe3e4aSElliott Hughes 917*e1fe3e4aSElliott Hughes def test_hhcurveto_peephole(self): 918*e1fe3e4aSElliott Hughes test_charstr = "1 2 3 4 5 6 1 2 3 4 5 0 1 2 3 4 5 6 rrcurveto" 919*e1fe3e4aSElliott Hughes xpct_charstr = test_charstr 920*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 921*e1fe3e4aSElliott Hughes 922*e1fe3e4aSElliott Hughes def test_vvcurveto_peephole(self): 923*e1fe3e4aSElliott Hughes test_charstr = "1 2 3 4 5 6 1 2 3 4 0 6 1 2 3 4 5 6 rrcurveto" 924*e1fe3e4aSElliott Hughes xpct_charstr = test_charstr 925*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 926*e1fe3e4aSElliott Hughes 927*e1fe3e4aSElliott Hughes def test_hvcurveto_peephole(self): 928*e1fe3e4aSElliott Hughes test_charstr = "1 2 3 4 5 6 1 0 3 4 5 6 1 2 3 4 5 6 rrcurveto" 929*e1fe3e4aSElliott Hughes xpct_charstr = test_charstr 930*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 931*e1fe3e4aSElliott Hughes 932*e1fe3e4aSElliott Hughes def test_vhcurveto_peephole(self): 933*e1fe3e4aSElliott Hughes test_charstr = "1 2 3 4 5 6 0 2 3 4 5 6 1 2 3 4 5 6 rrcurveto" 934*e1fe3e4aSElliott Hughes xpct_charstr = test_charstr 935*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 936*e1fe3e4aSElliott Hughes 937*e1fe3e4aSElliott Hughes def test_rcurveline_6_2(self): 938*e1fe3e4aSElliott Hughes test_charstr = "21 -76 21 -72 24 -73 rrcurveto 31 -100 rlineto" 939*e1fe3e4aSElliott Hughes xpct_charstr = "21 -76 21 -72 24 -73 31 -100 rcurveline" 940*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 941*e1fe3e4aSElliott Hughes 942*e1fe3e4aSElliott Hughes def test_rcurveline_6_6_2(self): 943*e1fe3e4aSElliott Hughes test_charstr = ( 944*e1fe3e4aSElliott Hughes "-73 80 -80 121 -49 96 rrcurveto 60 65 55 41 54 17 rrcurveto -8 78 rlineto" 945*e1fe3e4aSElliott Hughes ) 946*e1fe3e4aSElliott Hughes xpct_charstr = "-73 80 -80 121 -49 96 60 65 55 41 54 17 -8 78 rcurveline" 947*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 948*e1fe3e4aSElliott Hughes 949*e1fe3e4aSElliott Hughes def test_rcurveline_6_6_6_2(self): 950*e1fe3e4aSElliott Hughes test_charstr = "1 64 10 51 29 39 rrcurveto 15 21 15 20 15 18 rrcurveto 47 -89 63 -98 52 -59 rrcurveto 91 8 rlineto" 951*e1fe3e4aSElliott Hughes xpct_charstr = ( 952*e1fe3e4aSElliott Hughes "1 64 10 51 29 39 15 21 15 20 15 18 47 -89 63 -98 52 -59 91 8 rcurveline" 953*e1fe3e4aSElliott Hughes ) 954*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 955*e1fe3e4aSElliott Hughes 956*e1fe3e4aSElliott Hughes def test_rlinecurve_2_6(self): 957*e1fe3e4aSElliott Hughes test_charstr = "21 -76 rlineto 21 -72 24 -73 31 -100 rrcurveto" 958*e1fe3e4aSElliott Hughes xpct_charstr = "21 -76 21 -72 24 -73 31 -100 rlinecurve" 959*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 960*e1fe3e4aSElliott Hughes 961*e1fe3e4aSElliott Hughes def test_rlinecurve_2_2_6(self): 962*e1fe3e4aSElliott Hughes test_charstr = "-73 80 rlineto -80 121 rlineto -49 96 60 65 55 41 rrcurveto" 963*e1fe3e4aSElliott Hughes xpct_charstr = "-73 80 -80 121 -49 96 60 65 55 41 rlinecurve" 964*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 965*e1fe3e4aSElliott Hughes 966*e1fe3e4aSElliott Hughes def test_rlinecurve_2_2_2_6(self): 967*e1fe3e4aSElliott Hughes test_charstr = ( 968*e1fe3e4aSElliott Hughes "1 64 rlineto 10 51 rlineto 29 39 rlineto 15 21 15 20 15 18 rrcurveto" 969*e1fe3e4aSElliott Hughes ) 970*e1fe3e4aSElliott Hughes xpct_charstr = "1 64 10 51 29 39 15 21 15 20 15 18 rlinecurve" 971*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 972*e1fe3e4aSElliott Hughes 973*e1fe3e4aSElliott Hughes # maxstack CFF=48, specializer uses up to 47 974*e1fe3e4aSElliott Hughes def test_maxstack(self): 975*e1fe3e4aSElliott Hughes operands = "1 2 3 4 5 6 " 976*e1fe3e4aSElliott Hughes operator = "rrcurveto " 977*e1fe3e4aSElliott Hughes test_charstr = (operands + operator) * 9 978*e1fe3e4aSElliott Hughes xpct_charstr = (operands * 2 + operator + operands * 7 + operator).rstrip() 979*e1fe3e4aSElliott Hughes self.assertEqual(get_specialized_charstr(test_charstr), xpct_charstr) 980*e1fe3e4aSElliott Hughes 981*e1fe3e4aSElliott Hughes 982*e1fe3e4aSElliott Hughesclass CFF2VFTestSpecialize(DataFilesHandler): 983*e1fe3e4aSElliott Hughes def test_blend_round_trip(self): 984*e1fe3e4aSElliott Hughes ttx_path = self.getpath("TestSparseCFF2VF.ttx") 985*e1fe3e4aSElliott Hughes ttf_font = TTFont(recalcBBoxes=False, recalcTimestamp=False) 986*e1fe3e4aSElliott Hughes ttf_font.importXML(ttx_path) 987*e1fe3e4aSElliott Hughes fontGlyphList = ttf_font.getGlyphOrder() 988*e1fe3e4aSElliott Hughes topDict = ttf_font["CFF2"].cff.topDictIndex[0] 989*e1fe3e4aSElliott Hughes charstrings = topDict.CharStrings 990*e1fe3e4aSElliott Hughes for glyphName in fontGlyphList: 991*e1fe3e4aSElliott Hughes cs = charstrings[glyphName] 992*e1fe3e4aSElliott Hughes cs.decompile() 993*e1fe3e4aSElliott Hughes cmds = programToCommands(cs.program, getNumRegions=cs.getNumRegions) 994*e1fe3e4aSElliott Hughes cmds_g = generalizeCommands(cmds) 995*e1fe3e4aSElliott Hughes cmds = specializeCommands(cmds_g, generalizeFirst=False) 996*e1fe3e4aSElliott Hughes program = commandsToProgram(cmds) 997*e1fe3e4aSElliott Hughes self.assertEqual(program, cs.program) 998*e1fe3e4aSElliott Hughes program = specializeProgram(program, getNumRegions=cs.getNumRegions) 999*e1fe3e4aSElliott Hughes self.assertEqual(program, cs.program) 1000*e1fe3e4aSElliott Hughes program_g = generalizeProgram(program, getNumRegions=cs.getNumRegions) 1001*e1fe3e4aSElliott Hughes program = commandsToProgram(cmds_g) 1002*e1fe3e4aSElliott Hughes self.assertEqual(program, program_g) 1003*e1fe3e4aSElliott Hughes 1004*e1fe3e4aSElliott Hughes def test_blend_programToCommands(self): 1005*e1fe3e4aSElliott Hughes ttx_path = self.getpath("TestCFF2Widths.ttx") 1006*e1fe3e4aSElliott Hughes ttf_font = TTFont(recalcBBoxes=False, recalcTimestamp=False) 1007*e1fe3e4aSElliott Hughes ttf_font.importXML(ttx_path) 1008*e1fe3e4aSElliott Hughes fontGlyphList = ttf_font.getGlyphOrder() 1009*e1fe3e4aSElliott Hughes topDict = ttf_font["CFF2"].cff.topDictIndex[0] 1010*e1fe3e4aSElliott Hughes charstrings = topDict.CharStrings 1011*e1fe3e4aSElliott Hughes for glyphName in fontGlyphList: 1012*e1fe3e4aSElliott Hughes cs = charstrings[glyphName] 1013*e1fe3e4aSElliott Hughes cs.decompile() 1014*e1fe3e4aSElliott Hughes cmds = programToCommands(cs.program, getNumRegions=cs.getNumRegions) 1015*e1fe3e4aSElliott Hughes program = commandsToProgram(cmds) 1016*e1fe3e4aSElliott Hughes self.assertEqual(program, cs.program) 1017*e1fe3e4aSElliott Hughes 1018*e1fe3e4aSElliott Hughes 1019*e1fe3e4aSElliott Hughesif __name__ == "__main__": 1020*e1fe3e4aSElliott Hughes import sys 1021*e1fe3e4aSElliott Hughes 1022*e1fe3e4aSElliott Hughes sys.exit(unittest.main()) 1023