Skip to content

Commit 46151d5

Browse files
committed
ole: add _OleObjectElementCreator._icon_width
1 parent 407627d commit 46151d5

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

pptx/oxml/shapes/graphfrm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def new_graphicFrame(cls, id_, name, x, y, cx, cy):
193193

194194
@classmethod
195195
def new_ole_object_graphicFrame(
196-
cls, id_, name, ole_object_rId, progId, icon_rId, x, y, cx, cy
196+
cls, id_, name, ole_object_rId, progId, icon_rId, x, y, cx, cy, imgW
197197
):
198198
"""Return newly-created `<p:graphicFrame>` for embedded OLE-object.
199199

pptx/shapes/shapetree.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,7 @@ def _graphicFrame(self):
10871087
self._y,
10881088
self._cx,
10891089
self._cy,
1090+
self._icon_width,
10901091
)
10911092

10921093
@lazyproperty
@@ -1146,6 +1147,16 @@ def _icon_rId(self):
11461147
_, rId = self._slide_part.get_or_add_image_part(self._icon_image_file)
11471148
return rId
11481149

1150+
@lazyproperty
1151+
def _icon_width(self):
1152+
"""Width of enclosed EMF icon within the OLE graphic-frame.
1153+
1154+
This must be specified when a custom icon is used, to avoid stretching of the
1155+
image and possible undesired resizing by PowerPoint when the OLE shape is
1156+
double-clicked to open it.
1157+
"""
1158+
return self._icon_width_arg if self._icon_width_arg is not None else Emu(965200)
1159+
11491160
@lazyproperty
11501161
def _ole_object_rId(self):
11511162
"""str rId like "rId6" of relationship to embedded ole_object part.

tests/shapes/test_shapetree.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2284,6 +2284,16 @@ def it_adds_and_relates_the_icon_image_part_to_help(
22842284
slide_part_.get_or_add_image_part.assert_called_once_with("obj-icon.emf")
22852285
assert rId == "rId16"
22862286

2287+
@pytest.mark.parametrize(
2288+
"icon_width_arg, expected_value",
2289+
((Emu(666666), Emu(666666)), (None, Emu(965200))),
2290+
)
2291+
def it_determines_the_icon_width_to_help(self, icon_width_arg, expected_value):
2292+
element_creator = _OleObjectElementCreator(
2293+
None, None, None, None, None, None, None, None, None, icon_width_arg, None
2294+
)
2295+
assert element_creator._icon_width == expected_value
2296+
22872297
def it_adds_and_relates_the_ole_object_part_to_help(
22882298
self, request, _slide_part_prop_, slide_part_
22892299
):

0 commit comments

Comments
 (0)