mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #7003 (Error when converting HTML/ZIP to RTF)
This commit is contained in:
parent
67722fca23
commit
a22dbab0c0
@ -10,13 +10,6 @@ Transform OEB content into RTF markup
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
try:
|
|
||||||
from PIL import Image
|
|
||||||
Image
|
|
||||||
except ImportError:
|
|
||||||
import Image
|
|
||||||
|
|
||||||
import cStringIO
|
import cStringIO
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
@ -26,6 +19,7 @@ from calibre.ebooks.oeb.base import XHTML, XHTML_NS, barename, namespace, \
|
|||||||
from calibre.ebooks.oeb.stylizer import Stylizer
|
from calibre.ebooks.oeb.stylizer import Stylizer
|
||||||
from calibre.ebooks.metadata import authors_to_string
|
from calibre.ebooks.metadata import authors_to_string
|
||||||
from calibre.utils.filenames import ascii_text
|
from calibre.utils.filenames import ascii_text
|
||||||
|
from calibre.utils.magick.draw import save_cover_data_to, identify_data
|
||||||
|
|
||||||
TAGS = {
|
TAGS = {
|
||||||
'b': '\\b',
|
'b': '\\b',
|
||||||
@ -153,10 +147,8 @@ class RTFMLizer(object):
|
|||||||
return text
|
return text
|
||||||
|
|
||||||
def image_to_hexstring(self, data):
|
def image_to_hexstring(self, data):
|
||||||
im = Image.open(cStringIO.StringIO(data))
|
data = save_cover_data_to(data, 'cover.jpg', return_data=True)
|
||||||
data = cStringIO.StringIO()
|
width, height = identify_data(data)[:2]
|
||||||
im.convert('RGB').save(data, 'JPEG')
|
|
||||||
data = data.getvalue()
|
|
||||||
|
|
||||||
raw_hex = ''
|
raw_hex = ''
|
||||||
for char in data:
|
for char in data:
|
||||||
@ -173,7 +165,7 @@ class RTFMLizer(object):
|
|||||||
col += 1
|
col += 1
|
||||||
hex_string += char
|
hex_string += char
|
||||||
|
|
||||||
return (hex_string, im.size[0], im.size[1])
|
return (hex_string, width, height)
|
||||||
|
|
||||||
def clean_text(self, text):
|
def clean_text(self, text):
|
||||||
# Remove excess spaces at beginning and end of lines
|
# Remove excess spaces at beginning and end of lines
|
||||||
|
Loading…
x
Reference in New Issue
Block a user