From 4c4cfb843c5114cf28adefc6d30cf8e86bb30941 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 9 Jun 2023 09:23:41 +0530 Subject: [PATCH] DOCX Input: Add support for SVG images --- src/calibre/ebooks/docx/images.py | 11 +++++++---- src/calibre/ebooks/docx/names.py | 5 ++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/calibre/ebooks/docx/images.py b/src/calibre/ebooks/docx/images.py index ac00d1d371..c8e1694b94 100644 --- a/src/calibre/ebooks/docx/images.py +++ b/src/calibre/ebooks/docx/images.py @@ -10,7 +10,7 @@ from lxml.html.builder import HR, IMG from calibre import sanitize_file_name from calibre.constants import iswindows -from calibre.ebooks.docx.names import barename +from calibre.ebooks.docx.names import SVG_BLIP_URI, barename from calibre.utils.filenames import ascii_filename from calibre.utils.img import image_to_data, resize_to_fit from calibre.utils.imghdr import what @@ -236,9 +236,12 @@ class Images: name = image_filename(name) alt = pr.get('descr') or alt for a in XPath('descendant::a:blip[@r:embed or @r:link]')(pic): - rid = get(a, 'r:embed') - if not rid: - rid = get(a, 'r:link') + rid = get(a, 'r:embed') or get(a, 'r:link') + for asvg in XPath(f'./a:extLst/a:ext[@uri="{SVG_BLIP_URI}"]/asvg:svgBlip[@r:embed or @r:link]')(a): + svg_rid = get(asvg, 'r:embed') or get(asvg, 'r:link') + if svg_rid and svg_rid in self.rid_map: + rid = svg_rid + break if rid and rid in self.rid_map: try: src = self.generate_filename(rid, name) diff --git a/src/calibre/ebooks/docx/names.py b/src/calibre/ebooks/docx/names.py index f045efcef6..6124eb3941 100644 --- a/src/calibre/ebooks/docx/names.py +++ b/src/calibre/ebooks/docx/names.py @@ -63,7 +63,9 @@ TRANSITIONAL_NAMESPACES = { 'pr': 'http://schemas.openxmlformats.org/package/2006/relationships', # Dublin Core document properties 'dcmitype': 'http://purl.org/dc/dcmitype/', - 'dcterms': 'http://purl.org/dc/terms/' + 'dcterms': 'http://purl.org/dc/terms/', + # SVG embeds + 'asvg': 'http://schemas.microsoft.com/office/drawing/2016/SVG/main', } STRICT_NAMESPACES = { @@ -73,6 +75,7 @@ STRICT_NAMESPACES = { 'http://schemas.openxmlformats.org/drawingml/2006', 'http://purl.oclc.org/ooxml/drawingml') for k, v in iteritems(TRANSITIONAL_NAMESPACES) } +SVG_BLIP_URI = '{96DAC541-7B7A-43D3-8B79-37D633B846F1}' # }}}