本文整理汇总了Python中defcon.Font.save方法的典型用法代码示例。如果您正苦于以下问题:Python Font.save方法的具体用法?Python Font.save怎么用?Python Font.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类defcon.Font
的用法示例。
在下文中一共展示了Font.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: separate
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import save [as 别名]
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."
示例2: test_delitem
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import save [as 别名]
def test_delitem(self):
font = Font(makeTestFontCopy())
path = os.path.join(font.path, "glyphs.public.background")
self.assertTrue(os.path.exists(path))
layers = font.layers
del layers["public.background"]
layers.dirty = True
self.assertEqual(layers.layerOrder, ["public.default", "Layer 1"])
self.assertNotIn("public.background", layers)
self.assertEqual(len(layers), 2)
with self.assertRaisesRegex(KeyError, "public.background"):
layers["public.background"]
font.save()
path = os.path.join(font.path, "glyphs.public.background")
self.assertFalse(os.path.exists(path))
tearDownTestFontCopy()
font = Font(makeTestFontCopy())
path = os.path.join(font.path, "glyphs.public.background")
del font.layers["public.background"]
layer = font.newLayer("public.background")
layer.newGlyph("B")
font.save()
self.assertFalse(os.path.exists(os.path.join(path, "A_.glif")))
self.assertTrue(os.path.exists(os.path.join(path, "B_.glif")))
示例3: run
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import save [as 别名]
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"
示例4: test_delitem_glyph_dirty
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import save [as 别名]
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)
示例5: interpolate
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import save [as 别名]
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
示例6: injectOS2TableToUFO
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import save [as 别名]
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()
示例7: main
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import save [as 别名]
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)
示例8: test_rename_default_layer
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import save [as 别名]
def test_rename_default_layer(self):
# https://github.com/unified-font-object/ufoLib/issues/123
path = getTestFontCopyPath()
font = Font()
font.save(path)
font.layers.defaultLayer.name = "somethingElse"
font.save()
self.assertEqual(Font(path).layers.defaultLayer.name, "somethingElse")
示例9: injectKerningToUFO
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import save [as 别名]
def injectKerningToUFO(ufoPath, groups, kerning):
ufo = Font(ufoPath)
ufo.kerning.clear()
ufo.groups.clear()
print 'Injecting OTF groups and kerning into %s ...' % ufoPath
ufo.groups.update(groups)
ufo.kerning.update(kerning)
ufo.save()
示例10: test_save
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import save [as 别名]
def test_save(self):
path = makeTestFontCopy()
font = Font(path)
for glyph in font:
glyph.dirty = True
font.save()
fileNames = glob.glob(os.path.join(path, 'glyphs', '*.glif'))
fileNames = [os.path.basename(fileName) for fileName in fileNames]
self.assertEqual(sorted(fileNames), ["A_.glif", "B_.glif", "C_.glif"])
示例11: test_save_as
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import save [as 别名]
def test_save_as(self):
path = getTestFontPath()
font = Font(path)
saveAsPath = getTestFontCopyPath(path)
font.save(saveAsPath)
fileNames = glob.glob(os.path.join(saveAsPath, 'glyphs', '*.glif'))
fileNames = [os.path.basename(fileName) for fileName in fileNames]
self.assertEqual(sorted(fileNames), ["A_.glif", "B_.glif", "C_.glif"])
self.assertEqual(font.path, saveAsPath)
tearDownTestFontCopy(saveAsPath)
示例12: test_save_same_path_different_structure
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import save [as 别名]
def test_save_same_path_different_structure(self):
for ufo in ("TestFont.ufo", "TestFont.ufoz"):
path = getTestFontPath(ufo)
isZip = zipfile.is_zipfile(path)
font = Font(path)
with self.assertRaisesRegex(
DefconError,
"Can't save font in-place with a different structure"
):
font.save(path, structure="package" if isZip else "zip")
示例13: test_save_new_font_to_exsisting_directory
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import save [as 别名]
def test_save_new_font_to_exsisting_directory(self):
for ufo in ("TestFont.ufo", "TestFont.ufoz"):
path = makeTestFontCopy(getTestFontPath(ufo))
try:
self.assertTrue(os.path.exists(path))
font = Font()
font.save(path)
self.assertTrue(os.path.isdir(path))
finally:
tearDownTestFontCopy(path)
示例14: test_save_as
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import save [as 别名]
def test_save_as(self):
path = getTestFontPath()
font = Font(path)
saveAsPath = getTestFontCopyPath(path)
font.save(saveAsPath)
imagesDirectory = os.path.join(saveAsPath, "images")
self.assertTrue(os.path.exists(imagesDirectory))
imagePath = os.path.join(imagesDirectory, "image 1.png")
self.assertTrue(os.path.exists(imagePath))
imagePath = os.path.join(imagesDirectory, "image 2.png")
self.assertTrue(os.path.exists(imagePath))
tearDownTestFontCopy(saveAsPath)
示例15: test_unreferenced_images
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import save [as 别名]
def test_unreferenced_images(self):
path = getTestFontPath()
font = Font(path)
self.assertEqual(font.images.unreferencedFileNames, ["image 2.png"])
path = makeTestFontCopy()
font = Font(path)
font.save(removeUnreferencedImages=True)
p = os.path.join(path, "images", "image 1.png")
self.assertTrue(os.path.exists(p))
p = os.path.join(path, "images", "image 2.png")
self.assertFalse(os.path.exists(p))
tearDownTestFontCopy()