MCPcopy Create free account
hub / github.com/PageBot/PageBot / path2FontName

Function path2FontName

Lib/pagebot/toolbox/transformer.py:649–671  ·  view source on GitHub ↗

Take that file part of the path, and get the chunk until the first period to remove the extension, version numbers, etc. If the extension is not in extensions (default id ('ttf', 'otf')) then answer None >>> path2FontName('/xxx/yyy/zzz/Agency_FB-Compressed.otf') 'Agency_FB-

(path, extensions=None)

Source from the content-addressed store, hash-verified

647 return scaledPath + fileName + params + '.' + extension
648
649def path2FontName(path, extensions=None):
650 """
651 Take that file part of the path, and get the chunk until the first
652 period to remove the extension, version numbers, etc.
653 If the extension is not in extensions (default id ('ttf', 'otf'))
654 then answer None
655
656 >>> path2FontName('/xxx/yyy/zzz/Agency_FB-Compressed.otf')
657 'Agency_FB-Compressed'
658 >>> path2FontName('/xxx/yyy/zzz/Agency_FB-Compressed.version01.ufo') is None
659 True
660 >>> path2FontName('/xxx/yyy/zzz/Agency_FB-Compressed.version01.ufo', ['ufo'])
661 'Agency_FB-Compressed'
662 >>> path2FontName('#xxx/yyy/zzz/Agency_FB-Bold.0001646411.ttf')
663 'Agency_FB-Bold'
664 """
665 if extensions is None:
666 extensions = ('ttf', 'otf', 'ttc')
667 if path2Extension(path) in extensions:
668 name = path2Name(path)
669 if name is not None:
670 return name.split('.')[0]
671 return None
672
673familyNameParts = re.compile('([A-Za-z]*)')
674

Callers 8

_get_nameMethod · 0.90
__repr__Method · 0.90
nameMatchMethod · 0.90
weightMatchMethod · 0.90
widthMatchMethod · 0.90
isItalicMethod · 0.90
matchMethod · 0.90

Calls 2

path2ExtensionFunction · 0.85
path2NameFunction · 0.85

Tested by

no test coverage detected