本文整理汇总了Python中fontTools.ttLib.tables.TupleVariation.TupleVariation.compile方法的典型用法代码示例。如果您正苦于以下问题:Python TupleVariation.compile方法的具体用法?Python TupleVariation.compile怎么用?Python TupleVariation.compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fontTools.ttLib.tables.TupleVariation.TupleVariation
的用法示例。
在下文中一共展示了TupleVariation.compile方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _add_gvar
# 需要导入模块: from fontTools.ttLib.tables.TupleVariation import TupleVariation [as 别名]
# 或者: from fontTools.ttLib.tables.TupleVariation.TupleVariation import compile [as 别名]
def _add_gvar(font, model, master_ttfs, tolerance=0.5, optimize=True):
assert tolerance >= 0
log.info("Generating gvar")
assert "gvar" not in font
gvar = font["gvar"] = newTable('gvar')
gvar.version = 1
gvar.reserved = 0
gvar.variations = {}
for glyph in font.getGlyphOrder():
allData = [_GetCoordinates(m, glyph) for m in master_ttfs]
allCoords = [d[0] for d in allData]
allControls = [d[1] for d in allData]
control = allControls[0]
if (any(c != control for c in allControls)):
log.warning("glyph %s has incompatible masters; skipping" % glyph)
continue
del allControls
# Update gvar
gvar.variations[glyph] = []
deltas = model.getDeltas(allCoords)
supports = model.supports
assert len(deltas) == len(supports)
# Prepare for IUP optimization
origCoords = deltas[0]
endPts = control[1] if control[0] >= 1 else list(range(len(control[1])))
for i,(delta,support) in enumerate(zip(deltas[1:], supports[1:])):
if all(abs(v) <= tolerance for v in delta.array):
continue
var = TupleVariation(support, delta)
if optimize:
delta_opt = iup_delta_optimize(delta, origCoords, endPts, tolerance=tolerance)
if None in delta_opt:
# Use "optimized" version only if smaller...
var_opt = TupleVariation(support, delta_opt)
axis_tags = sorted(support.keys()) # Shouldn't matter that this is different from fvar...?
tupleData, auxData, _ = var.compile(axis_tags, [], None)
unoptimized_len = len(tupleData) + len(auxData)
tupleData, auxData, _ = var_opt.compile(axis_tags, [], None)
optimized_len = len(tupleData) + len(auxData)
if optimized_len < unoptimized_len:
var = var_opt
gvar.variations[glyph].append(var)
示例2: test_compile_embeddedPeak_nonIntermediate_sharedConstants
# 需要导入模块: from fontTools.ttLib.tables.TupleVariation import TupleVariation [as 别名]
# 或者: from fontTools.ttLib.tables.TupleVariation.TupleVariation import compile [as 别名]
def test_compile_embeddedPeak_nonIntermediate_sharedConstants(self):
var = TupleVariation(
{"wght": (0.0, 0.5, 0.5), "wdth": (0.0, 0.8, 0.8)},
[3, 1, 4])
tup, deltas = var.compile(axisTags=["wght", "wdth"],
sharedCoordIndices={}, sharedPoints={0, 1, 2})
# len(deltas)=4; flags=EMBEDDED_PEAK_TUPLE
# embeddedPeak=[(0.5, 0.8)]; intermediateCoord=[]
self.assertEqual("00 04 80 00 20 00 33 33", hexencode(tup))
self.assertEqual("02 03 01 04", # delta: [3, 1, 4]
hexencode(deltas))
示例3: test_compile_embeddedPeak_nonIntermediate_privateConstants
# 需要导入模块: from fontTools.ttLib.tables.TupleVariation import TupleVariation [as 别名]
# 或者: from fontTools.ttLib.tables.TupleVariation.TupleVariation import compile [as 别名]
def test_compile_embeddedPeak_nonIntermediate_privateConstants(self):
var = TupleVariation(
{"wght": (0.0, 0.5, 0.5), "wdth": (0.0, 0.8, 0.8)},
[7, 8, 9])
tup, deltas = var.compile(
axisTags=["wght", "wdth"], sharedCoordIndices={}, sharedPoints=None)
# len(deltas)=5; flags=PRIVATE_POINT_NUMBERS|EMBEDDED_PEAK_TUPLE
# embeddedPeak=[(0.5, 0.8)]; intermediateCoord=[]
self.assertEqual("00 05 A0 00 20 00 33 33", hexencode(tup))
self.assertEqual("00 " # all points in glyph
"02 07 08 09", # delta: [7, 8, 9]
hexencode(deltas))
示例4: test_compile_embeddedPeak_nonIntermediate_sharedPoints
# 需要导入模块: from fontTools.ttLib.tables.TupleVariation import TupleVariation [as 别名]
# 或者: from fontTools.ttLib.tables.TupleVariation.TupleVariation import compile [as 别名]
def test_compile_embeddedPeak_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)])
tup, deltas = var.compile(axisTags=["wght", "wdth"],
sharedCoordIndices={}, sharedPoints={0, 1, 2})
# len(deltas)=8; flags=EMBEDDED_PEAK_TUPLE
# embeddedPeak=[(0.5, 0.8)]; intermediateCoord=[]
self.assertEqual("00 08 80 00 20 00 33 33", hexencode(tup))
self.assertEqual("02 07 08 09 " # deltaX: [7, 8, 9]
"02 04 05 06", # deltaY: [4, 5, 6]
hexencode(deltas))
示例5: test_compile_sharedPeaks_intermediate_sharedPoints
# 需要导入模块: from fontTools.ttLib.tables.TupleVariation import TupleVariation [as 别名]
# 或者: from fontTools.ttLib.tables.TupleVariation.TupleVariation import compile [as 别名]
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))
示例6: test_compile_sharedPeaks_nonIntermediate_sharedPoints
# 需要导入模块: from fontTools.ttLib.tables.TupleVariation import TupleVariation [as 别名]
# 或者: from fontTools.ttLib.tables.TupleVariation.TupleVariation import compile [as 别名]
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))
示例7: test_compile_embeddedPeak_intermediate_privateConstants
# 需要导入模块: from fontTools.ttLib.tables.TupleVariation import TupleVariation [as 别名]
# 或者: from fontTools.ttLib.tables.TupleVariation.TupleVariation import compile [as 别名]
def test_compile_embeddedPeak_intermediate_privateConstants(self):
var = TupleVariation(
{"wght": (0.4, 0.5, 0.6), "wdth": (0.7, 0.8, 0.9)},
[7, 8, 9])
tup, deltas = var.compile(
axisTags = ["wght", "wdth"],
sharedCoordIndices={}, sharedPoints=None)
# len(deltas)=5;
# flags=PRIVATE_POINT_NUMBERS|INTERMEDIATE_REGION|EMBEDDED_PEAK_TUPLE
# embeddedPeak=(0.5, 0.8); intermediateCoord=[(0.4, 0.7), (0.6, 0.9)]
self.assertEqual("00 05 E0 00 20 00 33 33 19 9A 2C CD 26 66 39 9A",
hexencode(tup))
self.assertEqual("00 " # all points in glyph
"02 07 08 09", # delta: [7, 8, 9]
hexencode(deltas))
示例8: test_compile_sharedPeaks_nonIntermediate_privatePoints
# 需要导入模块: from fontTools.ttLib.tables.TupleVariation import TupleVariation [as 别名]
# 或者: from fontTools.ttLib.tables.TupleVariation.TupleVariation import compile [as 别名]
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))
示例9: _add_gvar
# 需要导入模块: from fontTools.ttLib.tables.TupleVariation import TupleVariation [as 别名]
# 或者: from fontTools.ttLib.tables.TupleVariation.TupleVariation import compile [as 别名]
def _add_gvar(font, masterModel, master_ttfs, tolerance=0.5, optimize=True):
assert tolerance >= 0
log.info("Generating gvar")
assert "gvar" not in font
gvar = font["gvar"] = newTable('gvar')
gvar.version = 1
gvar.reserved = 0
gvar.variations = {}
glyf = font['glyf']
for glyph in font.getGlyphOrder():
isComposite = glyf[glyph].isComposite()
allData = [_GetCoordinates(m, glyph) for m in master_ttfs]
model, allData = masterModel.getSubModel(allData)
allCoords = [d[0] for d in allData]
allControls = [d[1] for d in allData]
control = allControls[0]
if not models.allEqual(allControls):
log.warning("glyph %s has incompatible masters; skipping" % glyph)
continue
del allControls
# Update gvar
gvar.variations[glyph] = []
deltas = model.getDeltas(allCoords)
supports = model.supports
assert len(deltas) == len(supports)
# Prepare for IUP optimization
origCoords = deltas[0]
endPts = control[1] if control[0] >= 1 else list(range(len(control[1])))
for i,(delta,support) in enumerate(zip(deltas[1:], supports[1:])):
if all(abs(v) <= tolerance for v in delta.array) and not isComposite:
continue
var = TupleVariation(support, delta)
if optimize:
delta_opt = iup_delta_optimize(delta, origCoords, endPts, tolerance=tolerance)
if None in delta_opt:
"""In composite glyphs, there should be one 0 entry
to make sure the gvar entry is written to the font.
This is to work around an issue with macOS 10.14 and can be
removed once the behaviour of macOS is changed.
https://github.com/fonttools/fonttools/issues/1381
"""
if all(d is None for d in delta_opt):
delta_opt = [(0, 0)] + [None] * (len(delta_opt) - 1)
# Use "optimized" version only if smaller...
var_opt = TupleVariation(support, delta_opt)
axis_tags = sorted(support.keys()) # Shouldn't matter that this is different from fvar...?
tupleData, auxData, _ = var.compile(axis_tags, [], None)
unoptimized_len = len(tupleData) + len(auxData)
tupleData, auxData, _ = var_opt.compile(axis_tags, [], None)
optimized_len = len(tupleData) + len(auxData)
if optimized_len < unoptimized_len:
var = var_opt
gvar.variations[glyph].append(var)