示例#1
0
    def convert_images(self, pages, opts, wide):
        from calibre.ebooks.lrf.pylrs.pylrs import Book, BookSetting, ImageStream, ImageBlock
        from uuid import uuid4
        from calibre.constants import __appname__, __version__

        width, height = (784, 1012) if wide else (584, 754)

        ps = {}
        ps['topmargin'] = 0
        ps['evensidemargin'] = 0
        ps['oddsidemargin'] = 0
        ps['textwidth'] = width
        ps['textheight'] = height
        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))
        for page in pages:
            imageStream = ImageStream(page)
            _page = book.create_page()
            _page.append(
                ImageBlock(refstream=imageStream,
                           blockwidth=width,
                           blockheight=height,
                           xsize=width,
                           ysize=height,
                           x1=width,
                           y1=height))
            book.append(_page)

        book.renderLrf(open(opts.output, 'wb'))
示例#2
0
    def first_pass(self):
        info = self.soup.find('bbebxylog').find('bookinformation').find('info')
        bookinfo = info.find('bookinfo')
        docinfo = info.find('docinfo')

        def me(base, tagname):
            tag = base.find(tagname.lower())
            if tag is None:
                return ('', '', '')
            tag = (self.tag_to_string(tag),
                   tag.get('reading') if tag.has_key('reading') else ''
                   )  # noqa
            return tag

        title = me(bookinfo, 'Title')
        author = me(bookinfo, 'Author')
        publisher = me(bookinfo, 'Publisher')
        category = me(bookinfo, 'Category')[0]
        classification = me(bookinfo, 'Classification')[0]
        freetext = me(bookinfo, 'FreeText')[0]
        language = me(docinfo, 'Language')[0]
        creator = me(docinfo, 'Creator')[0]
        producer = me(docinfo, 'Producer')[0]
        bookid = me(bookinfo, 'BookID')[0]

        sd = self.soup.find('setdefault')
        sd = StyleDefault(
            **self.attrs_to_dict(sd, ['page_tree_id', 'rubyalignandadjust']))
        bs = self.soup.find('booksetting')
        bs = BookSetting(**self.attrs_to_dict(bs, []))

        settings = {}
        thumbnail = self.soup.find('cthumbnail')
        if thumbnail is not None:
            f = thumbnail['file']
            if os.access(f, os.R_OK):
                settings['thumbnail'] = f
            else:
                print _('Could not read from thumbnail file:'), f

        self.book = Book(title=title,
                         author=author,
                         publisher=publisher,
                         category=category,
                         classification=classification,
                         freetext=freetext,
                         language=language,
                         creator=creator,
                         producer=producer,
                         bookid=bookid,
                         setdefault=sd,
                         booksetting=bs,
                         **settings)

        for hdr in self.soup.findAll(['header', 'footer']):
            elem = Header if hdr.name == 'header' else Footer
            self.parsed_objects[hdr.get('objid')] = elem(
                **self.attrs_to_dict(hdr))