def test_new_autoshape_sp_generates_correct_xml(self):
     """CT_Shape._new_autoshape_sp() returns correct XML"""
     # setup ------------------------
     id_ = 9
     name = 'Rounded Rectangle 8'
     prst = 'roundRect'
     left, top, width, height = 111, 222, 333, 444
     xml = (
         '<p:sp %s>\n  <p:nvSpPr>\n    <p:cNvPr id="%d" name="%s"/>\n    <'
         'p:cNvSpPr/>\n    <p:nvPr/>\n  </p:nvSpPr>\n  <p:spPr>\n    <a:xf'
         'rm>\n      <a:off x="%d" y="%d"/>\n      <a:ext cx="%d" cy="%d"/'
         '>\n    </a:xfrm>\n    <a:prstGeom prst="%s">\n      <a:avLst/>\n'
         '    </a:prstGeom>\n  </p:spPr>\n  <p:style>\n    <a:lnRef idx="1'
         '">\n      <a:schemeClr val="accent1"/>\n    </a:lnRef>\n    <a:f'
         'illRef idx="3">\n      <a:schemeClr val="accent1"/>\n    </a:fil'
         'lRef>\n    <a:effectRef idx="2">\n      <a:schemeClr val="accent'
         '1"/>\n    </a:effectRef>\n    <a:fontRef idx="minor">\n      <a:'
         'schemeClr val="lt1"/>\n    </a:fontRef>\n  </p:style>\n  <p:txBo'
         'dy>\n    <a:bodyPr rtlCol="0" anchor="ctr"/>\n    <a:lstStyle/>'
         '\n    <a:p>\n      <a:pPr algn="ctr"/>\n    </a:p>\n  </p:txBody'
         '>\n</p:sp>\n' %
         (nsdecls('a', 'p'), id_, name, left, top, width, height, prst)
     )
     # exercise ---------------------
     sp = CT_Shape.new_autoshape_sp(id_, name, prst, left, top,
                                    width, height)
     # verify -----------------------
     self.assertEqualLineByLine(xml, sp)
Exemple #2
0
    def add_shape(self, autoshape_type_id, left, top, width, height):
        """
        Add auto shape of type specified by *autoshape_type_id* (like
        ``MSO.SHAPE_RECTANGLE``) and of specified size at specified position.
        """
        autoshape_type = AutoShapeType(autoshape_type_id)
        id_ = self._next_shape_id
        name = '%s %d' % (autoshape_type.basename, id_-1)

        sp = CT_Shape.new_autoshape_sp(id_, name, autoshape_type.prst,
                                       left, top, width, height)
        shape = Shape(sp, self)

        self._spTree.append(sp)
        self._shapes.append(shape)
        return shape