本文整理匯總了Python中fontTools.ttLib.tables._f_v_a_r.NamedInstance.postscriptNameID方法的典型用法代碼示例。如果您正苦於以下問題:Python NamedInstance.postscriptNameID方法的具體用法?Python NamedInstance.postscriptNameID怎麽用?Python NamedInstance.postscriptNameID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類fontTools.ttLib.tables._f_v_a_r.NamedInstance
的用法示例。
在下文中一共展示了NamedInstance.postscriptNameID方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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 postscriptNameID [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))
示例2: _add_fvar
# 需要導入模塊: from fontTools.ttLib.tables._f_v_a_r import NamedInstance [as 別名]
# 或者: from fontTools.ttLib.tables._f_v_a_r.NamedInstance import postscriptNameID [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
示例3: _add_fvar
# 需要導入模塊: from fontTools.ttLib.tables._f_v_a_r import NamedInstance [as 別名]
# 或者: from fontTools.ttLib.tables._f_v_a_r.NamedInstance import postscriptNameID [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
示例4: test_toXML_withPostScriptName
# 需要導入模塊: from fontTools.ttLib.tables._f_v_a_r import NamedInstance [as 別名]
# 或者: from fontTools.ttLib.tables._f_v_a_r.NamedInstance import postscriptNameID [as 別名]
def test_toXML_withPostScriptName(self):
font = MakeFont()
inst = NamedInstance()
inst.subfamilyNameID = AddName(font, "Light Condensed").nameID
inst.postscriptNameID = AddName(font, "Test-LightCondensed").nameID
inst.coordinates = {"wght": 0.7, "wdth": 0.5}
writer = XMLWriter(BytesIO())
inst.toXML(writer, font)
self.assertEqual([
'',
'<!-- Light Condensed -->',
'<!-- PostScript: Test-LightCondensed -->',
'<NamedInstance postscriptNameID="%s" subfamilyNameID="%s">' % (
inst.postscriptNameID, inst.subfamilyNameID),
'<coord axis="wght" value="0.7"/>',
'<coord axis="wdth" value="0.5"/>',
'</NamedInstance>'
], xml_lines(writer))
示例5: _add_fvar_avar
# 需要導入模塊: from fontTools.ttLib.tables._f_v_a_r import NamedInstance [as 別名]
# 或者: from fontTools.ttLib.tables._f_v_a_r.NamedInstance import postscriptNameID [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