Skip to content

Commit a284dee

Browse files
committed
ole: add _OleObjectElementCreator._icon_height
1 parent 46151d5 commit a284dee

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-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, imgW
196+
cls, id_, name, ole_object_rId, progId, icon_rId, x, y, cx, cy, imgW, imgH
197197
):
198198
"""Return newly-created `<p:graphicFrame>` for embedded OLE-object.
199199

pptx/shapes/shapetree.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,7 @@ def _graphicFrame(self):
10881088
self._cx,
10891089
self._cy,
10901090
self._icon_width,
1091+
self._icon_height,
10911092
)
10921093

10931094
@lazyproperty
@@ -1120,6 +1121,21 @@ def _cy(self):
11201121
else Emu(609600)
11211122
)
11221123

1124+
@lazyproperty
1125+
def _icon_height(self):
1126+
"""Vertical size of enclosed EMF icon within the OLE graphic-frame.
1127+
1128+
This must be specified when a custom icon is used, to avoid stretching of the
1129+
image and possible undesired resizing by PowerPoint when the OLE shape is
1130+
double-clicked to open it.
1131+
1132+
The correct size can be determined by creating an example PPTX using PowerPoint
1133+
and then inspecting the XML of the OLE graphics-frame (p:oleObj.imgH).
1134+
"""
1135+
return (
1136+
self._icon_height_arg if self._icon_height_arg is not None else Emu(609600)
1137+
)
1138+
11231139
@lazyproperty
11241140
def _icon_image_file(self):
11251141
"""Reference to image file containing icon to show in lieu of this object.

tests/shapes/test_shapetree.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,6 +2246,16 @@ def it_determines_the_shape_height_to_help(self, cy_arg, prog_id, expected_value
22462246
)
22472247
assert element_creator._cy == expected_value
22482248

2249+
@pytest.mark.parametrize(
2250+
"icon_height_arg, expected_value",
2251+
((Emu(666666), Emu(666666)), (None, Emu(609600)),),
2252+
)
2253+
def it_determines_the_icon_height_to_help(self, icon_height_arg, expected_value):
2254+
element_creator = _OleObjectElementCreator(
2255+
None, None, None, None, None, None, None, None, None, None, icon_height_arg
2256+
)
2257+
assert element_creator._icon_height == expected_value
2258+
22492259
@pytest.mark.parametrize(
22502260
"icon_file_arg, prog_id, expected_value",
22512261
(

0 commit comments

Comments
 (0)