mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
AZW3 Input: Handle files that use unneccessary svg: prefixes. Fixes #1182257 (Image display issue in Kindle AZW3 file.)
This commit is contained in:
parent
968df1f682
commit
906b541230
@ -100,7 +100,7 @@ def update_flow_links(mobi8_reader, resource_map, log):
|
|||||||
mr = mobi8_reader
|
mr = mobi8_reader
|
||||||
flows = []
|
flows = []
|
||||||
|
|
||||||
img_pattern = re.compile(r'''(<[img\s|image\s][^>]*>)''', re.IGNORECASE)
|
img_pattern = re.compile(r'''(<[img\s|image\s|svg:image\s][^>]*>)''', re.IGNORECASE)
|
||||||
img_index_pattern = re.compile(r'''['"]kindle:embed:([0-9|A-V]+)[^'"]*['"]''', re.IGNORECASE)
|
img_index_pattern = re.compile(r'''['"]kindle:embed:([0-9|A-V]+)[^'"]*['"]''', re.IGNORECASE)
|
||||||
|
|
||||||
tag_pattern = re.compile(r'''(<[^>]*>)''')
|
tag_pattern = re.compile(r'''(<[^>]*>)''')
|
||||||
@ -128,7 +128,7 @@ def update_flow_links(mobi8_reader, resource_map, log):
|
|||||||
srcpieces = img_pattern.split(flow)
|
srcpieces = img_pattern.split(flow)
|
||||||
for j in range(1, len(srcpieces), 2):
|
for j in range(1, len(srcpieces), 2):
|
||||||
tag = srcpieces[j]
|
tag = srcpieces[j]
|
||||||
if tag.startswith('<im'):
|
if tag.startswith('<im') or tag.startswith('<svg:image'):
|
||||||
for m in img_index_pattern.finditer(tag):
|
for m in img_index_pattern.finditer(tag):
|
||||||
num = int(m.group(1), 32)
|
num = int(m.group(1), 32)
|
||||||
href = resource_map[num-1]
|
href = resource_map[num-1]
|
||||||
|
@ -228,7 +228,7 @@ class Mobi8Reader(object):
|
|||||||
|
|
||||||
self.flowinfo.append(FlowInfo(None, None, None, None))
|
self.flowinfo.append(FlowInfo(None, None, None, None))
|
||||||
svg_tag_pattern = re.compile(br'''(<svg[^>]*>)''', re.IGNORECASE)
|
svg_tag_pattern = re.compile(br'''(<svg[^>]*>)''', re.IGNORECASE)
|
||||||
image_tag_pattern = re.compile(br'''(<image[^>]*>)''', re.IGNORECASE)
|
image_tag_pattern = re.compile(br'''(<(?:svg:)?image[^>]*>)''', re.IGNORECASE)
|
||||||
for j in xrange(1, len(self.flows)):
|
for j in xrange(1, len(self.flows)):
|
||||||
flowpart = self.flows[j]
|
flowpart = self.flows[j]
|
||||||
nstr = '%04d' % j
|
nstr = '%04d' % j
|
||||||
@ -243,7 +243,7 @@ class Mobi8Reader(object):
|
|||||||
dir = None
|
dir = None
|
||||||
fname = None
|
fname = None
|
||||||
# strip off anything before <svg if inlining
|
# strip off anything before <svg if inlining
|
||||||
flowpart = flowpart[start:]
|
flowpart = re.sub(br'(</?)svg:', r'\1', flowpart[start:])
|
||||||
else:
|
else:
|
||||||
format = 'file'
|
format = 'file'
|
||||||
dir = "images"
|
dir = "images"
|
||||||
|
@ -11,7 +11,7 @@ import re
|
|||||||
|
|
||||||
from calibre import guess_type
|
from calibre import guess_type
|
||||||
|
|
||||||
class EntityDeclarationProcessor(object): # {{{
|
class EntityDeclarationProcessor(object): # {{{
|
||||||
|
|
||||||
def __init__(self, html):
|
def __init__(self, html):
|
||||||
self.declared_entities = {}
|
self.declared_entities = {}
|
||||||
@ -51,7 +51,7 @@ def load_html(path, view, codec='utf-8', mime_type=None,
|
|||||||
loading_url = QUrl.fromLocalFile(path)
|
loading_url = QUrl.fromLocalFile(path)
|
||||||
pre_load_callback(loading_url)
|
pre_load_callback(loading_url)
|
||||||
|
|
||||||
if force_as_html or re.search(r'<[:a-zA-Z0-9-]*svg', html) is None:
|
if force_as_html or re.search(r'<[a-zA-Z0-9-]+:svg', html) is None:
|
||||||
view.setHtml(html, loading_url)
|
view.setHtml(html, loading_url)
|
||||||
else:
|
else:
|
||||||
view.setContent(QByteArray(html.encode(codec)), mime_type,
|
view.setContent(QByteArray(html.encode(codec)), mime_type,
|
||||||
@ -61,4 +61,3 @@ def load_html(path, view, codec='utf-8', mime_type=None,
|
|||||||
if not elem.isNull():
|
if not elem.isNull():
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user