本文整理汇总了Python中fontTools.designspaceLib.DesignSpaceDocument.updateFilenameFromPath方法的典型用法代码示例。如果您正苦于以下问题:Python DesignSpaceDocument.updateFilenameFromPath方法的具体用法?Python DesignSpaceDocument.updateFilenameFromPath怎么用?Python DesignSpaceDocument.updateFilenameFromPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fontTools.designspaceLib.DesignSpaceDocument
的用法示例。
在下文中一共展示了DesignSpaceDocument.updateFilenameFromPath方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pathNameResolve
# 需要导入模块: from fontTools.designspaceLib import DesignSpaceDocument [as 别名]
# 或者: from fontTools.designspaceLib.DesignSpaceDocument import updateFilenameFromPath [as 别名]
#.........这里部分代码省略.........
# Case 1: filename and path are both empty. Nothing to calculate, nothing to put in the file.
doc = DesignSpaceDocument()
doc.addAxis(a1)
s = SourceDescriptor()
s.filename = None
s.path = None
s.copyInfo = True
s.location = dict(weight=0)
s.familyName = "MasterFamilyName"
s.styleName = "MasterStyleNameOne"
doc.addSource(s)
doc.write(testDocPath1)
verify = DesignSpaceDocument()
verify.read(testDocPath1)
assert verify.sources[0].filename == None
assert verify.sources[0].path == None
# Case 2: filename is empty, path points somewhere: calculate a new filename.
doc = DesignSpaceDocument()
doc.addAxis(a1)
s = SourceDescriptor()
s.filename = None
s.path = masterPath1
s.copyInfo = True
s.location = dict(weight=0)
s.familyName = "MasterFamilyName"
s.styleName = "MasterStyleNameOne"
doc.addSource(s)
doc.write(testDocPath2)
verify = DesignSpaceDocument()
verify.read(testDocPath2)
assert verify.sources[0].filename == "masters/masterTest1.ufo"
assert verify.sources[0].path == posix(masterPath1)
# Case 3: the filename is set, the path is None.
doc = DesignSpaceDocument()
doc.addAxis(a1)
s = SourceDescriptor()
s.filename = "../somewhere/over/the/rainbow.ufo"
s.path = None
s.copyInfo = True
s.location = dict(weight=0)
s.familyName = "MasterFamilyName"
s.styleName = "MasterStyleNameOne"
doc.addSource(s)
doc.write(testDocPath3)
verify = DesignSpaceDocument()
verify.read(testDocPath3)
assert verify.sources[0].filename == "../somewhere/over/the/rainbow.ufo"
# make the absolute path for filename so we can see if it matches the path
p = os.path.abspath(os.path.join(os.path.dirname(testDocPath3), verify.sources[0].filename))
assert verify.sources[0].path == posix(p)
# Case 4: the filename points to one file, the path points to another. The path takes precedence.
doc = DesignSpaceDocument()
doc.addAxis(a1)
s = SourceDescriptor()
s.filename = "../somewhere/over/the/rainbow.ufo"
s.path = masterPath1
s.copyInfo = True
s.location = dict(weight=0)
s.familyName = "MasterFamilyName"
s.styleName = "MasterStyleNameOne"
doc.addSource(s)
doc.write(testDocPath4)
verify = DesignSpaceDocument()
verify.read(testDocPath4)
assert verify.sources[0].filename == "masters/masterTest1.ufo"
# Case 5: the filename is None, path has a value, update the filename
doc = DesignSpaceDocument()
doc.addAxis(a1)
s = SourceDescriptor()
s.filename = None
s.path = masterPath1
s.copyInfo = True
s.location = dict(weight=0)
s.familyName = "MasterFamilyName"
s.styleName = "MasterStyleNameOne"
doc.addSource(s)
doc.write(testDocPath5) # so that the document has a path
doc.updateFilenameFromPath()
assert doc.sources[0].filename == "masters/masterTest1.ufo"
# Case 6: the filename has a value, path has a value, update the filenames with force
doc = DesignSpaceDocument()
doc.addAxis(a1)
s = SourceDescriptor()
s.filename = "../somewhere/over/the/rainbow.ufo"
s.path = masterPath1
s.copyInfo = True
s.location = dict(weight=0)
s.familyName = "MasterFamilyName"
s.styleName = "MasterStyleNameOne"
doc.write(testDocPath5) # so that the document has a path
doc.addSource(s)
assert doc.sources[0].filename == "../somewhere/over/the/rainbow.ufo"
doc.updateFilenameFromPath(force=True)
assert doc.sources[0].filename == "masters/masterTest1.ufo"