Skip to content

Commit 6760bea

Browse files
committed
Preserve old behavior for adding non-SVG images
1 parent 8f54818 commit 6760bea

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

docx/oxml/shape.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,21 @@ def new(cls, pic_id, filename, rId, cx, cy):
134134
contents required to define a viable picture element, based on the
135135
values passed as parameters.
136136
"""
137-
pic = parse_xml(cls._pic_xml())
137+
if filename.endswith(".svg"):
138+
pic = parse_xml(cls._pic_xml_svg())
139+
pic.blipFill.blip.extLst.ext.svgBlip.embed = rId
140+
else:
141+
pic = parse_xml(cls._pic_xml())
142+
pic.blipFill.blip.embed = rId
143+
138144
pic.nvPicPr.cNvPr.id = pic_id
139145
pic.nvPicPr.cNvPr.name = filename
140-
pic.blipFill.blip.extLst.ext.svgBlip.embed = rId
141146
pic.spPr.cx = cx
142147
pic.spPr.cy = cy
143148
return pic
144149

145150
@classmethod
146-
def _pic_xml(cls):
151+
def _pic_xml_svg(cls):
147152
return (
148153
'<pic:pic %s>\n'
149154
' <pic:nvPicPr>\n'
@@ -172,6 +177,30 @@ def _pic_xml(cls):
172177
'</pic:pic>' % nsdecls('pic', 'a', 'r', 'asvg')
173178
)
174179

180+
@classmethod
181+
def _pic_xml(cls):
182+
return (
183+
'<pic:pic %s>\n'
184+
' <pic:nvPicPr>\n'
185+
' <pic:cNvPr id="666" name="unnamed"/>\n'
186+
' <pic:cNvPicPr/>\n'
187+
' </pic:nvPicPr>\n'
188+
' <pic:blipFill>\n'
189+
' <a:blip/>\n'
190+
' <a:stretch>\n'
191+
' <a:fillRect/>\n'
192+
' </a:stretch>\n'
193+
' </pic:blipFill>\n'
194+
' <pic:spPr>\n'
195+
' <a:xfrm>\n'
196+
' <a:off x="0" y="0"/>\n'
197+
' <a:ext cx="914400" cy="914400"/>\n'
198+
' </a:xfrm>\n'
199+
' <a:prstGeom prst="rect"/>\n'
200+
' </pic:spPr>\n'
201+
'</pic:pic>' % nsdecls('pic', 'a', 'r', 'asvg')
202+
)
203+
175204

176205
class CT_PictureNonVisual(BaseOxmlElement):
177206
"""

0 commit comments

Comments
 (0)