mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
DOCX Input: Add support for SVG images
This commit is contained in:
parent
e0d2c5cfcf
commit
4c4cfb843c
@ -10,7 +10,7 @@ from lxml.html.builder import HR, IMG
|
|||||||
|
|
||||||
from calibre import sanitize_file_name
|
from calibre import sanitize_file_name
|
||||||
from calibre.constants import iswindows
|
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.filenames import ascii_filename
|
||||||
from calibre.utils.img import image_to_data, resize_to_fit
|
from calibre.utils.img import image_to_data, resize_to_fit
|
||||||
from calibre.utils.imghdr import what
|
from calibre.utils.imghdr import what
|
||||||
@ -236,9 +236,12 @@ class Images:
|
|||||||
name = image_filename(name)
|
name = image_filename(name)
|
||||||
alt = pr.get('descr') or alt
|
alt = pr.get('descr') or alt
|
||||||
for a in XPath('descendant::a:blip[@r:embed or @r:link]')(pic):
|
for a in XPath('descendant::a:blip[@r:embed or @r:link]')(pic):
|
||||||
rid = get(a, 'r:embed')
|
rid = get(a, 'r:embed') or get(a, 'r:link')
|
||||||
if not rid:
|
for asvg in XPath(f'./a:extLst/a:ext[@uri="{SVG_BLIP_URI}"]/asvg:svgBlip[@r:embed or @r:link]')(a):
|
||||||
rid = get(a, 'r:link')
|
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:
|
if rid and rid in self.rid_map:
|
||||||
try:
|
try:
|
||||||
src = self.generate_filename(rid, name)
|
src = self.generate_filename(rid, name)
|
||||||
|
@ -63,7 +63,9 @@ TRANSITIONAL_NAMESPACES = {
|
|||||||
'pr': 'http://schemas.openxmlformats.org/package/2006/relationships',
|
'pr': 'http://schemas.openxmlformats.org/package/2006/relationships',
|
||||||
# Dublin Core document properties
|
# Dublin Core document properties
|
||||||
'dcmitype': 'http://purl.org/dc/dcmitype/',
|
'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 = {
|
STRICT_NAMESPACES = {
|
||||||
@ -73,6 +75,7 @@ STRICT_NAMESPACES = {
|
|||||||
'http://schemas.openxmlformats.org/drawingml/2006', 'http://purl.oclc.org/ooxml/drawingml')
|
'http://schemas.openxmlformats.org/drawingml/2006', 'http://purl.oclc.org/ooxml/drawingml')
|
||||||
for k, v in iteritems(TRANSITIONAL_NAMESPACES)
|
for k, v in iteritems(TRANSITIONAL_NAMESPACES)
|
||||||
}
|
}
|
||||||
|
SVG_BLIP_URI = '{96DAC541-7B7A-43D3-8B79-37D633B846F1}'
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user