Skip to content

Commit 63748d8

Browse files
committed
Fixed some duplicate code
1 parent 350fd46 commit 63748d8

File tree

3 files changed

+148
-572
lines changed

3 files changed

+148
-572
lines changed

src/PhpPresentation/Writer/PowerPoint2007/AbstractSlide.php

Lines changed: 82 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -193,82 +193,84 @@ protected function writeShapeText(XMLWriter $objWriter, RichText $shape, $shapeI
193193
$objWriter->endElement();
194194
// p:sp\p:spPr
195195
$objWriter->startElement('p:spPr');
196-
// p:sp\p:spPr\a:xfrm
197-
$objWriter->startElement('a:xfrm');
198-
$objWriter->writeAttributeIf($shape->getRotation() != 0, 'rot', CommonDrawing::degreesToAngle($shape->getRotation()));
199-
// p:sp\p:spPr\a:xfrm\a:off
200-
$objWriter->startElement('a:off');
201-
$objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($shape->getOffsetX()));
202-
$objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($shape->getOffsetY()));
203-
$objWriter->endElement();
204-
// p:sp\p:spPr\a:xfrm\a:ext
205-
$objWriter->startElement('a:ext');
206-
$objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($shape->getWidth()));
207-
$objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($shape->getHeight()));
208-
$objWriter->endElement();
209-
// > p:sp\p:spPr\a:xfrm
210-
$objWriter->endElement();
211-
// p:sp\p:spPr\a:prstGeom
212-
$objWriter->startElement('a:prstGeom');
213-
$objWriter->writeAttribute('prst', 'rect');
214196

215-
// p:sp\p:spPr\a:prstGeom\a:avLst
216-
$objWriter->writeElement('a:avLst');
197+
if (!$shape->isPlaceholder()) {
198+
// p:sp\p:spPr\a:xfrm
199+
$objWriter->startElement('a:xfrm');
200+
$objWriter->writeAttributeIf($shape->getRotation() != 0, 'rot', CommonDrawing::degreesToAngle($shape->getRotation()));
201+
// p:sp\p:spPr\a:xfrm\a:off
202+
$objWriter->startElement('a:off');
203+
$objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($shape->getOffsetX()));
204+
$objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($shape->getOffsetY()));
205+
$objWriter->endElement();
206+
// p:sp\p:spPr\a:xfrm\a:ext
207+
$objWriter->startElement('a:ext');
208+
$objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($shape->getWidth()));
209+
$objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($shape->getHeight()));
210+
$objWriter->endElement();
211+
// > p:sp\p:spPr\a:xfrm
212+
$objWriter->endElement();
213+
// p:sp\p:spPr\a:prstGeom
214+
$objWriter->startElement('a:prstGeom');
215+
$objWriter->writeAttribute('prst', 'rect');
217216

218-
$objWriter->endElement();
219-
$this->writeFill($objWriter, $shape->getFill());
220-
if ($shape->getBorder()->getLineStyle() != Border::LINE_NONE) {
221-
$this->writeBorder($objWriter, $shape->getBorder(), '');
222-
}
223-
if ($shape->getShadow()->isVisible()) {
224-
$this->writeShadow($objWriter, $shape->getShadow());
217+
// p:sp\p:spPr\a:prstGeom\a:avLst
218+
$objWriter->writeElement('a:avLst');
219+
220+
$objWriter->endElement();
225221
}
222+
$this->writeFill($objWriter, $shape->getFill());
223+
$this->writeBorder($objWriter, $shape->getBorder(), '');
224+
$this->writeShadow($objWriter, $shape->getShadow());
225+
226226
// > p:sp\p:spPr
227227
$objWriter->endElement();
228228
// p:txBody
229229
$objWriter->startElement('p:txBody');
230230
// a:bodyPr
231231
//@link :http://msdn.microsoft.com/en-us/library/documentformat.openxml.drawing.bodyproperties%28v=office.14%29.aspx
232232
$objWriter->startElement('a:bodyPr');
233-
$verticalAlign = $shape->getActiveParagraph()->getAlignment()->getVertical();
234-
if ($verticalAlign != Alignment::VERTICAL_BASE && $verticalAlign != Alignment::VERTICAL_AUTO) {
235-
$objWriter->writeAttribute('anchor', $verticalAlign);
236-
}
237-
if ($shape->getWrap() != RichText::WRAP_SQUARE) {
238-
$objWriter->writeAttribute('wrap', $shape->getWrap());
239-
}
240-
$objWriter->writeAttribute('rtlCol', '0');
241-
if ($shape->getHorizontalOverflow() != RichText::OVERFLOW_OVERFLOW) {
242-
$objWriter->writeAttribute('horzOverflow', $shape->getHorizontalOverflow());
243-
}
244-
if ($shape->getVerticalOverflow() != RichText::OVERFLOW_OVERFLOW) {
245-
$objWriter->writeAttribute('vertOverflow', $shape->getVerticalOverflow());
246-
}
247-
if ($shape->isUpright()) {
248-
$objWriter->writeAttribute('upright', '1');
249-
}
250-
if ($shape->isVertical()) {
251-
$objWriter->writeAttribute('vert', 'vert');
252-
}
253-
$objWriter->writeAttribute('bIns', CommonDrawing::pixelsToEmu($shape->getInsetBottom()));
254-
$objWriter->writeAttribute('lIns', CommonDrawing::pixelsToEmu($shape->getInsetLeft()));
255-
$objWriter->writeAttribute('rIns', CommonDrawing::pixelsToEmu($shape->getInsetRight()));
256-
$objWriter->writeAttribute('tIns', CommonDrawing::pixelsToEmu($shape->getInsetTop()));
257-
if ($shape->getColumns() <> 1) {
258-
$objWriter->writeAttribute('numCol', $shape->getColumns());
259-
}
260-
// a:spAutoFit
261-
$objWriter->startElement('a:' . $shape->getAutoFit());
262-
if ($shape->getAutoFit() == RichText::AUTOFIT_NORMAL) {
263-
if (!is_null($shape->getFontScale())) {
264-
$objWriter->writeAttribute('fontScale', (int)($shape->getFontScale() * 1000));
233+
if (!$shape->isPlaceholder()) {
234+
$verticalAlign = $shape->getActiveParagraph()->getAlignment()->getVertical();
235+
if ($verticalAlign != Alignment::VERTICAL_BASE && $verticalAlign != Alignment::VERTICAL_AUTO) {
236+
$objWriter->writeAttribute('anchor', $verticalAlign);
237+
}
238+
if ($shape->getWrap() != RichText::WRAP_SQUARE) {
239+
$objWriter->writeAttribute('wrap', $shape->getWrap());
240+
}
241+
$objWriter->writeAttribute('rtlCol', '0');
242+
if ($shape->getHorizontalOverflow() != RichText::OVERFLOW_OVERFLOW) {
243+
$objWriter->writeAttribute('horzOverflow', $shape->getHorizontalOverflow());
244+
}
245+
if ($shape->getVerticalOverflow() != RichText::OVERFLOW_OVERFLOW) {
246+
$objWriter->writeAttribute('vertOverflow', $shape->getVerticalOverflow());
247+
}
248+
if ($shape->isUpright()) {
249+
$objWriter->writeAttribute('upright', '1');
265250
}
266-
if (!is_null($shape->getLineSpaceReduction())) {
267-
$objWriter->writeAttribute('lnSpcReduction', (int)($shape->getLineSpaceReduction() * 1000));
251+
if ($shape->isVertical()) {
252+
$objWriter->writeAttribute('vert', 'vert');
268253
}
254+
$objWriter->writeAttribute('bIns', CommonDrawing::pixelsToEmu($shape->getInsetBottom()));
255+
$objWriter->writeAttribute('lIns', CommonDrawing::pixelsToEmu($shape->getInsetLeft()));
256+
$objWriter->writeAttribute('rIns', CommonDrawing::pixelsToEmu($shape->getInsetRight()));
257+
$objWriter->writeAttribute('tIns', CommonDrawing::pixelsToEmu($shape->getInsetTop()));
258+
if ($shape->getColumns() <> 1) {
259+
$objWriter->writeAttribute('numCol', $shape->getColumns());
260+
}
261+
// a:spAutoFit
262+
$objWriter->startElement('a:' . $shape->getAutoFit());
263+
if ($shape->getAutoFit() == RichText::AUTOFIT_NORMAL) {
264+
if (!is_null($shape->getFontScale())) {
265+
$objWriter->writeAttribute('fontScale', (int)($shape->getFontScale() * 1000));
266+
}
267+
if (!is_null($shape->getLineSpaceReduction())) {
268+
$objWriter->writeAttribute('lnSpcReduction', (int)($shape->getLineSpaceReduction() * 1000));
269+
}
270+
}
271+
$objWriter->endElement();
269272
}
270273
$objWriter->endElement();
271-
$objWriter->endElement();
272274
// a:lstStyle
273275
$objWriter->writeElement('a:lstStyle', null);
274276
if ($shape->isPlaceholder() &&
@@ -642,7 +644,13 @@ protected function writeShapeLine(XMLWriter $objWriter, Line $shape, $shapeId)
642644
// p:cNvCxnSpPr
643645
$objWriter->writeElement('p:cNvCxnSpPr', null);
644646
// p:nvPr
645-
$objWriter->writeElement('p:nvPr', null);
647+
$objWriter->startElement('p:nvPr');
648+
if ($shape->isPlaceholder()) {
649+
$objWriter->startElement('p:ph');
650+
$objWriter->writeAttribute('type', $shape->getPlaceholder()->getType());
651+
$objWriter->endElement();
652+
}
653+
$objWriter->endElement();
646654
$objWriter->endElement();
647655
// p:spPr
648656
$objWriter->startElement('p:spPr');
@@ -704,9 +712,7 @@ protected function writeShapeLine(XMLWriter $objWriter, Line $shape, $shapeId)
704712
$objWriter->writeElement('a:avLst');
705713

706714
$objWriter->endElement();
707-
if ($shape->getBorder()->getLineStyle() != Border::LINE_NONE) {
708-
$this->writeBorder($objWriter, $shape->getBorder(), '');
709-
}
715+
$this->writeBorder($objWriter, $shape->getBorder(), '');
710716
$objWriter->endElement();
711717
$objWriter->endElement();
712718
}
@@ -752,6 +758,9 @@ protected function writeShadow(XMLWriter $objWriter, $oShadow)
752758
*/
753759
protected function writeHyperlink(XMLWriter $objWriter, $shape)
754760
{
761+
if (!$shape->hasHyperlink()) {
762+
return;
763+
}
755764
// a:hlinkClick
756765
$objWriter->startElement('a:hlinkClick');
757766
$objWriter->writeAttribute('r:id', $shape->getHyperlink()->relationId);
@@ -1071,7 +1080,13 @@ protected function writeShapeChart(XMLWriter $objWriter, ShapeChart $shape, $sha
10711080
// p:cNvGraphicFramePr
10721081
$objWriter->writeElement('p:cNvGraphicFramePr', null);
10731082
// p:nvPr
1074-
$objWriter->writeElement('p:nvPr', null);
1083+
$objWriter->startElement('p:nvPr');
1084+
if ($shape->isPlaceholder()) {
1085+
$objWriter->startElement('p:ph');
1086+
$objWriter->writeAttribute('type', $shape->getPlaceholder()->getType());
1087+
$objWriter->endElement();
1088+
}
1089+
$objWriter->endElement();
10751090
$objWriter->endElement();
10761091
// p:xfrm
10771092
$objWriter->startElement('p:xfrm');

0 commit comments

Comments
 (0)