122
122
MSFolders = \
123
123
r'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders'
124
124
125
- MSFontDirectories = [
125
+
126
+ MSFontDirectories = [
126
127
r'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts' ,
127
128
r'SOFTWARE\Microsoft\Windows\CurrentVersion\Fonts' ]
128
129
129
- X11FontDirectories = [
130
+
131
+ X11FontDirectories = [
130
132
# an old standard installation point
131
133
"/usr/X11R6/lib/X11/fonts/TTF/" ,
132
134
"/usr/X11/lib/X11/fonts" ,
156
158
path = os .path .join (home , '.fonts' )
157
159
X11FontDirectories .append (path )
158
160
161
+
159
162
def get_fontext_synonyms (fontext ):
160
163
"""
161
164
Return a list of file extensions extensions that are synonyms for
@@ -165,6 +168,7 @@ def get_fontext_synonyms(fontext):
165
168
'otf' : ('ttf' , 'otf' ),
166
169
'afm' : ('afm' ,)}[fontext ]
167
170
171
+
168
172
def list_fonts (directory , extensions ):
169
173
"""
170
174
Return a list of all fonts matching any of the extensions,
@@ -174,6 +178,7 @@ def list_fonts(directory, extensions):
174
178
for ext in extensions ])
175
179
return cbook .listFiles (directory , pattern )
176
180
181
+
177
182
def win32FontDirectory ():
178
183
"""
179
184
Return the user-specified font directory for Win32. This is
@@ -186,21 +191,22 @@ def win32FontDirectory():
186
191
try :
187
192
from six .moves import winreg
188
193
except ImportError :
189
- pass # Fall through to default
194
+ pass # Fall through to default
190
195
else :
191
196
try :
192
197
user = winreg .OpenKey (winreg .HKEY_CURRENT_USER , MSFolders )
193
198
try :
194
199
try :
195
200
return winreg .QueryValueEx (user , 'Fonts' )[0 ]
196
201
except OSError :
197
- pass # Fall through to default
202
+ pass # Fall through to default
198
203
finally :
199
204
winreg .CloseKey (user )
200
205
except OSError :
201
- pass # Fall through to default
206
+ pass # Fall through to default
202
207
return os .path .join (os .environ ['WINDIR' ], 'Fonts' )
203
208
209
+
204
210
def win32InstalledFonts (directory = None , fontext = 'ttf' ):
205
211
"""
206
212
Search for fonts in the specified font directory, or use the
@@ -246,6 +252,7 @@ def win32InstalledFonts(directory=None, fontext='ttf'):
246
252
winreg .CloseKey (local )
247
253
return None
248
254
255
+
249
256
def OSXInstalledFonts (directories = None , fontext = 'ttf' ):
250
257
"""
251
258
Get list of font files on OS X - ignores font suffix by default.
@@ -297,6 +304,7 @@ def get_fontconfig_fonts(fontext='ttf'):
297
304
if os .path .splitext (fname )[1 ][1 :] in fontext ]
298
305
299
306
307
+
300
308
def findSystemFonts (fontpaths = None , fontext = 'ttf' ):
301
309
"""
302
310
Search for fonts in the specified font paths. If no paths are
@@ -338,6 +346,7 @@ def findSystemFonts(fontpaths=None, fontext='ttf'):
338
346
339
347
return [fname for fname in fontfiles if os .path .exists (fname )]
340
348
349
+
341
350
def weight_as_number (weight ):
342
351
"""
343
352
Return the weight property as a numeric value. String values
@@ -419,7 +428,6 @@ def ttfFontProperty(font):
419
428
else :
420
429
style = 'normal'
421
430
422
-
423
431
# Variants are: small-caps and normal (default)
424
432
425
433
# !!!! Untested
@@ -451,8 +459,8 @@ def ttfFontProperty(font):
451
459
# Relative stretches are: wider, narrower
452
460
# Child value is: inherit
453
461
454
- if sfnt4 .find ('narrow' ) >= 0 or sfnt4 .find ('condensed' ) >= 0 or \
455
- sfnt4 .find ('cond' ) >= 0 :
462
+ if ( sfnt4 .find ('narrow' ) >= 0 or sfnt4 .find ('condensed' ) >= 0 or
463
+ sfnt4 .find ('cond' ) >= 0 ) :
456
464
stretch = 'condensed'
457
465
elif sfnt4 .find ('demi cond' ) >= 0 :
458
466
stretch = 'semi-condensed'
0 commit comments