mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-04-21 13:41:30 +02:00
Cleanup get_path usage in favor of pkg_resources.
This commit is contained in:
@@ -5,29 +5,40 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
from PIL import ImageFont
|
||||
|
||||
from ebook_converter.utils.fonts.scanner import font_scanner
|
||||
|
||||
'''
|
||||
Default fonts used in the PRS500
|
||||
'''
|
||||
|
||||
|
||||
LIBERATION_FONT_MAP = {
|
||||
'Swis721 BT Roman' : 'LiberationSans-Regular',
|
||||
'Dutch801 Rm BT Roman' : 'LiberationSerif-Regular',
|
||||
'Courier10 BT Roman' : 'LiberationMono-Regular',
|
||||
}
|
||||
|
||||
LIBERATION_FONT_MAP = {'Swis721 BT Roman': 'Liberation Sans Regular',
|
||||
'Dutch801 Rm BT Roman': 'Liberation Serif Regular',
|
||||
'Courier10 BT Roman': 'Liberation Mono Regular'}
|
||||
_LIB_CACHE = {}
|
||||
FONT_FILE_MAP = {}
|
||||
|
||||
|
||||
def get_font(name, size, encoding='unic'):
|
||||
'''
|
||||
"""
|
||||
Get an ImageFont object by name.
|
||||
@param size: Font height in pixels. To convert from pts:
|
||||
sz in pixels = (dpi/72) * size in pts
|
||||
@param encoding: Font encoding to use. E.g. 'unic', 'symbol', 'ADOB', 'ADBE', 'aprm'
|
||||
@param manager: A dict that will store the PersistentTemporary
|
||||
'''
|
||||
@param encoding: Font encoding to use. E.g. 'unic', 'symbol', 'ADOB',
|
||||
'ADBE', 'aprm'
|
||||
"""
|
||||
if name in LIBERATION_FONT_MAP:
|
||||
return ImageFont.truetype(P('fonts/liberation/%s.ttf' % LIBERATION_FONT_MAP[name]), size, encoding=encoding)
|
||||
if not _LIB_CACHE:
|
||||
for key in font_scanner.cache['fonts']:
|
||||
record = font_scanner.cache['fonts'][key]
|
||||
_LIB_CACHE[record['family_name'] + ' ' +
|
||||
record['subfamily_name']] = record['path']
|
||||
|
||||
fpath = _LIB_CACHE.get(LIBERATION_FONT_MAP[name])
|
||||
if not fpath:
|
||||
raise ValueError('There is no liberation font existing in the '
|
||||
'system. Please install them before converter '
|
||||
'use.')
|
||||
return ImageFont.truetype(fpath, size, encoding=encoding)
|
||||
elif name in FONT_FILE_MAP:
|
||||
return ImageFont.truetype(FONT_FILE_MAP[name], size, encoding=encoding)
|
||||
|
||||
Reference in New Issue
Block a user