def test_compileCoord(self): var = TupleVariation( { "wght": (-1.0, -1.0, -1.0), "wdth": (0.4, 0.5, 0.6) }, [None] * 4) self.assertEqual("C0 00 20 00", hexencode(var.compileCoord(["wght", "wdth"]))) self.assertEqual("20 00 C0 00", hexencode(var.compileCoord(["wdth", "wght"]))) self.assertEqual("C0 00", hexencode(var.compileCoord(["wght"])))
def test_decompileCoord_roundTrip(self): # Make sure we are not affected by https://github.com/behdad/fonttools/issues/286 data = deHexStr("7F B9 80 35") values, _ = TupleVariation.decompileCoord_(["wght", "wdth"], data, 0) axisValues = {axis:(val, val, val) for axis, val in values.items()} var = TupleVariation(axisValues, [None] * 4) self.assertEqual("7F B9 80 35", hexencode(var.compileCoord(["wght", "wdth"])))
def test_decompileCoord_roundTrip(self): # Make sure we are not affected by https://github.com/fonttools/fonttools/issues/286 data = deHexStr("7F B9 80 35") values, _ = TupleVariation.decompileCoord_(["wght", "wdth"], data, 0) axisValues = {axis:(val, val, val) for axis, val in values.items()} var = TupleVariation(axisValues, [None] * 4) self.assertEqual("7F B9 80 35", hexencode(var.compileCoord(["wght", "wdth"])))
def test_compile_sharedPeaks_intermediate_sharedPoints(self): var = TupleVariation( {"wght": (0.3, 0.5, 0.7), "wdth": (0.1, 0.8, 0.9)}, [(7,4), (8,5), (9,6)]) axisTags = ["wght", "wdth"] sharedPeakIndices = { var.compileCoord(axisTags): 0x77 } tup, deltas = var.compile(axisTags, sharedPeakIndices, pointData=b'') # len(deltas)=8; flags=INTERMEDIATE_REGION; tupleIndex=0x77 # embeddedPeak=[]; intermediateCoord=[(0.3, 0.1), (0.7, 0.9)] self.assertEqual("00 08 40 77 13 33 06 66 2C CD 39 9A", hexencode(tup)) self.assertEqual("02 07 08 09 " # deltaX: [7, 8, 9] "02 04 05 06", # deltaY: [4, 5, 6] hexencode(deltas))
def test_compile_sharedPeaks_nonIntermediate_sharedPoints(self): var = TupleVariation( {"wght": (0.0, 0.5, 0.5), "wdth": (0.0, 0.8, 0.8)}, [(7,4), (8,5), (9,6)]) axisTags = ["wght", "wdth"] sharedPeakIndices = { var.compileCoord(axisTags): 0x77 } tup, deltas = var.compile(axisTags, sharedPeakIndices, pointData=b'') # len(deltas)=8; flags=None; tupleIndex=0x77 # embeddedPeaks=[]; intermediateCoord=[] self.assertEqual("00 08 00 77", hexencode(tup)) self.assertEqual("02 07 08 09 " # deltaX: [7, 8, 9] "02 04 05 06", # deltaY: [4, 5, 6] hexencode(deltas))
def test_compile_sharedPeaks_intermediate_sharedPoints(self): var = TupleVariation( {"wght": (0.3, 0.5, 0.7), "wdth": (0.1, 0.8, 0.9)}, [(7,4), (8,5), (9,6)]) axisTags = ["wght", "wdth"] sharedPeakIndices = { var.compileCoord(axisTags): 0x77 } tup, deltas = var.compile(axisTags, sharedPeakIndices, sharedPoints={0,1,2}) # len(deltas)=8; flags=INTERMEDIATE_REGION; tupleIndex=0x77 # embeddedPeak=[]; intermediateCoord=[(0.3, 0.1), (0.7, 0.9)] self.assertEqual("00 08 40 77 13 33 06 66 2C CD 39 9A", hexencode(tup)) self.assertEqual("02 07 08 09 " # deltaX: [7, 8, 9] "02 04 05 06", # deltaY: [4, 5, 6] hexencode(deltas))
def test_compile_sharedPeaks_nonIntermediate_sharedPoints(self): var = TupleVariation( {"wght": (0.0, 0.5, 0.5), "wdth": (0.0, 0.8, 0.8)}, [(7,4), (8,5), (9,6)]) axisTags = ["wght", "wdth"] sharedPeakIndices = { var.compileCoord(axisTags): 0x77 } tup, deltas = var.compile(axisTags, sharedPeakIndices, sharedPoints={0,1,2}) # len(deltas)=8; flags=None; tupleIndex=0x77 # embeddedPeaks=[]; intermediateCoord=[] self.assertEqual("00 08 00 77", hexencode(tup)) self.assertEqual("02 07 08 09 " # deltaX: [7, 8, 9] "02 04 05 06", # deltaY: [4, 5, 6] hexencode(deltas))
def test_compile_sharedPeaks_nonIntermediate_privatePoints(self): var = TupleVariation( {"wght": (0.0, 0.5, 0.5), "wdth": (0.0, 0.8, 0.8)}, [(7,4), (8,5), (9,6)]) axisTags = ["wght", "wdth"] sharedPeakIndices = { var.compileCoord(axisTags): 0x77 } tup, deltas = var.compile(axisTags, sharedPeakIndices) # len(deltas)=9; flags=PRIVATE_POINT_NUMBERS; tupleIndex=0x77 # embeddedPeak=[]; intermediateCoord=[] self.assertEqual("00 09 20 77", hexencode(tup)) self.assertEqual("00 " # all points in glyph "02 07 08 09 " # deltaX: [7, 8, 9] "02 04 05 06", # deltaY: [4, 5, 6] hexencode(deltas))
def test_compile_sharedPeaks_nonIntermediate_privatePoints(self): var = TupleVariation( {"wght": (0.0, 0.5, 0.5), "wdth": (0.0, 0.8, 0.8)}, [(7,4), (8,5), (9,6)]) axisTags = ["wght", "wdth"] sharedPeakIndices = { var.compileCoord(axisTags): 0x77 } tup, deltas, _ = var.compile(axisTags, sharedPeakIndices, sharedPoints=None) # len(deltas)=9; flags=PRIVATE_POINT_NUMBERS; tupleIndex=0x77 # embeddedPeak=[]; intermediateCoord=[] self.assertEqual("00 09 20 77", hexencode(tup)) self.assertEqual("00 " # all points in glyph "02 07 08 09 " # deltaX: [7, 8, 9] "02 04 05 06", # deltaY: [4, 5, 6] hexencode(deltas))
def test_compileCoord(self): var = TupleVariation({"wght": (-1.0, -1.0, -1.0), "wdth": (0.4, 0.5, 0.6)}, [None] * 4) self.assertEqual("C0 00 20 00", hexencode(var.compileCoord(["wght", "wdth"]))) self.assertEqual("20 00 C0 00", hexencode(var.compileCoord(["wdth", "wght"]))) self.assertEqual("C0 00", hexencode(var.compileCoord(["wght"])))