mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
RTF Output: Fix a regression that slowed down conversion. Fixes #1857732 [RTF Conversion Failure](https://bugs.launchpad.net/calibre/+bug/1857732)
This commit is contained in:
parent
c4afe06792
commit
4c2d255d86
@ -12,6 +12,7 @@ Transform OEB content into RTF markup
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import io
|
import io
|
||||||
|
from binascii import hexlify
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
|
||||||
@ -184,24 +185,14 @@ class RTFMLizer(object):
|
|||||||
return text
|
return text
|
||||||
|
|
||||||
def image_to_hexstring(self, data):
|
def image_to_hexstring(self, data):
|
||||||
|
# Images must be hex-encoded in 128 character lines
|
||||||
data = save_cover_data_to(data)
|
data = save_cover_data_to(data)
|
||||||
width, height = identify(data)[1:]
|
width, height = identify(data)[1:]
|
||||||
|
lines = []
|
||||||
raw_hex = ''
|
v = memoryview(data)
|
||||||
for char in bytearray(data):
|
for i in range(0, len(data), 64):
|
||||||
raw_hex += hex(char).replace('0x', '').rjust(2, '0')
|
lines.append(hexlify(v[i:i+64]))
|
||||||
|
hex_string = b'\n'.join(lines).decode('ascii')
|
||||||
# Images must be broken up so that they are no longer than 129 chars
|
|
||||||
# per line
|
|
||||||
hex_string = ''
|
|
||||||
col = 1
|
|
||||||
for char in raw_hex:
|
|
||||||
if col == 129:
|
|
||||||
hex_string += '\n'
|
|
||||||
col = 1
|
|
||||||
col += 1
|
|
||||||
hex_string += char
|
|
||||||
|
|
||||||
return hex_string, width, height
|
return hex_string, width, height
|
||||||
|
|
||||||
def clean_text(self, text):
|
def clean_text(self, text):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user