mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
RTF Input: Add option to ignore WMF images
RTF Input: Add option to ignore WMF images iinstead of replacing them with a placeholder. Fixes #1213599 [RTF input conversion creates too large an image when failing to convert .wmf file](https://bugs.launchpad.net/calibre/+bug/1213599)
This commit is contained in:
parent
6c7ff4e4e6
commit
079c685f1a
@ -4,7 +4,7 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import os, glob, re, textwrap
|
||||
|
||||
from calibre.customize.conversion import InputFormatPlugin
|
||||
from calibre.customize.conversion import InputFormatPlugin, OptionRecommendation
|
||||
|
||||
border_style_map = {
|
||||
'single' : 'solid',
|
||||
@ -45,6 +45,11 @@ class RTFInput(InputFormatPlugin):
|
||||
description = 'Convert RTF files to HTML'
|
||||
file_types = set(['rtf'])
|
||||
|
||||
options = {
|
||||
OptionRecommendation(name='ignore_wmf', recommended_value=False,
|
||||
help=_('Ignore WMF images instead of replacing them with a placeholder image.')),
|
||||
}
|
||||
|
||||
def generate_xml(self, stream):
|
||||
from calibre.ebooks.rtf2xml.ParseRtf import ParseRtf
|
||||
ofile = u'dataxml.xml'
|
||||
@ -156,6 +161,9 @@ class RTFInput(InputFormatPlugin):
|
||||
return self.replace_wmf(name)
|
||||
|
||||
def replace_wmf(self, name):
|
||||
if self.opts.ignore_wmf:
|
||||
os.remove(name)
|
||||
return '__REMOVE_ME__'
|
||||
from calibre.ebooks import calibre_cover
|
||||
if self.default_img is None:
|
||||
self.default_img = calibre_cover('Conversion of WMF images is not supported',
|
||||
@ -177,7 +185,6 @@ class RTFInput(InputFormatPlugin):
|
||||
f.write(data)
|
||||
return name
|
||||
|
||||
|
||||
def write_inline_css(self, ic, border_styles):
|
||||
font_size_classes = ['span.fs%d { font-size: %spt }'%(i, x) for i, x in
|
||||
enumerate(ic.font_sizes)]
|
||||
@ -300,4 +307,15 @@ class RTFInput(InputFormatPlugin):
|
||||
opf.render(open(u'metadata.opf', 'wb'))
|
||||
return os.path.abspath(u'metadata.opf')
|
||||
|
||||
def postprocess_book(self, oeb, opts, log):
|
||||
for item in oeb.spine:
|
||||
for img in item.data.xpath('//*[local-name()="img" and @src="__REMOVE_ME__"]'):
|
||||
p = img.getparent()
|
||||
idx = p.index(img)
|
||||
p.remove(img)
|
||||
if img.tail:
|
||||
if idx == 0:
|
||||
p.text = (p.text or '') + img.tail
|
||||
else:
|
||||
p[idx-1].tail = (p[idx-1].tail or '') + img.tail
|
||||
|
||||
|
23
src/calibre/gui2/convert/rtf_input.py
Normal file
23
src/calibre/gui2/convert/rtf_input.py
Normal file
@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=utf-8
|
||||
from __future__ import (unicode_literals, division, absolute_import,
|
||||
print_function)
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
from calibre.gui2.convert.rtf_input_ui import Ui_Form
|
||||
from calibre.gui2.convert import Widget
|
||||
|
||||
class PluginWidget(Widget, Ui_Form):
|
||||
|
||||
TITLE = _('RTF Input')
|
||||
HELP = _('Options specific to')+' RTF '+_('input')
|
||||
COMMIT_NAME = 'rtf_input'
|
||||
ICON = I('mimetypes/rtf.png')
|
||||
|
||||
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
|
||||
Widget.__init__(self, parent,
|
||||
['ignore_wmf', ])
|
||||
self.initialize_options(get_option, get_help, db, book_id)
|
||||
|
41
src/calibre/gui2/convert/rtf_input.ui
Normal file
41
src/calibre/gui2/convert/rtf_input.ui
Normal file
@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Form</class>
|
||||
<widget class="QWidget" name="Form">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>518</width>
|
||||
<height>353</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="opt_ignore_wmf">
|
||||
<property name="text">
|
||||
<string>Ignore &WMF images in the RTF file</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>213</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
x
Reference in New Issue
Block a user