Esempio n. 1
0
    def it_can_create_a_new_pic_element(self, desc, xml_desc):
        """`desc` attr (often filename) is XML-escaped to handle special characters.

        In particular, ampersand ('&'), less/greater-than ('</>') etc.
        """
        pic = CT_Picture.new_pic(
            shape_id=9, name="Picture 8", desc=desc, rId="rId42", x=1, y=2, cx=3, cy=4
        )

        assert pic.xml == (
            "<p:pic %s>\n"
            "  <p:nvPicPr>\n"
            '    <p:cNvPr id="9" name="Picture 8" descr="%s"/>\n'
            "    <p:cNvPicPr>\n"
            '      <a:picLocks noChangeAspect="1"/>\n'
            "    </p:cNvPicPr>\n"
            "    <p:nvPr/>\n"
            "  </p:nvPicPr>\n"
            "  <p:blipFill>\n"
            '    <a:blip r:embed="rId42"/>\n'
            "    <a:stretch>\n"
            "      <a:fillRect/>\n"
            "    </a:stretch>\n"
            "  </p:blipFill>\n"
            "  <p:spPr>\n"
            "    <a:xfrm>\n"
            '      <a:off x="1" y="2"/>\n'
            '      <a:ext cx="3" cy="4"/>\n'
            "    </a:xfrm>\n"
            '    <a:prstGeom prst="rect">\n'
            "      <a:avLst/>\n"
            "    </a:prstGeom>\n"
            "  </p:spPr>\n"
            "</p:pic>\n" % (nsdecls("a", "p", "r"), xml_desc)
        )
Esempio n. 2
0
 def add_pic(self, id_, name, desc, rId, x, y, cx, cy):
     """
     Append a ``<p:pic>`` shape to the group/shapetree having properties
     as specified in call.
     """
     pic = CT_Picture.new_pic(id_, name, desc, rId, x, y, cx, cy)
     self.insert_element_before(pic, 'p:extLst')
     return pic
Esempio n. 3
0
 def it_can_create_a_new_video_pic_element(self, video_pic_fixture):
     shape_id, shape_name, video_rId, media_rId = video_pic_fixture[:4]
     poster_frame_rId, x, y, cx, cy, expected_xml = video_pic_fixture[4:]
     pic = CT_Picture.new_video_pic(shape_id, shape_name, video_rId,
                                    media_rId, poster_frame_rId, x, y, cx,
                                    cy)
     print(pic.xml)
     assert pic.xml == expected_xml
Esempio n. 4
0
 def _new_placeholder_pic(self, image_file):
     """
     Return a new `p:pic` element depicting the image in *image_file*,
     suitable for use as a placeholder. In particular this means not
     having an `a:xfrm` element, allowing its extents to be inherited from
     its layout placeholder.
     """
     rId, desc, image_size = self._get_or_add_image(image_file)
     shape_id, name = self.shape_id, self.name
     pic = CT_Picture.new_ph_pic(shape_id, name, desc, rId)
     pic.crop_to_fit(image_size, (self.width, self.height))
     return pic
 def _pic(self):
     """Return the new `p:pic` element referencing the video."""
     return CT_Picture.new_video_pic(
         self._shape_id,
         self._shape_name,
         self._video_rId,
         self._media_rId,
         self._poster_frame_rId,
         self._x,
         self._y,
         self._cx,
         self._cy,
     )
Esempio n. 6
0
    def it_can_create_a_new_video_pic_element(self):
        pic = CT_Picture.new_video_pic(
            shape_id=42,
            shape_name="Media 41",
            video_rId="rId1",
            media_rId="rId2",
            poster_frame_rId="rId3",
            x=1,
            y=2,
            cx=3,
            cy=4,
        )

        assert pic.xml == (
            "<p:pic %s>\n"
            "  <p:nvPicPr>\n"
            '    <p:cNvPr id="42" name="Media 41">\n'
            '      <a:hlinkClick r:id="" action="ppaction://media"/>\n'
            "    </p:cNvPr>\n"
            "    <p:cNvPicPr>\n"
            '      <a:picLocks noChangeAspect="1"/>\n'
            "    </p:cNvPicPr>\n"
            "    <p:nvPr>\n"
            '      <a:videoFile r:link="rId1"/>\n'
            "      <p:extLst>\n"
            '        <p:ext uri="{DAA4B4D4-6D71-4841-9C94-3DE7FCFB9230}">\n'
            '          <p14:media xmlns:p14="http://schemas.microsoft.com/office/power'
            'point/2010/main" r:embed="rId2"/>\n'
            "        </p:ext>\n"
            "      </p:extLst>\n"
            "    </p:nvPr>\n"
            "  </p:nvPicPr>\n"
            "  <p:blipFill>\n"
            '    <a:blip r:embed="rId3"/>\n'
            "    <a:stretch>\n"
            "      <a:fillRect/>\n"
            "    </a:stretch>\n"
            "  </p:blipFill>\n"
            "  <p:spPr>\n"
            "    <a:xfrm>\n"
            '      <a:off x="1" y="2"/>\n'
            '      <a:ext cx="3" cy="4"/>\n'
            "    </a:xfrm>\n"
            '    <a:prstGeom prst="rect">\n'
            "      <a:avLst/>\n"
            "    </a:prstGeom>\n"
            "  </p:spPr>\n"
            "</p:pic>\n"
        ) % nsdecls("a", "p", "r")
Esempio n. 7
0
 def test_new_pic_generates_correct_xml(self):
     """CT_Picture.new_pic() returns correct XML"""
     # setup ------------------------
     id_, name, desc, rId = 9, 'Picture 8', 'test-image.png', 'rId7'
     left, top, width, height = 111, 222, 333, 444
     xml = (
         '<p:pic %s>\n  <p:nvPicPr>\n    <p:cNvPr id="%d" name="%s" descr='
         '"%s"/>\n    <p:cNvPicPr>\n      <a:picLocks noChangeAspect="1"/>'
         '\n    </p:cNvPicPr>\n    <p:nvPr/>\n  </p:nvPicPr>\n  <p:blipFil'
         'l>\n    <a:blip r:embed="%s"/>\n    <a:stretch>\n      <a:fillRe'
         'ct/>\n    </a:stretch>\n  </p:blipFill>\n  <p:spPr>\n    <a:xfrm'
         '>\n      <a:off x="%d" y="%d"/>\n      <a:ext cx="%d" cy="%d"/>'
         '\n    </a:xfrm>\n    <a:prstGeom prst="rect">\n      <a:avLst/>'
         '\n    </a:prstGeom>\n  </p:spPr>\n</p:pic>\n' %
         (nsdecls('a', 'p',
                  'r'), id_, name, desc, rId, left, top, width, height))
     # exercise ---------------------
     pic = CT_Picture.new_pic(id_, name, desc, rId, left, top, width,
                              height)
     # verify -----------------------
     assert pic.xml == xml
Esempio n. 8
0
 def it_can_generate_a_new_pic_element(self, new_fixture):
     id_, name, desc, rId, x, y, cx, cy, expected_xml = new_fixture
     pic = CT_Picture.new_pic(id_, name, desc, rId, x, y, cx, cy)
     print(expected_xml)
     assert pic.xml == expected_xml
Esempio n. 9
0
 def it_can_create_a_new_pic_element(self, pic_fixture):
     shape_id, name, desc, rId, x, y, cx, cy, expected_xml = pic_fixture
     pic = CT_Picture.new_pic(shape_id, name, desc, rId, x, y, cx, cy)
     assert pic.xml == expected_xml