本文整理汇总了Python中defcon.Font.kerning[kern]方法的典型用法代码示例。如果您正苦于以下问题:Python Font.kerning[kern]方法的具体用法?Python Font.kerning[kern]怎么用?Python Font.kerning[kern]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类defcon.Font
的用法示例。
在下文中一共展示了Font.kerning[kern]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: merge
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import kerning[kern] [as 别名]
def merge(args):
"""Merges Arabic and Latin fonts together, and messages the combined font a
bit. Returns the combined font."""
ufo = Font(args.arabicfile)
latin = Font(args.latinfile)
# Parse the GlyphOrderAndAliasDB file for Unicode values and production
# glyph names of the Latin glyphs.
goadb = GOADBParser(os.path.dirname(args.latinfile) + "/../GlyphOrderAndAliasDB")
ufo.lib[POSTSCRIPT_NAMES] = {}
# Generate production glyph names for Arabic glyphs, in case it differs
# from working names. This will be used by ufo2ft to set the final glyph
# names in the font file.
for glyph in ufo:
if glyph.unicode is not None:
if glyph.unicode < 0xffff:
postName = "uni%04X" % glyph.unicode
else:
postName = "u%06X" % glyph.unicode
if postName != glyph.name:
ufo.lib[POSTSCRIPT_NAMES][glyph.name] = postName
# Populate the font’s feature text, we keep our main feature file out of
# the UFO to share it between the fonts.
features = ufo.features
with open(args.feature_file) as feafile:
fea = feafile.read()
# Set Latin language system, ufo2ft will use it when generating kern
# feature.
features.text += fea.replace("#{languagesystems}", "languagesystem latn dflt;")
features.text += generateStyleSets(ufo)
for glyph in latin:
if glyph.name in goadb.encodings:
uni = goadb.encodings[glyph.name]
# Source Sans Pro has different advance widths for space and NBSP
# glyphs, so we drop the later, and map both Unicode characters to
# the space glyph.
if uni == 0x00A0: # NBSP
continue
glyph.unicode = uni
if uni == 0x0020: # space
glyph.unicodes = glyph.unicodes + [0x00A0]
glyphs, components = collectGlyphs(latin, args.latin_subset)
counter = Counter(components)
uniqueComponents = set()
for name in counter:
if name not in glyphs:
latin[name].unicode = None
if counter[name] == 1:
uniqueComponents.add(name)
else:
glyphs.add(name)
# Set Latin production names
ufo.lib[POSTSCRIPT_NAMES].update(goadb.names)
# Copy Latin glyphs.
for name in glyphs:
glyph = latin[name]
for component in glyph.components:
if component.baseGlyph in uniqueComponents:
glyph.decomposeComponent(component)
# Remove anchors from spacing marks, otherwise ufo2ft will give them
# mark glyph class which will cause HarfBuzz to zero their width.
if glyph.unicode and unicodedata.category(unichr(glyph.unicode)) in ("Sk", "Lm"):
for anchor in glyph.anchors:
glyph.removeAnchor(anchor)
# Add Arabic anchors to the dotted circle, we use an offset of 100
# units because the Latin anchors are too close to the glyph.
offset = 100
if glyph.unicode == 0x25CC:
for anchor in glyph.anchors:
if anchor.name == "aboveLC":
glyph.appendAnchor(dict(name="markAbove", x=anchor.x, y=anchor.y + offset))
glyph.appendAnchor(dict(name="hamzaAbove", x=anchor.x, y=anchor.y + offset))
if anchor.name == "belowLC":
glyph.appendAnchor(dict(name="markBelow", x=anchor.x, y=anchor.y - offset))
glyph.appendAnchor(dict(name="hamzaBelow", x=anchor.x, y=anchor.y - offset))
# Break loudly if we have duplicated glyph in Latin and Arabic.
# TODO should check duplicated Unicode values as well
assert glyph.name not in ufo, glyph.name
ufo.insertGlyph(glyph)
# Copy kerning and groups.
for group in latin.groups:
ufo.groups[group] = latin.groups[group]
for kern in latin.kerning:
ufo.kerning[kern] = latin.kerning[kern]
# We don’t set these in the Arabic font, so we just copy the Latin’s.
for attr in ("xHeight", "capHeight"):
value = getattr(latin.info, attr)
if value is not None:
setattr(ufo.info, attr, getattr(latin.info, attr))
#.........这里部分代码省略.........