home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_913 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  2.0 KB  |  53 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __license__ = 'GPL v3'
  5. __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
  6. import os
  7.  
  8. try:
  9.     from PIL import ImageFont
  10.     ImageFont
  11. except ImportError:
  12.     import ImageFont
  13.  
  14. SYSTEM_FONT_PATH = '/usr/share/fonts/truetype/ttf-liberation/'
  15. FONT_MAP = {
  16.     'Swis721 BT Roman': 'tt0003m_',
  17.     'Dutch801 Rm BT Roman': 'tt0011m_',
  18.     'Courier10 BT Roman': 'tt0419m_' }
  19. LIBERATION_FONT_MAP = {
  20.     'Swis721 BT Roman': 'LiberationSans-Regular',
  21.     'Dutch801 Rm BT Roman': 'LiberationSerif-Regular',
  22.     'Courier10 BT Roman': 'LiberationMono-Regular' }
  23. FONT_FILE_MAP = { }
  24. SYSTEM_FONT_MAP = { }
  25. for key, val in LIBERATION_FONT_MAP.items():
  26.     SYSTEM_FONT_MAP[key] = SYSTEM_FONT_PATH + val + '.ttf'
  27.  
  28.  
  29. def get_font_path(name):
  30.     if FONT_FILE_MAP.has_key(name) and os.access(FONT_FILE_MAP[name], os.R_OK):
  31.         return FONT_FILE_MAP[name]
  32.     for m, s in ((FONT_MAP, 'prs500'), (LIBERATION_FONT_MAP, 'liberation')):
  33.         fname = m[name] + '.ttf'
  34.         etc_file = os.path.join(os.path.sep, 'etc', 'calibre', 'fonts', fname)
  35.         if os.access(etc_file, os.R_OK):
  36.             return etc_file
  37.         f = P('fonts/%s/%s' % (s, fname))
  38.         if os.path.exists(f):
  39.             return f
  40.     
  41.     if SYSTEM_FONT_MAP.has_key(name) and os.access(SYSTEM_FONT_MAP[name], os.R_OK):
  42.         return SYSTEM_FONT_MAP[name]
  43.     raise SystemError('font %s (in file %s) not installed' % (name, fname))
  44.  
  45.  
  46. def get_font(name, size, encoding = 'unic'):
  47.     if name in FONT_MAP.keys():
  48.         path = get_font_path(name)
  49.         return ImageFont.truetype(path, size, encoding = encoding)
  50.     if name in FONT_FILE_MAP.keys():
  51.         return ImageFont.truetype(FONT_FILE_MAP[name], size, encoding = encoding)
  52.  
  53.