def test_compileCoord(self): gvar = GlyphVariation( { "wght": (-1.0, -1.0, -1.0), "wdth": (0.4, 0.5, 0.6) }, [None] * 4) self.assertEqual("C0 00 20 00", hexencode(gvar.compileCoord(["wght", "wdth"]))) self.assertEqual("20 00 C0 00", hexencode(gvar.compileCoord(["wdth", "wght"]))) self.assertEqual("C0 00", hexencode(gvar.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, _ = GlyphVariation.decompileCoord_(["wght", "wdth"], data, 0) axisValues = {axis:(val, val, val) for axis, val in values.items()} gvar = GlyphVariation(axisValues, [None] * 4) self.assertEqual("7F B9 80 35", hexencode(gvar.compileCoord(["wght", "wdth"])))
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, _ = GlyphVariation.decompileCoord_(["wght", "wdth"], data, 0) axisValues = {axis: (val, val, val) for axis, val in values.items()} gvar = GlyphVariation(axisValues, [None] * 4) self.assertEqual("7F B9 80 35", hexencode(gvar.compileCoord(["wght", "wdth"])))
def test_compile_sharedCoords_intermediate_sharedPoints(self): gvar = GlyphVariation({"wght": (0.3, 0.5, 0.7), "wdth": (0.1, 0.8, 0.9)}, [(7,4), (8,5), (9,6)]) axisTags = ["wght", "wdth"] sharedCoordIndices = { gvar.compileCoord(axisTags): 0x77 } tuple, data = gvar.compile(axisTags, sharedCoordIndices, sharedPoints={0,1,2}) # len(data)=8; flags=INTERMEDIATE_TUPLE; tupleIndex=0x77 # embeddedCoord=[]; intermediateCoord=[(0.3, 0.1), (0.7, 0.9)] self.assertEqual("00 08 40 77 13 33 06 66 2C CD 39 9A", hexencode(tuple)) self.assertEqual("02 07 08 09 " # deltaX: [7, 8, 9] "02 04 05 06", # deltaY: [4, 5, 6] hexencode(data))
def test_compile_sharedCoords_nonIntermediate_sharedPoints(self): gvar = GlyphVariation({"wght": (0.0, 0.5, 0.5), "wdth": (0.0, 0.8, 0.8)}, [(7,4), (8,5), (9,6)]) axisTags = ["wght", "wdth"] sharedCoordIndices = { gvar.compileCoord(axisTags): 0x77 } tuple, data = gvar.compile(axisTags, sharedCoordIndices, sharedPoints={0,1,2}) # len(data)=8; flags=None; tupleIndex=0x77 # embeddedCoord=[]; intermediateCoord=[] self.assertEqual("00 08 00 77", hexencode(tuple)) self.assertEqual("02 07 08 09 " # deltaX: [7, 8, 9] "02 04 05 06", # deltaY: [4, 5, 6] hexencode(data))
def test_compile_sharedCoords_intermediate_privatePoints(self): gvar = GlyphVariation({"wght": (0.0, 0.5, 1.0), "wdth": (0.0, 0.8, 1.0)}, [(7,4), (8,5), (9,6)]) axisTags = ["wght", "wdth"] sharedCoordIndices = { gvar.compileCoord(axisTags): 0x77 } tuple, data = gvar.compile(axisTags, sharedCoordIndices, sharedPoints=None) # len(data)=13; flags=PRIVATE_POINT_NUMBERS; tupleIndex=0x77 # embeddedCoord=[]; intermediateCoord=[(0.0, 0.0), (1.0, 1.0)] self.assertEqual("00 09 60 77 00 00 00 00 40 00 40 00", hexencode(tuple)) self.assertEqual("00 " # all points in glyph "02 07 08 09 " # deltaX: [7, 8, 9] "02 04 05 06", # deltaY: [4, 5, 6] hexencode(data))
def test_compile_sharedCoords_nonIntermediate_privatePoints(self): gvar = GlyphVariation({"wght": (0.0, 0.5, 0.5), "wdth": (0.0, 0.8, 0.8)}, GlyphCoordinates([(7,4), (8,5), (9,6)])) axisTags = ["wght", "wdth"] sharedCoordIndices = { gvar.compileCoord(axisTags): 0x77 } tuple, data = gvar.compile(axisTags, sharedCoordIndices, sharedPoints=None) # len(data)=13; flags=PRIVATE_POINT_NUMBERS; tupleIndex=0x77 # embeddedCoord=[]; intermediateCoord=[] self.assertEqual("00 0D 20 77", hexencode(tuple)) self.assertEqual("03 02 00 01 01 " # 3 points: [0, 1, 2] "02 07 08 09 " # deltaX: [7, 8, 9] "02 04 05 06", # deltaY: [4, 5, 6] hexencode(data))
def test_compile_sharedCoords_nonIntermediate_sharedPoints(self): gvar = GlyphVariation( { "wght": (0.0, 0.5, 0.5), "wdth": (0.0, 0.8, 0.8) }, [(7, 4), (8, 5), (9, 6)]) axisTags = ["wght", "wdth"] sharedCoordIndices = {gvar.compileCoord(axisTags): 0x77} tuple, data = gvar.compile(axisTags, sharedCoordIndices, sharedPoints={0, 1, 2}) # len(data)=8; flags=None; tupleIndex=0x77 # embeddedCoord=[]; intermediateCoord=[] self.assertEqual("00 08 00 77", hexencode(tuple)) self.assertEqual( "02 07 08 09 " # deltaX: [7, 8, 9] "02 04 05 06", # deltaY: [4, 5, 6] hexencode(data))
def test_compile_sharedCoords_intermediate_sharedPoints(self): gvar = GlyphVariation( { "wght": (0.3, 0.5, 0.7), "wdth": (0.1, 0.8, 0.9) }, [(7, 4), (8, 5), (9, 6)]) axisTags = ["wght", "wdth"] sharedCoordIndices = {gvar.compileCoord(axisTags): 0x77} tuple, data = gvar.compile(axisTags, sharedCoordIndices, sharedPoints={0, 1, 2}) # len(data)=8; flags=INTERMEDIATE_TUPLE; tupleIndex=0x77 # embeddedCoord=[]; intermediateCoord=[(0.3, 0.1), (0.7, 0.9)] self.assertEqual("00 08 40 77 13 33 06 66 2C CD 39 9A", hexencode(tuple)) self.assertEqual( "02 07 08 09 " # deltaX: [7, 8, 9] "02 04 05 06", # deltaY: [4, 5, 6] hexencode(data))
def test_compile_sharedCoords_intermediate_privatePoints(self): gvar = GlyphVariation( { "wght": (0.0, 0.5, 1.0), "wdth": (0.0, 0.8, 1.0) }, [(7, 4), (8, 5), (9, 6)]) axisTags = ["wght", "wdth"] sharedCoordIndices = {gvar.compileCoord(axisTags): 0x77} tuple, data = gvar.compile(axisTags, sharedCoordIndices, sharedPoints=None) # len(data)=13; flags=PRIVATE_POINT_NUMBERS; tupleIndex=0x77 # embeddedCoord=[]; intermediateCoord=[(0.0, 0.0), (1.0, 1.0)] self.assertEqual("00 09 60 77 00 00 00 00 40 00 40 00", hexencode(tuple)) self.assertEqual( "00 " # all points in glyph "02 07 08 09 " # deltaX: [7, 8, 9] "02 04 05 06", # deltaY: [4, 5, 6] hexencode(data))
def test_compileCoord(self): gvar = GlyphVariation({"wght": (-1.0, -1.0, -1.0), "wdth": (0.4, 0.5, 0.6)}, [None] * 4) self.assertEqual("C0 00 20 00", hexencode(gvar.compileCoord(["wght", "wdth"]))) self.assertEqual("20 00 C0 00", hexencode(gvar.compileCoord(["wdth", "wght"]))) self.assertEqual("C0 00", hexencode(gvar.compileCoord(["wght"])))