本文整理汇总了Python中defcon.Font.testForExternalChanges方法的典型用法代码示例。如果您正苦于以下问题:Python Font.testForExternalChanges方法的具体用法?Python Font.testForExternalChanges怎么用?Python Font.testForExternalChanges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类defcon.Font
的用法示例。
在下文中一共展示了Font.testForExternalChanges方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_delitem_glyph_dirty
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import testForExternalChanges [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)
示例2: test_testForExternalChanges
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import testForExternalChanges [as 别名]
def test_testForExternalChanges(self):
for ufo in (u"TestExternalEditing.ufo", u"TestExternalEditing.ufoz"):
path = getTestFontPath(ufo)
path = makeTestFontCopy(path)
font = Font(path)
# load all the objects so that they get stamped
font.info # i = font.info
k = font.kerning
font.groups # g = font.groups
font.lib # l = font.lib
font["A"] # g = font["A"]
d = font.testForExternalChanges()
self.assertFalse(d["info"])
self.assertFalse(d["kerning"])
self.assertFalse(d["groups"])
self.assertFalse(d["lib"])
# make a simple change to the kerning data
fileSystem = openTestFontAsFileSystem(font.path)
path = u"kerning.plist"
t = fileSystem.getbytes(path)
t += b"<!-- test -->"
fileSystem.setbytes(path, t)
k._dataOnDiskTimeStamp -= 1
closeTestFontAsFileSystem(fileSystem, font.path)
d = font.testForExternalChanges()
self.assertTrue(d["kerning"])
self.assertFalse(d["groups"])
self.assertFalse(d["info"])
self.assertFalse(d["lib"])
# save the kerning data and test again
font.kerning.dirty = True
font.save()
d = font.testForExternalChanges()
self.assertFalse(d["kerning"])
self.assertFalse(d["groups"])
self.assertFalse(d["info"])
self.assertFalse(d["lib"])
tearDownTestFontCopy(font.path)
示例3: test_testForExternalChanges
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import testForExternalChanges [as 别名]
def test_testForExternalChanges(self):
path = getTestFontPath("TestExternalEditing.ufo")
font = Font(path)
# load all the objects so that they get stamped
font.info # i = font.info
k = font.kerning
font.groups # g = font.groups
font.lib # l = font.lib
font["A"] # g = font["A"]
d = font.testForExternalChanges()
self.assertFalse(d["info"])
self.assertFalse(d["kerning"])
self.assertFalse(d["groups"])
self.assertFalse(d["lib"])
# make a simple change to the kerning data
path = os.path.join(font.path, "kerning.plist")
f = open(path, "r")
t = f.read()
f.close()
t += " "
f = open(path, "w")
f.write(t)
f.close()
os.utime(path,
(k._dataOnDiskTimeStamp + 1, k._dataOnDiskTimeStamp + 1))
d = font.testForExternalChanges()
self.assertTrue(d["kerning"])
self.assertFalse(d["groups"])
self.assertFalse(d["info"])
self.assertFalse(d["lib"])
# save the kerning data and test again
font.kerning.dirty = True
font.save()
d = font.testForExternalChanges()
self.assertFalse(d["kerning"])
self.assertFalse(d["groups"])
self.assertFalse(d["info"])
self.assertFalse(d["lib"])
示例4: test_delitem_glyph_not_dirty
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import testForExternalChanges [as 别名]
def test_delitem_glyph_not_dirty(self):
path = makeTestFontCopy()
font = Font(path)
font["A"] # glyph = font["A"]
glyphPath = os.path.join(path, "glyphs", "A_.glif")
os.remove(glyphPath)
contentsPath = os.path.join(path, "glyphs", "contents.plist")
with open(contentsPath, "rb") as f:
plist = load(f)
del plist["A"]
with open(contentsPath, "wb") as f:
dump(plist, f)
r = font.testForExternalChanges()
self.assertEqual(r["deletedGlyphs"], ["A"])
del font["A"]
font.save()
self.assertFalse(os.path.exists(glyphPath))
示例5: test_delitem_glyph_dirty
# 需要导入模块: from defcon import Font [as 别名]
# 或者: from defcon.Font import testForExternalChanges [as 别名]
def test_delitem_glyph_dirty(self):
path = self.path
font = Font(path)
layer = font.layers["public.default"]
glyph = layer["A"]
glyph.dirty = True
glyphPath = os.path.join(path, "glyphs", "A_.glif")
os.remove(glyphPath)
contentsPath = os.path.join(path, "glyphs", "contents.plist")
with open(contentsPath, "rb") as f:
plist = load(f)
del plist["A"]
with open(contentsPath, "wb") as f:
dump(plist, f)
r = font.testForExternalChanges()
self.assertEqual(r["deletedGlyphs"], ["A"])
del layer["A"]
font.save()
self.assertFalse(os.path.exists(glyphPath))