本文整理汇总了Python中defcon.Font类的典型用法代码示例。如果您正苦于以下问题:Python Font类的具体用法?Python Font怎么用?Python Font使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Font类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_guidelineIndex
def test_guidelineIndex(self):
font = Font(getTestFontPath())
guideline1 = Guideline(guidelineDict={"x": 100})
guideline2 = Guideline(guidelineDict={"y": 200})
font.guidelines = [guideline1, guideline2]
self.assertEqual(font.guidelineIndex(guideline1), 0)
self.assertEqual(font.guidelineIndex(guideline2), 1)
示例2: test_glyph_dispatcher_inserted
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: interpolate
def interpolate(ufos, master_dir, out_dir, instance_data, debug=False):
"""Create MutatorMath designspace and generate instances.
Returns instance UFOs, or unused instance data if debug is True.
"""
from defcon import Font
from mutatorMath.ufo import build
designspace_path, instance_files = build_designspace(
ufos, master_dir, out_dir, instance_data)
print('>>> Building instances')
for path, _ in instance_files:
clean_ufo(path)
build(designspace_path, outputUFOFormatVersion=3)
instance_ufos = []
for path, data in instance_files:
ufo = Font(path)
set_custom_params(ufo, data=data)
set_redundant_data(ufo)
ufo.save()
instance_ufos.append(ufo)
if debug:
return clear_data(instance_data)
return instance_ufos
示例4: test_insertGlyph
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"])
示例5: separate
def separate(fontPath, unicodeScript, DELETE=False):
""" Takes a font and removes any kerning that isn't either a group kern or
a kern with a glyph from the specified unicode script category. See
http://www.unicode.org/Public/6.1.0/ucd/Scripts.txt for a list of possible
values for the script.
By default the script will not actually delete anything, but will list what
it would delete. Set DELETE to True if you want the script to delete pairs.
If DELETE is set to True, the input UFO will be modified, use with caution.
"""
font = Font(fontPath)
for pair, value in sorted(font.kerning.items()):
if pair[0].startswith("@") or pair[1].startswith("@"):
pass
elif font.unicodeData.scriptForGlyphName(pair[0]) != unicodeScript and font.unicodeData.scriptForGlyphName(pair[1]) != unicodeScript:
if DELETE:
print str(pair) + " deleted"
del font.kerning[pair]
else:
print str(pair) + " would be deleted"
if DELETE:
font.save()
print "Saved UFO."
示例6: test_removeGuideline
def test_removeGuideline(self):
font = Font(getTestFontPath())
guideline1 = Guideline(guidelineDict={"x": 100})
guideline2 = Guideline(guidelineDict={"y": 200})
font.guidelines = [guideline1, guideline2]
font.removeGuideline(guideline1)
self.assertEqual(font.guidelines, [guideline2])
示例7: test_updateGlyphOrder_remove
def test_updateGlyphOrder_remove(self):
font = Font(getTestFontPath())
self.assertEqual(font.glyphOrder, [])
font.glyphOrder = ["test"]
self.assertEqual(font.glyphOrder, ["test"])
font.updateGlyphOrder(removedGlyph="test")
self.assertEqual(font.glyphOrder, [])
示例8: test_updateGlyphOrder_rename
def test_updateGlyphOrder_rename(self):
font = Font(getTestFontPath())
self.assertEqual(font.glyphOrder, [])
font.glyphOrder = sorted(font.keys())
self.assertEqual(font.glyphOrder, ["A", "B", "C"])
font.updateGlyphOrder(addedGlyph="new", removedGlyph="B")
self.assertEqual(font.glyphOrder, ["A", "new", "C"])
示例9: compileDecompileCompareDumps
def compileDecompileCompareDumps(features, expectedDump):
# make the font
font = Font()
font.info.unitsPerEm = 1000
font.info.ascender = 750
font.info.descender = -250
font.info.xHeight = 500
font.info.capHeight = 750
font.info.familyName = "Test"
font.info.styleName = "Regular"
glyphNames = [i for i in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
for glyphName in glyphNames:
font.newGlyph(glyphName)
glyph = font[glyphName]
glyph.unicode = AGL2UV.get(glyphName)
font.features.text = features
# compile to OTF
handle, path = tempfile.mkstemp()
compiler = OTFCompiler()
errors = compiler.compile(font, path)["makeotf"]
# extract the features
try:
tables = decompileBinaryToObject(path, compress=True)
# print compiler errors
except TTLibError:
print errors
# get rid of the temp file
finally:
os.remove(path)
# dump
writer = DumpWriter()
tables["GSUB"].write(writer)
dump = writer.dump()
# compare
compareDumps(expectedDump, dump)
示例10: run
def run():
(options, args) = parseOptions()
if len(args) >= 1:
if os.path.exists(args[0]) and os.path.exists(options.inpath):
ufoPath = args[0]
else:
print "File does not exist."
# main business
try:
with open(options.inpath, "r") as groupsfile:
groups = eval(groupsfile.read())
font = Font(ufoPath)
for name, content in groups.items():
if name not in font.groups:
font.groups[name] = content
else:
for g in content:
if g not in font.groups[name]:
font.groups[name].append(g)
font.save()
except:
print "Errors during processing."
else:
print "Add -h for help"
示例11: injectOS2TableToUFO
def injectOS2TableToUFO(otfPath, ufoPath):
otfFont = ttLib.TTFont(otfPath)
os2Table = otfFont['OS/2']
ufo = Font(ufoPath)
print 'Injecting OS/2 table into %s ...' % ufoPath
ufo.info.ascender = os2Table.sTypoAscender
ufo.info.capHeight = os2Table.sCapHeight
ufo.info.descender = os2Table.sTypoDescender
ufo.info.xHeight = os2Table.sxHeight
ufo.info.openTypeOS2VendorID = os2Table.achVendID
ufo.info.openTypeOS2TypoAscender = os2Table.sTypoAscender
ufo.info.openTypeOS2TypoDescender = os2Table.sTypoDescender
ufo.info.openTypeOS2TypoLineGap = os2Table.sTypoLineGap
ufo.info.openTypeOS2StrikeoutPosition = os2Table.yStrikeoutPosition
ufo.info.openTypeOS2StrikeoutSize = os2Table.yStrikeoutSize
ufo.info.openTypeOS2SubscriptXOffset = os2Table.ySubscriptXOffset
ufo.info.openTypeOS2SubscriptXSize = os2Table.ySubscriptXSize
ufo.info.openTypeOS2SubscriptYOffset = os2Table.ySubscriptYOffset
ufo.info.openTypeOS2SubscriptYSize = os2Table.ySubscriptYSize
ufo.info.openTypeOS2SuperscriptXOffset = os2Table.ySuperscriptXOffset
ufo.info.openTypeOS2SuperscriptXSize = os2Table.ySuperscriptXSize
ufo.info.openTypeOS2SuperscriptYOffset = os2Table.ySuperscriptYOffset
ufo.info.openTypeOS2SuperscriptYSize = os2Table.ySuperscriptYSize
ufo.save()
示例12: main
def main():
parser = argparse.ArgumentParser(description="Build Mada slanted fonts.")
parser.add_argument("file", metavar="FILE", help="input font to process")
parser.add_argument("outfile", metavar="FILE", help="output font to write")
parser.add_argument("angle", metavar="FILE", help="slant angle", type=float)
args = parser.parse_args()
matrix = Identity.skew(math.radians(-args.angle))
font = Font(args.file)
info = font.info
if args.angle < 0:
style = "Italic"
else:
style = "Slanted"
info.styleName += " " + style
info.italicAngle = info.postscriptSlantAngle = args.angle
for glyph in font:
for contour in glyph:
for point in contour:
point.x, point.y = matrix.transformPoint((point.x, point.y))
for anchor in glyph.anchors:
anchor.x, anchor.y = matrix.transformPoint((anchor.x, anchor.y))
font.save(args.outfile)
示例13: test_glyph_dispatcher_new
def test_glyph_dispatcher_new(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]
self.assertEqual(contour.getParent(), glyph)
self.assertEqual(contour.dispatcher, font.dispatcher)
component = Component()
glyph.appendComponent(component)
self.assertEqual(component.getParent(), glyph)
self.assertEqual(component.dispatcher, font.dispatcher)
anchor = Anchor()
glyph.appendAnchor(anchor)
self.assertEqual(anchor.getParent(), glyph)
self.assertEqual(anchor.dispatcher, font.dispatcher)
guideline = Guideline()
glyph.appendGuideline(guideline)
self.assertEqual(guideline.getParent(), glyph)
self.assertEqual(guideline.dispatcher, font.dispatcher)
示例14: test_delitem_glyph_dirty
def test_delitem_glyph_dirty(self):
for ufo in (u"TestExternalEditing.ufo", u"TestExternalEditing.ufoz"):
path = getTestFontPath(ufo)
path = makeTestFontCopy(path)
font = Font(path)
glyph = font["A"]
glyph.dirty = True
fileSystem = openTestFontAsFileSystem(path)
glyphPath = fs.path.join("glyphs", "A_.glif")
fileSystem.remove(glyphPath)
contentsPath = fs.path.join("glyphs", "contents.plist")
with fileSystem.open(contentsPath, "rb") as f:
plist = load(f)
del plist["A"]
with fileSystem.open(contentsPath, "wb") as f:
dump(plist, f)
closeTestFontAsFileSystem(fileSystem, path)
r = font.testForExternalChanges()
self.assertEqual(r["deletedGlyphs"], ["A"])
del font["A"]
font.save()
fileSystem = openTestFontAsFileSystem(path)
self.assertFalse(fileSystem.exists(glyphPath))
closeTestFontAsFileSystem(fileSystem, path)
tearDownTestFontCopy(font.path)
示例15: test_newGlyph
def test_newGlyph(self):
font = Font(getTestFontPath())
glyph = font.newGlyph("NewGlyphTest")
self.assertEqual(glyph.name, "NewGlyphTest")
self.assertTrue(glyph.dirty)
self.assertTrue(font.dirty)
self.assertEqual(sorted(font.keys()), ["A", "B", "C", "NewGlyphTest"])