From c73c00ad0ba2dd9a6b2137c28ea38189bb8dc53a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 4 Jun 2013 16:09:56 +0530 Subject: [PATCH] DOCX: Handle images in v:pict tags --- src/calibre/ebooks/docx/images.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/docx/images.py b/src/calibre/ebooks/docx/images.py index 5cee6a595d..8f6cd3a4a3 100644 --- a/src/calibre/ebooks/docx/images.py +++ b/src/calibre/ebooks/docx/images.py @@ -157,6 +157,17 @@ class Images(object): ans.set('style', '; '.join('%s: %s' % (k, v) for k, v in style.iteritems())) yield ans + def pict_to_html(self, pict, page): + for imagedata in XPath('descendant::v:imagedata[@r:id]')(pict): + rid = get(imagedata, 'r:id') + if rid in self.rid_map: + src = self.generate_filename(rid) + img = IMG(src='images/%s' % src, style="display:block") + alt = get(imagedata, 'o:title') + if alt: + img(alt=alt) + yield img + def get_float_properties(self, anchor, style, page): if 'display' not in style: style['display'] = 'block' @@ -200,6 +211,8 @@ class Images(object): if elem.tag.endswith('}drawing'): for tag in self.drawing_to_html(elem, page): yield tag - # TODO: Handle w:pict + else: + for tag in self.pict_to_html(elem, page): + yield tag