Complex classes like Content 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 Content, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
47 | class Content extends AbstractPart |
||
48 | { |
||
49 | |||
50 | /** |
||
51 | * Stores bullet styles for text shapes that include lists. |
||
52 | * |
||
53 | * @var array |
||
54 | */ |
||
55 | private $arrStyleBullet = array(); |
||
56 | |||
57 | /** |
||
58 | * Stores paragraph information for text shapes. |
||
59 | * |
||
60 | * @var array |
||
61 | */ |
||
62 | private $arrStyleParagraph = array(); |
||
63 | |||
64 | /** |
||
65 | * Stores font styles for text shapes that include lists. |
||
66 | * |
||
67 | * @var array |
||
68 | */ |
||
69 | private $arrStyleTextFont = array(); |
||
70 | |||
71 | /** |
||
72 | * Used to track the current shape ID. |
||
73 | * |
||
74 | * @var integer |
||
75 | */ |
||
76 | private $shapeId; |
||
77 | |||
78 | /** |
||
79 | * Write content file to XML format |
||
80 | * |
||
81 | * @param PhpPresentation $pPhpPresentation |
||
82 | * @return string XML Output |
||
83 | * @throws \Exception |
||
84 | */ |
||
85 | 41 | public function writePart(PhpPresentation $pPhpPresentation) |
|
86 | { |
||
87 | // Create XML writer |
||
88 | 41 | $objWriter = $this->getXMLWriter(); |
|
89 | |||
90 | // XML header |
||
91 | 41 | $objWriter->startDocument('1.0', 'UTF-8'); |
|
92 | |||
93 | // office:document-content |
||
94 | 41 | $objWriter->startElement('office:document-content'); |
|
95 | 41 | $objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0'); |
|
96 | 41 | $objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0'); |
|
97 | 41 | $objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0'); |
|
98 | 41 | $objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0'); |
|
99 | 41 | $objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0'); |
|
100 | 41 | $objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0'); |
|
101 | 41 | $objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); |
|
102 | 41 | $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); |
|
103 | 41 | $objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0'); |
|
104 | 41 | $objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0'); |
|
105 | 41 | $objWriter->writeAttribute('xmlns:presentation', 'urn:oasis:names:tc:opendocument:xmlns:presentation:1.0'); |
|
106 | 41 | $objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0'); |
|
107 | 41 | $objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0'); |
|
108 | 41 | $objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0'); |
|
109 | 41 | $objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML'); |
|
110 | 41 | $objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0'); |
|
111 | 41 | $objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0'); |
|
112 | 41 | $objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office'); |
|
113 | 41 | $objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer'); |
|
114 | 41 | $objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc'); |
|
115 | 41 | $objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events'); |
|
116 | 41 | $objWriter->writeAttribute('xmlns:xforms', 'http://www.w3.org/2002/xforms'); |
|
117 | 41 | $objWriter->writeAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema'); |
|
118 | 41 | $objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); |
|
119 | 41 | $objWriter->writeAttribute('xmlns:smil', 'urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0'); |
|
120 | 41 | $objWriter->writeAttribute('xmlns:anim', 'urn:oasis:names:tc:opendocument:xmlns:animation:1.0'); |
|
121 | 41 | $objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report'); |
|
122 | 41 | $objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2'); |
|
123 | 41 | $objWriter->writeAttribute('xmlns:rdfa', 'http://docs.oasis-open.org/opendocument/meta/rdfa#'); |
|
124 | 41 | $objWriter->writeAttribute('xmlns:field', 'urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0'); |
|
125 | 41 | $objWriter->writeAttribute('office:version', '1.2'); |
|
126 | |||
127 | // office:automatic-styles |
||
128 | 41 | $objWriter->startElement('office:automatic-styles'); |
|
129 | |||
130 | 41 | $this->shapeId = 0; |
|
131 | 41 | $incSlide = 0; |
|
132 | 41 | foreach ($pPhpPresentation->getAllSlides() as $pSlide) { |
|
133 | // Slides |
||
134 | 41 | $this->writeStyleSlide($objWriter, $pSlide, $incSlide); |
|
135 | |||
136 | // Images |
||
137 | 41 | $shapes = $pSlide->getShapeCollection(); |
|
138 | 41 | foreach ($shapes as $shape) { |
|
139 | // Increment $this->shapeId |
||
140 | 36 | ++$this->shapeId; |
|
141 | |||
142 | // Check type |
||
143 | 36 | if ($shape instanceof RichText) { |
|
144 | 13 | $this->writeTxtStyle($objWriter, $shape); |
|
145 | 13 | } |
|
146 | 36 | if ($shape instanceof AbstractDrawing) { |
|
147 | 23 | $this->writeDrawingStyle($objWriter, $shape); |
|
148 | 23 | } |
|
149 | 36 | if ($shape instanceof Line) { |
|
150 | 1 | $this->writeLineStyle($objWriter, $shape); |
|
151 | 1 | } |
|
152 | 36 | if ($shape instanceof Table) { |
|
153 | 7 | $this->writeTableStyle($objWriter, $shape); |
|
154 | 7 | } |
|
155 | 36 | if ($shape instanceof Group) { |
|
156 | 1 | $this->writeGroupStyle($objWriter, $shape); |
|
157 | 1 | } |
|
158 | 41 | } |
|
159 | |||
160 | 41 | $incSlide++; |
|
161 | 41 | } |
|
162 | // Style : Bullet |
||
163 | 41 | if (!empty($this->arrStyleBullet)) { |
|
164 | 13 | foreach ($this->arrStyleBullet as $key => $item) { |
|
165 | 13 | $oStyle = $item['oStyle']; |
|
166 | 13 | $arrLevel = explode(';', $item['level']); |
|
167 | // style:style |
||
168 | 13 | $objWriter->startElement('text:list-style'); |
|
169 | 13 | $objWriter->writeAttribute('style:name', 'L_' . $key); |
|
170 | 13 | foreach ($arrLevel as $level) { |
|
171 | 13 | if ($level != '') { |
|
172 | 13 | $oAlign = $item['oAlign_' . $level]; |
|
173 | // text:list-level-style-bullet |
||
174 | 13 | $objWriter->startElement('text:list-level-style-bullet'); |
|
175 | 13 | $objWriter->writeAttribute('text:level', $level + 1); |
|
176 | 13 | $objWriter->writeAttribute('text:bullet-char', $oStyle->getBulletChar()); |
|
177 | // style:list-level-properties |
||
178 | 13 | $objWriter->startElement('style:list-level-properties'); |
|
179 | 13 | if ($oAlign->getIndent() < 0) { |
|
180 | 1 | $objWriter->writeAttribute('text:space-before', CommonDrawing::pixelsToCentimeters($oAlign->getMarginLeft() - (-1 * $oAlign->getIndent())) . 'cm'); |
|
181 | 1 | $objWriter->writeAttribute('text:min-label-width', CommonDrawing::pixelsToCentimeters(-1 * $oAlign->getIndent()) . 'cm'); |
|
182 | 1 | } else { |
|
183 | 12 | $objWriter->writeAttribute('text:space-before', (CommonDrawing::pixelsToCentimeters($oAlign->getMarginLeft() - $oAlign->getIndent())) . 'cm'); |
|
184 | 12 | $objWriter->writeAttribute('text:min-label-width', CommonDrawing::pixelsToCentimeters($oAlign->getIndent()) . 'cm'); |
|
185 | } |
||
186 | |||
187 | 13 | $objWriter->endElement(); |
|
188 | // style:text-properties |
||
189 | 13 | $objWriter->startElement('style:text-properties'); |
|
190 | 13 | $objWriter->writeAttribute('fo:font-family', $oStyle->getBulletFont()); |
|
191 | 13 | $objWriter->writeAttribute('style:font-family-generic', 'swiss'); |
|
192 | 13 | $objWriter->writeAttribute('style:use-window-font-color', 'true'); |
|
193 | 13 | $objWriter->writeAttribute('fo:font-size', '100'); |
|
194 | 13 | $objWriter->endElement(); |
|
195 | 13 | $objWriter->endElement(); |
|
196 | 13 | } |
|
197 | 13 | } |
|
198 | 13 | $objWriter->endElement(); |
|
199 | 13 | } |
|
200 | 13 | } |
|
201 | // Style : Paragraph |
||
202 | 41 | if (!empty($this->arrStyleParagraph)) { |
|
203 | 13 | foreach ($this->arrStyleParagraph as $key => $item) { |
|
204 | // style:style |
||
205 | 13 | $objWriter->startElement('style:style'); |
|
206 | 13 | $objWriter->writeAttribute('style:name', 'P_' . $key); |
|
207 | 13 | $objWriter->writeAttribute('style:family', 'paragraph'); |
|
208 | // style:paragraph-properties |
||
209 | 13 | $objWriter->startElement('style:paragraph-properties'); |
|
210 | 13 | switch ($item->getAlignment()->getHorizontal()) { |
|
211 | 13 | case Alignment::HORIZONTAL_LEFT: |
|
212 | 13 | $objWriter->writeAttribute('fo:text-align', 'left'); |
|
213 | 13 | break; |
|
214 | 1 | case Alignment::HORIZONTAL_RIGHT: |
|
215 | 1 | $objWriter->writeAttribute('fo:text-align', 'right'); |
|
216 | 1 | break; |
|
217 | 1 | case Alignment::HORIZONTAL_CENTER: |
|
218 | 1 | $objWriter->writeAttribute('fo:text-align', 'center'); |
|
219 | 1 | break; |
|
220 | 1 | case Alignment::HORIZONTAL_JUSTIFY: |
|
221 | 1 | $objWriter->writeAttribute('fo:text-align', 'justify'); |
|
222 | 1 | break; |
|
223 | 1 | case Alignment::HORIZONTAL_DISTRIBUTED: |
|
224 | 1 | $objWriter->writeAttribute('fo:text-align', 'justify'); |
|
225 | 1 | break; |
|
226 | 1 | default: |
|
227 | 1 | $objWriter->writeAttribute('fo:text-align', 'left'); |
|
228 | 1 | break; |
|
229 | 13 | } |
|
230 | 13 | $objWriter->endElement(); |
|
231 | 13 | $objWriter->endElement(); |
|
232 | 13 | } |
|
233 | 13 | } |
|
234 | // Style : Text : Font |
||
235 | 41 | if (!empty($this->arrStyleTextFont)) { |
|
236 | 9 | foreach ($this->arrStyleTextFont as $key => $item) { |
|
237 | // style:style |
||
238 | 9 | $objWriter->startElement('style:style'); |
|
239 | 9 | $objWriter->writeAttribute('style:name', 'T_' . $key); |
|
240 | 9 | $objWriter->writeAttribute('style:family', 'text'); |
|
241 | // style:text-properties |
||
242 | 9 | $objWriter->startElement('style:text-properties'); |
|
243 | 9 | $objWriter->writeAttribute('fo:color', '#' . $item->getColor()->getRGB()); |
|
244 | 9 | $objWriter->writeAttribute('fo:font-family', $item->getName()); |
|
245 | 9 | $objWriter->writeAttribute('fo:font-size', $item->getSize() . 'pt'); |
|
246 | // @todo : fo:font-style |
||
247 | 9 | if ($item->isBold()) { |
|
248 | 1 | $objWriter->writeAttribute('fo:font-weight', 'bold'); |
|
249 | 1 | } |
|
250 | // @todo : style:text-underline-style |
||
251 | 9 | $objWriter->endElement(); |
|
252 | 9 | $objWriter->endElement(); |
|
253 | 9 | } |
|
254 | 9 | } |
|
255 | 41 | $objWriter->endElement(); |
|
256 | |||
257 | //=============================================== |
||
258 | // Body |
||
259 | //=============================================== |
||
260 | // office:body |
||
261 | 41 | $objWriter->startElement('office:body'); |
|
262 | // office:presentation |
||
263 | 41 | $objWriter->startElement('office:presentation'); |
|
264 | |||
265 | // Write slides |
||
266 | 41 | $slideCount = $pPhpPresentation->getSlideCount(); |
|
267 | 41 | $this->shapeId = 0; |
|
268 | 41 | for ($i = 0; $i < $slideCount; ++$i) { |
|
269 | 41 | $pSlide = $pPhpPresentation->getSlide($i); |
|
270 | 41 | $objWriter->startElement('draw:page'); |
|
271 | 41 | $name = $pSlide->getName(); |
|
272 | 41 | if (!is_null($name)) { |
|
273 | 1 | $objWriter->writeAttribute('draw:name', $name); |
|
274 | 1 | } |
|
275 | 41 | $objWriter->writeAttribute('draw:master-page-name', 'Standard'); |
|
276 | 41 | $objWriter->writeAttribute('draw:style-name', 'stylePage' . $i); |
|
277 | // Images |
||
278 | 41 | $shapes = $pSlide->getShapeCollection(); |
|
279 | 41 | foreach ($shapes as $shape) { |
|
280 | // Increment $this->shapeId |
||
281 | 36 | ++$this->shapeId; |
|
282 | |||
283 | // Check type |
||
284 | 36 | if ($shape instanceof RichText) { |
|
285 | 13 | $this->writeShapeTxt($objWriter, $shape); |
|
286 | 36 | } elseif ($shape instanceof Table) { |
|
287 | 7 | $this->writeShapeTable($objWriter, $shape); |
|
288 | 24 | } elseif ($shape instanceof Line) { |
|
289 | 1 | $this->writeShapeLine($objWriter, $shape); |
|
290 | 18 | } elseif ($shape instanceof Chart) { |
|
291 | 14 | $this->writeShapeChart($objWriter, $shape); |
|
292 | 18 | } elseif ($shape instanceof AbstractDrawing) { |
|
293 | 4 | $this->writeShapePic($objWriter, $shape); |
|
294 | 5 | } elseif ($shape instanceof Group) { |
|
295 | 1 | $this->writeShapeGroup($objWriter, $shape); |
|
296 | 1 | } |
|
297 | 41 | } |
|
298 | // Slide Note |
||
299 | 41 | if ($pSlide->getNote() instanceof Note) { |
|
300 | 41 | $this->writeSlideNote($objWriter, $pSlide->getNote()); |
|
301 | 41 | } |
|
302 | |||
303 | 41 | $objWriter->endElement(); |
|
304 | 41 | } |
|
305 | |||
306 | 41 | if ($pPhpPresentation->getPresentationProperties()->isLoopContinuouslyUntilEsc()) { |
|
307 | $objWriter->startElement('presentation:settings'); |
||
308 | $objWriter->writeAttribute('presentation:endless', 'true'); |
||
309 | $objWriter->writeAttribute('presentation:pause', 'P0s'); |
||
310 | $objWriter->writeAttribute('presentation:mouse-visible', 'false'); |
||
311 | $objWriter->endElement(); |
||
312 | } |
||
313 | // > office:presentation |
||
314 | 41 | $objWriter->endElement(); |
|
315 | // > office:body |
||
316 | 41 | $objWriter->endElement(); |
|
317 | // > office:document-content |
||
318 | 41 | $objWriter->endElement(); |
|
319 | |||
320 | // Return |
||
321 | 41 | return $objWriter->getData(); |
|
322 | } |
||
323 | |||
324 | /** |
||
325 | * Write picture |
||
326 | * |
||
327 | * @param \PhpOffice\Common\XMLWriter $objWriter |
||
328 | * @param \PhpOffice\PhpPresentation\Shape\AbstractDrawing $shape |
||
329 | */ |
||
330 | 5 | public function writeShapePic(XMLWriter $objWriter, AbstractDrawing $shape) |
|
331 | { |
||
332 | // draw:frame |
||
333 | 5 | $objWriter->startElement('draw:frame'); |
|
334 | 5 | $objWriter->writeAttribute('draw:name', $shape->getName()); |
|
335 | 5 | $objWriter->writeAttribute('svg:width', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getWidth()), 3) . 'cm'); |
|
336 | 5 | $objWriter->writeAttribute('svg:height', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getHeight()), 3) . 'cm'); |
|
337 | 5 | $objWriter->writeAttribute('svg:x', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetX()), 3) . 'cm'); |
|
338 | 5 | $objWriter->writeAttribute('svg:y', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetY()), 3) . 'cm'); |
|
339 | 5 | $objWriter->writeAttribute('draw:style-name', 'gr' . $this->shapeId); |
|
340 | // draw:image |
||
341 | 5 | $objWriter->startElement('draw:image'); |
|
342 | 5 | if ($shape instanceof ShapeDrawing) { |
|
343 | 4 | $objWriter->writeAttribute('xlink:href', 'Pictures/' . md5($shape->getPath()) . '.' . $shape->getExtension()); |
|
344 | 5 | } elseif ($shape instanceof MemoryDrawing) { |
|
345 | 1 | $objWriter->writeAttribute('xlink:href', 'Pictures/' . $shape->getIndexedFilename()); |
|
346 | 1 | } |
|
347 | 5 | $objWriter->writeAttribute('xlink:type', 'simple'); |
|
348 | 5 | $objWriter->writeAttribute('xlink:show', 'embed'); |
|
349 | 5 | $objWriter->writeAttribute('xlink:actuate', 'onLoad'); |
|
350 | 5 | $objWriter->writeElement('text:p'); |
|
351 | 5 | $objWriter->endElement(); |
|
352 | |||
353 | 5 | if ($shape->hasHyperlink()) { |
|
354 | // office:event-listeners |
||
355 | 2 | $objWriter->startElement('office:event-listeners'); |
|
356 | // presentation:event-listener |
||
357 | 2 | $objWriter->startElement('presentation:event-listener'); |
|
358 | 2 | $objWriter->writeAttribute('script:event-name', 'dom:click'); |
|
359 | 2 | $objWriter->writeAttribute('presentation:action', 'show'); |
|
360 | 2 | $objWriter->writeAttribute('xlink:href', $shape->getHyperlink()->getUrl()); |
|
361 | 2 | $objWriter->writeAttribute('xlink:type', 'simple'); |
|
362 | 2 | $objWriter->writeAttribute('xlink:show', 'embed'); |
|
363 | 2 | $objWriter->writeAttribute('xlink:actuate', 'onRequest'); |
|
364 | // > presentation:event-listener |
||
365 | 2 | $objWriter->endElement(); |
|
366 | // > office:event-listeners |
||
367 | 2 | $objWriter->endElement(); |
|
368 | 2 | } |
|
369 | |||
370 | 5 | $objWriter->endElement(); |
|
371 | 5 | } |
|
372 | |||
373 | /** |
||
374 | * Write text |
||
375 | * |
||
376 | * @param \PhpOffice\Common\XMLWriter $objWriter |
||
377 | * @param \PhpOffice\PhpPresentation\Shape\RichText $shape |
||
378 | */ |
||
379 | 14 | public function writeShapeTxt(XMLWriter $objWriter, RichText $shape) |
|
380 | { |
||
381 | // draw:frame |
||
382 | 14 | $objWriter->startElement('draw:frame'); |
|
383 | 14 | $objWriter->writeAttribute('draw:style-name', 'gr' . $this->shapeId); |
|
384 | 14 | $objWriter->writeAttribute('svg:width', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getWidth()), 3) . 'cm'); |
|
385 | 14 | $objWriter->writeAttribute('svg:height', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getHeight()), 3) . 'cm'); |
|
386 | 14 | $objWriter->writeAttribute('svg:x', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetX()), 3) . 'cm'); |
|
387 | 14 | $objWriter->writeAttribute('svg:y', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetY()), 3) . 'cm'); |
|
388 | // draw:text-box |
||
389 | 14 | $objWriter->startElement('draw:text-box'); |
|
390 | |||
391 | 14 | $paragraphs = $shape->getParagraphs(); |
|
392 | 14 | $paragraphId = 0; |
|
393 | 14 | $sCstShpLastBullet = ''; |
|
394 | 14 | $iCstShpLastBulletLvl = 0; |
|
395 | 14 | $bCstShpHasBullet = false; |
|
396 | |||
397 | 14 | foreach ($paragraphs as $paragraph) { |
|
398 | // Close the bullet list |
||
399 | 14 | if ($sCstShpLastBullet != 'bullet' && $bCstShpHasBullet === true) { |
|
400 | for ($iInc = $iCstShpLastBulletLvl; $iInc >= 0; $iInc--) { |
||
401 | // text:list-item |
||
402 | $objWriter->endElement(); |
||
403 | // text:list |
||
404 | $objWriter->endElement(); |
||
405 | } |
||
406 | } |
||
407 | //=============================================== |
||
408 | // Paragraph |
||
409 | //=============================================== |
||
410 | 14 | if ($paragraph->getBulletStyle()->getBulletType() == 'none') { |
|
411 | 11 | ++$paragraphId; |
|
412 | // text:p |
||
413 | 11 | $objWriter->startElement('text:p'); |
|
414 | 11 | $objWriter->writeAttribute('text:style-name', 'P_' . $paragraph->getHashCode()); |
|
415 | |||
416 | // Loop trough rich text elements |
||
417 | 11 | $richtexts = $paragraph->getRichTextElements(); |
|
418 | 11 | $richtextId = 0; |
|
419 | 11 | foreach ($richtexts as $richtext) { |
|
420 | 5 | ++$richtextId; |
|
421 | 5 | if ($richtext instanceof TextElement || $richtext instanceof Run) { |
|
422 | // text:span |
||
423 | 5 | $objWriter->startElement('text:span'); |
|
424 | 5 | if ($richtext instanceof Run) { |
|
425 | 5 | $objWriter->writeAttribute('text:style-name', 'T_' . $richtext->getFont()->getHashCode()); |
|
426 | 5 | } |
|
427 | 5 | if ($richtext->hasHyperlink() === true && $richtext->getHyperlink()->getUrl() != '') { |
|
428 | // text:a |
||
429 | 1 | $objWriter->startElement('text:a'); |
|
430 | 1 | $objWriter->writeAttribute('xlink:href', $richtext->getHyperlink()->getUrl()); |
|
431 | 1 | $objWriter->text($richtext->getText()); |
|
432 | 1 | $objWriter->endElement(); |
|
433 | 1 | } else { |
|
434 | 5 | $objWriter->text($richtext->getText()); |
|
435 | } |
||
436 | 5 | $objWriter->endElement(); |
|
437 | 5 | } elseif ($richtext instanceof BreakElement) { |
|
438 | // text:span |
||
439 | 1 | $objWriter->startElement('text:span'); |
|
440 | // text:line-break |
||
441 | 1 | $objWriter->startElement('text:line-break'); |
|
442 | 1 | $objWriter->endElement(); |
|
443 | 1 | $objWriter->endElement(); |
|
444 | 1 | } else { |
|
445 | //echo '<pre>'.print_r($richtext, true).'</pre>'; |
||
446 | } |
||
447 | 11 | } |
|
448 | 11 | $objWriter->endElement(); |
|
449 | //=============================================== |
||
450 | // Bullet list |
||
451 | //=============================================== |
||
452 | 14 | } elseif ($paragraph->getBulletStyle()->getBulletType() == 'bullet') { |
|
453 | 3 | $bCstShpHasBullet = true; |
|
454 | // Open the bullet list |
||
455 | 3 | if ($sCstShpLastBullet != 'bullet' || ($sCstShpLastBullet == $paragraph->getBulletStyle()->getBulletType() && $iCstShpLastBulletLvl < $paragraph->getAlignment()->getLevel())) { |
|
456 | // text:list |
||
457 | 3 | $objWriter->startElement('text:list'); |
|
458 | 3 | $objWriter->writeAttribute('text:style-name', 'L_' . $paragraph->getBulletStyle()->getHashCode()); |
|
459 | 3 | } |
|
460 | 3 | if ($sCstShpLastBullet == 'bullet') { |
|
461 | 2 | if ($iCstShpLastBulletLvl == $paragraph->getAlignment()->getLevel()) { |
|
462 | // text:list-item |
||
463 | 2 | $objWriter->endElement(); |
|
464 | 2 | } elseif ($iCstShpLastBulletLvl > $paragraph->getAlignment()->getLevel()) { |
|
465 | // text:list-item |
||
466 | 1 | $objWriter->endElement(); |
|
467 | // text:list |
||
468 | 1 | $objWriter->endElement(); |
|
469 | // text:list-item |
||
470 | 1 | $objWriter->endElement(); |
|
471 | 1 | } |
|
472 | 2 | } |
|
473 | |||
474 | // text:list-item |
||
475 | 3 | $objWriter->startElement('text:list-item'); |
|
476 | 3 | ++$paragraphId; |
|
477 | // text:p |
||
478 | 3 | $objWriter->startElement('text:p'); |
|
479 | 3 | $objWriter->writeAttribute('text:style-name', 'P_' . $paragraph->getHashCode()); |
|
480 | |||
481 | // Loop trough rich text elements |
||
482 | 3 | $richtexts = $paragraph->getRichTextElements(); |
|
483 | 3 | $richtextId = 0; |
|
484 | 3 | foreach ($richtexts as $richtext) { |
|
485 | 3 | ++$richtextId; |
|
486 | 3 | if ($richtext instanceof TextElement || $richtext instanceof Run) { |
|
487 | // text:span |
||
488 | 3 | $objWriter->startElement('text:span'); |
|
489 | 3 | if ($richtext instanceof Run) { |
|
490 | 3 | $objWriter->writeAttribute('text:style-name', 'T_' . $richtext->getFont()->getHashCode()); |
|
491 | 3 | } |
|
492 | 3 | if ($richtext->hasHyperlink() === true && $richtext->getHyperlink()->getUrl() != '') { |
|
493 | // text:a |
||
494 | 1 | $objWriter->startElement('text:a'); |
|
495 | 1 | $objWriter->writeAttribute('xlink:href', $richtext->getHyperlink()->getUrl()); |
|
496 | 1 | $objWriter->text($richtext->getText()); |
|
497 | 1 | $objWriter->endElement(); |
|
498 | 1 | } else { |
|
499 | 3 | $objWriter->text($richtext->getText()); |
|
500 | } |
||
501 | 3 | $objWriter->endElement(); |
|
502 | 3 | } elseif ($richtext instanceof BreakElement) { |
|
503 | // text:span |
||
504 | 1 | $objWriter->startElement('text:span'); |
|
505 | // text:line-break |
||
506 | 1 | $objWriter->startElement('text:line-break'); |
|
507 | 1 | $objWriter->endElement(); |
|
508 | 1 | $objWriter->endElement(); |
|
509 | 1 | } else { |
|
510 | //echo '<pre>'.print_r($richtext, true).'</pre>'; |
||
511 | } |
||
512 | 3 | } |
|
513 | 3 | $objWriter->endElement(); |
|
514 | 3 | } |
|
515 | 14 | $sCstShpLastBullet = $paragraph->getBulletStyle()->getBulletType(); |
|
516 | 14 | $iCstShpLastBulletLvl = $paragraph->getAlignment()->getLevel(); |
|
517 | 14 | } |
|
518 | |||
519 | // Close the bullet list |
||
520 | 14 | if ($sCstShpLastBullet == 'bullet' && $bCstShpHasBullet === true) { |
|
521 | 3 | for ($iInc = $iCstShpLastBulletLvl; $iInc >= 0; $iInc--) { |
|
522 | // text:list-item |
||
523 | 3 | $objWriter->endElement(); |
|
524 | // text:list |
||
525 | 3 | $objWriter->endElement(); |
|
526 | 3 | } |
|
527 | 3 | } |
|
528 | |||
529 | // > draw:text-box |
||
530 | 14 | $objWriter->endElement(); |
|
531 | // > draw:frame |
||
532 | 14 | $objWriter->endElement(); |
|
533 | 14 | } |
|
534 | |||
535 | /** |
||
536 | * @param XMLWriter $objWriter |
||
537 | * @param Line $shape |
||
538 | */ |
||
539 | 1 | public function writeShapeLine(XMLWriter $objWriter, Line $shape) |
|
554 | |||
555 | /** |
||
556 | * Write table Shape |
||
557 | * @param XMLWriter $objWriter |
||
558 | * @param Table $shape |
||
559 | */ |
||
560 | 7 | public function writeShapeTable(XMLWriter $objWriter, Table $shape) |
|
641 | |||
642 | /** |
||
643 | * Write table Chart |
||
644 | * @param XMLWriter $objWriter |
||
645 | * @param Chart $shape |
||
646 | */ |
||
647 | 14 | public function writeShapeChart(XMLWriter $objWriter, Chart $shape) |
|
674 | |||
675 | /** |
||
676 | * Writes a group of shapes |
||
677 | * |
||
678 | * @param XMLWriter $objWriter |
||
679 | * @param Group $group |
||
680 | */ |
||
681 | 1 | public function writeShapeGroup(XMLWriter $objWriter, Group $group) |
|
709 | |||
710 | /** |
||
711 | * Writes the style information for a group of shapes |
||
712 | * |
||
713 | * @param XMLWriter $objWriter |
||
714 | * @param Group $group |
||
715 | */ |
||
716 | 1 | public function writeGroupStyle(XMLWriter $objWriter, Group $group) |
|
738 | |||
739 | /** |
||
740 | * Write the default style information for a RichText shape |
||
741 | * |
||
742 | * @param \PhpOffice\Common\XMLWriter $objWriter |
||
743 | * @param \PhpOffice\PhpPresentation\Shape\RichText $shape |
||
744 | */ |
||
745 | 13 | public function writeTxtStyle(XMLWriter $objWriter, RichText $shape) |
|
849 | |||
850 | /** |
||
851 | * Write the default style information for an AbstractDrawing |
||
852 | * |
||
853 | * @param \PhpOffice\Common\XMLWriter $objWriter |
||
854 | * @param \PhpOffice\PhpPresentation\Shape\AbstractDrawing $shape |
||
855 | */ |
||
856 | 24 | public function writeDrawingStyle(XMLWriter $objWriter, AbstractDrawing $shape) |
|
875 | |||
876 | /** |
||
877 | * Write the default style information for a Line shape. |
||
878 | * |
||
879 | * @param XMLWriter $objWriter |
||
880 | * @param Line $shape |
||
881 | */ |
||
882 | 1 | public function writeLineStyle(XMLWriter $objWriter, Line $shape) |
|
910 | |||
911 | /** |
||
912 | * Write the default style information for a Table shape |
||
913 | * |
||
914 | * @param XMLWriter $objWriter |
||
915 | * @param Table $shape |
||
916 | */ |
||
917 | 7 | public function writeTableStyle(XMLWriter $objWriter, Table $shape) |
|
1018 | |||
1019 | /** |
||
1020 | * Write the slide note |
||
1021 | * @param XMLWriter $objWriter |
||
1022 | * @param \PhpOffice\PhpPresentation\Slide\Note $note |
||
1023 | */ |
||
1024 | 41 | public function writeSlideNote(XMLWriter $objWriter, Note $note) |
|
1042 | |||
1043 | /** |
||
1044 | * Write style of a slide |
||
1045 | * @param XMLWriter $objWriter |
||
1046 | * @param Slide $slide |
||
1047 | * @param int $incPage |
||
1048 | */ |
||
1049 | 41 | public function writeStyleSlide(XMLWriter $objWriter, Slide $slide, $incPage) |
|
1243 | |||
1244 | |||
1245 | /** |
||
1246 | * @param XMLWriter $objWriter |
||
1247 | * @param Shadow $oShadow |
||
1248 | * @todo Improve for supporting any direction (https://sinepost.wordpress.com/2012/02/16/theyve-got-atan-you-want-atan2/) |
||
1249 | */ |
||
1250 | 1 | protected function writeStylePartShadow(XMLWriter $objWriter, Shadow $oShadow) |
|
1283 | } |
||
1284 |