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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from __future__ import with_statement
  5. __license__ = 'GPL v3'
  6. __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
  7. __docformat__ = 'restructuredtext en'
  8. import sys
  9. import os
  10. from calibre.customize.conversion import OutputFormatPlugin
  11. from calibre.customize.conversion import OptionRecommendation
  12.  
  13. class LRFOptions(object):
  14.     
  15.     def __init__(self, output, opts, oeb):
  16.         
  17.         def f2s(f):
  18.             
  19.             try:
  20.                 return unicode(f[0])
  21.             except:
  22.                 return ''
  23.  
  24.  
  25.         m = oeb.metadata
  26.         self.title = None
  27.         self.author = self.publisher = _('Unknown')
  28.         self.title_sort = self.author_sort = ''
  29.         for x in m.creator:
  30.             if x.role == 'aut':
  31.                 self.author = unicode(x)
  32.                 fa = unicode(getattr(x, 'file_as', ''))
  33.                 if fa:
  34.                     self.author_sort = fa
  35.                 
  36.             fa
  37.         
  38.         for x in m.title:
  39.             if unicode(x.file_as):
  40.                 self.title_sort = unicode(x.file_as)
  41.                 continue
  42.         
  43.         self.freetext = f2s(m.description)
  44.         self.category = f2s(m.subject)
  45.         self.cover = None
  46.         self.use_metadata_cover = True
  47.         self.output = output
  48.         self.ignore_tables = opts.linearize_tables
  49.         if opts.disable_font_rescaling:
  50.             self.base_font_size = 0
  51.         else:
  52.             self.base_font_size = opts.base_font_size
  53.         self.blank_after_para = opts.insert_blank_line
  54.         self.use_spine = True
  55.         self.font_delta = 0
  56.         self.ignore_colors = False
  57.         PRS500_PROFILE = PRS500_PROFILE
  58.         import calibre.ebooks.lrf
  59.         self.profile = PRS500_PROFILE
  60.         self.link_levels = sys.maxint
  61.         self.link_exclude = '@'
  62.         self.no_links_in_toc = True
  63.         self.disable_chapter_detection = True
  64.         self.chapter_regex = 'dsadcdswcdec'
  65.         self.chapter_attr = '$,,$'
  66.         self.override_css = self._override_css = ''
  67.         self.page_break = 'h[12]'
  68.         self.force_page_break = '$'
  69.         self.force_page_break_attr = '$'
  70.         self.add_chapters_to_toc = False
  71.         self.baen = self.pdftohtml = self.book_designer = False
  72.         self.verbose = opts.verbose
  73.         self.encoding = 'utf-8'
  74.         self.lrs = False
  75.         self.minimize_memory_usage = False
  76.         self.autorotation = opts.enable_autorotation
  77.         self.header_separation = (self.profile.dpi / 72) * opts.header_separation
  78.         self.headerformat = opts.header_format
  79.         for x in ('top', 'bottom', 'left', 'right'):
  80.             setattr(self, x + '_margin', (self.profile.dpi / 72) * float(getattr(opts, 'margin_' + x)))
  81.         
  82.         for x in ('wordspace', 'header', 'header_format', 'minimum_indent', 'serif_family', 'render_tables_as_images', 'sans_family', 'mono_family', 'text_size_multiplier_for_rendered_tables'):
  83.             setattr(self, x, getattr(opts, x))
  84.         
  85.  
  86.  
  87.  
  88. class LRFOutput(OutputFormatPlugin):
  89.     name = 'LRF Output'
  90.     author = 'Kovid Goyal'
  91.     file_type = 'lrf'
  92.     options = set([
  93.         OptionRecommendation(name = 'enable_autorotation', recommended_value = False, help = _('Enable autorotation of images that are wider than the screen width.')),
  94.         OptionRecommendation(name = 'wordspace', recommended_value = 2.5, level = OptionRecommendation.LOW, help = _('Set the space between words in pts. Default is %default')),
  95.         OptionRecommendation(name = 'header', recommended_value = False, help = _('Add a header to all the pages with title and author.')),
  96.         OptionRecommendation(name = 'header_format', recommended_value = '%t by %a', help = _('Set the format of the header. %a is replaced by the author and %t by the title. Default is %default')),
  97.         OptionRecommendation(name = 'header_separation', recommended_value = 0, help = _('Add extra spacing below the header. Default is %default pt.')),
  98.         OptionRecommendation(name = 'minimum_indent', recommended_value = 0, help = _('Minimum paragraph indent (the indent of the first line of a paragraph) in pts. Default: %default')),
  99.         OptionRecommendation(name = 'render_tables_as_images', recommended_value = False, help = _('Render tables in the HTML as images (useful if the document has large or complex tables)')),
  100.         OptionRecommendation(name = 'text_size_multiplier_for_rendered_tables', recommended_value = 1, help = _('Multiply the size of text in rendered tables by this factor. Default is %default')),
  101.         OptionRecommendation(name = 'serif_family', recommended_value = None, help = _('The serif family of fonts to embed')),
  102.         OptionRecommendation(name = 'sans_family', recommended_value = None, help = _('The sans-serif family of fonts to embed')),
  103.         OptionRecommendation(name = 'mono_family', recommended_value = None, help = _('The monospace family of fonts to embed'))])
  104.     recommendations = set([
  105.         ('change_justification', 'original', OptionRecommendation.HIGH)])
  106.     
  107.     def convert_images(self, pages, opts, wide):
  108.         Book = Book
  109.         BookSetting = BookSetting
  110.         ImageStream = ImageStream
  111.         ImageBlock = ImageBlock
  112.         import calibre.ebooks.lrf.pylrs.pylrs
  113.         uuid4 = uuid4
  114.         import uuid
  115.         __appname__ = __appname__
  116.         __version__ = __version__
  117.         import calibre.constants
  118.         (width, height) = None if wide else (584, 754)
  119.         ps = { }
  120.         ps['topmargin'] = 0
  121.         ps['evensidemargin'] = 0
  122.         ps['oddsidemargin'] = 0
  123.         ps['textwidth'] = width
  124.         ps['textheight'] = height
  125.         book = Book(title = opts.title, author = opts.author, bookid = uuid4().hex, publisher = '%s %s' % (__appname__, __version__), category = _('Comic'), pagestyledefault = ps, booksetting = BookSetting(screenwidth = width, screenheight = height))
  126.         for page in pages:
  127.             imageStream = ImageStream(page)
  128.             _page = book.create_page()
  129.             _page.append(ImageBlock(refstream = imageStream, blockwidth = width, blockheight = height, xsize = width, ysize = height, x1 = width, y1 = height))
  130.             book.append(_page)
  131.         
  132.         book.renderLrf(open(opts.output, 'wb'))
  133.  
  134.     
  135.     def flatten_toc(self):
  136.         TOC = TOC
  137.         import calibre.ebooks.oeb.base
  138.         nroot = TOC()
  139.         for x in self.oeb.toc.iterdescendants():
  140.             nroot.add(x.title, x.href)
  141.         
  142.         self.oeb.toc = nroot
  143.  
  144.     
  145.     def convert(self, oeb, output_path, input_plugin, opts, log):
  146.         self.log = log
  147.         self.opts = opts
  148.         self.oeb = oeb
  149.         lrf_opts = LRFOptions(output_path, opts, oeb)
  150.         if input_plugin.is_image_collection:
  151.             self.convert_images(input_plugin.get_images(), lrf_opts, getattr(opts, 'wide', False))
  152.             return None
  153.         self.flatten_toc()
  154.         TemporaryDirectory = TemporaryDirectory
  155.         import calibre.ptempfile
  156.         
  157.         try:
  158.             tdir = _[1]
  159.             plugin_for_output_format = plugin_for_output_format
  160.             import calibre.customize.ui
  161.             oeb_output = plugin_for_output_format('oeb')
  162.             oeb_output.convert(oeb, tdir, input_plugin, opts, log)
  163.             opf = _[2][0]
  164.             process_file = process_file
  165.             import calibre.ebooks.lrf.html.convert_from
  166.             process_file(os.path.join(tdir, opf), lrf_opts, self.log)
  167.         finally:
  168.             pass
  169.  
  170.  
  171.  
  172.