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

Function findFont

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

Answers the font the has name fontName. >>> f = findFont('Roboto-Regular') >>> f >>> notSkiaFont = findFont('Skia-cannot-be-found') >>> notSkiaFont is None True >>> # Default is a font. >>> # Set RobotoFont as default. >>> notSkiaFont = find

(fontPath, default=None, lazy=True)

Source from the content-addressed store, hash-verified

145 return fonts
146
147def findFont(fontPath, default=None, lazy=True):
148 """Answers the font the has name fontName.
149
150 >>> f = findFont('Roboto-Regular')
151 >>> f
152 <Font Roboto-Regular>
153 >>> notSkiaFont = findFont('Skia-cannot-be-found')
154 >>> notSkiaFont is None
155 True
156 >>> # Default is a font.
157 >>> # Set RobotoFont as default.
158 >>> notSkiaFont = findFont('Skia-cannot-be-found', default=f)
159 >>> notSkiaFont is f # Found robotoFont instead
160 True
161 >>> # Default is a name.
162 >>> f = findFont('Skia-cannot-be-found', default='Roboto-Regular') # Found default RobotoFont instead
163 >>> f
164 <Font Roboto-Regular>
165 """
166 if isinstance(fontPath, Font): # It's already a Font instance, just answer it.
167 return fontPath
168
169 fontPaths = getFontPaths() # Otherwise, let's see if we can find it by name.
170 if fontPath in fontPaths:
171 font = getFont(fontPaths[fontPath], lazy=lazy)
172 if font is not None:
173 return font
174
175 font = getFont(fontPath)
176 if font is not None:
177 return font
178
179 # A default is defined. If it's a string, try to find it. Avoid c76ircular
180 # calls.
181 if isinstance(default, str) and default != fontPath:
182 return findFont(default, lazy=lazy)
183
184 assert default is None or isinstance(default, Font)
185 # Otherwise assume it is a Font instance or None.
186 return default
187
188def getFontPath(font):
189 """Answer the font file path for @font.

Callers 15

getFontByNameFunction · 0.90
_getFlatFontMethod · 0.90
getTextLinesMethod · 0.90
fromBabelStringMethod · 0.90
build_scssMethod · 0.90
getFontMethod · 0.90
getFontMethod · 0.90
__init__Method · 0.90
fontMethod · 0.90
_get_fontMethod · 0.90
__init__Method · 0.90
drawAnimatedFrameMethod · 0.90

Calls 2

getFontPathsFunction · 0.90
getFontFunction · 0.85

Tested by

no test coverage detected