Complex classes like AbstractSlide often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AbstractSlide, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 45 | abstract class AbstractSlide extends AbstractDecoratorWriter |
||
| 46 | { |
||
| 47 | /** |
||
| 48 | * @param AbstractSlideAlias $pSlideMaster |
||
| 49 | * @param $objWriter |
||
| 50 | * @param $relId |
||
| 51 | * @throws \Exception |
||
| 52 | */ |
||
| 53 | 113 | protected function writeDrawingRelations(AbstractSlideAlias $pSlideMaster, $objWriter, $relId) |
|
| 54 | { |
||
| 55 | 113 | if ($pSlideMaster->getShapeCollection()->count() > 0) { |
|
| 56 | // Loop trough images and write relationships |
||
| 57 | 2 | $iterator = $pSlideMaster->getShapeCollection()->getIterator(); |
|
| 58 | 2 | while ($iterator->valid()) { |
|
| 59 | 2 | if ($iterator->current() instanceof ShapeDrawingFile || $iterator->current() instanceof ShapeDrawingGd) { |
|
| 60 | // Write relationship for image drawing |
||
| 61 | 1 | $this->writeRelationship( |
|
| 62 | $objWriter, |
||
| 63 | $relId, |
||
| 64 | 1 | 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', |
|
| 65 | 1 | '../media/' . str_replace(' ', '_', $iterator->current()->getIndexedFilename()) |
|
| 66 | ); |
||
| 67 | 1 | $iterator->current()->relationId = 'rId' . $relId; |
|
| 68 | 1 | ++$relId; |
|
| 69 | 1 | } elseif ($iterator->current() instanceof ShapeChart) { |
|
| 70 | // Write relationship for chart drawing |
||
| 71 | $this->writeRelationship( |
||
| 72 | $objWriter, |
||
| 73 | $relId, |
||
| 74 | 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', |
||
| 75 | '../charts/' . $iterator->current()->getIndexedFilename() |
||
| 76 | ); |
||
| 77 | $iterator->current()->relationId = 'rId' . $relId; |
||
| 78 | ++$relId; |
||
| 79 | 1 | } elseif ($iterator->current() instanceof Group) { |
|
| 80 | $iterator2 = $iterator->current()->getShapeCollection()->getIterator(); |
||
| 81 | while ($iterator2->valid()) { |
||
| 82 | if ($iterator2->current() instanceof ShapeDrawingFile || |
||
| 83 | $iterator2->current() instanceof ShapeDrawingGd |
||
| 84 | ) { |
||
| 85 | // Write relationship for image drawing |
||
| 86 | $this->writeRelationship( |
||
| 87 | $objWriter, |
||
| 88 | $relId, |
||
| 89 | 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', |
||
| 90 | '../media/' . str_replace(' ', '_', $iterator2->current()->getIndexedFilename()) |
||
| 91 | ); |
||
| 92 | $iterator2->current()->relationId = 'rId' . $relId; |
||
| 93 | ++$relId; |
||
| 94 | } elseif ($iterator2->current() instanceof ShapeChart) { |
||
| 95 | // Write relationship for chart drawing |
||
| 96 | $this->writeRelationship( |
||
| 97 | $objWriter, |
||
| 98 | $relId, |
||
| 99 | 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', |
||
| 100 | '../charts/' . $iterator2->current()->getIndexedFilename() |
||
| 101 | ); |
||
| 102 | $iterator2->current()->relationId = 'rId' . $relId; |
||
| 103 | ++$relId; |
||
| 104 | } |
||
| 105 | $iterator2->next(); |
||
| 106 | } |
||
| 107 | } |
||
| 108 | 2 | $iterator->next(); |
|
| 109 | } |
||
| 110 | } |
||
| 111 | |||
| 112 | 113 | return $relId; |
|
| 113 | } |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @param XMLWriter $objWriter |
||
| 117 | * @param \ArrayObject|\PhpOffice\PhpPresentation\AbstractShape[] $shapes |
||
| 118 | * @param int $shapeId |
||
| 119 | * @throws \Exception |
||
| 120 | */ |
||
| 121 | 112 | protected function writeShapeCollection(XMLWriter $objWriter, $shapes = array(), &$shapeId = 0) |
|
| 122 | { |
||
| 123 | 112 | if (count($shapes) == 0) { |
|
| 124 | 112 | return; |
|
| 125 | } |
||
| 126 | 85 | foreach ($shapes as $shape) { |
|
| 127 | // Increment $shapeId |
||
| 128 | 85 | ++$shapeId; |
|
| 129 | // Check type |
||
| 130 | 85 | if ($shape instanceof RichText) { |
|
| 131 | 26 | $this->writeShapeText($objWriter, $shape, $shapeId); |
|
| 132 | } elseif ($shape instanceof ShapeTable) { |
||
| 133 | 11 | $this->writeShapeTable($objWriter, $shape, $shapeId); |
|
| 134 | } elseif ($shape instanceof Line) { |
||
| 135 | 1 | $this->writeShapeLine($objWriter, $shape, $shapeId); |
|
| 136 | } elseif ($shape instanceof ShapeChart) { |
||
| 137 | 34 | $this->writeShapeChart($objWriter, $shape, $shapeId); |
|
| 138 | } elseif ($shape instanceof AbstractGraphic) { |
||
| 139 | 9 | $this->writeShapePic($objWriter, $shape, $shapeId); |
|
| 140 | } elseif ($shape instanceof Group) { |
||
| 141 | 1 | $this->writeShapeGroup($objWriter, $shape, $shapeId); |
|
| 142 | 8 | } elseif ($shape instanceof Comment) { |
|
| 143 | } else { |
||
| 144 | 85 | throw new \Exception("Unknown Shape type: {get_class($shape)}"); |
|
| 145 | } |
||
| 146 | } |
||
| 147 | 85 | } |
|
| 148 | |||
| 149 | /** |
||
| 150 | * Write txt |
||
| 151 | * |
||
| 152 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 153 | * @param \PhpOffice\PhpPresentation\Shape\RichText $shape |
||
| 154 | * @param int $shapeId |
||
| 155 | * @throws \Exception |
||
| 156 | */ |
||
| 157 | 26 | protected function writeShapeText(XMLWriter $objWriter, RichText $shape, $shapeId) |
|
| 158 | { |
||
| 159 | // p:sp |
||
| 160 | 26 | $objWriter->startElement('p:sp'); |
|
| 161 | // p:sp\p:nvSpPr |
||
| 162 | 26 | $objWriter->startElement('p:nvSpPr'); |
|
| 163 | // p:sp\p:nvSpPr\p:cNvPr |
||
| 164 | 26 | $objWriter->startElement('p:cNvPr'); |
|
| 165 | 26 | $objWriter->writeAttribute('id', $shapeId); |
|
| 166 | 26 | if ($shape->isPlaceholder()) { |
|
| 167 | 1 | $objWriter->writeAttribute('name', 'Placeholder for ' . $shape->getPlaceholder()->getType()); |
|
| 168 | } else { |
||
| 169 | 26 | $objWriter->writeAttribute('name', ''); |
|
| 170 | } |
||
| 171 | // Hyperlink |
||
| 172 | 26 | if ($shape->hasHyperlink()) { |
|
| 173 | 1 | $this->writeHyperlink($objWriter, $shape); |
|
| 174 | } |
||
| 175 | // > p:sp\p:nvSpPr |
||
| 176 | 26 | $objWriter->endElement(); |
|
| 177 | // p:sp\p:cNvSpPr |
||
| 178 | 26 | $objWriter->startElement('p:cNvSpPr'); |
|
| 179 | 26 | $objWriter->writeAttribute('txBox', '1'); |
|
| 180 | 26 | $objWriter->endElement(); |
|
| 181 | // p:sp\p:cNvSpPr\p:nvPr |
||
| 182 | 26 | if ($shape->isPlaceholder()) { |
|
| 183 | 1 | $objWriter->startElement('p:nvPr'); |
|
| 184 | 1 | $objWriter->startElement('p:ph'); |
|
| 185 | 1 | $objWriter->writeAttribute('type', $shape->getPlaceholder()->getType()); |
|
| 186 | 1 | if (!is_null($shape->getPlaceholder()->getIdx())) { |
|
| 187 | $objWriter->writeAttribute('idx', $shape->getPlaceholder()->getIdx()); |
||
| 188 | } |
||
| 189 | 1 | $objWriter->endElement(); |
|
| 190 | 1 | $objWriter->endElement(); |
|
| 191 | } else { |
||
| 192 | 26 | $objWriter->writeElement('p:nvPr', null); |
|
| 193 | } |
||
| 194 | // > p:sp\p:cNvSpPr |
||
| 195 | 26 | $objWriter->endElement(); |
|
| 196 | // p:sp\p:spPr |
||
| 197 | 26 | $objWriter->startElement('p:spPr'); |
|
| 198 | |||
| 199 | 26 | if (!$shape->isPlaceholder()) { |
|
| 200 | // p:sp\p:spPr\a:xfrm |
||
| 201 | 26 | $objWriter->startElement('a:xfrm'); |
|
| 202 | 26 | $objWriter->writeAttributeIf($shape->getRotation() != 0, 'rot', CommonDrawing::degreesToAngle($shape->getRotation())); |
|
| 203 | // p:sp\p:spPr\a:xfrm\a:off |
||
| 204 | 26 | $objWriter->startElement('a:off'); |
|
| 205 | 26 | $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($shape->getOffsetX())); |
|
| 206 | 26 | $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($shape->getOffsetY())); |
|
| 207 | 26 | $objWriter->endElement(); |
|
| 208 | // p:sp\p:spPr\a:xfrm\a:ext |
||
| 209 | 26 | $objWriter->startElement('a:ext'); |
|
| 210 | 26 | $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($shape->getWidth())); |
|
| 211 | 26 | $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($shape->getHeight())); |
|
| 212 | 26 | $objWriter->endElement(); |
|
| 213 | // > p:sp\p:spPr\a:xfrm |
||
| 214 | 26 | $objWriter->endElement(); |
|
| 215 | // p:sp\p:spPr\a:prstGeom |
||
| 216 | 26 | $objWriter->startElement('a:prstGeom'); |
|
| 217 | 26 | $objWriter->writeAttribute('prst', 'rect'); |
|
| 218 | |||
| 219 | // p:sp\p:spPr\a:prstGeom\a:avLst |
||
| 220 | 26 | $objWriter->writeElement('a:avLst'); |
|
| 221 | |||
| 222 | 26 | $objWriter->endElement(); |
|
| 223 | } |
||
| 224 | 26 | $this->writeFill($objWriter, $shape->getFill()); |
|
| 225 | 26 | $this->writeBorder($objWriter, $shape->getBorder(), ''); |
|
| 226 | 26 | $this->writeShadow($objWriter, $shape->getShadow()); |
|
| 227 | |||
| 228 | // > p:sp\p:spPr |
||
| 229 | 26 | $objWriter->endElement(); |
|
| 230 | // p:txBody |
||
| 231 | 26 | $objWriter->startElement('p:txBody'); |
|
| 232 | // a:bodyPr |
||
| 233 | //@link :http://msdn.microsoft.com/en-us/library/documentformat.openxml.drawing.bodyproperties%28v=office.14%29.aspx |
||
| 234 | 26 | $objWriter->startElement('a:bodyPr'); |
|
| 235 | 26 | if (!$shape->isPlaceholder()) { |
|
| 236 | 26 | $verticalAlign = $shape->getActiveParagraph()->getAlignment()->getVertical(); |
|
| 237 | 26 | if ($verticalAlign != Alignment::VERTICAL_BASE && $verticalAlign != Alignment::VERTICAL_AUTO) { |
|
| 238 | 3 | $objWriter->writeAttribute('anchor', $verticalAlign); |
|
| 239 | } |
||
| 240 | 26 | if ($shape->getWrap() != RichText::WRAP_SQUARE) { |
|
| 241 | $objWriter->writeAttribute('wrap', $shape->getWrap()); |
||
| 242 | } |
||
| 243 | 26 | $objWriter->writeAttribute('rtlCol', '0'); |
|
| 244 | 26 | if ($shape->getHorizontalOverflow() != RichText::OVERFLOW_OVERFLOW) { |
|
| 245 | $objWriter->writeAttribute('horzOverflow', $shape->getHorizontalOverflow()); |
||
| 246 | } |
||
| 247 | 26 | if ($shape->getVerticalOverflow() != RichText::OVERFLOW_OVERFLOW) { |
|
| 248 | $objWriter->writeAttribute('vertOverflow', $shape->getVerticalOverflow()); |
||
| 249 | } |
||
| 250 | 26 | if ($shape->isUpright()) { |
|
| 251 | 1 | $objWriter->writeAttribute('upright', '1'); |
|
| 252 | } |
||
| 253 | 26 | if ($shape->isVertical()) { |
|
| 254 | 1 | $objWriter->writeAttribute('vert', 'vert'); |
|
| 255 | } |
||
| 256 | 26 | $objWriter->writeAttribute('bIns', CommonDrawing::pixelsToEmu($shape->getInsetBottom())); |
|
| 257 | 26 | $objWriter->writeAttribute('lIns', CommonDrawing::pixelsToEmu($shape->getInsetLeft())); |
|
| 258 | 26 | $objWriter->writeAttribute('rIns', CommonDrawing::pixelsToEmu($shape->getInsetRight())); |
|
| 259 | 26 | $objWriter->writeAttribute('tIns', CommonDrawing::pixelsToEmu($shape->getInsetTop())); |
|
| 260 | 26 | if ($shape->getColumns() <> 1) { |
|
| 261 | $objWriter->writeAttribute('numCol', $shape->getColumns()); |
||
| 262 | } |
||
| 263 | // a:spAutoFit |
||
| 264 | 26 | $objWriter->startElement('a:' . $shape->getAutoFit()); |
|
| 265 | 26 | if ($shape->getAutoFit() == RichText::AUTOFIT_NORMAL) { |
|
| 266 | 1 | if (!is_null($shape->getFontScale())) { |
|
| 267 | 1 | $objWriter->writeAttribute('fontScale', (int)($shape->getFontScale() * 1000)); |
|
| 268 | } |
||
| 269 | 1 | if (!is_null($shape->getLineSpaceReduction())) { |
|
| 270 | 1 | $objWriter->writeAttribute('lnSpcReduction', (int)($shape->getLineSpaceReduction() * 1000)); |
|
| 271 | } |
||
| 272 | } |
||
| 273 | 26 | $objWriter->endElement(); |
|
| 274 | } |
||
| 275 | 26 | $objWriter->endElement(); |
|
| 276 | // a:lstStyle |
||
| 277 | 26 | $objWriter->writeElement('a:lstStyle', null); |
|
| 278 | 26 | if ($shape->isPlaceholder() && |
|
| 279 | 1 | ($shape->getPlaceholder()->getType() == Placeholder::PH_TYPE_SLIDENUM || |
|
| 280 | 26 | $shape->getPlaceholder()->getType() == Placeholder::PH_TYPE_DATETIME) |
|
| 281 | ) { |
||
| 282 | 1 | $objWriter->startElement('a:p'); |
|
| 283 | 1 | $objWriter->startElement('a:fld'); |
|
| 284 | 1 | $objWriter->writeAttribute('id', $this->getGUID()); |
|
| 285 | 1 | $objWriter->writeAttribute('type', ( |
|
| 286 | 1 | $shape->getPlaceholder()->getType() == Placeholder::PH_TYPE_SLIDENUM ? 'slidenum' : 'datetime')); |
|
| 287 | 1 | $objWriter->writeElement('a:t', ( |
|
| 288 | 1 | $shape->getPlaceholder()->getType() == Placeholder::PH_TYPE_SLIDENUM ? '<nr.>' : '03-04-05')); |
|
| 289 | 1 | $objWriter->endElement(); |
|
| 290 | 1 | $objWriter->endElement(); |
|
| 291 | } else { |
||
| 292 | // Write paragraphs |
||
| 293 | 26 | $this->writeParagraphs($objWriter, $shape->getParagraphs()); |
|
| 294 | } |
||
| 295 | 26 | $objWriter->endElement(); |
|
| 296 | 26 | $objWriter->endElement(); |
|
| 297 | 26 | } |
|
| 298 | |||
| 299 | /** |
||
| 300 | * Write table |
||
| 301 | * |
||
| 302 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 303 | * @param \PhpOffice\PhpPresentation\Shape\Table $shape |
||
| 304 | * @param int $shapeId |
||
| 305 | * @throws \Exception |
||
| 306 | */ |
||
| 307 | 11 | protected function writeShapeTable(XMLWriter $objWriter, ShapeTable $shape, $shapeId) |
|
| 308 | { |
||
| 309 | // p:graphicFrame |
||
| 310 | 11 | $objWriter->startElement('p:graphicFrame'); |
|
| 311 | // p:graphicFrame/p:nvGraphicFramePr |
||
| 312 | 11 | $objWriter->startElement('p:nvGraphicFramePr'); |
|
| 313 | // p:graphicFrame/p:nvGraphicFramePr/p:cNvPr |
||
| 314 | 11 | $objWriter->startElement('p:cNvPr'); |
|
| 315 | 11 | $objWriter->writeAttribute('id', $shapeId); |
|
| 316 | 11 | $objWriter->writeAttribute('name', $shape->getName()); |
|
| 317 | 11 | $objWriter->writeAttribute('descr', $shape->getDescription()); |
|
| 318 | 11 | $objWriter->endElement(); |
|
| 319 | // p:graphicFrame/p:nvGraphicFramePr/p:cNvGraphicFramePr |
||
| 320 | 11 | $objWriter->startElement('p:cNvGraphicFramePr'); |
|
| 321 | // p:graphicFrame/p:nvGraphicFramePr/p:cNvGraphicFramePr/a:graphicFrameLocks |
||
| 322 | 11 | $objWriter->startElement('a:graphicFrameLocks'); |
|
| 323 | 11 | $objWriter->writeAttribute('noGrp', '1'); |
|
| 324 | 11 | $objWriter->endElement(); |
|
| 325 | // p:graphicFrame/p:nvGraphicFramePr/p:cNvGraphicFramePr/ |
||
| 326 | 11 | $objWriter->endElement(); |
|
| 327 | // p:graphicFrame/p:nvGraphicFramePr/p:nvPr |
||
| 328 | 11 | $objWriter->startElement('p:nvPr'); |
|
| 329 | 11 | if ($shape->isPlaceholder()) { |
|
| 330 | $objWriter->startElement('p:ph'); |
||
| 331 | $objWriter->writeAttribute('type', $shape->getPlaceholder()->getType()); |
||
| 332 | $objWriter->endElement(); |
||
| 333 | } |
||
| 334 | 11 | $objWriter->endElement(); |
|
| 335 | // p:graphicFrame/p:nvGraphicFramePr/ |
||
| 336 | 11 | $objWriter->endElement(); |
|
| 337 | // p:graphicFrame/p:xfrm |
||
| 338 | 11 | $objWriter->startElement('p:xfrm'); |
|
| 339 | // p:graphicFrame/p:xfrm/a:off |
||
| 340 | 11 | $objWriter->startElement('a:off'); |
|
| 341 | 11 | $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($shape->getOffsetX())); |
|
| 342 | 11 | $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($shape->getOffsetY())); |
|
| 343 | 11 | $objWriter->endElement(); |
|
| 344 | // p:graphicFrame/p:xfrm/a:ext |
||
| 345 | 11 | $objWriter->startElement('a:ext'); |
|
| 346 | 11 | $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($shape->getWidth())); |
|
| 347 | 11 | $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($shape->getHeight())); |
|
| 348 | 11 | $objWriter->endElement(); |
|
| 349 | // p:graphicFrame/p:xfrm/ |
||
| 350 | 11 | $objWriter->endElement(); |
|
| 351 | // p:graphicFrame/a:graphic |
||
| 352 | 11 | $objWriter->startElement('a:graphic'); |
|
| 353 | // p:graphicFrame/a:graphic/a:graphicData |
||
| 354 | 11 | $objWriter->startElement('a:graphicData'); |
|
| 355 | 11 | $objWriter->writeAttribute('uri', 'http://schemas.openxmlformats.org/drawingml/2006/table'); |
|
| 356 | // p:graphicFrame/a:graphic/a:graphicData/a:tbl |
||
| 357 | 11 | $objWriter->startElement('a:tbl'); |
|
| 358 | // p:graphicFrame/a:graphic/a:graphicData/a:tbl/a:tblPr |
||
| 359 | 11 | $objWriter->startElement('a:tblPr'); |
|
| 360 | 11 | $objWriter->writeAttribute('firstRow', '1'); |
|
| 361 | 11 | $objWriter->writeAttribute('bandRow', '1'); |
|
| 362 | 11 | $objWriter->endElement(); |
|
| 363 | // p:graphicFrame/a:graphic/a:graphicData/a:tbl/a:tblGrid |
||
| 364 | 11 | $objWriter->startElement('a:tblGrid'); |
|
| 365 | // Write cell widths |
||
| 366 | 11 | $countCells = count($shape->getRow(0)->getCells()); |
|
| 367 | 11 | for ($cell = 0; $cell < $countCells; $cell++) { |
|
| 368 | // p:graphicFrame/a:graphic/a:graphicData/a:tbl/a:tblGrid/a:gridCol |
||
| 369 | 11 | $objWriter->startElement('a:gridCol'); |
|
| 370 | // Calculate column width |
||
| 371 | 11 | $width = $shape->getRow(0)->getCell($cell)->getWidth(); |
|
| 372 | 11 | if ($width == 0) { |
|
| 373 | 11 | $colCount = count($shape->getRow(0)->getCells()); |
|
| 374 | 11 | $totalWidth = $shape->getWidth(); |
|
| 375 | 11 | $width = $totalWidth / $colCount; |
|
| 376 | } |
||
| 377 | 11 | $objWriter->writeAttribute('w', CommonDrawing::pixelsToEmu($width)); |
|
| 378 | 11 | $objWriter->endElement(); |
|
| 379 | } |
||
| 380 | // p:graphicFrame/a:graphic/a:graphicData/a:tbl/a:tblGrid/ |
||
| 381 | 11 | $objWriter->endElement(); |
|
| 382 | // Colspan / rowspan containers |
||
| 383 | 11 | $colSpan = array(); |
|
| 384 | 11 | $rowSpan = array(); |
|
| 385 | // Default border style |
||
| 386 | 11 | $defaultBorder = new Border(); |
|
| 387 | // Write rows |
||
| 388 | 11 | $countRows = count($shape->getRows()); |
|
| 389 | 11 | for ($row = 0; $row < $countRows; $row++) { |
|
| 390 | // p:graphicFrame/a:graphic/a:graphicData/a:tbl/a:tr |
||
| 391 | 11 | $objWriter->startElement('a:tr'); |
|
| 392 | 11 | $objWriter->writeAttribute('h', CommonDrawing::pixelsToEmu($shape->getRow($row)->getHeight())); |
|
| 393 | // Write cells |
||
| 394 | 11 | $countCells = count($shape->getRow($row)->getCells()); |
|
| 395 | 11 | for ($cell = 0; $cell < $countCells; $cell++) { |
|
| 396 | // Current cell |
||
| 397 | 11 | $currentCell = $shape->getRow($row)->getCell($cell); |
|
| 398 | // Next cell right |
||
| 399 | 11 | $nextCellRight = $shape->getRow($row)->getCell($cell + 1, true); |
|
| 400 | // Next cell below |
||
| 401 | 11 | $nextRowBelow = $shape->getRow($row + 1, true); |
|
| 402 | 11 | $nextCellBelow = null; |
|
| 403 | 11 | if ($nextRowBelow != null) { |
|
| 404 | 3 | $nextCellBelow = $nextRowBelow->getCell($cell, true); |
|
| 405 | } |
||
| 406 | // a:tc |
||
| 407 | 11 | $objWriter->startElement('a:tc'); |
|
| 408 | // Colspan |
||
| 409 | 11 | if ($currentCell->getColSpan() > 1) { |
|
| 410 | 2 | $objWriter->writeAttribute('gridSpan', $currentCell->getColSpan()); |
|
| 411 | 2 | $colSpan[$row] = $currentCell->getColSpan() - 1; |
|
| 412 | 11 | } elseif (isset($colSpan[$row]) && $colSpan[$row] > 0) { |
|
| 413 | 2 | $colSpan[$row]--; |
|
| 414 | 2 | $objWriter->writeAttribute('hMerge', '1'); |
|
| 415 | } |
||
| 416 | // Rowspan |
||
| 417 | 11 | if ($currentCell->getRowSpan() > 1) { |
|
| 418 | 1 | $objWriter->writeAttribute('rowSpan', $currentCell->getRowSpan()); |
|
| 419 | 1 | $rowSpan[$cell] = $currentCell->getRowSpan() - 1; |
|
| 420 | 11 | } elseif (isset($rowSpan[$cell]) && $rowSpan[$cell] > 0) { |
|
| 421 | 1 | $rowSpan[$cell]--; |
|
| 422 | 1 | $objWriter->writeAttribute('vMerge', '1'); |
|
| 423 | } |
||
| 424 | // a:txBody |
||
| 425 | 11 | $objWriter->startElement('a:txBody'); |
|
| 426 | // a:txBody/a:bodyPr |
||
| 427 | 11 | $objWriter->startElement('a:bodyPr'); |
|
| 428 | 11 | $objWriter->writeAttribute('wrap', 'square'); |
|
| 429 | 11 | $objWriter->writeAttribute('rtlCol', '0'); |
|
| 430 | // a:txBody/a:bodyPr/a:spAutoFit |
||
| 431 | 11 | $objWriter->writeElement('a:spAutoFit', null); |
|
| 432 | // a:txBody/a:bodyPr/ |
||
| 433 | 11 | $objWriter->endElement(); |
|
| 434 | // a:lstStyle |
||
| 435 | 11 | $objWriter->writeElement('a:lstStyle', null); |
|
| 436 | // Write paragraphs |
||
| 437 | 11 | $this->writeParagraphs($objWriter, $currentCell->getParagraphs()); |
|
| 438 | 11 | $objWriter->endElement(); |
|
| 439 | // a:tcPr |
||
| 440 | 11 | $objWriter->startElement('a:tcPr'); |
|
| 441 | 11 | $firstParagraph = $currentCell->getParagraph(0); |
|
| 442 | 11 | $firstParagraphAlignment = $firstParagraph->getAlignment(); |
|
| 443 | |||
| 444 | // Text Direction |
||
| 445 | 11 | $textDirection = $firstParagraphAlignment->getTextDirection(); |
|
| 446 | 11 | if ($textDirection != Alignment::TEXT_DIRECTION_HORIZONTAL) { |
|
| 447 | 1 | $objWriter->writeAttribute('vert', $textDirection); |
|
| 448 | } |
||
| 449 | // Alignment (horizontal) |
||
| 450 | 11 | $verticalAlign = $firstParagraphAlignment->getVertical(); |
|
| 451 | 11 | if ($verticalAlign != Alignment::VERTICAL_BASE && $verticalAlign != Alignment::VERTICAL_AUTO) { |
|
| 452 | 1 | $objWriter->writeAttribute('anchor', $verticalAlign); |
|
| 453 | } |
||
| 454 | |||
| 455 | // Margins |
||
| 456 | 11 | $objWriter->writeAttribute('marL', CommonDrawing::pixelsToEmu($firstParagraphAlignment->getMarginLeft())); |
|
| 457 | 11 | $objWriter->writeAttribute('marR', CommonDrawing::pixelsToEmu($firstParagraphAlignment->getMarginRight())); |
|
| 458 | 11 | $objWriter->writeAttribute('marT', CommonDrawing::pixelsToEmu($firstParagraphAlignment->getMarginTop())); |
|
| 459 | 11 | $objWriter->writeAttribute('marB', CommonDrawing::pixelsToEmu($firstParagraphAlignment->getMarginBottom())); |
|
| 460 | |||
| 461 | // Determine borders |
||
| 462 | 11 | $borderLeft = $currentCell->getBorders()->getLeft(); |
|
| 463 | 11 | $borderRight = $currentCell->getBorders()->getRight(); |
|
| 464 | 11 | $borderTop = $currentCell->getBorders()->getTop(); |
|
| 465 | 11 | $borderBottom = $currentCell->getBorders()->getBottom(); |
|
| 466 | 11 | $borderDiagonalDown = $currentCell->getBorders()->getDiagonalDown(); |
|
| 467 | 11 | $borderDiagonalUp = $currentCell->getBorders()->getDiagonalUp(); |
|
| 468 | // Fix PowerPoint implementation |
||
| 469 | 11 | if (!is_null($nextCellRight) |
|
| 470 | 11 | && $nextCellRight->getBorders()->getRight()->getHashCode() != $defaultBorder->getHashCode() |
|
| 471 | ) { |
||
| 472 | 1 | $borderRight = $nextCellRight->getBorders()->getLeft(); |
|
| 473 | } |
||
| 474 | 11 | if (!is_null($nextCellBelow) |
|
| 475 | 11 | && $nextCellBelow->getBorders()->getBottom()->getHashCode() != $defaultBorder->getHashCode() |
|
| 476 | ) { |
||
| 477 | 1 | $borderBottom = $nextCellBelow->getBorders()->getTop(); |
|
| 478 | } |
||
| 479 | // Write borders |
||
| 480 | 11 | $this->writeBorder($objWriter, $borderLeft, 'L'); |
|
| 481 | 11 | $this->writeBorder($objWriter, $borderRight, 'R'); |
|
| 482 | 11 | $this->writeBorder($objWriter, $borderTop, 'T'); |
|
| 483 | 11 | $this->writeBorder($objWriter, $borderBottom, 'B'); |
|
| 484 | 11 | $this->writeBorder($objWriter, $borderDiagonalDown, 'TlToBr'); |
|
| 485 | 11 | $this->writeBorder($objWriter, $borderDiagonalUp, 'BlToTr'); |
|
| 486 | // Fill |
||
| 487 | 11 | $this->writeFill($objWriter, $currentCell->getFill()); |
|
| 488 | 11 | $objWriter->endElement(); |
|
| 489 | 11 | $objWriter->endElement(); |
|
| 490 | } |
||
| 491 | 11 | $objWriter->endElement(); |
|
| 492 | } |
||
| 493 | 11 | $objWriter->endElement(); |
|
| 494 | 11 | $objWriter->endElement(); |
|
| 495 | 11 | $objWriter->endElement(); |
|
| 496 | 11 | $objWriter->endElement(); |
|
| 497 | 11 | } |
|
| 498 | |||
| 499 | /** |
||
| 500 | * Write paragraphs |
||
| 501 | * |
||
| 502 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 503 | * @param \PhpOffice\PhpPresentation\Shape\RichText\Paragraph[] $paragraphs |
||
| 504 | * @param bool $bIsPlaceholder |
||
| 505 | * @throws \Exception |
||
| 506 | */ |
||
| 507 | 37 | protected function writeParagraphs(XMLWriter $objWriter, $paragraphs, $bIsPlaceholder = false) |
|
| 627 | |||
| 628 | /** |
||
| 629 | * Write Line Shape |
||
| 630 | * |
||
| 631 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 632 | * @param \PhpOffice\PhpPresentation\Shape\Line $shape |
||
| 633 | * @param int $shapeId |
||
| 634 | */ |
||
| 635 | 1 | protected function writeShapeLine(XMLWriter $objWriter, Line $shape, $shapeId) |
|
| 636 | { |
||
| 637 | // p:sp |
||
| 638 | 1 | $objWriter->startElement('p:cxnSp'); |
|
| 639 | // p:nvSpPr |
||
| 640 | 1 | $objWriter->startElement('p:nvCxnSpPr'); |
|
| 641 | // p:cNvPr |
||
| 642 | 1 | $objWriter->startElement('p:cNvPr'); |
|
| 643 | 1 | $objWriter->writeAttribute('id', $shapeId); |
|
| 644 | 1 | $objWriter->writeAttribute('name', ''); |
|
| 645 | 1 | $objWriter->endElement(); |
|
| 646 | // p:cNvCxnSpPr |
||
| 647 | 1 | $objWriter->writeElement('p:cNvCxnSpPr', null); |
|
| 648 | // p:nvPr |
||
| 649 | 1 | $objWriter->startElement('p:nvPr'); |
|
| 650 | 1 | if ($shape->isPlaceholder()) { |
|
| 651 | $objWriter->startElement('p:ph'); |
||
| 652 | $objWriter->writeAttribute('type', $shape->getPlaceholder()->getType()); |
||
| 653 | $objWriter->endElement(); |
||
| 654 | } |
||
| 655 | 1 | $objWriter->endElement(); |
|
| 656 | 1 | $objWriter->endElement(); |
|
| 657 | // p:spPr |
||
| 658 | 1 | $objWriter->startElement('p:spPr'); |
|
| 659 | // a:xfrm |
||
| 660 | 1 | $objWriter->startElement('a:xfrm'); |
|
| 661 | 1 | if ($shape->getWidth() >= 0 && $shape->getHeight() >= 0) { |
|
| 662 | // a:off |
||
| 663 | 1 | $objWriter->startElement('a:off'); |
|
| 664 | 1 | $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($shape->getOffsetX())); |
|
| 665 | 1 | $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($shape->getOffsetY())); |
|
| 666 | 1 | $objWriter->endElement(); |
|
| 667 | // a:ext |
||
| 668 | 1 | $objWriter->startElement('a:ext'); |
|
| 669 | 1 | $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($shape->getWidth())); |
|
| 670 | 1 | $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($shape->getHeight())); |
|
| 671 | 1 | $objWriter->endElement(); |
|
| 672 | 1 | } elseif ($shape->getWidth() < 0 && $shape->getHeight() < 0) { |
|
| 673 | // a:off |
||
| 674 | 1 | $objWriter->startElement('a:off'); |
|
| 675 | 1 | $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($shape->getOffsetX() + $shape->getWidth())); |
|
| 676 | 1 | $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($shape->getOffsetY() + $shape->getHeight())); |
|
| 677 | 1 | $objWriter->endElement(); |
|
| 678 | // a:ext |
||
| 679 | 1 | $objWriter->startElement('a:ext'); |
|
| 680 | 1 | $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu(-$shape->getWidth())); |
|
| 681 | 1 | $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu(-$shape->getHeight())); |
|
| 682 | 1 | $objWriter->endElement(); |
|
| 683 | 1 | } elseif ($shape->getHeight() < 0) { |
|
| 684 | 1 | $objWriter->writeAttribute('flipV', 1); |
|
| 685 | // a:off |
||
| 686 | 1 | $objWriter->startElement('a:off'); |
|
| 687 | 1 | $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($shape->getOffsetX())); |
|
| 688 | 1 | $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($shape->getOffsetY() + $shape->getHeight())); |
|
| 689 | 1 | $objWriter->endElement(); |
|
| 690 | // a:ext |
||
| 691 | 1 | $objWriter->startElement('a:ext'); |
|
| 692 | 1 | $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($shape->getWidth())); |
|
| 693 | 1 | $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu(-$shape->getHeight())); |
|
| 694 | 1 | $objWriter->endElement(); |
|
| 695 | 1 | } elseif ($shape->getWidth() < 0) { |
|
| 696 | 1 | $objWriter->writeAttribute('flipV', 1); |
|
| 697 | // a:off |
||
| 698 | 1 | $objWriter->startElement('a:off'); |
|
| 699 | 1 | $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($shape->getOffsetX() + $shape->getWidth())); |
|
| 700 | 1 | $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($shape->getOffsetY())); |
|
| 701 | 1 | $objWriter->endElement(); |
|
| 702 | // a:ext |
||
| 703 | 1 | $objWriter->startElement('a:ext'); |
|
| 704 | 1 | $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu(-$shape->getWidth())); |
|
| 705 | 1 | $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($shape->getHeight())); |
|
| 706 | 1 | $objWriter->endElement(); |
|
| 707 | } |
||
| 708 | 1 | $objWriter->endElement(); |
|
| 709 | // a:prstGeom |
||
| 710 | 1 | $objWriter->startElement('a:prstGeom'); |
|
| 711 | 1 | $objWriter->writeAttribute('prst', 'line'); |
|
| 712 | |||
| 713 | // a:prstGeom/a:avLst |
||
| 714 | 1 | $objWriter->writeElement('a:avLst'); |
|
| 715 | |||
| 716 | 1 | $objWriter->endElement(); |
|
| 717 | 1 | $this->writeBorder($objWriter, $shape->getBorder(), ''); |
|
| 718 | 1 | $objWriter->endElement(); |
|
| 719 | 1 | $objWriter->endElement(); |
|
| 720 | 1 | } |
|
| 721 | |||
| 722 | /** |
||
| 723 | * Write Shadow |
||
| 724 | * @param XMLWriter $objWriter |
||
| 725 | * @param Shadow $oShadow |
||
| 726 | */ |
||
| 727 | 27 | protected function writeShadow(XMLWriter $objWriter, $oShadow) |
|
| 728 | { |
||
| 729 | 27 | if (!($oShadow instanceof Shadow)) { |
|
| 730 | return; |
||
| 731 | } |
||
| 732 | |||
| 733 | 27 | if (!$oShadow->isVisible()) { |
|
| 734 | 25 | return; |
|
| 735 | } |
||
| 736 | |||
| 737 | // a:effectLst |
||
| 738 | 3 | $objWriter->startElement('a:effectLst'); |
|
| 739 | |||
| 740 | // a:outerShdw |
||
| 741 | 3 | $objWriter->startElement('a:outerShdw'); |
|
| 742 | 3 | $objWriter->writeAttribute('blurRad', CommonDrawing::pixelsToEmu($oShadow->getBlurRadius())); |
|
| 743 | 3 | $objWriter->writeAttribute('dist', CommonDrawing::pixelsToEmu($oShadow->getDistance())); |
|
| 744 | 3 | $objWriter->writeAttribute('dir', CommonDrawing::degreesToAngle($oShadow->getDirection())); |
|
| 745 | 3 | $objWriter->writeAttribute('algn', $oShadow->getAlignment()); |
|
| 746 | 3 | $objWriter->writeAttribute('rotWithShape', '0'); |
|
| 747 | |||
| 748 | 3 | $this->writeColor($objWriter, $oShadow->getColor(), $oShadow->getAlpha()); |
|
| 749 | |||
| 750 | 3 | $objWriter->endElement(); |
|
| 751 | |||
| 752 | 3 | $objWriter->endElement(); |
|
| 753 | 3 | } |
|
| 754 | |||
| 755 | /** |
||
| 756 | * Write hyperlink |
||
| 757 | * |
||
| 758 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 759 | * @param \PhpOffice\PhpPresentation\AbstractShape|\PhpOffice\PhpPresentation\Shape\RichText\TextElement $shape |
||
| 760 | */ |
||
| 761 | 33 | protected function writeHyperlink(XMLWriter $objWriter, $shape) |
|
| 775 | |||
| 776 | /** |
||
| 777 | * Write Note Slide |
||
| 778 | * @param Note $pNote |
||
| 779 | * @throws \Exception |
||
| 780 | * @return string |
||
| 781 | */ |
||
| 782 | 2 | protected function writeNote(Note $pNote) |
|
| 1062 | |||
| 1063 | /** |
||
| 1064 | * Write chart |
||
| 1065 | * |
||
| 1066 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 1067 | * @param \PhpOffice\PhpPresentation\Shape\Chart $shape |
||
| 1068 | * @param int $shapeId |
||
| 1069 | */ |
||
| 1070 | 34 | protected function writeShapeChart(XMLWriter $objWriter, ShapeChart $shape, $shapeId) |
|
| 1071 | { |
||
| 1072 | // p:graphicFrame |
||
| 1073 | 34 | $objWriter->startElement('p:graphicFrame'); |
|
| 1074 | // p:nvGraphicFramePr |
||
| 1075 | 34 | $objWriter->startElement('p:nvGraphicFramePr'); |
|
| 1076 | // p:cNvPr |
||
| 1077 | 34 | $objWriter->startElement('p:cNvPr'); |
|
| 1078 | 34 | $objWriter->writeAttribute('id', $shapeId); |
|
| 1079 | 34 | $objWriter->writeAttribute('name', $shape->getName()); |
|
| 1080 | 34 | $objWriter->writeAttribute('descr', $shape->getDescription()); |
|
| 1081 | 34 | $objWriter->endElement(); |
|
| 1082 | // p:cNvGraphicFramePr |
||
| 1083 | 34 | $objWriter->writeElement('p:cNvGraphicFramePr', null); |
|
| 1084 | // p:nvPr |
||
| 1085 | 34 | $objWriter->startElement('p:nvPr'); |
|
| 1086 | 34 | if ($shape->isPlaceholder()) { |
|
| 1087 | $objWriter->startElement('p:ph'); |
||
| 1088 | $objWriter->writeAttribute('type', $shape->getPlaceholder()->getType()); |
||
| 1089 | $objWriter->endElement(); |
||
| 1090 | } |
||
| 1091 | 34 | $objWriter->endElement(); |
|
| 1092 | 34 | $objWriter->endElement(); |
|
| 1093 | // p:xfrm |
||
| 1094 | 34 | $objWriter->startElement('p:xfrm'); |
|
| 1095 | 34 | $objWriter->writeAttributeIf($shape->getRotation() != 0, 'rot', CommonDrawing::degreesToAngle($shape->getRotation())); |
|
| 1096 | // a:off |
||
| 1097 | 34 | $objWriter->startElement('a:off'); |
|
| 1098 | 34 | $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($shape->getOffsetX())); |
|
| 1099 | 34 | $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($shape->getOffsetY())); |
|
| 1100 | 34 | $objWriter->endElement(); |
|
| 1101 | // a:ext |
||
| 1102 | 34 | $objWriter->startElement('a:ext'); |
|
| 1103 | 34 | $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($shape->getWidth())); |
|
| 1104 | 34 | $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($shape->getHeight())); |
|
| 1105 | 34 | $objWriter->endElement(); |
|
| 1106 | 34 | $objWriter->endElement(); |
|
| 1107 | // a:graphic |
||
| 1108 | 34 | $objWriter->startElement('a:graphic'); |
|
| 1109 | // a:graphicData |
||
| 1110 | 34 | $objWriter->startElement('a:graphicData'); |
|
| 1111 | 34 | $objWriter->writeAttribute('uri', 'http://schemas.openxmlformats.org/drawingml/2006/chart'); |
|
| 1112 | // c:chart |
||
| 1113 | 34 | $objWriter->startElement('c:chart'); |
|
| 1114 | 34 | $objWriter->writeAttribute('xmlns:c', 'http://schemas.openxmlformats.org/drawingml/2006/chart'); |
|
| 1115 | 34 | $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); |
|
| 1116 | 34 | $objWriter->writeAttribute('r:id', $shape->relationId); |
|
| 1117 | 34 | $objWriter->endElement(); |
|
| 1118 | 34 | $objWriter->endElement(); |
|
| 1119 | 34 | $objWriter->endElement(); |
|
| 1120 | 34 | $objWriter->endElement(); |
|
| 1121 | 34 | } |
|
| 1122 | |||
| 1123 | /** |
||
| 1124 | * Write pic |
||
| 1125 | * |
||
| 1126 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 1127 | * @param \PhpOffice\PhpPresentation\Shape\AbstractGraphic $shape |
||
| 1128 | * @param int $shapeId |
||
| 1129 | * @throws \Exception |
||
| 1130 | */ |
||
| 1131 | 9 | protected function writeShapePic(XMLWriter $objWriter, AbstractGraphic $shape, $shapeId) |
|
| 1225 | |||
| 1226 | /** |
||
| 1227 | * Write group |
||
| 1228 | * |
||
| 1229 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 1230 | * @param \PhpOffice\PhpPresentation\Shape\Group $group |
||
| 1231 | * @param int $shapeId |
||
| 1232 | */ |
||
| 1233 | 1 | protected function writeShapeGroup(XMLWriter $objWriter, Group $group, &$shapeId) |
|
| 1281 | |||
| 1282 | /** |
||
| 1283 | * @param \PhpOffice\PhpPresentation\Slide\AbstractSlide $pSlide |
||
| 1284 | * @param $objWriter |
||
| 1285 | */ |
||
| 1286 | 112 | protected function writeSlideBackground(AbstractSlideAlias $pSlide, XMLWriter $objWriter) |
|
| 1350 | |||
| 1351 | |||
| 1352 | /** |
||
| 1353 | * Write Transition Slide |
||
| 1354 | * @link http://officeopenxml.com/prSlide-transitions.php |
||
| 1355 | * @param XMLWriter $objWriter |
||
| 1356 | * @param Slide\Transition $transition |
||
| 1357 | */ |
||
| 1358 | 112 | protected function writeSlideTransition(XMLWriter $objWriter, $transition) |
|
| 1605 | |||
| 1606 | 1 | private function getGUID() |
|
| 1607 | { |
||
| 1608 | 1 | if (function_exists('com_create_guid')) { |
|
| 1609 | return com_create_guid(); |
||
| 1610 | } else { |
||
| 1611 | 1 | mt_srand((double)microtime() * 10000);//optional for php 4.2.0 and up. |
|
| 1612 | 1 | $charid = strtoupper(md5(uniqid(rand(), true))); |
|
| 1624 | } |
||
| 1625 |