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

Function findFonts

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

Answers a list of Font instances where the pattern fits the font path. If pattern is a list, all parts should have a match. # TODO: make case insensitive

(pattern, lazy=True)

Source from the content-addressed store, hash-verified

112 return None
113
114def findFonts(pattern, lazy=True):
115 """Answers a list of Font instances where the pattern fits the font path.
116 If pattern is a list, all parts should have a match.
117
118
119 # TODO: make case insensitive
120 """
121 """
122 >>> findFonts('Roboto-Thi')
123 [<Font Roboto-Thin>, <Font Roboto-ThinItalic>]
124 >>> # Select on family and name parts.
125 >>> findFonts(('Robo', 'Ita', 'Thi'))
126 [<Font Roboto-ThinItalic>]
127 >>> # Select on style parts only.
128 >>> findFonts(('Ita', 'Bol', 'Con'))
129 [<Font RobotoCondensed-BoldItalic>]
130 """
131 fontPaths = getFontPaths()
132 fonts = []
133
134 if not isinstance(pattern, (list, tuple)):
135 pattern = [pattern]
136
137 for fontPath in fontPaths:
138 found = True
139 for match in pattern:
140 if not match in fontPath:
141 found = False
142 break
143 if found:
144 fonts.append(findFont(fontPath, lazy=lazy))
145 return fonts
146
147def findFont(fontPath, default=None, lazy=True):
148 """Answers the font the has name fontName.

Callers

nothing calls this directly

Calls 3

getFontPathsFunction · 0.90
findFontFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected