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

Function getFont

Lib/pagebot/fonttoolbox/objects/font.py:85–112  ·  view source on GitHub ↗

Answers the Font instance, that connects to the fontPath. Note that there is no check if there is already anothe Font created on that path, as for PageBot purposes it is most likely for reading only. >>> from pagebot.fonttoolbox.fontpaths import getTestFontsPath >>> fontPath = getTe

(fontOrPath, lazy=True)

Source from the content-addressed store, hash-verified

83 return None
84
85def getFont(fontOrPath, lazy=True):
86 """Answers the Font instance, that connects to the fontPath. Note that
87 there is no check if there is already anothe Font created on that path,
88 as for PageBot purposes it is most likely for reading only.
89
90 >>> from pagebot.fonttoolbox.fontpaths import getTestFontsPath
91 >>> fontPath = getTestFontsPath()
92 >>> path = fontPath + '/fontbureau/Amstelvar-Roman-VF.ttf'
93 >>> fontName = path2FontName(path)
94 >>> font = getFont(path)
95 >>> font.path == path
96 True
97 >>> # Answer the same font, if it is already one.
98 >>> font == getFont(font)
99 True
100 """
101 if isinstance(fontOrPath, Font):
102 return fontOrPath
103
104 fontOrPath = asFontPath(fontOrPath) # Find the real path, case corrected.
105 if not fontOrPath:
106 return None
107
108 try:
109 return Font(fontOrPath, lazy=lazy)
110 except TTLibError:
111 # Could not open font, due to bad font file.
112 return None
113
114def findFonts(pattern, lazy=True):
115 """Answers a list of Font instances where the pattern fits the font path.

Callers 4

getVarFontInstanceFunction · 0.90
getFamilyPathsFunction · 0.90
addFontMethod · 0.90
findFontFunction · 0.85

Calls 2

asFontPathFunction · 0.85
FontClass · 0.85

Tested by

no test coverage detected