Complex classes like PptSlides 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 PptSlides, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 29 | class PptSlides extends AbstractSlide |
||
| 30 | { |
||
| 31 | /** |
||
| 32 | * Add slides (drawings, ...) and slide relationships (drawings, ...) |
||
| 33 | * @return \PhpOffice\Common\Adapter\Zip\ZipInterface |
||
| 34 | */ |
||
| 35 | 97 | public function render() |
|
| 55 | |||
| 56 | /** |
||
| 57 | * Write slide relationships to XML format |
||
| 58 | * |
||
| 59 | * @param \PhpOffice\PhpPresentation\Slide $pSlide |
||
| 60 | * @return string XML Output |
||
| 61 | * @throws \Exception |
||
| 62 | */ |
||
| 63 | 97 | protected function writeSlideRelationships(Slide $pSlide) |
|
| 64 | { |
||
| 65 | //@todo Group all getShapeCollection()->getIterator |
||
| 66 | |||
| 67 | // Create XML writer |
||
| 68 | 97 | $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); |
|
| 69 | |||
| 70 | // XML header |
||
| 71 | 97 | $objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
|
| 72 | |||
| 73 | // Relationships |
||
| 74 | 97 | $objWriter->startElement('Relationships'); |
|
| 75 | 97 | $objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/package/2006/relationships'); |
|
| 76 | |||
| 77 | // Starting relation id |
||
| 78 | 97 | $relId = 1; |
|
| 79 | 97 | $idxSlide = $pSlide->getParent()->getIndex($pSlide); |
|
| 80 | |||
| 81 | // Write slideLayout relationship |
||
| 82 | 97 | $layoutId = 1; |
|
| 83 | 97 | if ($pSlide->getSlideLayout()) { |
|
| 84 | $layoutId = $pSlide->getSlideLayout()->layoutNr; |
||
| 85 | } |
||
| 86 | 97 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slideLayout', '../slideLayouts/slideLayout' . $layoutId . '.xml'); |
|
| 87 | |||
| 88 | // Write drawing relationships? |
||
| 89 | 97 | if ($pSlide->getShapeCollection()->count() > 0) { |
|
| 90 | // Loop trough images and write relationships |
||
| 91 | 72 | $iterator = $pSlide->getShapeCollection()->getIterator(); |
|
| 92 | 72 | while ($iterator->valid()) { |
|
| 93 | 72 | if ($iterator->current() instanceof Media) { |
|
| 94 | // Write relationship for image drawing |
||
| 95 | 1 | $this->writeRelationship($objWriter, $relId, 'http://schemas.microsoft.com/office/2007/relationships/media', '../media/' . $iterator->current()->getIndexedFilename()); |
|
| 96 | 1 | $iterator->current()->relationId = 'rId' . $relId; |
|
| 97 | 1 | ++$relId; |
|
| 98 | 72 | } elseif ($iterator->current() instanceof ShapeDrawing\AbstractDrawingAdapter) { |
|
| 99 | // Write relationship for image drawing |
||
| 100 | 7 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', '../media/' . $iterator->current()->getIndexedFilename()); |
|
| 101 | 7 | $iterator->current()->relationId = 'rId' . $relId; |
|
| 102 | 7 | ++$relId; |
|
| 103 | 71 | } elseif ($iterator->current() instanceof ShapeChart) { |
|
| 104 | // Write relationship for chart drawing |
||
| 105 | 24 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', '../charts/' . $iterator->current()->getIndexedFilename()); |
|
| 106 | |||
| 107 | 24 | $iterator->current()->relationId = 'rId' . $relId; |
|
| 108 | |||
| 109 | 24 | ++$relId; |
|
| 110 | 64 | } elseif ($iterator->current() instanceof Group) { |
|
| 111 | 1 | $iterator2 = $iterator->current()->getShapeCollection()->getIterator(); |
|
| 112 | 1 | while ($iterator2->valid()) { |
|
| 113 | 1 | if ($iterator->current() instanceof Media) { |
|
| 114 | // Write relationship for image drawing |
||
| 115 | $this->writeRelationship($objWriter, $relId, 'http://schemas.microsoft.com/office/2007/relationships/media', '../media/' . $iterator->current()->getIndexedFilename()); |
||
| 116 | $iterator->current()->relationId = 'rId' . $relId; |
||
| 117 | ++$relId; |
||
| 118 | 1 | } elseif ($iterator->current() instanceof ShapeDrawing\AbstractDrawingAdapter) { |
|
| 119 | // Write relationship for image drawing |
||
| 120 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', '../media/' . $iterator2->current()->getIndexedFilename()); |
||
| 121 | $iterator2->current()->relationId = 'rId' . $relId; |
||
| 122 | |||
| 123 | ++$relId; |
||
| 124 | 1 | } elseif ($iterator2->current() instanceof ShapeChart) { |
|
| 125 | // Write relationship for chart drawing |
||
| 126 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart', '../charts/' . $iterator2->current()->getIndexedFilename()); |
||
| 127 | $iterator2->current()->relationId = 'rId' . $relId; |
||
| 128 | |||
| 129 | ++$relId; |
||
| 130 | } |
||
| 131 | 1 | $iterator2->next(); |
|
| 132 | 1 | } |
|
| 133 | 1 | } |
|
| 134 | |||
| 135 | 72 | $iterator->next(); |
|
| 136 | 72 | } |
|
| 137 | 72 | } |
|
| 138 | |||
| 139 | // Write background relationships? |
||
| 140 | 97 | $oBackground = $pSlide->getBackground(); |
|
| 141 | 97 | if ($oBackground instanceof Image) { |
|
| 142 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image', '../media/' . $oBackground->getIndexedFilename($idxSlide)); |
||
| 143 | $oBackground->relationId = 'rId' . $relId; |
||
| 144 | ++$relId; |
||
| 145 | } |
||
| 146 | |||
| 147 | // Write hyperlink relationships? |
||
| 148 | 97 | if ($pSlide->getShapeCollection()->count() > 0) { |
|
| 149 | // Loop trough hyperlinks and write relationships |
||
| 150 | 72 | $iterator = $pSlide->getShapeCollection()->getIterator(); |
|
| 151 | 72 | while ($iterator->valid()) { |
|
| 152 | // Hyperlink on shape |
||
| 153 | 72 | if ($iterator->current()->hasHyperlink()) { |
|
| 154 | // Write relationship for hyperlink |
||
| 155 | 2 | $hyperlink = $iterator->current()->getHyperlink(); |
|
| 156 | 2 | $hyperlink->relationId = 'rId' . $relId; |
|
| 157 | |||
| 158 | 2 | if (!$hyperlink->isInternal()) { |
|
| 159 | 2 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', $hyperlink->getUrl(), 'External'); |
|
| 160 | 2 | } else { |
|
| 161 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slide' . $hyperlink->getSlideNumber() . '.xml'); |
||
| 162 | } |
||
| 163 | |||
| 164 | 2 | ++$relId; |
|
| 165 | 2 | } |
|
| 166 | |||
| 167 | // Hyperlink on rich text run |
||
| 168 | 72 | if ($iterator->current() instanceof RichText) { |
|
| 169 | 23 | foreach ($iterator->current()->getParagraphs() as $paragraph) { |
|
| 170 | 23 | foreach ($paragraph->getRichTextElements() as $element) { |
|
| 171 | 18 | if ($element instanceof Run || $element instanceof RunTextElement) { |
|
| 172 | 17 | if ($element->hasHyperlink()) { |
|
| 173 | // Write relationship for hyperlink |
||
| 174 | 2 | $hyperlink = $element->getHyperlink(); |
|
| 175 | 2 | $hyperlink->relationId = 'rId' . $relId; |
|
| 176 | |||
| 177 | 2 | if (!$hyperlink->isInternal()) { |
|
| 178 | 1 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', $hyperlink->getUrl(), 'External'); |
|
| 179 | 1 | } else { |
|
| 180 | 1 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slide' . $hyperlink->getSlideNumber() . '.xml'); |
|
| 181 | } |
||
| 182 | |||
| 183 | 2 | ++$relId; |
|
| 184 | 2 | } |
|
| 185 | 17 | } |
|
| 186 | 23 | } |
|
| 187 | 23 | } |
|
| 188 | 23 | } |
|
| 189 | |||
| 190 | // Hyperlink in table |
||
| 191 | 72 | if ($iterator->current() instanceof ShapeTable) { |
|
| 192 | // Rows |
||
| 193 | 9 | $countRows = count($iterator->current()->getRows()); |
|
| 194 | 9 | for ($row = 0; $row < $countRows; $row++) { |
|
| 195 | // Cells in rows |
||
| 196 | 9 | $countCells = count($iterator->current()->getRow($row)->getCells()); |
|
| 197 | 9 | for ($cell = 0; $cell < $countCells; $cell++) { |
|
| 198 | 9 | $currentCell = $iterator->current()->getRow($row)->getCell($cell); |
|
| 199 | // Paragraphs in cell |
||
| 200 | 9 | foreach ($currentCell->getParagraphs() as $paragraph) { |
|
| 201 | // RichText in paragraph |
||
| 202 | 9 | foreach ($paragraph->getRichTextElements() as $element) { |
|
| 203 | // Run or Text in RichText |
||
| 204 | 9 | if ($element instanceof Run || $element instanceof TextElement) { |
|
| 205 | 9 | if ($element->hasHyperlink()) { |
|
| 206 | // Write relationship for hyperlink |
||
| 207 | 1 | $hyperlink = $element->getHyperlink(); |
|
| 208 | 1 | $hyperlink->relationId = 'rId' . $relId; |
|
| 209 | |||
| 210 | 1 | if (!$hyperlink->isInternal()) { |
|
| 211 | 1 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', $hyperlink->getUrl(), 'External'); |
|
| 212 | 1 | } else { |
|
| 213 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slide' . $hyperlink->getSlideNumber() . '.xml'); |
||
| 214 | } |
||
| 215 | |||
| 216 | 1 | ++$relId; |
|
| 217 | 1 | } |
|
| 218 | 9 | } |
|
| 219 | 9 | } |
|
| 220 | 9 | } |
|
| 221 | 9 | } |
|
| 222 | 9 | } |
|
| 223 | 9 | } |
|
| 224 | |||
| 225 | 72 | if ($iterator->current() instanceof Group) { |
|
| 226 | 1 | $iterator2 = $pSlide->getShapeCollection()->getIterator(); |
|
| 227 | 1 | while ($iterator2->valid()) { |
|
| 228 | // Hyperlink on shape |
||
| 229 | 1 | if ($iterator2->current()->hasHyperlink()) { |
|
| 230 | // Write relationship for hyperlink |
||
| 231 | $hyperlink = $iterator2->current()->getHyperlink(); |
||
| 232 | $hyperlink->relationId = 'rId' . $relId; |
||
| 233 | |||
| 234 | if (!$hyperlink->isInternal()) { |
||
| 235 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', $hyperlink->getUrl(), 'External'); |
||
| 236 | } else { |
||
| 237 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slide' . $hyperlink->getSlideNumber() . '.xml'); |
||
| 238 | } |
||
| 239 | |||
| 240 | ++$relId; |
||
| 241 | } |
||
| 242 | |||
| 243 | // Hyperlink on rich text run |
||
| 244 | 1 | if ($iterator2->current() instanceof RichText) { |
|
| 245 | foreach ($iterator2->current()->getParagraphs() as $paragraph) { |
||
| 246 | foreach ($paragraph->getRichTextElements() as $element) { |
||
| 247 | if ($element instanceof Run || $element instanceof TextElement) { |
||
| 248 | if ($element->hasHyperlink()) { |
||
| 249 | // Write relationship for hyperlink |
||
| 250 | $hyperlink = $element->getHyperlink(); |
||
| 251 | $hyperlink->relationId = 'rId' . $relId; |
||
| 252 | |||
| 253 | if (!$hyperlink->isInternal()) { |
||
| 254 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', $hyperlink->getUrl(), 'External'); |
||
| 255 | } else { |
||
| 256 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slide' . $hyperlink->getSlideNumber() . '.xml'); |
||
| 257 | } |
||
| 258 | |||
| 259 | ++$relId; |
||
| 260 | } |
||
| 261 | } |
||
| 262 | } |
||
| 263 | } |
||
| 264 | } |
||
| 265 | |||
| 266 | // Hyperlink in table |
||
| 267 | 1 | if ($iterator2->current() instanceof ShapeTable) { |
|
| 268 | // Rows |
||
| 269 | $countRows = count($iterator2->current()->getRows()); |
||
| 270 | for ($row = 0; $row < $countRows; $row++) { |
||
| 271 | // Cells in rows |
||
| 272 | $countCells = count($iterator2->current()->getRow($row)->getCells()); |
||
| 273 | for ($cell = 0; $cell < $countCells; $cell++) { |
||
| 274 | $currentCell = $iterator2->current()->getRow($row)->getCell($cell); |
||
| 275 | // Paragraphs in cell |
||
| 276 | foreach ($currentCell->getParagraphs() as $paragraph) { |
||
| 277 | // RichText in paragraph |
||
| 278 | foreach ($paragraph->getRichTextElements() as $element) { |
||
| 279 | // Run or Text in RichText |
||
| 280 | if ($element instanceof Run || $element instanceof TextElement) { |
||
| 281 | if ($element->hasHyperlink()) { |
||
| 282 | // Write relationship for hyperlink |
||
| 283 | $hyperlink = $element->getHyperlink(); |
||
| 284 | $hyperlink->relationId = 'rId' . $relId; |
||
| 285 | |||
| 286 | if (!$hyperlink->isInternal()) { |
||
| 287 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink', $hyperlink->getUrl(), 'External'); |
||
| 288 | } else { |
||
| 289 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/slide', 'slide' . $hyperlink->getSlideNumber() . '.xml'); |
||
| 290 | } |
||
| 291 | |||
| 292 | ++$relId; |
||
| 293 | } |
||
| 294 | } |
||
| 295 | } |
||
| 296 | } |
||
| 297 | } |
||
| 298 | } |
||
| 299 | } |
||
| 300 | |||
| 301 | 1 | $iterator2->next(); |
|
| 302 | 1 | } |
|
| 303 | 1 | } |
|
| 304 | |||
| 305 | 72 | $iterator->next(); |
|
| 306 | 72 | } |
|
| 307 | 72 | } |
|
| 308 | |||
| 309 | // Write comment relationships |
||
| 310 | 97 | if ($pSlide->getShapeCollection()->count() > 0) { |
|
| 311 | 72 | $hasSlideComment = false; |
|
| 312 | |||
| 313 | // Loop trough images and write relationships |
||
| 314 | 72 | $iterator = $pSlide->getShapeCollection()->getIterator(); |
|
| 315 | 72 | while ($iterator->valid()) { |
|
| 316 | 72 | if ($iterator->current() instanceof Comment) { |
|
| 317 | 6 | $hasSlideComment = true; |
|
| 318 | 6 | break; |
|
| 319 | 66 | } elseif ($iterator->current() instanceof Group) { |
|
| 320 | 1 | $iterator2 = $iterator->current()->getShapeCollection()->getIterator(); |
|
| 321 | 1 | while ($iterator2->valid()) { |
|
| 322 | 1 | if ($iterator2->current() instanceof Comment) { |
|
| 323 | 1 | $hasSlideComment = true; |
|
| 324 | 1 | break 2; |
|
| 325 | } |
||
| 326 | $iterator2->next(); |
||
| 327 | } |
||
| 328 | } |
||
| 329 | |||
| 330 | 65 | $iterator->next(); |
|
| 331 | 65 | } |
|
| 332 | |||
| 333 | 72 | if ($hasSlideComment) { |
|
| 334 | 7 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments', '../comments/comment'.($idxSlide + 1).'.xml'); |
|
| 335 | 7 | ++$relId; |
|
| 336 | 7 | } |
|
| 337 | 72 | } |
|
| 338 | |||
| 339 | 97 | if ($pSlide->getNote()->getShapeCollection()->count() > 0) { |
|
| 340 | 1 | $this->writeRelationship($objWriter, $relId, 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/notesSlide', '../notesSlides/notesSlide'.($idxSlide + 1).'.xml'); |
|
| 341 | 1 | } |
|
| 342 | |||
| 343 | 97 | $objWriter->endElement(); |
|
| 344 | |||
| 345 | // Return |
||
| 346 | 97 | return $objWriter->getData(); |
|
| 347 | } |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Write slide to XML format |
||
| 351 | * |
||
| 352 | * @param \PhpOffice\PhpPresentation\Slide $pSlide |
||
| 353 | * @return string XML Output |
||
| 354 | * @throws \Exception |
||
| 355 | */ |
||
| 356 | 97 | public function writeSlide(Slide $pSlide) |
|
| 357 | { |
||
| 358 | // Create XML writer |
||
| 359 | 97 | $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY); |
|
| 360 | |||
| 361 | // XML header |
||
| 362 | 97 | $objWriter->startDocument('1.0', 'UTF-8', 'yes'); |
|
| 363 | |||
| 364 | // p:sld |
||
| 365 | 97 | $objWriter->startElement('p:sld'); |
|
| 366 | 97 | $objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main'); |
|
| 367 | 97 | $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships'); |
|
| 368 | 97 | $objWriter->writeAttribute('xmlns:p', 'http://schemas.openxmlformats.org/presentationml/2006/main'); |
|
| 369 | 97 | $objWriter->writeAttributeIf(!$pSlide->isVisible(), 'show', 0); |
|
| 370 | |||
| 371 | // p:sld/p:cSld |
||
| 372 | 97 | $objWriter->startElement('p:cSld'); |
|
| 373 | |||
| 374 | // Background |
||
| 375 | 97 | if ($pSlide->getBackground() instanceof Slide\AbstractBackground) { |
|
| 376 | $oBackground = $pSlide->getBackground(); |
||
| 377 | // p:bg |
||
| 378 | $objWriter->startElement('p:bg'); |
||
| 379 | |||
| 380 | // p:bgPr |
||
| 381 | $objWriter->startElement('p:bgPr'); |
||
| 382 | |||
| 383 | if ($oBackground instanceof Slide\Background\Color) { |
||
| 384 | // a:solidFill |
||
| 385 | $objWriter->startElement('a:solidFill'); |
||
| 386 | |||
| 387 | $this->writeColor($objWriter, $oBackground->getColor()); |
||
| 388 | |||
| 389 | // > a:solidFill |
||
| 390 | $objWriter->endElement(); |
||
| 391 | } |
||
| 392 | |||
| 393 | if ($oBackground instanceof Slide\Background\Image) { |
||
| 394 | // a:blipFill |
||
| 395 | $objWriter->startElement('a:blipFill'); |
||
| 396 | |||
| 397 | // a:blip |
||
| 398 | $objWriter->startElement('a:blip'); |
||
| 399 | $objWriter->writeAttribute('r:embed', $oBackground->relationId); |
||
| 400 | |||
| 401 | // > a:blipFill |
||
| 402 | $objWriter->endElement(); |
||
| 403 | |||
| 404 | // a:stretch |
||
| 405 | $objWriter->startElement('a:stretch'); |
||
| 406 | |||
| 407 | // a:fillRect |
||
| 408 | $objWriter->writeElement('a:fillRect'); |
||
| 409 | |||
| 410 | // > a:stretch |
||
| 411 | $objWriter->endElement(); |
||
| 412 | |||
| 413 | // > a:blipFill |
||
| 414 | $objWriter->endElement(); |
||
| 415 | } |
||
| 416 | |||
| 417 | // > p:bgPr |
||
| 418 | $objWriter->endElement(); |
||
| 419 | |||
| 420 | // > p:bg |
||
| 421 | $objWriter->endElement(); |
||
| 422 | } |
||
| 423 | |||
| 424 | // p:spTree |
||
| 425 | 97 | $objWriter->startElement('p:spTree'); |
|
| 426 | |||
| 427 | // p:nvGrpSpPr |
||
| 428 | 97 | $objWriter->startElement('p:nvGrpSpPr'); |
|
| 429 | |||
| 430 | // p:cNvPr |
||
| 431 | 97 | $objWriter->startElement('p:cNvPr'); |
|
| 432 | 97 | $objWriter->writeAttribute('id', '1'); |
|
| 433 | 97 | $objWriter->writeAttribute('name', ''); |
|
| 434 | 97 | $objWriter->endElement(); |
|
| 435 | |||
| 436 | // p:cNvGrpSpPr |
||
| 437 | 97 | $objWriter->writeElement('p:cNvGrpSpPr', null); |
|
| 438 | |||
| 439 | // p:nvPr |
||
| 440 | 97 | $objWriter->writeElement('p:nvPr', null); |
|
| 441 | |||
| 442 | 97 | $objWriter->endElement(); |
|
| 443 | |||
| 444 | // p:grpSpPr |
||
| 445 | 97 | $objWriter->startElement('p:grpSpPr'); |
|
| 446 | |||
| 447 | // a:xfrm |
||
| 448 | 97 | $objWriter->startElement('a:xfrm'); |
|
| 449 | |||
| 450 | // a:off |
||
| 451 | 97 | $objWriter->startElement('a:off'); |
|
| 452 | 97 | $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($pSlide->getOffsetX())); |
|
| 453 | 97 | $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($pSlide->getOffsetY())); |
|
| 454 | 97 | $objWriter->endElement(); // a:off |
|
| 455 | |||
| 456 | // a:ext |
||
| 457 | 97 | $objWriter->startElement('a:ext'); |
|
| 458 | 97 | $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($pSlide->getExtentX())); |
|
| 459 | 97 | $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($pSlide->getExtentY())); |
|
| 460 | 97 | $objWriter->endElement(); // a:ext |
|
| 461 | |||
| 462 | // a:chOff |
||
| 463 | 97 | $objWriter->startElement('a:chOff'); |
|
| 464 | 97 | $objWriter->writeAttribute('x', CommonDrawing::pixelsToEmu($pSlide->getOffsetX())); |
|
| 465 | 97 | $objWriter->writeAttribute('y', CommonDrawing::pixelsToEmu($pSlide->getOffsetY())); |
|
| 466 | 97 | $objWriter->endElement(); // a:chOff |
|
| 467 | |||
| 468 | // a:chExt |
||
| 469 | 97 | $objWriter->startElement('a:chExt'); |
|
| 470 | 97 | $objWriter->writeAttribute('cx', CommonDrawing::pixelsToEmu($pSlide->getExtentX())); |
|
| 471 | 97 | $objWriter->writeAttribute('cy', CommonDrawing::pixelsToEmu($pSlide->getExtentY())); |
|
| 472 | 97 | $objWriter->endElement(); // a:chExt |
|
| 473 | |||
| 474 | 97 | $objWriter->endElement(); |
|
| 475 | |||
| 476 | 97 | $objWriter->endElement(); |
|
| 477 | |||
| 478 | // Loop shapes |
||
| 479 | 97 | $this->writeShapeCollection($objWriter, $pSlide->getShapeCollection()); |
|
| 480 | |||
| 481 | // TODO |
||
| 482 | 97 | $objWriter->endElement(); |
|
| 483 | |||
| 484 | 97 | $objWriter->endElement(); |
|
| 485 | |||
| 486 | // p:clrMapOvr |
||
| 487 | 97 | $objWriter->startElement('p:clrMapOvr'); |
|
| 488 | // p:clrMapOvr\a:masterClrMapping |
||
| 489 | 97 | $objWriter->writeElement('a:masterClrMapping', null); |
|
| 490 | // ##p:clrMapOvr |
||
| 491 | 97 | $objWriter->endElement(); |
|
| 492 | |||
| 493 | 97 | $this->writeSlideTransition($objWriter, $pSlide->getTransition()); |
|
| 494 | |||
| 495 | 97 | $this->writeSlideAnimations($objWriter, $pSlide); |
|
| 496 | |||
| 497 | 97 | $objWriter->endElement(); |
|
| 498 | |||
| 499 | // Return |
||
| 500 | 97 | return $objWriter->getData(); |
|
| 501 | } |
||
| 502 | |||
| 503 | /** |
||
| 504 | * @param XMLWriter $objWriter |
||
| 505 | * @param Slide $oSlide |
||
| 506 | */ |
||
| 507 | 97 | protected function writeSlideAnimations(XMLWriter $objWriter, Slide $oSlide) |
|
| 508 | { |
||
| 509 | 97 | $arrayAnimations = $oSlide->getAnimations(); |
|
| 510 | 97 | if (empty($arrayAnimations)) { |
|
| 511 | 96 | return; |
|
| 512 | } |
||
| 513 | |||
| 514 | // Variables |
||
| 515 | 1 | $shapeId = 1; |
|
| 516 | 1 | $idCount = 1; |
|
| 517 | 1 | $hashToIdMap = array(); |
|
| 518 | 1 | $arrayAnimationIds = array(); |
|
| 519 | |||
| 520 | 1 | foreach ($oSlide->getShapeCollection() as $shape) { |
|
| 521 | 1 | $hashToIdMap[$shape->getHashCode()] = ++$shapeId; |
|
| 522 | 1 | } |
|
| 523 | 1 | foreach ($arrayAnimations as $oAnimation) { |
|
| 524 | 1 | foreach ($oAnimation->getShapeCollection() as $oShape) { |
|
| 525 | 1 | $arrayAnimationIds[] = $hashToIdMap[$oShape->getHashCode()]; |
|
| 526 | 1 | } |
|
| 527 | 1 | } |
|
| 528 | |||
| 529 | // p:timing |
||
| 530 | 1 | $objWriter->startElement('p:timing'); |
|
| 531 | // p:timing/p:tnLst |
||
| 532 | 1 | $objWriter->startElement('p:tnLst'); |
|
| 533 | // p:timing/p:tnLst/p:par |
||
| 534 | 1 | $objWriter->startElement('p:par'); |
|
| 535 | // p:timing/p:tnLst/p:par/p:cTn |
||
| 536 | 1 | $objWriter->startElement('p:cTn'); |
|
| 537 | 1 | $objWriter->writeAttribute('id', $idCount++); |
|
| 538 | 1 | $objWriter->writeAttribute('dur', 'indefinite'); |
|
| 539 | 1 | $objWriter->writeAttribute('restart', 'never'); |
|
| 540 | 1 | $objWriter->writeAttribute('nodeType', 'tmRoot'); |
|
| 541 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst |
||
| 542 | 1 | $objWriter->startElement('p:childTnLst'); |
|
| 543 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq |
||
| 544 | 1 | $objWriter->startElement('p:seq'); |
|
| 545 | 1 | $objWriter->writeAttribute('concurrent', '1'); |
|
| 546 | 1 | $objWriter->writeAttribute('nextAc', 'seek'); |
|
| 547 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn |
||
| 548 | 1 | $objWriter->startElement('p:cTn'); |
|
| 549 | 1 | $objWriter->writeAttribute('id', $idCount++); |
|
| 550 | 1 | $objWriter->writeAttribute('dur', 'indefinite'); |
|
| 551 | 1 | $objWriter->writeAttribute('nodeType', 'mainSeq'); |
|
| 552 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst |
||
| 553 | 1 | $objWriter->startElement('p:childTnLst'); |
|
| 554 | |||
| 555 | // Each animation has multiple shapes |
||
| 556 | 1 | foreach ($arrayAnimations as $oAnimation) { |
|
| 557 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par |
||
| 558 | 1 | $objWriter->startElement('p:par'); |
|
| 559 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn |
||
| 560 | 1 | $objWriter->startElement('p:cTn'); |
|
| 561 | 1 | $objWriter->writeAttribute('id', $idCount++); |
|
| 562 | 1 | $objWriter->writeAttribute('fill', 'hold'); |
|
| 563 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:stCondLst |
||
| 564 | 1 | $objWriter->startElement('p:stCondLst'); |
|
| 565 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:stCondLst/p:cond |
||
| 566 | 1 | $objWriter->startElement('p:cond'); |
|
| 567 | 1 | $objWriter->writeAttribute('delay', 'indefinite'); |
|
| 568 | 1 | $objWriter->endElement(); |
|
| 569 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn\##p:stCondLst |
||
| 570 | 1 | $objWriter->endElement(); |
|
| 571 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst |
||
| 572 | 1 | $objWriter->startElement('p:childTnLst'); |
|
| 573 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst/p:par |
||
| 574 | 1 | $objWriter->startElement('p:par'); |
|
| 575 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst/p:par/p:cTn |
||
| 576 | 1 | $objWriter->startElement('p:cTn'); |
|
| 577 | 1 | $objWriter->writeAttribute('id', $idCount++); |
|
| 578 | 1 | $objWriter->writeAttribute('fill', 'hold'); |
|
| 579 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst/p:par/p:cTn/p:stCondLst |
||
| 580 | 1 | $objWriter->startElement('p:stCondLst'); |
|
| 581 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst/p:par/p:cTn/p:stCondLst/p:cond |
||
| 582 | 1 | $objWriter->startElement('p:cond'); |
|
| 583 | 1 | $objWriter->writeAttribute('delay', '0'); |
|
| 584 | 1 | $objWriter->endElement(); |
|
| 585 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst/p:par/p:cTn\##p:stCondLst |
||
| 586 | 1 | $objWriter->endElement(); |
|
| 587 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst |
||
| 588 | 1 | $objWriter->startElement('p:childTnLst'); |
|
| 589 | |||
| 590 | 1 | $firstAnimation = true; |
|
| 591 | 1 | foreach ($oAnimation->getShapeCollection() as $oShape) { |
|
| 592 | 1 | $nodeType = $firstAnimation ? 'clickEffect' : 'withEffect'; |
|
| 593 | 1 | $shapeId = $hashToIdMap[$oShape->getHashCode()]; |
|
| 594 | |||
| 595 | // p:par |
||
| 596 | 1 | $objWriter->startElement('p:par'); |
|
| 597 | // p:par/p:cTn |
||
| 598 | 1 | $objWriter->startElement('p:cTn'); |
|
| 599 | 1 | $objWriter->writeAttribute('id', $idCount++); |
|
| 600 | 1 | $objWriter->writeAttribute('presetID', '1'); |
|
| 601 | 1 | $objWriter->writeAttribute('presetClass', 'entr'); |
|
| 602 | 1 | $objWriter->writeAttribute('fill', 'hold'); |
|
| 603 | 1 | $objWriter->writeAttribute('presetSubtype', '0'); |
|
| 604 | 1 | $objWriter->writeAttribute('grpId', '0'); |
|
| 605 | 1 | $objWriter->writeAttribute('nodeType', $nodeType); |
|
| 606 | // p:par/p:cTn/p:stCondLst |
||
| 607 | 1 | $objWriter->startElement('p:stCondLst'); |
|
| 608 | // p:par/p:cTn/p:stCondLst/p:cond |
||
| 609 | 1 | $objWriter->startElement('p:cond'); |
|
| 610 | 1 | $objWriter->writeAttribute('delay', '0'); |
|
| 611 | 1 | $objWriter->endElement(); |
|
| 612 | // p:par/p:cTn\##p:stCondLst |
||
| 613 | 1 | $objWriter->endElement(); |
|
| 614 | // p:par/p:cTn/p:childTnLst |
||
| 615 | 1 | $objWriter->startElement('p:childTnLst'); |
|
| 616 | // p:par/p:cTn/p:childTnLst/p:set |
||
| 617 | 1 | $objWriter->startElement('p:set'); |
|
| 618 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr |
||
| 619 | 1 | $objWriter->startElement('p:cBhvr'); |
|
| 620 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr/p:cTn |
||
| 621 | 1 | $objWriter->startElement('p:cTn'); |
|
| 622 | 1 | $objWriter->writeAttribute('id', $idCount++); |
|
| 623 | 1 | $objWriter->writeAttribute('dur', '1'); |
|
| 624 | 1 | $objWriter->writeAttribute('fill', 'hold'); |
|
| 625 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr/p:cTn/p:stCondLst |
||
| 626 | 1 | $objWriter->startElement('p:stCondLst'); |
|
| 627 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr/p:cTn/p:stCondLst/p:cond |
||
| 628 | 1 | $objWriter->startElement('p:cond'); |
|
| 629 | 1 | $objWriter->writeAttribute('delay', '0'); |
|
| 630 | 1 | $objWriter->endElement(); |
|
| 631 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr/p:cTn\##p:stCondLst |
||
| 632 | 1 | $objWriter->endElement(); |
|
| 633 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr\##p:cTn |
||
| 634 | 1 | $objWriter->endElement(); |
|
| 635 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr/p:tgtEl |
||
| 636 | 1 | $objWriter->startElement('p:tgtEl'); |
|
| 637 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr/p:tgtEl/p:spTgt |
||
| 638 | 1 | $objWriter->startElement('p:spTgt'); |
|
| 639 | 1 | $objWriter->writeAttribute('spid', $shapeId); |
|
| 640 | 1 | $objWriter->endElement(); |
|
| 641 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr\##p:tgtEl |
||
| 642 | 1 | $objWriter->endElement(); |
|
| 643 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr/p:attrNameLst |
||
| 644 | 1 | $objWriter->startElement('p:attrNameLst'); |
|
| 645 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr/p:attrNameLst/p:attrName |
||
| 646 | 1 | $objWriter->writeElement('p:attrName', 'style.visibility'); |
|
| 647 | // p:par/p:cTn/p:childTnLst/p:set/p:cBhvr\##p:attrNameLst |
||
| 648 | 1 | $objWriter->endElement(); |
|
| 649 | // p:par/p:cTn/p:childTnLst/p:set\##p:cBhvr |
||
| 650 | 1 | $objWriter->endElement(); |
|
| 651 | // p:par/p:cTn/p:childTnLst/p:set/p:to |
||
| 652 | 1 | $objWriter->startElement('p:to'); |
|
| 653 | // p:par/p:cTn/p:childTnLst/p:set/p:to/p:strVal |
||
| 654 | 1 | $objWriter->startElement('p:strVal'); |
|
| 655 | 1 | $objWriter->writeAttribute('val', 'visible'); |
|
| 656 | 1 | $objWriter->endElement(); |
|
| 657 | // p:par/p:cTn/p:childTnLst/p:set\##p:to |
||
| 658 | 1 | $objWriter->endElement(); |
|
| 659 | // p:par/p:cTn/p:childTnLst\##p:set |
||
| 660 | 1 | $objWriter->endElement(); |
|
| 661 | // p:par/p:cTn\##p:childTnLst |
||
| 662 | 1 | $objWriter->endElement(); |
|
| 663 | // p:par\##p:cTn |
||
| 664 | 1 | $objWriter->endElement(); |
|
| 665 | // ##p:par |
||
| 666 | 1 | $objWriter->endElement(); |
|
| 667 | |||
| 668 | 1 | $firstAnimation = false; |
|
| 669 | 1 | } |
|
| 670 | |||
| 671 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst/p:par/p:cTn\##p:childTnLst |
||
| 672 | 1 | $objWriter->endElement(); |
|
| 673 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst/p:par\##p:cTn |
||
| 674 | 1 | $objWriter->endElement(); |
|
| 675 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn/p:childTnLst\##p:par |
||
| 676 | 1 | $objWriter->endElement(); |
|
| 677 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par/p:cTn\##p:childTnLst |
||
| 678 | 1 | $objWriter->endElement(); |
|
| 679 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst/p:par\##p:cTn |
||
| 680 | 1 | $objWriter->endElement(); |
|
| 681 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn/p:childTnLst\##p:par |
||
| 682 | 1 | $objWriter->endElement(); |
|
| 683 | 1 | } |
|
| 684 | |||
| 685 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:cTn\##p:childTnLst |
||
| 686 | 1 | $objWriter->endElement(); |
|
| 687 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq\##p:cTn |
||
| 688 | 1 | $objWriter->endElement(); |
|
| 689 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:prevCondLst |
||
| 690 | 1 | $objWriter->startElement('p:prevCondLst'); |
|
| 691 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:prevCondLst/p:cond |
||
| 692 | 1 | $objWriter->startElement('p:cond'); |
|
| 693 | 1 | $objWriter->writeAttribute('evt', 'onPrev'); |
|
| 694 | 1 | $objWriter->writeAttribute('delay', '0'); |
|
| 695 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:prevCondLst/p:cond/p:tgtEl |
||
| 696 | 1 | $objWriter->startElement('p:tgtEl'); |
|
| 697 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:prevCondLst/p:cond/p:tgtEl/p:sldTgt |
||
| 698 | 1 | $objWriter->writeElement('p:sldTgt', null); |
|
| 699 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:prevCondLst/p:cond\##p:tgtEl |
||
| 700 | 1 | $objWriter->endElement(); |
|
| 701 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:prevCondLst\##p:cond |
||
| 702 | 1 | $objWriter->endElement(); |
|
| 703 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq\##p:prevCondLst |
||
| 704 | 1 | $objWriter->endElement(); |
|
| 705 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:nextCondLst |
||
| 706 | 1 | $objWriter->startElement('p:nextCondLst'); |
|
| 707 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:nextCondLst/p:cond |
||
| 708 | 1 | $objWriter->startElement('p:cond'); |
|
| 709 | 1 | $objWriter->writeAttribute('evt', 'onNext'); |
|
| 710 | 1 | $objWriter->writeAttribute('delay', '0'); |
|
| 711 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:nextCondLst/p:cond/p:tgtEl |
||
| 712 | 1 | $objWriter->startElement('p:tgtEl'); |
|
| 713 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:nextCondLst/p:cond/p:tgtEl/p:sldTgt |
||
| 714 | 1 | $objWriter->writeElement('p:sldTgt', null); |
|
| 715 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:nextCondLst/p:cond\##p:tgtEl |
||
| 716 | 1 | $objWriter->endElement(); |
|
| 717 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq/p:nextCondLst\##p:cond |
||
| 718 | 1 | $objWriter->endElement(); |
|
| 719 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst/p:seq\##p:nextCondLst |
||
| 720 | 1 | $objWriter->endElement(); |
|
| 721 | // p:timing/p:tnLst/p:par/p:cTn/p:childTnLst\##p:seq |
||
| 722 | 1 | $objWriter->endElement(); |
|
| 723 | // p:timing/p:tnLst/p:par/p:cTn\##p:childTnLst |
||
| 724 | 1 | $objWriter->endElement(); |
|
| 725 | // p:timing/p:tnLst/p:par\##p:cTn |
||
| 726 | 1 | $objWriter->endElement(); |
|
| 727 | // p:timing/p:tnLst\##p:par |
||
| 728 | 1 | $objWriter->endElement(); |
|
| 729 | // p:timing\##p:tnLst |
||
| 730 | 1 | $objWriter->endElement(); |
|
| 731 | |||
| 732 | // p:timing/p:bldLst |
||
| 733 | 1 | $objWriter->startElement('p:bldLst'); |
|
| 734 | |||
| 735 | // Add in ids of all shapes in this slides animations |
||
| 736 | 1 | foreach ($arrayAnimationIds as $id) { |
|
| 737 | // p:timing/p:bldLst/p:bldP |
||
| 738 | 1 | $objWriter->startElement('p:bldP'); |
|
| 739 | 1 | $objWriter->writeAttribute('spid', $id); |
|
| 740 | 1 | $objWriter->writeAttribute('grpId', 0); |
|
| 741 | 1 | $objWriter->endELement(); |
|
| 742 | 1 | } |
|
| 743 | |||
| 744 | // p:timing\##p:bldLst |
||
| 745 | 1 | $objWriter->endElement(); |
|
| 746 | |||
| 747 | // ##p:timing |
||
| 748 | 1 | $objWriter->endElement(); |
|
| 749 | 1 | } |
|
| 750 | |||
| 751 | /** |
||
| 752 | * Write group |
||
| 753 | * |
||
| 754 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 755 | * @param \PhpOffice\PhpPresentation\Shape\Group $group |
||
| 756 | * @param int $shapeId |
||
| 757 | */ |
||
| 758 | 1 | protected function writeShapeGroup(XMLWriter $objWriter, Group $group, &$shapeId) |
|
| 818 | |||
| 819 | /** |
||
| 820 | * Write chart |
||
| 821 | * |
||
| 822 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 823 | * @param \PhpOffice\PhpPresentation\Shape\Chart $shape |
||
| 824 | * @param int $shapeId |
||
| 825 | */ |
||
| 826 | 24 | protected function writeShapeChart(XMLWriter $objWriter, ShapeChart $shape, $shapeId) |
|
| 893 | |||
| 894 | /** |
||
| 895 | * Write pic |
||
| 896 | * |
||
| 897 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 898 | * @param \PhpOffice\PhpPresentation\Shape\Drawing\AbstractDrawingAdapter $shape |
||
| 899 | * @param int $shapeId |
||
| 900 | * @throws \Exception |
||
| 901 | */ |
||
| 902 | protected function writeShapeDrawing(XMLWriter $objWriter, ShapeDrawing\AbstractDrawingAdapter $shape, $shapeId) |
||
| 1021 | |||
| 1022 | /** |
||
| 1023 | * Write txt |
||
| 1024 | * |
||
| 1025 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 1026 | * @param \PhpOffice\PhpPresentation\Shape\RichText $shape |
||
| 1027 | * @param int $shapeId |
||
| 1028 | * @throws \Exception |
||
| 1029 | */ |
||
| 1030 | 23 | protected function writeShapeText(XMLWriter $objWriter, RichText $shape, $shapeId) |
|
| 1167 | |||
| 1168 | /** |
||
| 1169 | * Write table |
||
| 1170 | * |
||
| 1171 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 1172 | * @param \PhpOffice\PhpPresentation\Shape\Table $shape |
||
| 1173 | * @param int $shapeId |
||
| 1174 | * @throws \Exception |
||
| 1175 | */ |
||
| 1176 | 9 | protected function writeShapeTable(XMLWriter $objWriter, ShapeTable $shape, $shapeId) |
|
| 1393 | |||
| 1394 | /** |
||
| 1395 | * Write paragraphs |
||
| 1396 | * |
||
| 1397 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 1398 | * @param \PhpOffice\PhpPresentation\Shape\RichText\Paragraph[] $paragraphs |
||
| 1399 | * @param bool $bIsPlaceholder |
||
| 1400 | * @throws \Exception |
||
| 1401 | */ |
||
| 1402 | 33 | protected function writeParagraphs(XMLWriter $objWriter, $paragraphs, $bIsPlaceholder = false) |
|
| 1403 | { |
||
| 1404 | // Loop trough paragraphs |
||
| 1405 | 33 | foreach ($paragraphs as $paragraph) { |
|
| 1406 | // a:p |
||
| 1407 | 33 | $objWriter->startElement('a:p'); |
|
| 1408 | |||
| 1409 | // a:pPr |
||
| 1410 | 33 | if (!$bIsPlaceholder) { |
|
| 1411 | 33 | $objWriter->startElement('a:pPr'); |
|
| 1412 | 33 | $objWriter->writeAttribute('algn', $paragraph->getAlignment()->getHorizontal()); |
|
| 1413 | 33 | $objWriter->writeAttribute('fontAlgn', $paragraph->getAlignment()->getVertical()); |
|
| 1414 | 33 | $objWriter->writeAttribute('marL', CommonDrawing::pixelsToEmu($paragraph->getAlignment()->getMarginLeft())); |
|
| 1415 | 33 | $objWriter->writeAttribute('marR', CommonDrawing::pixelsToEmu($paragraph->getAlignment()->getMarginRight())); |
|
| 1416 | 33 | $objWriter->writeAttribute('indent', CommonDrawing::pixelsToEmu($paragraph->getAlignment()->getIndent())); |
|
| 1417 | 33 | $objWriter->writeAttribute('lvl', $paragraph->getAlignment()->getLevel()); |
|
| 1418 | |||
| 1419 | // Bullet type specified? |
||
| 1420 | 33 | if ($paragraph->getBulletStyle()->getBulletType() != Bullet::TYPE_NONE) { |
|
| 1421 | // a:buFont |
||
| 1422 | 2 | $objWriter->startElement('a:buFont'); |
|
| 1423 | 2 | $objWriter->writeAttribute('typeface', $paragraph->getBulletStyle()->getBulletFont()); |
|
| 1424 | 2 | $objWriter->endElement(); |
|
| 1425 | |||
| 1426 | 2 | if ($paragraph->getBulletStyle()->getBulletType() == Bullet::TYPE_BULLET) { |
|
| 1427 | // a:buChar |
||
| 1428 | 1 | $objWriter->startElement('a:buChar'); |
|
| 1429 | 1 | $objWriter->writeAttribute('char', $paragraph->getBulletStyle()->getBulletChar()); |
|
| 1430 | 1 | $objWriter->endElement(); |
|
| 1431 | 2 | } elseif ($paragraph->getBulletStyle()->getBulletType() == Bullet::TYPE_NUMERIC) { |
|
| 1432 | // a:buAutoNum |
||
| 1433 | 1 | $objWriter->startElement('a:buAutoNum'); |
|
| 1434 | 1 | $objWriter->writeAttribute('type', $paragraph->getBulletStyle()->getBulletNumericStyle()); |
|
| 1435 | 1 | if ($paragraph->getBulletStyle()->getBulletNumericStartAt() != 1) { |
|
| 1436 | 1 | $objWriter->writeAttribute('startAt', $paragraph->getBulletStyle()->getBulletNumericStartAt()); |
|
| 1437 | 1 | } |
|
| 1438 | 1 | $objWriter->endElement(); |
|
| 1439 | 1 | } |
|
| 1440 | 2 | if ($paragraph->getBulletStyle()->getBulletColor() instanceof Color) { |
|
| 1441 | 2 | $objWriter->startElement('a:buClr'); |
|
| 1442 | 2 | $this->writeColor($objWriter, $paragraph->getBulletStyle()->getBulletColor()); |
|
| 1443 | 2 | $objWriter->endElement(); |
|
| 1444 | 2 | } |
|
| 1445 | 2 | } |
|
| 1446 | |||
| 1447 | 33 | $objWriter->startElement('a:lnSpc'); |
|
| 1448 | 33 | $objWriter->startElement('a:spcPct'); |
|
| 1449 | 33 | $objWriter->writeAttribute('val', $paragraph->getLineSpacing() * 1000); |
|
| 1450 | 33 | $objWriter->endElement(); |
|
| 1451 | 33 | $objWriter->endElement(); |
|
| 1452 | |||
| 1453 | 33 | $objWriter->endElement(); |
|
| 1454 | 33 | } |
|
| 1455 | |||
| 1456 | // Loop trough rich text elements |
||
| 1457 | 33 | $elements = $paragraph->getRichTextElements(); |
|
| 1458 | 33 | foreach ($elements as $element) { |
|
| 1459 | 28 | if ($element instanceof BreakElement) { |
|
| 1460 | // a:br |
||
| 1461 | 1 | $objWriter->writeElement('a:br', null); |
|
| 1462 | 28 | } elseif ($element instanceof Run || $element instanceof TextElement) { |
|
| 1463 | // a:r |
||
| 1464 | 27 | $objWriter->startElement('a:r'); |
|
| 1465 | |||
| 1466 | // a:rPr |
||
| 1467 | 27 | if ($element instanceof Run && !$bIsPlaceholder) { |
|
| 1468 | // a:rPr |
||
| 1469 | 27 | $objWriter->startElement('a:rPr'); |
|
| 1470 | |||
| 1471 | // Lang |
||
| 1472 | 27 | $objWriter->writeAttribute('lang', ($element->getLanguage() ? $element->getLanguage() : 'en-US')); |
|
| 1473 | |||
| 1474 | 27 | $objWriter->writeAttributeIf($element->getFont()->isBold(), 'b', '1'); |
|
| 1475 | 27 | $objWriter->writeAttributeIf($element->getFont()->isItalic(), 'i', '1'); |
|
| 1476 | 27 | $objWriter->writeAttributeIf($element->getFont()->isStrikethrough(), 'strike', 'sngStrike'); |
|
| 1477 | |||
| 1478 | // Size |
||
| 1479 | 27 | $objWriter->writeAttribute('sz', ($element->getFont()->getSize() * 100)); |
|
| 1480 | |||
| 1481 | // Character spacing |
||
| 1482 | 27 | $objWriter->writeAttribute('spc', $element->getFont()->getCharacterSpacing()); |
|
| 1483 | |||
| 1484 | // Underline |
||
| 1485 | 27 | $objWriter->writeAttribute('u', $element->getFont()->getUnderline()); |
|
| 1486 | |||
| 1487 | // Superscript / subscript |
||
| 1488 | 27 | $objWriter->writeAttributeIf($element->getFont()->isSuperScript(), 'baseline', '30000'); |
|
| 1489 | 27 | $objWriter->writeAttributeIf($element->getFont()->isSubScript(), 'baseline', '-25000'); |
|
| 1490 | |||
| 1491 | // Color - a:solidFill |
||
| 1492 | 27 | $objWriter->startElement('a:solidFill'); |
|
| 1493 | 27 | $this->writeColor($objWriter, $element->getFont()->getColor()); |
|
| 1494 | 27 | $objWriter->endElement(); |
|
| 1495 | |||
| 1496 | // Font - a:latin |
||
| 1497 | 27 | $objWriter->startElement('a:latin'); |
|
| 1498 | 27 | $objWriter->writeAttribute('typeface', $element->getFont()->getName()); |
|
| 1499 | 27 | $objWriter->endElement(); |
|
| 1500 | |||
| 1501 | // a:hlinkClick |
||
| 1502 | 27 | $this->writeHyperlink($objWriter, $element); |
|
| 1503 | |||
| 1504 | 27 | $objWriter->endElement(); |
|
| 1505 | 27 | } |
|
| 1506 | |||
| 1507 | // t |
||
| 1508 | 27 | $objWriter->startElement('a:t'); |
|
| 1509 | 27 | $objWriter->writeCData(Text::controlCharacterPHP2OOXML($element->getText())); |
|
| 1510 | 27 | $objWriter->endElement(); |
|
| 1511 | |||
| 1512 | 27 | $objWriter->endElement(); |
|
| 1513 | 27 | } |
|
| 1514 | 33 | } |
|
| 1515 | |||
| 1516 | 33 | $objWriter->endElement(); |
|
| 1517 | 33 | } |
|
| 1518 | 33 | } |
|
| 1519 | |||
| 1520 | /** |
||
| 1521 | * Write Line Shape |
||
| 1522 | * |
||
| 1523 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 1524 | * @param \PhpOffice\PhpPresentation\Shape\Line $shape |
||
| 1525 | * @param int $shapeId |
||
| 1526 | */ |
||
| 1527 | 1 | protected function writeShapeLine(XMLWriter $objWriter, Line $shape, $shapeId) |
|
| 1631 | |||
| 1632 | /** |
||
| 1633 | * Write hyperlink |
||
| 1634 | * |
||
| 1635 | * @param \PhpOffice\Common\XMLWriter $objWriter XML Writer |
||
| 1636 | * @param \PhpOffice\PhpPresentation\AbstractShape|\PhpOffice\PhpPresentation\Shape\RichText\TextElement $shape |
||
| 1637 | */ |
||
| 1638 | 29 | protected function writeHyperlink(XMLWriter $objWriter, $shape) |
|
| 1652 | |||
| 1653 | /** |
||
| 1654 | * Write Note Slide |
||
| 1655 | * @param Note $pNote |
||
| 1656 | * @throws \Exception |
||
| 1657 | * @return string |
||
| 1658 | */ |
||
| 1659 | 1 | protected function writeNote(Note $pNote) |
|
| 1939 | |||
| 1940 | /** |
||
| 1941 | * Write Transition Slide |
||
| 1942 | * @link http://officeopenxml.com/prSlide-transitions.php |
||
| 1943 | * @param XMLWriter $objWriter |
||
| 1944 | * @param Transition $transition |
||
| 1945 | */ |
||
| 1946 | 97 | protected function writeSlideTransition(XMLWriter $objWriter, $transition) |
|
| 2193 | } |
||
| 2194 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: