~ubuntu-branches/ubuntu/karmic/calibre/karmic

« back to all changes in this revision

Viewing changes to src/calibre/ebooks/oeb/transforms/rasterize.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-30 12:49:41 UTC
  • mfrom: (1.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090730124941-qjdsmri25zt8zocn
Tags: 0.6.3+dfsg-0ubuntu1
* New upstream release. Please see http://calibre.kovidgoyal.net/new_in_6/
  for the list of new features and changes.
* remove_postinstall.patch: Update for new version.
* build_debug.patch: Does not apply any more, disable for now. Might not be
  necessary any more.
* debian/copyright: Fix reference to versionless GPL.
* debian/rules: Drop obsolete dh_desktop call.
* debian/rules: Add workaround for weird Python 2.6 setuptools behaviour of
  putting compiled .so files into src/calibre/plugins/calibre/plugins
  instead of src/calibre/plugins.
* debian/rules: Drop hal fdi moving, new upstream version does not use hal
  any more. Drop hal dependency, too.
* debian/rules: Install udev rules into /lib/udev/rules.d.
* Add debian/calibre.preinst: Remove unmodified
  /etc/udev/rules.d/95-calibre.rules on upgrade.
* debian/control: Bump Python dependencies to 2.6, since upstream needs
  it now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
__license__   = 'GPL v3'
7
7
__copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
8
8
 
9
 
import sys
10
9
import os
11
10
from urlparse import urldefrag
12
11
import base64
20
19
from PyQt4.QtGui import QPainter
21
20
from PyQt4.QtSvg import QSvgRenderer
22
21
from PyQt4.QtGui import QApplication
23
 
from calibre.ebooks.oeb.base import XHTML_NS, XHTML, SVG_NS, SVG, XLINK
24
 
from calibre.ebooks.oeb.base import SVG_MIME, PNG_MIME, JPEG_MIME
25
 
from calibre.ebooks.oeb.base import xml2str, xpath, namespace, barename
 
22
from calibre.ebooks.oeb.base import XHTML, XLINK
 
23
from calibre.ebooks.oeb.base import SVG_MIME, PNG_MIME
 
24
from calibre.ebooks.oeb.base import xml2str, xpath
26
25
from calibre.ebooks.oeb.base import urlnormalize
27
26
from calibre.ebooks.oeb.stylizer import Stylizer
28
27
 
34
33
        if QApplication.instance() is None:
35
34
            QApplication([])
36
35
 
37
 
    def transform(self, oeb, context):
 
36
    @classmethod
 
37
    def config(cls, cfg):
 
38
        return cfg
 
39
 
 
40
    @classmethod
 
41
    def generate(cls, opts):
 
42
        return cls()
 
43
 
 
44
    def __call__(self, oeb, context):
38
45
        oeb.logger.info('Rasterizing SVG images...')
39
46
        self.oeb = oeb
40
47
        self.profile = context.dest
80
87
        hrefs = self.oeb.manifest.hrefs
81
88
        for elem in xpath(svg, '//svg:*[@xl:href]'):
82
89
            href = urlnormalize(elem.attrib[XLINK('href')])
83
 
            path, frag = urldefrag(href)
 
90
            path = urldefrag(href)[0]
84
91
            if not path:
85
92
                continue
86
93
            abshref = item.abshref(path)
91
98
            data = "data:%s;base64,%s" % (linkee.media_type, data)
92
99
            elem.attrib[XLINK('href')] = data
93
100
        return svg
94
 
            
 
101
 
95
102
    def rasterize_spine(self):
96
103
        for item in self.oeb.spine:
97
104
            html = item.data
175
182
            elem.text = None
176
183
        for child in elem:
177
184
            elem.remove(child)
178
 
    
 
185
 
179
186
    def rasterize_cover(self):
180
187
        covers = self.oeb.metadata.cover
181
188
        if not covers:
182
189
            return
183
 
        cover = self.oeb.manifest.ids[str(covers[0])]
 
190
        cover = self.oeb.manifest.ids[unicode(covers[0])]
184
191
        if not cover.media_type == SVG_MIME:
185
192
            return
186
193
        width = (self.profile.width / 72) * self.profile.dpi