当前位置: 首页>>代码示例>>Python>>正文


Python TupleVariation.TupleVariation类代码示例

本文整理汇总了Python中fontTools.ttLib.tables.TupleVariation.TupleVariation的典型用法代码示例。如果您正苦于以下问题:Python TupleVariation类的具体用法?Python TupleVariation怎么用?Python TupleVariation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TupleVariation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_decompileCoord_roundTrip

	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"])))
开发者ID:anthrotype,项目名称:fonttools,代码行数:7,代码来源:TupleVariation_test.py

示例2: test_fromXML_badDeltaFormat

	def test_fromXML_badDeltaFormat(self):
		g = TupleVariation({}, [])
		with CapturingLogHandler(log, "WARNING") as captor:
			for name, attrs, content in parseXML('<delta a="1" b="2"/>'):
				g.fromXML(name, attrs, content)
		self.assertIn("bad delta format: a, b",
		              [r.msg for r in captor.records])
开发者ID:anthrotype,项目名称:fonttools,代码行数:7,代码来源:TupleVariation_test.py

示例3: test_decompilePoints_roundTrip

	def test_decompilePoints_roundTrip(self):
		numPointsInGlyph = 500  # greater than 255, so we also exercise code path for 16-bit encoding
		compile = lambda points: TupleVariation.compilePoints(points, numPointsInGlyph)
		decompile = lambda data: set(TupleVariation.decompilePoints_(numPointsInGlyph, data, 0, "gvar")[0])
		for i in range(50):
			points = set(random.sample(range(numPointsInGlyph), 30))
			self.assertSetEqual(points, decompile(compile(points)),
					    "failed round-trip decompile/compilePoints; points=%s" % points)
		allPoints = set(range(numPointsInGlyph))
		self.assertSetEqual(allPoints, decompile(compile(allPoints)))
开发者ID:anthrotype,项目名称:fonttools,代码行数:10,代码来源:TupleVariation_test.py

示例4: test_toXML_allDeltasNone

	def test_toXML_allDeltasNone(self):
		writer = XMLWriter(BytesIO())
		axes = {"wght":(0.0, 1.0, 1.0)}
		g = TupleVariation(axes, [None] * 5)
		g.toXML(writer, ["wght", "wdth"])
		self.assertEqual([
			'<tuple>',
			  '<coord axis="wght" value="1.0"/>',
			  '<!-- no deltas -->',
			'</tuple>'
		], TupleVariationTest.xml_lines(writer))
开发者ID:anthrotype,项目名称:fonttools,代码行数:11,代码来源:TupleVariation_test.py

示例5: test_fromXML_points

	def test_fromXML_points(self):
		g = TupleVariation({}, [None] * 4)
		for name, attrs, content in parseXML(
				'<coord axis="wdth" min="0.3" value="0.4" max="0.5"/>'
				'<coord axis="wght" value="1.0"/>'
				'<coord axis="opsz" value="-0.7"/>'
				'<delta pt="1" x="33" y="44"/>'
				'<delta pt="2" x="-2" y="170"/>'):
			g.fromXML(name, attrs, content)
		self.assertEqual(AXES, g.axes)
		self.assertEqual([None, (33, 44), (-2, 170), None], g.coordinates)
开发者ID:anthrotype,项目名称:fonttools,代码行数:11,代码来源:TupleVariation_test.py

示例6: test_fromXML_constants

	def test_fromXML_constants(self):
		g = TupleVariation({}, [None] * 4)
		for name, attrs, content in parseXML(
				'<coord axis="wdth" min="0.3" value="0.4" max="0.5"/>'
				'<coord axis="wght" value="1.0"/>'
				'<coord axis="opsz" value="-0.7"/>'
				'<delta cvt="1" value="42"/>'
				'<delta cvt="2" value="-23"/>'):
			g.fromXML(name, attrs, content)
		self.assertEqual(AXES, g.axes)
		self.assertEqual([None, 42, -23, None], g.coordinates)
开发者ID:anthrotype,项目名称:fonttools,代码行数:11,代码来源:TupleVariation_test.py

示例7: test_compile_embeddedPeak_nonIntermediate_sharedConstants

	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))
开发者ID:anthrotype,项目名称:fonttools,代码行数:11,代码来源:TupleVariation_test.py

示例8: test_toXML_badDeltaFormat

	def test_toXML_badDeltaFormat(self):
		writer = XMLWriter(BytesIO())
		g = TupleVariation(AXES, ["String"])
		with CapturingLogHandler(log, "ERROR") as captor:
			g.toXML(writer, ["wdth"])
		self.assertIn("bad delta format", [r.msg for r in captor.records])
		self.assertEqual([
			'<tuple>',
			  '<coord axis="wdth" max="0.5" min="0.3" value="0.4"/>',
			  '<!-- bad delta #0 -->',
			'</tuple>',
		], TupleVariationTest.xml_lines(writer))
开发者ID:anthrotype,项目名称:fonttools,代码行数:12,代码来源:TupleVariation_test.py

示例9: fromXML

 def fromXML(self, name, attrs, content, ttFont):
     if name == "version":
         self.majorVersion = int(attrs.get("major", "1"))
         self.minorVersion = int(attrs.get("minor", "0"))
     elif name == "tuple":
         valueCount = len(ttFont["cvt "].values)
         var = TupleVariation({}, [None] * valueCount)
         self.variations.append(var)
         for tupleElement in content:
             if isinstance(tupleElement, tuple):
                 tupleName, tupleAttrs, tupleContent = tupleElement
                 var.fromXML(tupleName, tupleAttrs, tupleContent)
开发者ID:anthrotype,项目名称:fonttools,代码行数:12,代码来源:_c_v_a_r.py

示例10: test_compile_embeddedPeak_nonIntermediate_privateConstants

	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))
开发者ID:anthrotype,项目名称:fonttools,代码行数:12,代码来源:TupleVariation_test.py

示例11: _add_gvar

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)
开发者ID:robmck-ms,项目名称:fonttools,代码行数:53,代码来源:__init__.py

示例12: test_compile_embeddedPeak_nonIntermediate_sharedPoints

	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))
开发者ID:anthrotype,项目名称:fonttools,代码行数:12,代码来源:TupleVariation_test.py

示例13: test_compile_sharedPeaks_nonIntermediate_sharedPoints

	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))
开发者ID:anthrotype,项目名称:fonttools,代码行数:14,代码来源:TupleVariation_test.py

示例14: test_compile_sharedPeaks_intermediate_sharedPoints

	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))
开发者ID:anthrotype,项目名称:fonttools,代码行数:14,代码来源:TupleVariation_test.py

示例15: test_compile_embeddedPeak_intermediate_privateConstants

	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))
开发者ID:anthrotype,项目名称:fonttools,代码行数:15,代码来源:TupleVariation_test.py


注:本文中的fontTools.ttLib.tables.TupleVariation.TupleVariation类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。