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


Python NamedInstance.coordinates方法代码示例

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


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

示例1: test_compile_withoutPostScriptName

# 需要导入模块: from fontTools.ttLib.tables._f_v_a_r import NamedInstance [as 别名]
# 或者: from fontTools.ttLib.tables._f_v_a_r.NamedInstance import coordinates [as 别名]
 def test_compile_withoutPostScriptName(self):
     inst = NamedInstance()
     inst.subfamilyNameID = 345
     inst.postscriptNameID = 564
     inst.coordinates = {"wght": 0.7, "wdth": 0.5}
     self.assertEqual(FVAR_INSTANCE_DATA_WITHOUT_PSNAME,
                      inst.compile(["wght", "wdth"], False))
开发者ID:wenzhuman,项目名称:fonttools,代码行数:9,代码来源:_f_v_a_r_test.py

示例2: _add_fvar

# 需要导入模块: from fontTools.ttLib.tables._f_v_a_r import NamedInstance [as 别名]
# 或者: from fontTools.ttLib.tables._f_v_a_r.NamedInstance import coordinates [as 别名]
def _add_fvar(font, axes, instances):
	"""
	Add 'fvar' table to font.

	axes is an ordered dictionary of DesignspaceAxis objects.

	instances is list of dictionary objects with 'location', 'stylename',
	and possibly 'postscriptfontname' entries.
	"""

	assert axes
	assert isinstance(axes, OrderedDict)

	log.info("Generating fvar")

	fvar = newTable('fvar')
	nameTable = font['name']

	for a in axes.values():
		axis = Axis()
		axis.axisTag = Tag(a.tag)
		# TODO Skip axes that have no variation.
		axis.minValue, axis.defaultValue, axis.maxValue = a.minimum, a.default, a.maximum
		axis.axisNameID = nameTable.addMultilingualName(a.labelNames, font)
		axis.flags = int(a.hidden)
		fvar.axes.append(axis)

	for instance in instances:
		coordinates = instance.location

		if "en" not in instance.localisedStyleName:
			assert instance.styleName
			localisedStyleName = dict(instance.localisedStyleName)
			localisedStyleName["en"] = tounicode(instance.styleName)
		else:
			localisedStyleName = instance.localisedStyleName

		psname = instance.postScriptFontName

		inst = NamedInstance()
		inst.subfamilyNameID = nameTable.addMultilingualName(localisedStyleName)
		if psname is not None:
			psname = tounicode(psname)
			inst.postscriptNameID = nameTable.addName(psname)
		inst.coordinates = {axes[k].tag:axes[k].map_backward(v) for k,v in coordinates.items()}
		#inst.coordinates = {axes[k].tag:v for k,v in coordinates.items()}
		fvar.instances.append(inst)

	assert "fvar" not in font
	font['fvar'] = fvar

	return fvar
开发者ID:khaledhosny,项目名称:fonttools,代码行数:54,代码来源:__init__.py

示例3: _add_fvar

# 需要导入模块: from fontTools.ttLib.tables._f_v_a_r import NamedInstance [as 别名]
# 或者: from fontTools.ttLib.tables._f_v_a_r.NamedInstance import coordinates [as 别名]
def _add_fvar(font, axes, instances):
	"""
	Add 'fvar' table to font.

	axes is an ordered dictionary of DesignspaceAxis objects.

	instances is list of dictionary objects with 'location', 'stylename',
	and possibly 'postscriptfontname' entries.
	"""

	assert axes
	assert isinstance(axes, OrderedDict)

	log.info("Generating fvar")

	fvar = newTable('fvar')
	nameTable = font['name']

	for a in axes.values():
		axis = Axis()
		axis.axisTag = Tag(a.tag)
		# TODO Skip axes that have no variation.
		axis.minValue, axis.defaultValue, axis.maxValue = a.minimum, a.default, a.maximum
		axis.axisNameID = nameTable.addName(tounicode(a.labelNames['en']))
		# TODO:
		# Replace previous line with the following when the following issues are resolved:
		# https://github.com/fonttools/fonttools/issues/930
		# https://github.com/fonttools/fonttools/issues/931
		# axis.axisNameID = nameTable.addMultilingualName(a.labelname, font)
		fvar.axes.append(axis)

	for instance in instances:
		coordinates = instance.location
		name = tounicode(instance.styleName)
		psname = instance.postScriptFontName

		inst = NamedInstance()
		inst.subfamilyNameID = nameTable.addName(name)
		if psname is not None:
			psname = tounicode(psname)
			inst.postscriptNameID = nameTable.addName(psname)
		inst.coordinates = {axes[k].tag:axes[k].map_backward(v) for k,v in coordinates.items()}
		#inst.coordinates = {axes[k].tag:v for k,v in coordinates.items()}
		fvar.instances.append(inst)

	assert "fvar" not in font
	font['fvar'] = fvar

	return fvar
开发者ID:robmck-ms,项目名称:fonttools,代码行数:51,代码来源:__init__.py

示例4: test_toXML

# 需要导入模块: from fontTools.ttLib.tables._f_v_a_r import NamedInstance [as 别名]
# 或者: from fontTools.ttLib.tables._f_v_a_r.NamedInstance import coordinates [as 别名]
 def test_toXML(self):
     font = MakeFont()
     inst = NamedInstance()
     inst.nameID = AddName(font, "Light Condensed").nameID
     inst.coordinates = {"wght": 0.7, "wdth": 0.5}
     writer = XMLWriter(StringIO())
     inst.toXML(writer, font)
     self.assertEqual([
         '',
         '<!-- Light Condensed -->',
         '<NamedInstance nameID="%s">' % inst.nameID,
           '<coord axis="wght" value="0.7"/>',
           '<coord axis="wdth" value="0.5"/>',
         '</NamedInstance>'
     ], xml_lines(writer))
开发者ID:quminzi,项目名称:fonttools,代码行数:17,代码来源:_f_v_a_r_test.py

示例5: _add_fvar

# 需要导入模块: from fontTools.ttLib.tables._f_v_a_r import NamedInstance [as 别名]
# 或者: from fontTools.ttLib.tables._f_v_a_r.NamedInstance import coordinates [as 别名]
def _add_fvar(font, axes, instances):
	assert "fvar" not in font
	font['fvar'] = fvar = table__f_v_a_r()

	for tag in sorted(axes.keys()):
		axis = Axis()
		axis.axisTag = tag
		name, axis.minValue, axis.defaultValue, axis.maxValue = axes[tag]
		axis.nameID = _AddName(font, name).nameID
		fvar.axes.append(axis)

	for name, coordinates in instances:
		inst = NamedInstance()
		inst.nameID = _AddName(font, name).nameID
		inst.coordinates = coordinates
		fvar.instances.append(inst)
开发者ID:n8willis,项目名称:fonttools,代码行数:18,代码来源:__init__.py

示例6: test_toXML_withoutPostScriptName

# 需要导入模块: from fontTools.ttLib.tables._f_v_a_r import NamedInstance [as 别名]
# 或者: from fontTools.ttLib.tables._f_v_a_r.NamedInstance import coordinates [as 别名]
 def test_toXML_withoutPostScriptName(self):
     font = MakeFont()
     inst = NamedInstance()
     inst.flags = 0xABC
     inst.subfamilyNameID = AddName(font, "Light Condensed").nameID
     inst.coordinates = {"wght": 0.7, "wdth": 0.5}
     writer = XMLWriter(BytesIO())
     inst.toXML(writer, font)
     self.assertEqual([
         '',
         '<!-- Light Condensed -->',
         '<NamedInstance flags="0xABC" subfamilyNameID="%s">' %
             inst.subfamilyNameID,
           '<coord axis="wght" value="0.7"/>',
           '<coord axis="wdth" value="0.5"/>',
         '</NamedInstance>'
     ], xml_lines(writer))
开发者ID:MrBrezina,项目名称:fonttools,代码行数:19,代码来源:_f_v_a_r_test.py

示例7: MakeFont

# 需要导入模块: from fontTools.ttLib.tables._f_v_a_r import NamedInstance [as 别名]
# 或者: from fontTools.ttLib.tables._f_v_a_r.NamedInstance import coordinates [as 别名]
def MakeFont():
    axes = [("wght", "Weight", 100, 400, 900), ("wdth", "Width", 50, 100, 200)]
    instances = [("Light", 300, 100), ("Light Condensed", 300, 75)]
    fvarTable = table__f_v_a_r()
    font = {"fvar": fvarTable}
    for tag, name, minValue, defaultValue, maxValue in axes:
        axis = Axis()
        axis.axisTag = tag
        axis.defaultValue = defaultValue
        axis.minValue, axis.maxValue = minValue, maxValue
        axis.nameID = AddName(font, name).nameID
        fvarTable.axes.append(axis)
    for name, weight, width in instances:
        inst = NamedInstance()
        inst.nameID = AddName(font, name).nameID
        inst.coordinates = {"wght": weight, "wdth": width}
        fvarTable.instances.append(inst)
    return font
开发者ID:quminzi,项目名称:fonttools,代码行数:20,代码来源:_f_v_a_r_test.py

示例8: AddFontVariations

# 需要导入模块: from fontTools.ttLib.tables._f_v_a_r import NamedInstance [as 别名]
# 或者: from fontTools.ttLib.tables._f_v_a_r.NamedInstance import coordinates [as 别名]
def AddFontVariations(font):
    assert "fvar" not in font
    fvar = font["fvar"] = table__f_v_a_r()

    weight = Axis()
    weight.axisTag = "wght"
    weight.nameID = AddName(font, "Weight").nameID
    weight.minValue, weight.defaultValue, weight.maxValue = (100, 400, 900)
    fvar.axes.append(weight)

    # https://www.microsoft.com/typography/otspec/os2.htm#wtc
    for name, wght in (
            ("Thin", 100),
            ("Light", 300),
            ("Regular", 400),
            ("Bold", 700),
            ("Black", 900)):
        inst = NamedInstance()
        inst.nameID = AddName(font, name).nameID
        inst.coordinates = {"wght": wght}
        fvar.instances.append(inst)
开发者ID:Moscarda,项目名称:fonttools,代码行数:23,代码来源:interpolate.py

示例9: test_compile

# 需要导入模块: from fontTools.ttLib.tables._f_v_a_r import NamedInstance [as 别名]
# 或者: from fontTools.ttLib.tables._f_v_a_r.NamedInstance import coordinates [as 别名]
 def test_compile(self):
     inst = NamedInstance()
     inst.nameID = 345
     inst.coordinates = {"wght": 0.7, "wdth": 0.5}
     self.assertEqual(FVAR_INSTANCE_DATA, inst.compile(["wght", "wdth"]))
开发者ID:quminzi,项目名称:fonttools,代码行数:7,代码来源:_f_v_a_r_test.py

示例10: _add_fvar_avar

# 需要导入模块: from fontTools.ttLib.tables._f_v_a_r import NamedInstance [as 别名]
# 或者: from fontTools.ttLib.tables._f_v_a_r.NamedInstance import coordinates [as 别名]
def _add_fvar_avar(font, axes, instances):
	"""
	Add 'fvar' table to font.

	axes is an ordered dictionary of DesignspaceAxis objects.

	instances is list of dictionary objects with 'location', 'stylename',
	and possibly 'postscriptfontname' entries.
	"""

	assert axes
	assert isinstance(axes, OrderedDict)

	log.info("Generating fvar / avar")

	fvar = newTable('fvar')
	nameTable = font['name']

	for a in axes.values():
		axis = Axis()
		axis.axisTag = Tag(a.tag)
		axis.minValue, axis.defaultValue, axis.maxValue = a.minimum, a.default, a.maximum
		axis.axisNameID = nameTable.addName(tounicode(a.labelname['en']))
		# TODO:
		# Replace previous line with the following when the following issues are resolved:
		# https://github.com/fonttools/fonttools/issues/930
		# https://github.com/fonttools/fonttools/issues/931
		# axis.axisNameID = nameTable.addMultilingualName(a.labelname, font)
		fvar.axes.append(axis)

	for instance in instances:
		coordinates = instance['location']
		name = tounicode(instance['stylename'])
		psname = instance.get('postscriptfontname')

		inst = NamedInstance()
		inst.subfamilyNameID = nameTable.addName(name)
		if psname is not None:
			psname = tounicode(psname)
			inst.postscriptNameID = nameTable.addName(psname)
		inst.coordinates = {axes[k].tag:axes[k].map_backward(v) for k,v in coordinates.items()}
		fvar.instances.append(inst)

	avar = newTable('avar')
	interesting = False
	for axis in axes.values():
		curve = avar.segments[axis.tag] = {}
		if not axis.map or all(k==v for k,v in axis.map.items()):
			continue
		interesting = True

		items = sorted(axis.map.items())
		keys   = [item[0] for item in items]
		vals = [item[1] for item in items]

		# Current avar requirements.  We don't have to enforce
		# these on the designer and can deduce some ourselves,
		# but for now just enforce them.
		assert axis.minimum == min(keys)
		assert axis.maximum == max(keys)
		assert axis.default in keys
		# No duplicates
		assert len(set(keys)) == len(keys)
		assert len(set(vals)) == len(vals)
		# Ascending values
		assert sorted(vals) == vals

		keys_triple = (axis.minimum, axis.default, axis.maximum)
		vals_triple = tuple(axis.map_forward(v) for v in keys_triple)

		keys = [models.normalizeValue(v, keys_triple) for v in keys]
		vals = [models.normalizeValue(v, vals_triple) for v in vals]
		curve.update(zip(keys, vals))

	if not interesting:
		log.info("No need for avar")
		avar = None

	assert "fvar" not in font
	font['fvar'] = fvar
	assert "avar" not in font
	if avar:
		font['avar'] = avar

	return fvar,avar
开发者ID:anthrotype,项目名称:fonttools,代码行数:87,代码来源:__init__.py


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