home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_937 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  4.2 KB  |  117 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. from uuid import uuid4
  7. from calibre.ebooks.lrf.pylrs.pylrs import Book as _Book
  8. from calibre.ebooks.lrf.pylrs.pylrs import TextBlock, Header, TextStyle, BlockStyle
  9. from calibre.ebooks.lrf.fonts import FONT_FILE_MAP
  10. from calibre.ebooks import ConversionError
  11. __docformat__ = 'epytext'
  12.  
  13. class LRFParseError(Exception):
  14.     pass
  15.  
  16.  
  17. class PRS500_PROFILE(object):
  18.     screen_width = 600
  19.     screen_height = 775
  20.     dpi = 166
  21.     fudge = 0
  22.     font_size = 10
  23.     parindent = 10
  24.     line_space = 1.2
  25.     header_font_size = 6
  26.     header_height = 30
  27.     default_fonts = {
  28.         'sans': 'Swis721 BT Roman',
  29.         'mono': 'Courier10 BT Roman',
  30.         'serif': 'Dutch801 Rm BT Roman' }
  31.     name = 'prs500'
  32.  
  33.  
  34. def find_custom_fonts(options, logger):
  35.     fontconfig = fontconfig
  36.     import calibre.utils.fonts
  37.     files_for_family = fontconfig.files_for_family
  38.     fonts = {
  39.         'serif': None,
  40.         'sans': None,
  41.         'mono': None }
  42.     
  43.     def family(cmd):
  44.         return cmd.split(',')[-1].strip()
  45.  
  46.     if options.serif_family:
  47.         f = family(options.serif_family)
  48.         fonts['serif'] = files_for_family(f)
  49.         if not fonts['serif']:
  50.             logger.warn('Unable to find serif family %s' % f)
  51.         
  52.     
  53.     if options.sans_family:
  54.         f = family(options.sans_family)
  55.         fonts['sans'] = files_for_family(f)
  56.         if not fonts['sans']:
  57.             logger.warn('Unable to find sans family %s' % f)
  58.         
  59.     
  60.     if options.mono_family:
  61.         f = family(options.mono_family)
  62.         fonts['mono'] = files_for_family(f)
  63.         if not fonts['mono']:
  64.             logger.warn('Unable to find mono family %s' % f)
  65.         
  66.     
  67.     return fonts
  68.  
  69.  
  70. def Book(options, logger, font_delta = 0, header = None, profile = PRS500_PROFILE, **settings):
  71.     ps = { }
  72.     ps['topmargin'] = options.top_margin
  73.     ps['evensidemargin'] = options.left_margin
  74.     ps['oddsidemargin'] = options.left_margin
  75.     ps['textwidth'] = profile.screen_width - (options.left_margin + options.right_margin)
  76.     ps['textheight'] = profile.screen_height - (options.top_margin + options.bottom_margin) - profile.fudge
  77.     if header:
  78.         hdr = Header()
  79.         hb = TextBlock(textStyle = TextStyle(align = 'foot', fontsize = int(profile.header_font_size * 10)), blockStyle = BlockStyle(blockwidth = ps['textwidth']))
  80.         hb.append(header)
  81.         hdr.PutObj(hb)
  82.         ps['headheight'] = profile.header_height
  83.         ps['headsep'] = options.header_separation
  84.         ps['header'] = hdr
  85.         ps['topmargin'] = 0
  86.         ps['textheight'] = profile.screen_height - (options.bottom_margin + ps['topmargin']) - ps['headheight'] - ps['headsep'] - profile.fudge
  87.     
  88.     fontsize = int(10 * profile.font_size + font_delta * 20)
  89.     baselineskip = fontsize + 20
  90.     fonts = find_custom_fonts(options, logger)
  91.     tsd = dict(fontsize = fontsize, parindent = int(10 * profile.parindent), linespace = int(10 * profile.line_space), baselineskip = baselineskip, wordspace = 10 * options.wordspace)
  92.     if fonts['serif'] and fonts['serif'].has_key('normal'):
  93.         tsd['fontfacename'] = fonts['serif']['normal'][1]
  94.     
  95.     book = _Book(textstyledefault = tsd, pagestyledefault = ps, blockstyledefault = dict(blockwidth = ps['textwidth']), bookid = uuid4().hex, **settings)
  96.     for family in fonts.keys():
  97.         if fonts[family]:
  98.             for font in fonts[family].values():
  99.                 book.embed_font(*font)
  100.                 FONT_FILE_MAP[font[1]] = font[0]
  101.             
  102.     
  103.     for family in [
  104.         'serif',
  105.         'sans',
  106.         'mono']:
  107.         if not fonts[family]:
  108.             fonts[family] = {
  109.                 'normal': (None, profile.default_fonts[family]) }
  110.             continue
  111.         if not fonts[family].has_key('normal'):
  112.             raise ConversionError, 'Could not find the normal version of the ' + family + ' font'
  113.         fonts[family].has_key('normal')
  114.     
  115.     return (book, fonts)
  116.  
  117.