mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
More robust system font finding
This commit is contained in:
parent
d5219ac296
commit
4f6955f989
@ -165,24 +165,36 @@ def set_translator():
|
|||||||
set_translator()
|
set_translator()
|
||||||
|
|
||||||
font_families = {}
|
font_families = {}
|
||||||
def get_font_families():
|
def get_font_families(cached=None):
|
||||||
global font_families
|
global font_families
|
||||||
|
if cached is not None:
|
||||||
|
font_families = cached
|
||||||
if not font_families:
|
if not font_families:
|
||||||
ffiles = findsystem.findFonts()
|
try:
|
||||||
zlist = []
|
ffiles = findsystem.findFonts()
|
||||||
for ff in ffiles:
|
except Exception, err:
|
||||||
try:
|
print 'WARNING: Could not find fonts on your system.'
|
||||||
font = describe.openFont(ff)
|
print err
|
||||||
except: # Some font files cause ttfquery to raise an exception, in which case they are ignored
|
else:
|
||||||
continue
|
zlist = []
|
||||||
try:
|
for ff in ffiles:
|
||||||
wt, italic = describe.modifiers(font)
|
try:
|
||||||
except:
|
font = describe.openFont(ff)
|
||||||
wt, italic = 0, 0
|
except: # Some font files cause ttfquery to raise an exception, in which case they are ignored
|
||||||
if wt == 400 and italic == 0:
|
continue
|
||||||
family = describe.shortName(font)[1].strip()
|
try:
|
||||||
zlist.append((family, ff))
|
wt, italic = describe.modifiers(font)
|
||||||
font_families = dict(zlist)
|
except:
|
||||||
|
wt, italic = 0, 0
|
||||||
|
if wt == 400 and italic == 0:
|
||||||
|
try:
|
||||||
|
family = describe.shortName(font)[1].strip()
|
||||||
|
except: # Windows strikes again!
|
||||||
|
continue
|
||||||
|
zlist.append((family, ff))
|
||||||
|
font_families = dict(zlist)
|
||||||
|
|
||||||
|
|
||||||
return font_families
|
return font_families
|
||||||
|
|
||||||
def sanitize_file_name(name):
|
def sanitize_file_name(name):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user