[gvar] Use flag names from OpenType 1.8
FontTools has initially been implemented using the Apple TrueType specification. When OpenType adopted variations, some identifier names were changed.
This commit is contained in:
parent
b61b92a96a
commit
a837a3950f
@ -15,7 +15,9 @@ import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# https://www.microsoft.com/typography/otspec/gvar.htm
|
||||
# https://www.microsoft.com/typography/otspec/otvarcommonformats.htm
|
||||
#
|
||||
# Apple's documentation of 'gvar':
|
||||
# https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6gvar.html
|
||||
#
|
||||
@ -39,8 +41,8 @@ GVAR_HEADER_SIZE = sstruct.calcsize(GVAR_HEADER_FORMAT)
|
||||
TUPLES_SHARE_POINT_NUMBERS = 0x8000
|
||||
TUPLE_COUNT_MASK = 0x0fff
|
||||
|
||||
EMBEDDED_TUPLE_COORD = 0x8000
|
||||
INTERMEDIATE_TUPLE = 0x4000
|
||||
EMBEDDED_PEAK_TUPLE = 0x8000
|
||||
INTERMEDIATE_REGION = 0x4000
|
||||
PRIVATE_POINT_NUMBERS = 0x2000
|
||||
TUPLE_INDEX_MASK = 0x0fff
|
||||
|
||||
@ -266,11 +268,11 @@ class table__g_v_a_r(DefaultTable.DefaultTable):
|
||||
flags = struct.unpack(">H", data[2:4])[0]
|
||||
|
||||
pos = 4
|
||||
if (flags & EMBEDDED_TUPLE_COORD) == 0:
|
||||
if (flags & EMBEDDED_PEAK_TUPLE) == 0:
|
||||
coord = sharedCoords[flags & TUPLE_INDEX_MASK]
|
||||
else:
|
||||
coord, pos = GlyphVariation.decompileCoord_(axisTags, data, pos)
|
||||
if (flags & INTERMEDIATE_TUPLE) != 0:
|
||||
if (flags & INTERMEDIATE_REGION) != 0:
|
||||
minCoord, pos = GlyphVariation.decompileCoord_(axisTags, data, pos)
|
||||
maxCoord, pos = GlyphVariation.decompileCoord_(axisTags, data, pos)
|
||||
else:
|
||||
@ -433,12 +435,12 @@ class GlyphVariation(object):
|
||||
if coord in sharedCoordIndices:
|
||||
flags = sharedCoordIndices[coord]
|
||||
else:
|
||||
flags = EMBEDDED_TUPLE_COORD
|
||||
flags = EMBEDDED_PEAK_TUPLE
|
||||
tupleData.append(coord)
|
||||
|
||||
intermediateCoord = self.compileIntermediateCoord(axisTags)
|
||||
if intermediateCoord is not None:
|
||||
flags |= INTERMEDIATE_TUPLE
|
||||
flags |= INTERMEDIATE_REGION
|
||||
tupleData.append(intermediateCoord)
|
||||
|
||||
if sharedPoints is not None:
|
||||
@ -742,8 +744,8 @@ class GlyphVariation(object):
|
||||
@staticmethod
|
||||
def getTupleSize_(flags, axisCount):
|
||||
size = 4
|
||||
if (flags & EMBEDDED_TUPLE_COORD) != 0:
|
||||
if (flags & EMBEDDED_PEAK_TUPLE) != 0:
|
||||
size += axisCount * 2
|
||||
if (flags & INTERMEDIATE_TUPLE) != 0:
|
||||
if (flags & INTERMEDIATE_REGION) != 0:
|
||||
size += axisCount * 4
|
||||
return size
|
||||
|
@ -254,7 +254,7 @@ class GlyphVariationTest(unittest.TestCase):
|
||||
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
|
||||
# len(data)=8; flags=INTERMEDIATE_REGION; 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]
|
||||
@ -294,7 +294,7 @@ class GlyphVariationTest(unittest.TestCase):
|
||||
[(7,4), (8,5), (9,6)])
|
||||
axisTags = ["wght", "wdth"]
|
||||
tuple, data = gvar.compile(axisTags, sharedCoordIndices={}, sharedPoints={0,1,2})
|
||||
# len(data)=8; flags=EMBEDDED_TUPLE_COORD
|
||||
# len(data)=8; flags=EMBEDDED_PEAK_TUPLE
|
||||
# embeddedCoord=[(0.5, 0.8)]; intermediateCoord=[]
|
||||
self.assertEqual("00 08 80 00 20 00 33 33", hexencode(tuple))
|
||||
self.assertEqual("02 07 08 09 " # deltaX: [7, 8, 9]
|
||||
@ -306,7 +306,7 @@ class GlyphVariationTest(unittest.TestCase):
|
||||
[(7,4), (8,5), (9,6)])
|
||||
axisTags = ["wght", "wdth"]
|
||||
tuple, data = gvar.compile(axisTags, sharedCoordIndices={}, sharedPoints={0,1,2})
|
||||
# len(data)=8; flags=EMBEDDED_TUPLE_COORD
|
||||
# len(data)=8; flags=EMBEDDED_PEAK_TUPLE
|
||||
# embeddedCoord=[(0.5, 0.8)]; intermediateCoord=[(0.0, 0.0), (1.0, 0.8)]
|
||||
self.assertEqual("00 08 C0 00 20 00 33 33 00 00 00 00 40 00 33 33", hexencode(tuple))
|
||||
self.assertEqual("02 07 08 09 " # deltaX: [7, 8, 9]
|
||||
@ -318,7 +318,7 @@ class GlyphVariationTest(unittest.TestCase):
|
||||
[(7,4), (8,5), (9,6)])
|
||||
axisTags = ["wght", "wdth"]
|
||||
tuple, data = gvar.compile(axisTags, sharedCoordIndices={}, sharedPoints=None)
|
||||
# len(data)=13; flags=PRIVATE_POINT_NUMBERS|EMBEDDED_TUPLE_COORD
|
||||
# len(data)=13; flags=PRIVATE_POINT_NUMBERS|EMBEDDED_PEAK_TUPLE
|
||||
# embeddedCoord=[(0.5, 0.8)]; intermediateCoord=[]
|
||||
self.assertEqual("00 09 A0 00 20 00 33 33", hexencode(tuple))
|
||||
self.assertEqual("00 " # all points in glyph
|
||||
@ -331,7 +331,7 @@ class GlyphVariationTest(unittest.TestCase):
|
||||
[(7,4), (8,5), (9,6)])
|
||||
axisTags = ["wght", "wdth"]
|
||||
tuple, data = gvar.compile(axisTags, sharedCoordIndices={}, sharedPoints=None)
|
||||
# len(data)=13; flags=PRIVATE_POINT_NUMBERS|INTERMEDIATE_TUPLE|EMBEDDED_TUPLE_COORD
|
||||
# len(data)=13; flags=PRIVATE_POINT_NUMBERS|INTERMEDIATE_REGION|EMBEDDED_PEAK_TUPLE
|
||||
# embeddedCoord=(0.5, 0.8); intermediateCoord=[(0.4, 0.7), (0.6, 0.9)]
|
||||
self.assertEqual("00 09 E0 00 20 00 33 33 19 9A 2C CD 26 66 39 9A", hexencode(tuple))
|
||||
self.assertEqual("00 " # all points in glyph
|
||||
|
Loading…
x
Reference in New Issue
Block a user