本文整理汇总了Python中defcon.Font.insertGlyph方法的典型用法代码示例。如果您正苦于以下问题:Python Font.insertGlyph方法的具体用法?Python Font.insertGlyph怎么用?Python Font.insertGlyph使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类defcon.Font
的用法示例。
在下文中一共展示了Font.insertGlyph方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_insertGlyph
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import insertGlyph [as 别名]
def test_insertGlyph(self):
font = Font(getTestFontPath())
glyph = Glyph()
glyph.name = "NewGlyphTest"
self.assertEqual(sorted(font.keys()), ["A", "B", "C"])
font.insertGlyph(glyph)
self.assertEqual(sorted(font.keys()), ["A", "B", "C", "NewGlyphTest"])
示例2: test_glyph_dispatcher_inserted
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import insertGlyph [as 别名]
def test_glyph_dispatcher_inserted(self):
font = Font()
font.newGlyph("A")
glyph = font["A"]
pen = glyph.getPointPen()
pen.beginPath()
pen.addPoint((0, 0), segmentType="line")
pen.addPoint((0, 100), segmentType="line")
pen.addPoint((100, 100), segmentType="line")
pen.addPoint((100, 0), segmentType="line")
pen.endPath()
contour = glyph[0]
component = Component()
glyph.appendComponent(component)
anchor = Anchor()
glyph.appendAnchor(anchor)
guideline = Guideline()
glyph.appendGuideline(guideline)
sourceGlyph = glyph
newFont = Font()
insertedGlyph = newFont.insertGlyph(sourceGlyph)
contour = insertedGlyph[0]
self.assertTrue(contour.getParent(), insertedGlyph)
self.assertTrue(contour.dispatcher, newFont.dispatcher)
component = insertedGlyph.components[0]
self.assertTrue(component.getParent(), insertedGlyph)
self.assertTrue(component.dispatcher, newFont.dispatcher)
anchor = insertedGlyph.anchors[0]
self.assertTrue(anchor.getParent(), insertedGlyph)
self.assertTrue(anchor.dispatcher, newFont.dispatcher)
guideline = insertedGlyph.guidelines[0]
self.assertTrue(guideline.getParent(), insertedGlyph)
self.assertTrue(guideline.dispatcher, newFont.dispatcher)
示例3: combineGlyphs
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import insertGlyph [as 别名]
def combineGlyphs(path1, path2, destPath):
"""
Combines the glyphs of two UFOs and saves result to a new ufo.
This only combines glyphs, so the first UFO path should be the one
that you want all the metadata from.
"""
ufo1 = Font(path1)
ufo2 = Font(path2)
added_glyphs = []
for glyph in ufo2:
if glyph.name not in ufo1:
print "Inserting %s" % glyph.name
ufo1.insertGlyph(glyph)
added_glyphs.append(glyph.name)
ufo1.save(destPath)
示例4: OrderedDict
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import insertGlyph [as 别名]
scripts[script].append(lang)
return OrderedDict((script, tuple(langs)) for script,langs in scripts.items())
if __name__ == '__main__':
from defcon import Font
font = Font(path=sys.argv[2])
for mergePath in sys.argv[3:]:
merge = Font(path=mergePath)
# merge glyphs
for name in merge.keys():
glyph = merge[name]
# had an error related to anchors, but I don't need anchors here
glyph.anchors = []
font.insertGlyph(glyph, name=name)
# merge groups
font.groups.update(merge.groups)
# merge kerning
font.kerning.update(merge.kerning)
# scripts = {'arab': ('dflt', 'ARA ', 'URD ', 'FAR '), 'latn': ('dflt', 'TRK ')}
# scripts = scriptsFromFea(sys.argv[1])
# scripts = {'arab': ('dflt', ), 'latn': ('dflt', )}
scripts = {
'arab': ('dflt', 'ARA ', 'URD ', 'FAR ')
, 'latn': ('dflt', 'AZE', 'CRT', 'KAZ', 'MOL', 'ROM', 'TAT', 'TRK' )
}
示例5: merge
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import insertGlyph [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))
#.........这里部分代码省略.........
示例6: merge
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import insertGlyph [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)
to_ufo_propagate_font_anchors(None, ufo)
latin = Font(args.latinfile)
ufo.lib[POSTSCRIPT_NAMES] = {}
# Save original glyph order, used below.
glyphOrder = ufo.glyphOrder + latin.glyphOrder
# 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
# Merge Arabic and Latin features, making sure languagesystem statements
# come first.
features = ufo.features
langsys = []
statements = []
for font in (ufo, latin):
featurefile = os.path.join(font.path, "features.fea")
fea = parser.Parser(featurefile, font.glyphOrder).parse()
langsys += [s for s in fea.statements if isinstance(s, ast.LanguageSystemStatement)]
statements += [s for s in fea.statements if not isinstance(s, ast.LanguageSystemStatement)]
# We will regenerate kern, mark and mkmk features, and aalt is useless.
statements = [s for s in statements if getattr(s, "name", None) not in ("aalt", "kern", "mark", "mkmk")]
# These will be regenerated as well
statements = [s for s in statements if not isinstance(s, ast.MarkClassDefinition)]
# Drop tables in fea, we don’t want them.
statements = [s for s in statements if not isinstance(s, ast.TableBlock)]
# Make sure DFLT is the first.
langsys = sorted(langsys, key=attrgetter("script"))
fea.statements = langsys + statements
features.text = fea.asFea()
features.text += generateStyleSets(ufo)
# Source Sans Pro has different advance widths for space and NBSP
# glyphs, fix it.
latin["nbspace"].width = latin["space"].width
# Set Latin production names
ufo.lib[POSTSCRIPT_NAMES].update(latin.lib[POSTSCRIPT_NAMES])
# Copy Latin glyphs.
for name in latin.glyphOrder:
glyph = latin[name]
# 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.
ufo.groups.update(latin.groups)
ufo.kerning.update(latin.kerning)
# 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))
# Make sure we don’t have glyphs with the same unicode value
unicodes = []
for glyph in ufo:
unicodes.extend(glyph.unicodes)
duplicates = set([u for u in unicodes if unicodes.count(u) > 1])
assert len(duplicates) == 0, "Duplicate unicodes: %s " % (["%04X" % d for d in duplicates])
# Make sure we have a fixed glyph order by using the original Arabic and
# Latin glyph order, not whatever we end up with after adding glyphs.
#.........这里部分代码省略.........