124
124
MSFolders = \
125
125
r'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders'
126
126
127
- MSFontDirectories = [
127
+
128
+ MSFontDirectories = [
128
129
r'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts' ,
129
130
r'SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts' ]
130
131
131
- X11FontDirectories = [
132
+
133
+ X11FontDirectories = [
132
134
# an old standard installation point
133
135
"/usr/X11R6/lib/X11/fonts/TTF/" ,
134
136
"/usr/X11/lib/X11/fonts" ,
158
160
path = os .path .join (home , '.fonts' )
159
161
X11FontDirectories .append (path )
160
162
163
+
161
164
def get_fontext_synonyms (fontext ):
162
165
"""
163
166
Return a list of file extensions extensions that are synonyms for
@@ -167,6 +170,7 @@ def get_fontext_synonyms(fontext):
167
170
'otf' : ('ttf' , 'otf' ),
168
171
'afm' : ('afm' ,)}[fontext ]
169
172
173
+
170
174
def list_fonts (directory , extensions ):
171
175
"""
172
176
Return a list of all fonts matching any of the extensions,
@@ -176,6 +180,7 @@ def list_fonts(directory, extensions):
176
180
for ext in extensions ])
177
181
return cbook .listFiles (directory , pattern )
178
182
183
+
179
184
def win32FontDirectory ():
180
185
"""
181
186
Return the user-specified font directory for Win32. This is
@@ -188,21 +193,22 @@ def win32FontDirectory():
188
193
try :
189
194
from six .moves import winreg
190
195
except ImportError :
191
- pass # Fall through to default
196
+ pass # Fall through to default
192
197
else :
193
198
try :
194
199
user = winreg .OpenKey (winreg .HKEY_CURRENT_USER , MSFolders )
195
200
try :
196
201
try :
197
202
return winreg .QueryValueEx (user , 'Fonts' )[0 ]
198
203
except OSError :
199
- pass # Fall through to default
204
+ pass # Fall through to default
200
205
finally :
201
206
winreg .CloseKey (user )
202
207
except OSError :
203
- pass # Fall through to default
208
+ pass # Fall through to default
204
209
return os .path .join (os .environ ['WINDIR' ], 'Fonts' )
205
210
211
+
206
212
def win32InstalledFonts (directory = None , fontext = 'ttf' ):
207
213
"""
208
214
Search for fonts in the specified font directory, or use the
@@ -248,6 +254,7 @@ def win32InstalledFonts(directory=None, fontext='ttf'):
248
254
winreg .CloseKey (local )
249
255
return None
250
256
257
+
251
258
def OSXInstalledFonts (directories = None , fontext = 'ttf' ):
252
259
"""
253
260
Get list of font files on OS X - ignores font suffix by default.
@@ -265,6 +272,7 @@ def OSXInstalledFonts(directories=None, fontext='ttf'):
265
272
files .extend (list_fonts (path , fontext ))
266
273
return files
267
274
275
+
268
276
def get_fontconfig_fonts (fontext = 'ttf' ):
269
277
"""
270
278
Grab a list of all the fonts that are being tracked by fontconfig
@@ -294,11 +302,12 @@ def get_fontconfig_fonts(fontext='ttf'):
294
302
except UnicodeDecodeError :
295
303
continue
296
304
if (os .path .splitext (fname )[1 ][1 :] in fontext and
297
- os .path .exists (fname )):
305
+ os .path .exists (fname )):
298
306
fontfiles [fname ] = 1
299
307
300
308
return fontfiles
301
309
310
+
302
311
def findSystemFonts (fontpaths = None , fontext = 'ttf' ):
303
312
"""
304
313
Search for fonts in the specified font paths. If no paths are
@@ -338,7 +347,9 @@ def findSystemFonts(fontpaths=None, fontext='ttf'):
338
347
for fname in files :
339
348
fontfiles [os .path .abspath (fname )] = 1
340
349
341
- return [fname for fname in six .iterkeys (fontfiles ) if os .path .exists (fname )]
350
+ return [fname for fname in six .iterkeys (fontfiles )
351
+ if os .path .exists (fname )]
352
+
342
353
343
354
def weight_as_number (weight ):
344
355
"""
@@ -421,7 +432,6 @@ def ttfFontProperty(font):
421
432
else :
422
433
style = 'normal'
423
434
424
-
425
435
# Variants are: small-caps and normal (default)
426
436
427
437
# !!!! Untested
@@ -453,8 +463,8 @@ def ttfFontProperty(font):
453
463
# Relative stretches are: wider, narrower
454
464
# Child value is: inherit
455
465
456
- if sfnt4 .find ('narrow' ) >= 0 or sfnt4 .find ('condensed' ) >= 0 or \
457
- sfnt4 .find ('cond' ) >= 0 :
466
+ if ( sfnt4 .find ('narrow' ) >= 0 or sfnt4 .find ('condensed' ) >= 0 or
467
+ sfnt4 .find ('cond' ) >= 0 ) :
458
468
stretch = 'condensed'
459
469
elif sfnt4 .find ('demi cond' ) >= 0 :
460
470
stretch = 'semi-condensed'
0 commit comments