Skip to content

Commit ab10d61

Browse files
mhasanshahidProgi1984
authored andcommitted
createAutoShape : Add method to create geometric shapes
1 parent d16456d commit ab10d61

File tree

6 files changed

+56
-9
lines changed

6 files changed

+56
-9
lines changed

docs/changes/1.2.0.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Group Shape: moving the shape now moves all contained shapes. Offsets and size are calculated based on the contained shapes by [@DennisBirkholz](https://github.com/DennisBirkholz) in [#690](https://github.com/PHPOffice/PHPPresentation/pull/690)
99
- Added support for PHP 8.4 by [@Progi1984](https://github.com/Progi1984) in [#839](https://github.com/PHPOffice/PHPPresentation/pull/839)
1010
- `phpoffice/phpspreadsheet`: Allow version 3.0 by [@Progi1984](https://github.com/Progi1984) fixing [#836](https://github.com/PHPOffice/PHPPresentation/pull/836) in [#839](https://github.com/PHPOffice/PHPPresentation/pull/839)
11+
- `createAutoShape` : Add method to create geometric shapes by [@mhasanshahid](https://github.com/mhasanshahid) & [@Progi1984](https://github.com/Progi1984) in [#848](https://github.com/PHPOffice/PHPPresentation/pull/848)
1112

1213
## Bug fixes
1314

docs/usage/shapes/autoshape.md

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ $shape = new AutoShape();
1414
$slide->addShape($shape)
1515
```
1616

17+
Or we can use `createAutoShape` method of slide.
18+
19+
Example:
20+
21+
```php
22+
$slide->createAutoShape();
23+
```
24+
1725
## Text
1826

1927
You can define text of the geometric form with `setText` method.

src/PhpPresentation/Shape/Group.php

+11
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,17 @@ public function createLineShape(int $fromX, int $fromY, int $toX, int $toY): Lin
194194
return $shape;
195195
}
196196

197+
/**
198+
* Create geometric shape.
199+
*/
200+
public function createAutoShape(): AutoShape
201+
{
202+
$shape = new AutoShape();
203+
$this->addShape($shape);
204+
205+
return $shape;
206+
}
207+
197208
/**
198209
* Create chart shape.
199210
*/

src/PhpPresentation/Slide/AbstractSlide.php

+12
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use PhpOffice\PhpPresentation\ComparableInterface;
2424
use PhpOffice\PhpPresentation\GeometryCalculator;
2525
use PhpOffice\PhpPresentation\PhpPresentation;
26+
use PhpOffice\PhpPresentation\Shape\AutoShape;
2627
use PhpOffice\PhpPresentation\Shape\Chart;
2728
use PhpOffice\PhpPresentation\Shape\Drawing\File;
2829
use PhpOffice\PhpPresentation\Shape\Group;
@@ -225,6 +226,17 @@ public function createLineShape(int $fromX, int $fromY, int $toX, int $toY): Lin
225226
return $shape;
226227
}
227228

229+
/**
230+
* Create geometric shape.
231+
*/
232+
public function createAutoShape(): AutoShape
233+
{
234+
$shape = new AutoShape();
235+
$this->addShape($shape);
236+
237+
return $shape;
238+
}
239+
228240
/**
229241
* Create chart shape.
230242
*/

tests/PhpPresentation/Tests/Shape/GroupTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ public function testAdd(): void
4848
{
4949
$object = new Group();
5050

51+
self::assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\AutoShape', $object->createAutoShape());
5152
self::assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart', $object->createChartShape());
5253
self::assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Drawing\\File', $object->createDrawingShape());
5354
self::assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Line', $object->createLineShape(10, 10, 10, 10));
5455
self::assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->createRichTextShape());
5556
self::assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Table', $object->createTableShape());
56-
self::assertCount(5, $object->getShapeCollection());
57+
self::assertCount(6, $object->getShapeCollection());
5758
}
5859

5960
public function testExtentX(): void

tests/PhpPresentation/Tests/Slide/AbstractSlideTest.php

+22-8
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,36 @@ class AbstractSlideTest extends TestCase
3535
{
3636
public function testCollection(): void
3737
{
38-
/** @var AbstractSlide $stub */
39-
$stub = $this->getMockForAbstractClass(AbstractSlide::class);
38+
/** @var AbstractSlide $object */
39+
$object = $this->getMockForAbstractClass(AbstractSlide::class);
4040

4141
$array = [];
42-
self::assertInstanceOf(AbstractSlide::class, $stub->setShapeCollection($array));
43-
self::assertIsArray($stub->getShapeCollection());
44-
self::assertCount(count($array), $stub->getShapeCollection());
42+
self::assertInstanceOf(AbstractSlide::class, $object->setShapeCollection($array));
43+
self::assertIsArray($object->getShapeCollection());
44+
self::assertCount(count($array), $object->getShapeCollection());
4545

4646
$array = [
4747
new RichText(),
4848
new RichText(),
4949
new RichText(),
5050
];
51-
self::assertInstanceOf(AbstractSlide::class, $stub->setShapeCollection($array));
52-
self::assertIsArray($stub->getShapeCollection());
53-
self::assertCount(count($array), $stub->getShapeCollection());
51+
self::assertInstanceOf(AbstractSlide::class, $object->setShapeCollection($array));
52+
self::assertIsArray($object->getShapeCollection());
53+
self::assertCount(count($array), $object->getShapeCollection());
54+
}
55+
56+
public function testAdd(): void
57+
{
58+
/** @var AbstractSlide $stub */
59+
$object = $this->getMockForAbstractClass(AbstractSlide::class);
60+
61+
self::assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\AutoShape', $object->createAutoShape());
62+
self::assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Chart', $object->createChartShape());
63+
self::assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Drawing\\File', $object->createDrawingShape());
64+
self::assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Line', $object->createLineShape(10, 10, 10, 10));
65+
self::assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\RichText', $object->createRichTextShape());
66+
self::assertInstanceOf('PhpOffice\\PhpPresentation\\Shape\\Table', $object->createTableShape());
67+
self::assertCount(6, $object->getShapeCollection());
5468
}
5569

5670
public function testSearchShapes(): void

0 commit comments

Comments
 (0)