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

« back to all changes in this revision

Viewing changes to src/calibre/ebooks/mobi/mobiml.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:
49
49
 
50
50
class FormatState(object):
51
51
    def __init__(self):
 
52
        self.rendered = False
52
53
        self.left = 0.
53
54
        self.halign = 'auto'
54
55
        self.indent = 0.
59
60
        self.bold = False
60
61
        self.preserve = False
61
62
        self.family = 'serif'
 
63
        self.bgcolor = 'transparent'
62
64
        self.href = None
63
65
        self.list_num = 0
64
66
        self.attrib = {}
70
72
               and self.href == other.href \
71
73
               and self.valign == other.valign \
72
74
               and self.preserve == other.preserve \
73
 
               and self.family == other.family
 
75
               and self.family == other.family \
 
76
               and self.bgcolor == other.bgcolor
74
77
 
75
78
    def __ne__(self, other):
76
79
        return not self.__eq__(other)
80
83
    def __init__(self, ignore_tables=False):
81
84
        self.ignore_tables = ignore_tables
82
85
 
83
 
    def transform(self, oeb, context):
 
86
    def __call__(self, oeb, context):
84
87
        oeb.logger.info('Converting XHTML to Mobipocket markup...')
85
88
        self.oeb = oeb
86
89
        self.profile = profile = context.dest
103
106
                self.oeb.manifest.remove(item)
104
107
 
105
108
    def mobimlize_spine(self):
 
109
        'Iterate over the spine and convert it to MOBIML'
106
110
        for item in self.oeb.spine:
107
111
            stylizer = Stylizer(item.data, item.href, self.oeb, self.profile)
108
112
            body = item.data.find(XHTML('body'))
136
140
        return result
137
141
 
138
142
    def mobimlize_content(self, tag, text, bstate, istates):
 
143
        'Convert text content'
139
144
        if text or tag != 'br':
140
145
            bstate.content = True
141
146
        istate = istates[-1]
157
162
                indent = 0
158
163
            elif indent != 0 and abs(indent) < self.profile.fbase:
159
164
                indent = (indent / abs(indent)) * self.profile.fbase
160
 
            if tag in NESTABLE_TAGS:
 
165
            if tag in NESTABLE_TAGS and not istate.rendered:
161
166
                para = wrapper = etree.SubElement(
162
167
                    parent, XHTML(tag), attrib=istate.attrib)
163
168
                bstate.nested.append(para)
164
169
                if tag == 'li' and len(istates) > 1:
165
170
                    istates[-2].list_num += 1
166
171
                    para.attrib['value'] = str(istates[-2].list_num)
 
172
            elif tag in NESTABLE_TAGS and istate.rendered:
 
173
                para = wrapper = bstate.nested[-1]
167
174
            elif left > 0 and indent >= 0:
168
175
                para = wrapper = etree.SubElement(parent, XHTML('blockquote'))
169
176
                para = wrapper
187
194
                    vspace -= 1
188
195
            if istate.halign != 'auto' and isinstance(istate.halign, (str, unicode)):
189
196
                para.attrib['align'] = istate.halign
 
197
        istate.rendered = True
190
198
        pstate = bstate.istate
191
199
        if tag in CONTENT_TAGS:
192
200
            bstate.inline = para
226
234
                inline = etree.SubElement(inline, XHTML('i'))
227
235
            if istate.bold:
228
236
                inline = etree.SubElement(inline, XHTML('b'))
 
237
            if istate.bgcolor is not None and istate.bgcolor != 'transparent' :
 
238
                inline = etree.SubElement(inline, XHTML('span'),
 
239
                        bgcolor=istate.bgcolor)
229
240
            bstate.inline = inline
230
241
        bstate.istate = istate
231
242
        inline = bstate.inline
251
262
            return
252
263
        tag = barename(elem.tag)
253
264
        istate = copy.copy(istates[-1])
 
265
        istate.rendered = False
254
266
        istate.list_num = 0
255
267
        istates.append(istate)
256
268
        left = 0
301
313
        weight = style['font-weight']
302
314
        istate.bold = weight in ('bold', 'bolder') or asfloat(weight) > 400
303
315
        istate.preserve = (style['white-space'] in ('pre', 'pre-wrap'))
 
316
        istate.bgcolor  = style['background-color']
304
317
        if 'monospace' in style['font-family']:
305
318
            istate.family = 'monospace'
306
319
        elif 'sans-serif' in style['font-family']: