Completed
Pull Request — develop (#322)
by Thomas
08:13 queued 03:00
created

Content::writeShapeTable()   C

Complexity

Conditions 13
Paths 19

Size

Total Lines 81
Code Lines 46

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 54
CRAP Score 13

Importance

Changes 0
Metric Value
dl 0
loc 81
ccs 54
cts 54
cp 1
rs 5.0112
c 0
b 0
f 0
cc 13
eloc 46
nc 19
nop 2
crap 13

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace PhpOffice\PhpPresentation\Writer\ODPresentation;
4
5
use PhpOffice\Common\Adapter\Zip\ZipInterface;
6
use PhpOffice\Common\Drawing as CommonDrawing;
7
use PhpOffice\Common\Text;
8
use PhpOffice\Common\XMLWriter;
9
use PhpOffice\PhpPresentation\Shape\Comment;
10
use PhpOffice\PhpPresentation\Shape\Media;
11
use PhpOffice\PhpPresentation\Slide;
12
use PhpOffice\PhpPresentation\Shape\AbstractDrawing;
13
use PhpOffice\PhpPresentation\Shape\Chart;
14
use PhpOffice\PhpPresentation\Shape\Drawing as ShapeDrawing;
15
use PhpOffice\PhpPresentation\Shape\Group;
16
use PhpOffice\PhpPresentation\Shape\Line;
17
use PhpOffice\PhpPresentation\Shape\RichText\BreakElement;
18
use PhpOffice\PhpPresentation\Shape\RichText\Run;
19
use PhpOffice\PhpPresentation\Shape\RichText\TextElement;
20
use PhpOffice\PhpPresentation\Shape\RichText;
21
use PhpOffice\PhpPresentation\Shape\Table;
22
use PhpOffice\PhpPresentation\Slide\Note;
23
use PhpOffice\PhpPresentation\Slide\Transition;
24
use PhpOffice\PhpPresentation\Style\Alignment;
25
use PhpOffice\PhpPresentation\Style\Border;
26
use PhpOffice\PhpPresentation\Style\Fill;
27
use PhpOffice\PhpPresentation\Style\Shadow;
28
use PhpOffice\PhpPresentation\Writer\ODPresentation;
29
30
class Content extends AbstractDecoratorWriter
31
{
32
    /**
33
     * Stores bullet styles for text shapes that include lists.
34
     *
35
     * @var []
36
     */
37
    protected $arrStyleBullet    = array();
38
39
    /**
40
     * Stores paragraph information for text shapes.
41
     *
42
     * @var array
43
     */
44
    protected $arrStyleParagraph = array();
45
46
    /**
47
     * Stores font styles for text shapes that include lists.
48
     *
49
     * @var Run[]
50
     */
51
    protected $arrStyleTextFont  = array();
52
53
    /**
54
     * Used to track the current shape ID.
55
     *
56
     * @var integer
57
     */
58
    protected $shapeId;
59
60
    /**
61
     * @return ZipInterface
62
     */
63 59
    public function render()
64
    {
65 59
        $this->getZip()->addFromString('content.xml', $this->writeContent());
66 59
        return $this->getZip();
67
    }
68
69
70
71
    /**
72
     * Write content file to XML format
73
     *
74
     * @return string        XML Output
75
     * @throws \Exception
76
     */
77 59
    public function writeContent()
78
    {
79
        // Create XML writer
80 59
        $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
81 59
        $objWriter->startDocument('1.0', 'UTF-8');
82
83
        // office:document-content
84 59
        $objWriter->startElement('office:document-content');
85 59
        $objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
86 59
        $objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
87 59
        $objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
88 59
        $objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
89 59
        $objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
90 59
        $objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
91 59
        $objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
92 59
        $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
93 59
        $objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
94 59
        $objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
95 59
        $objWriter->writeAttribute('xmlns:presentation', 'urn:oasis:names:tc:opendocument:xmlns:presentation:1.0');
96 59
        $objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
97 59
        $objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
98 59
        $objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
99 59
        $objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
100 59
        $objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
101 59
        $objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
102 59
        $objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
103 59
        $objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
104 59
        $objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
105 59
        $objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
106 59
        $objWriter->writeAttribute('xmlns:xforms', 'http://www.w3.org/2002/xforms');
107 59
        $objWriter->writeAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
108 59
        $objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
109 59
        $objWriter->writeAttribute('xmlns:smil', 'urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0');
110 59
        $objWriter->writeAttribute('xmlns:anim', 'urn:oasis:names:tc:opendocument:xmlns:animation:1.0');
111 59
        $objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
112 59
        $objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
113 59
        $objWriter->writeAttribute('xmlns:rdfa', 'http://docs.oasis-open.org/opendocument/meta/rdfa#');
114 59
        $objWriter->writeAttribute('xmlns:field', 'urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0');
115 59
        $objWriter->writeAttribute('xmlns:officeooo', 'http://openoffice.org/2009/office');
116 59
        $objWriter->writeAttribute('office:version', '1.2');
117
118
        // office:automatic-styles
119 59
        $objWriter->startElement('office:automatic-styles');
120
121 59
        $this->shapeId    = 0;
122 59
        $incSlide = 0;
123 59
        foreach ($this->getPresentation()->getAllSlides() as $pSlide) {
124
            // Slides
125 59
            $this->writeStyleSlide($objWriter, $pSlide, $incSlide);
126
127
            // Images
128 59
            $shapes = $pSlide->getShapeCollection();
129 59
            foreach ($shapes as $shape) {
130
                // Increment $this->shapeId
131 51
                ++$this->shapeId;
132
133
                // Check type
134 51
                if ($shape instanceof RichText) {
135 14
                    $this->writeTxtStyle($objWriter, $shape);
136 14
                }
137 51
                if ($shape instanceof AbstractDrawing) {
0 ignored issues
show
Bug introduced by
The class PhpOffice\PhpPresentation\Shape\AbstractDrawing does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
138
                    $this->writeDrawingStyle($objWriter, $shape);
139
                }
140 51
                if ($shape instanceof Line) {
141 1
                    $this->writeLineStyle($objWriter, $shape);
142 1
                }
143 51
                if ($shape instanceof Table) {
144 7
                    $this->writeTableStyle($objWriter, $shape);
145 7
                }
146 51
                if ($shape instanceof Group) {
147 1
                    $this->writeGroupStyle($objWriter, $shape);
148 1
                }
149 59
            }
150
151 59
            $incSlide++;
152 59
        }
153
        // Style : Bullet
154 59
        if (!empty($this->arrStyleBullet)) {
155 14
            foreach ($this->arrStyleBullet as $key => $item) {
156 14
                $oStyle   = $item['oStyle'];
157 14
                $arrLevel = explode(';', $item['level']);
158
                // style:style
159 14
                $objWriter->startElement('text:list-style');
160 14
                $objWriter->writeAttribute('style:name', 'L_' . $key);
161 14
                foreach ($arrLevel as $level) {
162 14
                    if ($level != '') {
163 14
                        $oAlign = $item['oAlign_' . $level];
164
                        // text:list-level-style-bullet
165 14
                        $objWriter->startElement('text:list-level-style-bullet');
166 14
                        $objWriter->writeAttribute('text:level', $level + 1);
167 14
                        $objWriter->writeAttribute('text:bullet-char', $oStyle->getBulletChar());
168
                        // style:list-level-properties
169 14
                        $objWriter->startElement('style:list-level-properties');
170 14
                        if ($oAlign->getIndent() < 0) {
171 1
                            $objWriter->writeAttribute('text:space-before', CommonDrawing::pixelsToCentimeters($oAlign->getMarginLeft() - (-1 * $oAlign->getIndent())) . 'cm');
172 1
                            $objWriter->writeAttribute('text:min-label-width', CommonDrawing::pixelsToCentimeters(-1 * $oAlign->getIndent()) . 'cm');
173 1
                        } else {
174 13
                            $objWriter->writeAttribute('text:space-before', (CommonDrawing::pixelsToCentimeters($oAlign->getMarginLeft() - $oAlign->getIndent())) . 'cm');
175 13
                            $objWriter->writeAttribute('text:min-label-width', CommonDrawing::pixelsToCentimeters($oAlign->getIndent()) . 'cm');
176
                        }
177
178 14
                        $objWriter->endElement();
179
                        // style:text-properties
180 14
                        $objWriter->startElement('style:text-properties');
181 14
                        $objWriter->writeAttribute('fo:font-family', $oStyle->getBulletFont());
182 14
                        $objWriter->writeAttribute('style:font-family-generic', 'swiss');
183 14
                        $objWriter->writeAttribute('style:use-window-font-color', 'true');
184 14
                        $objWriter->writeAttribute('fo:font-size', '100');
185 14
                        $objWriter->endElement();
186 14
                        $objWriter->endElement();
187 14
                    }
188 14
                }
189 14
                $objWriter->endElement();
190 14
            }
191 14
        }
192
        // Style : Paragraph
193 59
        if (!empty($this->arrStyleParagraph)) {
194 14
            foreach ($this->arrStyleParagraph as $key => $item) {
195
                // style:style
196 14
                $objWriter->startElement('style:style');
197 14
                $objWriter->writeAttribute('style:name', 'P_' . $key);
198 14
                $objWriter->writeAttribute('style:family', 'paragraph');
199
                // style:paragraph-properties
200 14
                $objWriter->startElement('style:paragraph-properties');
201 14
                switch ($item->getAlignment()->getHorizontal()) {
202 14
                    case Alignment::HORIZONTAL_LEFT:
203 14
                        $objWriter->writeAttribute('fo:text-align', 'left');
204 14
                        break;
205 1
                    case Alignment::HORIZONTAL_RIGHT:
206 1
                        $objWriter->writeAttribute('fo:text-align', 'right');
207 1
                        break;
208 1
                    case Alignment::HORIZONTAL_CENTER:
209 1
                        $objWriter->writeAttribute('fo:text-align', 'center');
210 1
                        break;
211 1
                    case Alignment::HORIZONTAL_JUSTIFY:
212 1
                        $objWriter->writeAttribute('fo:text-align', 'justify');
213 1
                        break;
214 1
                    case Alignment::HORIZONTAL_DISTRIBUTED:
215 1
                        $objWriter->writeAttribute('fo:text-align', 'justify');
216 1
                        break;
217 1
                    default:
218 1
                        $objWriter->writeAttribute('fo:text-align', 'left');
219 1
                        break;
220 14
                }
221 14
                $objWriter->endElement();
222 14
                $objWriter->endElement();
223 14
            }
224 14
        }
225
        // Style : Text : Font
226 59
        if (!empty($this->arrStyleTextFont)) {
227 10
            foreach ($this->arrStyleTextFont as $key => $item) {
228
                // style:style
229 10
                $objWriter->startElement('style:style');
230 10
                $objWriter->writeAttribute('style:name', 'T_' . $key);
231 10
                $objWriter->writeAttribute('style:family', 'text');
232
                // style:text-properties
233 10
                $objWriter->startElement('style:text-properties');
234 10
                $objWriter->writeAttribute('fo:color', '#' . $item->getFont()->getColor()->getRGB());
235 10
                $objWriter->writeAttribute('fo:font-family', $item->getFont()->getName());
236 10
                $objWriter->writeAttribute('fo:font-size', $item->getFont()->getSize() . 'pt');
237
                // @todo : fo:font-style
238 10
                if ($item->getFont()->isBold()) {
239 1
                    $objWriter->writeAttribute('fo:font-weight', 'bold');
240 1
                }
241 10
                $objWriter->writeAttribute('fo:language', ($item->getLanguage() ? $item->getLanguage() : 'en-US'));
242
243
                // @todo : style:text-underline-style
244 10
                $objWriter->endElement();
245 10
                $objWriter->endElement();
246 10
            }
247 10
        }
248 59
        $objWriter->endElement();
249
250
        //===============================================
251
        // Body
252
        //===============================================
253
        // office:body
254 59
        $objWriter->startElement('office:body');
255
        // office:presentation
256 59
        $objWriter->startElement('office:presentation');
257
258
        // Write slides
259 59
        $slideCount = $this->getPresentation()->getSlideCount();
260 59
        $this->shapeId    = 0;
261 59
        for ($i = 0; $i < $slideCount; ++$i) {
262 59
            $pSlide = $this->getPresentation()->getSlide($i);
263 59
            $objWriter->startElement('draw:page');
264 59
            $name = $pSlide->getName();
265 59
            if (!is_null($name)) {
266 1
                $objWriter->writeAttribute('draw:name', $name);
267 1
            }
268 59
            $objWriter->writeAttribute('draw:master-page-name', 'Standard');
269 59
            $objWriter->writeAttribute('draw:style-name', 'stylePage' . $i);
270
            // Images
271 59
            $shapes = $pSlide->getShapeCollection();
272 59
            foreach ($shapes as $shape) {
273
                // Increment $this->shapeId
274 51
                ++$this->shapeId;
275
276
                // Check type
277 51
                if ($shape instanceof RichText) {
278 14
                    $this->writeShapeTxt($objWriter, $shape);
279 51
                } elseif ($shape instanceof Table) {
280 7
                    $this->writeShapeTable($objWriter, $shape);
281 38
                } elseif ($shape instanceof Line) {
282 1
                    $this->writeShapeLine($objWriter, $shape);
283 32
                } elseif ($shape instanceof Chart) {
284 21
                    $this->writeShapeChart($objWriter, $shape);
285 32
                } elseif ($shape instanceof Media) {
286 1
                    $this->writeShapeMedia($objWriter, $shape);
287 12
                } elseif ($shape instanceof ShapeDrawing\AbstractDrawingAdapter) {
288 8
                    $this->writeShapeDrawing($objWriter, $shape);
289 11
                } elseif ($shape instanceof Group) {
290 1
                    $this->writeShapeGroup($objWriter, $shape);
291 3
                } elseif ($shape instanceof Comment) {
292 2
                    $this->writeShapeComment($objWriter, $shape);
293 2
                }
294 59
            }
295
            // Slide Note
296 59
            if ($pSlide->getNote() instanceof Note) {
297 59
                $this->writeSlideNote($objWriter, $pSlide->getNote());
298 59
            }
299
300 59
            $objWriter->endElement();
301 59
        }
302
303 59
        if ($this->getPresentation()->getPresentationProperties()->isLoopContinuouslyUntilEsc()) {
304
            $objWriter->startElement('presentation:settings');
305
            $objWriter->writeAttribute('presentation:endless', 'true');
306
            $objWriter->writeAttribute('presentation:pause', 'P0s');
307
            $objWriter->writeAttribute('presentation:mouse-visible', 'false');
308
            $objWriter->endElement();
309
        }
310
        // > office:presentation
311 59
        $objWriter->endElement();
312
        // > office:body
313 59
        $objWriter->endElement();
314
        // > office:document-content
315 59
        $objWriter->endElement();
316
317
        // Return
318 59
        return $objWriter->getData();
319
    }
320
321
    /**
322
     * Write picture
323
     *
324
     * @param \PhpOffice\Common\XMLWriter $objWriter
325
     * @param \PhpOffice\PhpPresentation\Shape\Media $shape
326
     */
327 1
    public function writeShapeMedia(XMLWriter $objWriter, Media $shape)
328
    {
329
        // draw:frame
330 1
        $objWriter->startElement('draw:frame');
331 1
        $objWriter->writeAttribute('draw:name', $shape->getName());
332 1
        $objWriter->writeAttribute('svg:width', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getWidth()), 3) . 'cm');
333 1
        $objWriter->writeAttribute('svg:height', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getHeight()), 3) . 'cm');
334 1
        $objWriter->writeAttribute('svg:x', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetX()), 3) . 'cm');
335 1
        $objWriter->writeAttribute('svg:y', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetY()), 3) . 'cm');
336 1
        $objWriter->writeAttribute('draw:style-name', 'gr' . $this->shapeId);
337
        // draw:frame > draw:plugin
338 1
        $objWriter->startElement('draw:plugin');
339 1
        $objWriter->writeAttribute('xlink:href', 'Pictures/' . $shape->getIndexedFilename());
340 1
        $objWriter->writeAttribute('xlink:type', 'simple');
341 1
        $objWriter->writeAttribute('xlink:show', 'embed');
342 1
        $objWriter->writeAttribute('xlink:actuate', 'onLoad');
343 1
        $objWriter->writeAttribute('draw:mime-type', 'application/vnd.sun.star.media');
344
345 1
        $objWriter->startElement('draw:param');
346 1
        $objWriter->writeAttribute('draw:name', 'Loop');
347 1
        $objWriter->writeAttribute('draw:value', 'false');
348 1
        $objWriter->endElement();
349 1
        $objWriter->startElement('draw:param');
350 1
        $objWriter->writeAttribute('draw:name', 'Mute');
351 1
        $objWriter->writeAttribute('draw:value', 'false');
352 1
        $objWriter->endElement();
353 1
        $objWriter->startElement('draw:param');
354 1
        $objWriter->writeAttribute('draw:name', 'VolumeDB');
355 1
        $objWriter->writeAttribute('draw:value', 0);
356 1
        $objWriter->endElement();
357 1
        $objWriter->startElement('draw:param');
358 1
        $objWriter->writeAttribute('draw:name', 'Zoom');
359 1
        $objWriter->writeAttribute('draw:value', 'fit');
360 1
        $objWriter->endElement();
361
362
        // draw:frame > ## draw:plugin
363 1
        $objWriter->endElement();
364
365
        // ## draw:frame
366 1
        $objWriter->endElement();
367 1
    }
368
369
    /**
370
     * Write picture
371
     *
372
     * @param \PhpOffice\Common\XMLWriter $objWriter
373
     * @param \PhpOffice\PhpPresentation\Shape\AbstractDrawing $shape
374
     */
375 9
    public function writeShapeDrawing(XMLWriter $objWriter, ShapeDrawing\AbstractDrawingAdapter $shape)
376
    {
377
        // draw:frame
378 9
        $objWriter->startElement('draw:frame');
379 9
        $objWriter->writeAttribute('draw:name', $shape->getName());
380 9
        $objWriter->writeAttribute('svg:width', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getWidth()), 3) . 'cm');
381 9
        $objWriter->writeAttribute('svg:height', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getHeight()), 3) . 'cm');
382 9
        $objWriter->writeAttribute('svg:x', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetX()), 3) . 'cm');
383 9
        $objWriter->writeAttribute('svg:y', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetY()), 3) . 'cm');
384 9
        $objWriter->writeAttribute('draw:style-name', 'gr' . $this->shapeId);
385
        // draw:image
386 9
        $objWriter->startElement('draw:image');
387 9
        if ($shape instanceof ShapeDrawing\AbstractDrawingAdapter) {
388 9
            $objWriter->writeAttribute('xlink:href', 'Pictures/' . $shape->getIndexedFilename());
389 9
        }
390 9
        $objWriter->writeAttribute('xlink:type', 'simple');
391 9
        $objWriter->writeAttribute('xlink:show', 'embed');
392 9
        $objWriter->writeAttribute('xlink:actuate', 'onLoad');
393 9
        $objWriter->writeElement('text:p');
394 9
        $objWriter->endElement();
395
396 9
        if ($shape->hasHyperlink()) {
397
            // office:event-listeners
398 2
            $objWriter->startElement('office:event-listeners');
399
            // presentation:event-listener
400 2
            $objWriter->startElement('presentation:event-listener');
401 2
            $objWriter->writeAttribute('script:event-name', 'dom:click');
402 2
            $objWriter->writeAttribute('presentation:action', 'show');
403 2
            $objWriter->writeAttribute('xlink:href', $shape->getHyperlink()->getUrl());
404 2
            $objWriter->writeAttribute('xlink:type', 'simple');
405 2
            $objWriter->writeAttribute('xlink:show', 'embed');
406 2
            $objWriter->writeAttribute('xlink:actuate', 'onRequest');
407
            // > presentation:event-listener
408 2
            $objWriter->endElement();
409
            // > office:event-listeners
410 2
            $objWriter->endElement();
411 2
        }
412
413 9
        $objWriter->endElement();
414 9
    }
415
416
    /**
417
     * Write text
418
     *
419
     * @param \PhpOffice\Common\XMLWriter $objWriter
420
     * @param \PhpOffice\PhpPresentation\Shape\RichText $shape
421
     */
422 15
    public function writeShapeTxt(XMLWriter $objWriter, RichText $shape)
423
    {
424
        // draw:frame
425 15
        $objWriter->startElement('draw:frame');
426 15
        $objWriter->writeAttribute('draw:style-name', 'gr' . $this->shapeId);
427 15
        $objWriter->writeAttribute('svg:width', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getWidth()), 3) . 'cm');
428 15
        $objWriter->writeAttribute('svg:height', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getHeight()), 3) . 'cm');
429 15
        $objWriter->writeAttribute('svg:x', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetX()), 3) . 'cm');
430 15
        $objWriter->writeAttribute('svg:y', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetY()), 3) . 'cm');
431
        // draw:text-box
432 15
        $objWriter->startElement('draw:text-box');
433
434 15
        $paragraphs             = $shape->getParagraphs();
435 15
        $paragraphId            = 0;
436 15
        $sCstShpLastBullet      = '';
437 15
        $iCstShpLastBulletLvl   = 0;
438 15
        $bCstShpHasBullet       = false;
439
440 15
        foreach ($paragraphs as $paragraph) {
441
            // Close the bullet list
442 15
            if ($sCstShpLastBullet != 'bullet' && $bCstShpHasBullet === true) {
443
                for ($iInc = $iCstShpLastBulletLvl; $iInc >= 0; $iInc--) {
444
                    // text:list-item
445
                    $objWriter->endElement();
446
                    // text:list
447
                    $objWriter->endElement();
448
                }
449
            }
450
            //===============================================
451
            // Paragraph
452
            //===============================================
453 15
            if ($paragraph->getBulletStyle()->getBulletType() == 'none') {
454 12
                ++$paragraphId;
455
                // text:p
456 12
                $objWriter->startElement('text:p');
457 12
                $objWriter->writeAttribute('text:style-name', 'P_' . $paragraph->getHashCode());
458
459
                // Loop trough rich text elements
460 12
                $richtexts  = $paragraph->getRichTextElements();
461 12
                $richtextId = 0;
462 12
                foreach ($richtexts as $richtext) {
463 6
                    ++$richtextId;
464 6
                    if ($richtext instanceof TextElement || $richtext instanceof Run) {
465
                        // text:span
466 6
                        $objWriter->startElement('text:span');
467 6
                        if ($richtext instanceof Run) {
468 6
                            $objWriter->writeAttribute('text:style-name', 'T_' . $richtext->getHashCode());
469 6
                        }
470 6
                        if ($richtext->hasHyperlink() === true && $richtext->getHyperlink()->getUrl() != '') {
471
                            // text:a
472 1
                            $objWriter->startElement('text:a');
473 1
                            $objWriter->writeAttribute('xlink:href', $richtext->getHyperlink()->getUrl());
474 1
                            $objWriter->text($richtext->getText());
475 1
                            $objWriter->endElement();
476 1
                        } else {
477 6
                            $objWriter->text($richtext->getText());
478
                        }
479 6
                        $objWriter->endElement();
480 6
                    } elseif ($richtext instanceof BreakElement) {
481
                        // text:span
482 1
                        $objWriter->startElement('text:span');
483
                        // text:line-break
484 1
                        $objWriter->startElement('text:line-break');
485 1
                        $objWriter->endElement();
486 1
                        $objWriter->endElement();
487 1
                    } else {
488
                        //echo '<pre>'.print_r($richtext, true).'</pre>';
489
                    }
490 12
                }
491 12
                $objWriter->endElement();
492
                //===============================================
493
                // Bullet list
494
                //===============================================
495 15
            } elseif ($paragraph->getBulletStyle()->getBulletType() == 'bullet') {
496 3
                $bCstShpHasBullet = true;
497
                // Open the bullet list
498 3
                if ($sCstShpLastBullet != 'bullet' || ($sCstShpLastBullet == $paragraph->getBulletStyle()->getBulletType() && $iCstShpLastBulletLvl < $paragraph->getAlignment()->getLevel())) {
499
                    // text:list
500 3
                    $objWriter->startElement('text:list');
501 3
                    $objWriter->writeAttribute('text:style-name', 'L_' . $paragraph->getBulletStyle()->getHashCode());
502 3
                }
503 3
                if ($sCstShpLastBullet == 'bullet') {
504 2
                    if ($iCstShpLastBulletLvl == $paragraph->getAlignment()->getLevel()) {
505
                        // text:list-item
506 2
                        $objWriter->endElement();
507 2
                    } elseif ($iCstShpLastBulletLvl > $paragraph->getAlignment()->getLevel()) {
508
                        // text:list-item
509 1
                        $objWriter->endElement();
510
                        // text:list
511 1
                        $objWriter->endElement();
512
                        // text:list-item
513 1
                        $objWriter->endElement();
514 1
                    }
515 2
                }
516
517
                // text:list-item
518 3
                $objWriter->startElement('text:list-item');
519 3
                ++$paragraphId;
520
                // text:p
521 3
                $objWriter->startElement('text:p');
522 3
                $objWriter->writeAttribute('text:style-name', 'P_' . $paragraph->getHashCode());
523
524
                // Loop trough rich text elements
525 3
                $richtexts  = $paragraph->getRichTextElements();
526 3
                $richtextId = 0;
527 3
                foreach ($richtexts as $richtext) {
528 3
                    ++$richtextId;
529 3
                    if ($richtext instanceof TextElement || $richtext instanceof Run) {
530
                        // text:span
531 3
                        $objWriter->startElement('text:span');
532 3
                        if ($richtext instanceof Run) {
533 3
                            $objWriter->writeAttribute('text:style-name', 'T_' . $richtext->getHashCode());
534 3
                        }
535 3
                        if ($richtext->hasHyperlink() === true && $richtext->getHyperlink()->getUrl() != '') {
536
                            // text:a
537 1
                            $objWriter->startElement('text:a');
538 1
                            $objWriter->writeAttribute('xlink:href', $richtext->getHyperlink()->getUrl());
539 1
                            $objWriter->text($richtext->getText());
540 1
                            $objWriter->endElement();
541 1
                        } else {
542 3
                            $objWriter->text($richtext->getText());
543
                        }
544 3
                        $objWriter->endElement();
545 3
                    } elseif ($richtext instanceof BreakElement) {
546
                        // text:span
547 1
                        $objWriter->startElement('text:span');
548
                        // text:line-break
549 1
                        $objWriter->startElement('text:line-break');
550 1
                        $objWriter->endElement();
551 1
                        $objWriter->endElement();
552 1
                    } else {
553
                        //echo '<pre>'.print_r($richtext, true).'</pre>';
554
                    }
555 3
                }
556 3
                $objWriter->endElement();
557 3
            }
558 15
            $sCstShpLastBullet      = $paragraph->getBulletStyle()->getBulletType();
559 15
            $iCstShpLastBulletLvl = $paragraph->getAlignment()->getLevel();
560 15
        }
561
562
        // Close the bullet list
563 15
        if ($sCstShpLastBullet == 'bullet' && $bCstShpHasBullet === true) {
564 3
            for ($iInc = $iCstShpLastBulletLvl; $iInc >= 0; $iInc--) {
565
                // text:list-item
566 3
                $objWriter->endElement();
567
                // text:list
568 3
                $objWriter->endElement();
569 3
            }
570 3
        }
571
572
        // > draw:text-box
573 15
        $objWriter->endElement();
574
        // > draw:frame
575 15
        $objWriter->endElement();
576 15
    }
577
    /**
578
     * Write Comment
579
     * @param XMLWriter $objWriter
580
     * @param Comment $oShape
581
     */
582 2
    public function writeShapeComment(XMLWriter $objWriter, Comment $oShape)
583
    {
584
        // officeooo:annotation
585 2
        $objWriter->startElement('officeooo:annotation');
586 2
        $objWriter->writeAttribute('svg:x', number_format(CommonDrawing::pixelsToCentimeters($oShape->getOffsetX()), 2, '.', '').'cm');
587 2
        $objWriter->writeAttribute('svg:y', number_format(CommonDrawing::pixelsToCentimeters($oShape->getOffsetY()), 2, '.', '').'cm');
588
589 2
        if ($oShape->getAuthor() instanceof Comment\Author) {
590 1
            $objWriter->writeElement('dc:creator', $oShape->getAuthor()->getName());
591 1
        }
592 2
        $objWriter->writeElement('dc:date', date('Y-m-d\TH:i:s', $oShape->getDate()));
593 2
        $objWriter->writeElement('text:p', $oShape->getText());
594
595
        // ## officeooo:annotation
596 2
        $objWriter->endElement();
597 2
    }
598
599
    /**
600
     * @param XMLWriter $objWriter
601
     * @param Line $shape
602
     */
603 1
    public function writeShapeLine(XMLWriter $objWriter, Line $shape)
604
    {
605
        // draw:line
606 1
        $objWriter->startElement('draw:line');
607 1
        $objWriter->writeAttribute('draw:style-name', 'gr' . $this->shapeId);
608 1
        $objWriter->writeAttribute('svg:x1', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetX()), 3) . 'cm');
609 1
        $objWriter->writeAttribute('svg:y1', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetY()), 3) . 'cm');
610 1
        $objWriter->writeAttribute('svg:x2', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetX()+$shape->getWidth()), 3) . 'cm');
611 1
        $objWriter->writeAttribute('svg:y2', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetY()+$shape->getHeight()), 3) . 'cm');
612
613
        // text:p
614 1
        $objWriter->writeElement('text:p');
615
616 1
        $objWriter->endElement();
617 1
    }
618
619
    /**
620
     * Write table Shape
621
     * @param XMLWriter $objWriter
622
     * @param Table $shape
623
     */
624 7
    public function writeShapeTable(XMLWriter $objWriter, Table $shape)
625
    {
626
        // draw:frame
627 7
        $objWriter->startElement('draw:frame');
628 7
        $objWriter->writeAttribute('svg:x', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetX()), 3) . 'cm');
629 7
        $objWriter->writeAttribute('svg:y', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetY()), 3) . 'cm');
630 7
        $objWriter->writeAttribute('svg:height', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getHeight()), 3) . 'cm');
631 7
        $objWriter->writeAttribute('svg:width', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getWidth()), 3) . 'cm');
632
633
        // table:table
634 7
        $objWriter->startElement('table:table');
635
636 7
        foreach ($shape->getRows() as $keyRow => $shapeRow) {
637
            // table:table-row
638 6
            $objWriter->startElement('table:table-row');
639 6
            $objWriter->writeAttribute('table:style-name', 'gr'.$this->shapeId.'r'.$keyRow);
640
            //@todo getFill
641
642 6
            $numColspan = 0;
643 6
            foreach ($shapeRow->getCells() as $keyCell => $shapeCell) {
644 6
                if ($numColspan == 0) {
645
                    // table:table-cell
646 6
                    $objWriter->startElement('table:table-cell');
647 6
                    $objWriter->writeAttribute('table:style-name', 'gr' . $this->shapeId.'r'.$keyRow.'c'.$keyCell);
648 6
                    if ($shapeCell->getColspan() > 1) {
649 1
                        $objWriter->writeAttribute('table:number-columns-spanned', $shapeCell->getColspan());
650 1
                        $numColspan = $shapeCell->getColspan() - 1;
651 1
                    }
652
653
                    // text:p
654 6
                    $objWriter->startElement('text:p');
655
656
                    // text:span
657 6
                    foreach ($shapeCell->getParagraphs() as $shapeParagraph) {
658 6
                        foreach ($shapeParagraph->getRichTextElements() as $shapeRichText) {
659 2
                            if ($shapeRichText instanceof TextElement || $shapeRichText instanceof Run) {
660
                                // text:span
661 2
                                $objWriter->startElement('text:span');
662 2
                                if ($shapeRichText instanceof Run) {
663 2
                                    $objWriter->writeAttribute('text:style-name', 'T_' . $shapeRichText->getHashCode());
664 2
                                }
665 2
                                if ($shapeRichText->hasHyperlink() === true && $shapeRichText->getHyperlink()->getUrl() != '') {
666
                                    // text:a
667 1
                                    $objWriter->startElement('text:a');
668 1
                                    $objWriter->writeAttribute('xlink:href', $shapeRichText->getHyperlink()->getUrl());
669 1
                                    $objWriter->text($shapeRichText->getText());
670 1
                                    $objWriter->endElement();
671 1
                                } else {
672 1
                                    $objWriter->text($shapeRichText->getText());
673
                                }
674 2
                                $objWriter->endElement();
675 2
                            } elseif ($shapeRichText instanceof BreakElement) {
676
                                // text:span
677 1
                                $objWriter->startElement('text:span');
678
                                // text:line-break
679 1
                                $objWriter->startElement('text:line-break');
680 1
                                $objWriter->endElement();
681 1
                                $objWriter->endElement();
682 1
                            }
683 6
                        }
684 6
                    }
685
686
                    // > text:p
687 6
                    $objWriter->endElement();
688
689
                    // > table:table-cell
690 6
                    $objWriter->endElement();
691 6
                } else {
692
                    // table:covered-table-cell
693 1
                    $objWriter->writeElement('table:covered-table-cell');
694 1
                    $numColspan--;
695
                }
696 6
            }
697
            // > table:table-row
698 6
            $objWriter->endElement();
699 7
        }
700
        // > table:table
701 7
        $objWriter->endElement();
702
        // > draw:frame
703 7
        $objWriter->endElement();
704 7
    }
705
706
    /**
707
     * Write table Chart
708
     * @param XMLWriter $objWriter
709
     * @param Chart $shape
710
     * @throws \Exception
711
     */
712 21
    public function writeShapeChart(XMLWriter $objWriter, Chart $shape)
713
    {
714 21
        $arrayChart = $this->getArrayChart();
715 21
        $arrayChart[$this->shapeId] = $shape;
716 21
        $this->setArrayChart($arrayChart);
717
718
        // draw:frame
719 21
        $objWriter->startElement('draw:frame');
720 21
        $objWriter->writeAttribute('draw:name', $shape->getTitle()->getText());
721 21
        $objWriter->writeAttribute('svg:x', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetX()), 3) . 'cm');
722 21
        $objWriter->writeAttribute('svg:y', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getOffsetY()), 3) . 'cm');
723 21
        $objWriter->writeAttribute('svg:height', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getHeight()), 3) . 'cm');
724 21
        $objWriter->writeAttribute('svg:width', Text::numberFormat(CommonDrawing::pixelsToCentimeters($shape->getWidth()), 3) . 'cm');
725
726
        // draw:object
727 21
        $objWriter->startElement('draw:object');
728 21
        $objWriter->writeAttribute('xlink:href', './Object '.$this->shapeId);
729 21
        $objWriter->writeAttribute('xlink:type', 'simple');
730 21
        $objWriter->writeAttribute('xlink:show', 'embed');
731
732
        // > draw:object
733 21
        $objWriter->endElement();
734
        // > draw:frame
735 21
        $objWriter->endElement();
736 21
    }
737
738
    /**
739
     * Writes a group of shapes
740
     *
741
     * @param XMLWriter $objWriter
742
     * @param Group $group
743
     */
744 1
    public function writeShapeGroup(XMLWriter $objWriter, Group $group)
745
    {
746
        // draw:g
747 1
        $objWriter->startElement('draw:g');
748
749 1
        $shapes = $group->getShapeCollection();
750 1
        foreach ($shapes as $shape) {
751
            // Increment $this->shapeId
752 1
            ++$this->shapeId;
753
754
            // Check type
755 1
            if ($shape instanceof RichText) {
756
                $this->writeShapeTxt($objWriter, $shape);
757 1
            } elseif ($shape instanceof Table) {
758
                $this->writeShapeTable($objWriter, $shape);
759 1
            } elseif ($shape instanceof Line) {
760
                $this->writeShapeLine($objWriter, $shape);
761 1
            } elseif ($shape instanceof Chart) {
762
                $this->writeShapeChart($objWriter, $shape);
763 1
            } elseif ($shape instanceof ShapeDrawing\AbstractDrawingAdapter) {
764 1
                $this->writeShapeDrawing($objWriter, $shape);
765 1
            } elseif ($shape instanceof Group) {
766
                $this->writeShapeGroup($objWriter, $shape);
767
            }
768 1
        }
769
770 1
        $objWriter->endElement(); // draw:g
771 1
    }
772
773
    /**
774
     * Writes the style information for a group of shapes
775
     *
776
     * @param XMLWriter $objWriter
777
     * @param Group $group
778
     */
779 1
    public function writeGroupStyle(XMLWriter $objWriter, Group $group)
780
    {
781 1
        $shapes = $group->getShapeCollection();
782 1
        foreach ($shapes as $shape) {
783
            // Increment $this->shapeId
784 1
            ++$this->shapeId;
785
786
            // Check type
787 1
            if ($shape instanceof RichText) {
788
                $this->writeTxtStyle($objWriter, $shape);
789
            }
790 1
            if ($shape instanceof AbstractDrawing) {
0 ignored issues
show
Bug introduced by
The class PhpOffice\PhpPresentation\Shape\AbstractDrawing does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
791
                $this->writeDrawingStyle($objWriter, $shape);
792
            }
793 1
            if ($shape instanceof Line) {
794
                $this->writeLineStyle($objWriter, $shape);
795
            }
796 1
            if ($shape instanceof Table) {
797
                $this->writeTableStyle($objWriter, $shape);
798
            }
799 1
        }
800 1
    }
801
802
    /**
803
     * Write the default style information for a RichText shape
804
     *
805
     * @param \PhpOffice\Common\XMLWriter $objWriter
806
     * @param \PhpOffice\PhpPresentation\Shape\RichText $shape
807
     */
808 14
    public function writeTxtStyle(XMLWriter $objWriter, RichText $shape)
809
    {
810
        // style:style
811 14
        $objWriter->startElement('style:style');
812 14
        $objWriter->writeAttribute('style:name', 'gr' . $this->shapeId);
813 14
        $objWriter->writeAttribute('style:family', 'graphic');
814 14
        $objWriter->writeAttribute('style:parent-style-name', 'standard');
815
        // style:graphic-properties
816 14
        $objWriter->startElement('style:graphic-properties');
817 14
        if ($shape->getShadow()->isVisible()) {
818 1
            $this->writeStylePartShadow($objWriter, $shape->getShadow());
819 1
        }
820 14
        if (is_bool($shape->hasAutoShrinkVertical())) {
821 1
            $objWriter->writeAttribute('draw:auto-grow-height', var_export($shape->hasAutoShrinkVertical(), true));
822 1
        }
823 14
        if (is_bool($shape->hasAutoShrinkHorizontal())) {
824 1
            $objWriter->writeAttribute('draw:auto-grow-width', var_export($shape->hasAutoShrinkHorizontal(), true));
825 1
        }
826
        // Fill
827 14
        switch ($shape->getFill()->getFillType()) {
828 14
            case Fill::FILL_GRADIENT_LINEAR:
829 14
            case Fill::FILL_GRADIENT_PATH:
830 1
                $objWriter->writeAttribute('draw:fill', 'gradient');
831 1
                $objWriter->writeAttribute('draw:fill-gradient-name', 'gradient_'.$shape->getFill()->getHashCode());
832 1
                break;
833 13
            case Fill::FILL_SOLID:
834 1
                $objWriter->writeAttribute('draw:fill', 'solid');
835 1
                $objWriter->writeAttribute('draw:fill-color', '#'.$shape->getFill()->getStartColor()->getRGB());
836 1
                break;
837 12
            case Fill::FILL_NONE:
838 12
            default:
839 12
                $objWriter->writeAttribute('draw:fill', 'none');
840 12
                $objWriter->writeAttribute('draw:fill-color', '#'.$shape->getFill()->getStartColor()->getRGB());
841 12
                break;
842 14
        }
843
        // Border
844 14
        if ($shape->getBorder()->getLineStyle() == Border::LINE_NONE) {
845 13
            $objWriter->writeAttribute('draw:stroke', 'none');
846 13
        } else {
847 2
            $objWriter->writeAttribute('svg:stroke-color', '#'.$shape->getBorder()->getColor()->getRGB());
848 2
            $objWriter->writeAttribute('svg:stroke-width', number_format(CommonDrawing::pointsToCentimeters($shape->getBorder()->getLineWidth()), 3, '.', '').'cm');
849 2
            switch ($shape->getBorder()->getDashStyle()) {
850 2
                case Border::DASH_SOLID:
851 1
                    $objWriter->writeAttribute('draw:stroke', 'solid');
852 1
                    break;
853 2
                case Border::DASH_DASH:
854 2
                case Border::DASH_DASHDOT:
855 2
                case Border::DASH_DOT:
856 2
                case Border::DASH_LARGEDASH:
857 2
                case Border::DASH_LARGEDASHDOT:
858 2
                case Border::DASH_LARGEDASHDOTDOT:
859 2
                case Border::DASH_SYSDASH:
860 2
                case Border::DASH_SYSDASHDOT:
861 2
                case Border::DASH_SYSDASHDOTDOT:
862 2
                case Border::DASH_SYSDOT:
863 2
                    $objWriter->writeAttribute('draw:stroke', 'dash');
864 2
                    $objWriter->writeAttribute('draw:stroke-dash', 'strokeDash_'.$shape->getBorder()->getDashStyle());
865 2
                    break;
866
                default:
867
                    $objWriter->writeAttribute('draw:stroke', 'none');
868
                    break;
869 2
            }
870
        }
871
872 14
        $objWriter->writeAttribute('fo:wrap-option', 'wrap');
873
        // > style:graphic-properties
874 14
        $objWriter->endElement();
875
        // > style:style
876 14
        $objWriter->endElement();
877
878 14
        $paragraphs  = $shape->getParagraphs();
879 14
        $paragraphId = 0;
880 14
        foreach ($paragraphs as $paragraph) {
881 14
            ++$paragraphId;
882
883
            // Style des paragraphes
884 14
            if (!isset($this->arrStyleParagraph[$paragraph->getHashCode()])) {
885 14
                $this->arrStyleParagraph[$paragraph->getHashCode()] = $paragraph;
886 14
            }
887
888
            // Style des listes
889 14
            $bulletStyleHashCode = $paragraph->getBulletStyle()->getHashCode();
890 14
            if (!isset($this->arrStyleBullet[$bulletStyleHashCode])) {
891 14
                $this->arrStyleBullet[$bulletStyleHashCode]['oStyle'] = $paragraph->getBulletStyle();
892 14
                $this->arrStyleBullet[$bulletStyleHashCode]['level']  = '';
893 14
            }
894 14
            if (strpos($this->arrStyleBullet[$bulletStyleHashCode]['level'], ';' . $paragraph->getAlignment()->getLevel()) === false) {
895 14
                $this->arrStyleBullet[$bulletStyleHashCode]['level'] .= ';' . $paragraph->getAlignment()->getLevel();
896 14
                $this->arrStyleBullet[$bulletStyleHashCode]['oAlign_' . $paragraph->getAlignment()->getLevel()] = $paragraph->getAlignment();
897 14
            }
898
899 14
            $richtexts  = $paragraph->getRichTextElements();
900 14
            $richtextId = 0;
901 14
            foreach ($richtexts as $richtext) {
902 8
                ++$richtextId;
903
                // Not a line break
904 8
                if ($richtext instanceof Run) {
905
                    // Style des font text
906 8
                    if (!isset($this->arrStyleTextFont[$richtext->getHashCode()])) {
907 8
                        $this->arrStyleTextFont[$richtext->getHashCode()] = $richtext;
908 8
                    }
909 8
                }
910 14
            }
911 14
        }
912 14
    }
913
914
    /**
915
     * Write the default style information for an AbstractDrawing
916
     *
917
     * @param \PhpOffice\Common\XMLWriter $objWriter
918
     * @param \PhpOffice\PhpPresentation\Shape\AbstractDrawing $shape
919
     */
920
    public function writeDrawingStyle(XMLWriter $objWriter, AbstractDrawing $shape)
921
    {
922
        // style:style
923
        $objWriter->startElement('style:style');
924
        $objWriter->writeAttribute('style:name', 'gr' . $this->shapeId);
925
        $objWriter->writeAttribute('style:family', 'graphic');
926
        $objWriter->writeAttribute('style:parent-style-name', 'standard');
927
928
        // style:graphic-properties
929
        $objWriter->startElement('style:graphic-properties');
930
        $objWriter->writeAttribute('draw:stroke', 'none');
931
        $objWriter->writeAttribute('draw:fill', 'none');
932
        if ($shape->getShadow()->isVisible()) {
933
            $this->writeStylePartShadow($objWriter, $shape->getShadow());
934
        }
935
        $objWriter->endElement();
936
937
        $objWriter->endElement();
938
    }
939
940
    /**
941
     * Write the default style information for a Line shape.
942
     *
943
     * @param XMLWriter $objWriter
944
     * @param Line $shape
945
     */
946 1
    public function writeLineStyle(XMLWriter $objWriter, Line $shape)
947
    {
948
        // style:style
949 1
        $objWriter->startElement('style:style');
950 1
        $objWriter->writeAttribute('style:name', 'gr' . $this->shapeId);
951 1
        $objWriter->writeAttribute('style:family', 'graphic');
952 1
        $objWriter->writeAttribute('style:parent-style-name', 'standard');
953
954
        // style:graphic-properties
955 1
        $objWriter->startElement('style:graphic-properties');
956 1
        $objWriter->writeAttribute('draw:fill', 'none');
957 1
        switch ($shape->getBorder()->getLineStyle()) {
958 1
            case Border::LINE_NONE:
959
                $objWriter->writeAttribute('draw:stroke', 'none');
960
                break;
961 1
            case Border::LINE_SINGLE:
962 1
                $objWriter->writeAttribute('draw:stroke', 'solid');
963 1
                break;
964
            default:
965
                $objWriter->writeAttribute('draw:stroke', 'none');
966
                break;
967 1
        }
968 1
        $objWriter->writeAttribute('svg:stroke-color', '#'.$shape->getBorder()->getColor()->getRGB());
969 1
        $objWriter->writeAttribute('svg:stroke-width', Text::numberFormat(CommonDrawing::pixelsToCentimeters((CommonDrawing::pointsToPixels($shape->getBorder()->getLineWidth()))), 3).'cm');
970 1
        $objWriter->endElement();
971
972 1
        $objWriter->endElement();
973 1
    }
974
975
    /**
976
     * Write the default style information for a Table shape
977
     *
978
     * @param XMLWriter $objWriter
979
     * @param Table $shape
980
     */
981 7
    public function writeTableStyle(XMLWriter $objWriter, Table $shape)
982
    {
983 7
        foreach ($shape->getRows() as $keyRow => $shapeRow) {
984
            // style:style
985 6
            $objWriter->startElement('style:style');
986 6
            $objWriter->writeAttribute('style:name', 'gr' . $this->shapeId.'r'.$keyRow);
987 6
            $objWriter->writeAttribute('style:family', 'table-row');
988
989
            // style:table-row-properties
990 6
            $objWriter->startElement('style:table-row-properties');
991 6
            $objWriter->writeAttribute('style:row-height', Text::numberFormat(CommonDrawing::pixelsToCentimeters(CommonDrawing::pointsToPixels($shapeRow->getHeight())), 3).'cm');
992 6
            $objWriter->endElement();
993
994 6
            $objWriter->endElement();
995
996 6
            foreach ($shapeRow->getCells() as $keyCell => $shapeCell) {
997
                // style:style
998 6
                $objWriter->startElement('style:style');
999 6
                $objWriter->writeAttribute('style:name', 'gr' . $this->shapeId.'r'.$keyRow.'c'.$keyCell);
1000 6
                $objWriter->writeAttribute('style:family', 'table-cell');
1001
1002
                // style:graphic-properties
1003 6
                $objWriter->startElement('style:graphic-properties');
1004 6
                if ($shapeCell->getFill()->getFillType() == Fill::FILL_SOLID) {
1005 1
                    $objWriter->writeAttribute('draw:fill', 'solid');
1006 1
                    $objWriter->writeAttribute('draw:fill-color', '#'.$shapeCell->getFill()->getStartColor()->getRGB());
1007 1
                }
1008 6
                if ($shapeCell->getFill()->getFillType() == Fill::FILL_GRADIENT_LINEAR) {
1009 1
                    $objWriter->writeAttribute('draw:fill', 'gradient');
1010 1
                    $objWriter->writeAttribute('draw:fill-gradient-name', 'gradient_'.$shapeCell->getFill()->getHashCode());
1011 1
                }
1012 6
                $objWriter->endElement();
1013
                // <style:graphic-properties
1014
1015
                // style:paragraph-properties
1016 6
                $objWriter->startElement('style:paragraph-properties');
1017 6
                $cellBorders = $shapeCell->getBorders();
1018 6
                if ($cellBorders->getBottom()->getHashCode() == $cellBorders->getTop()->getHashCode()
1019 6
                    && $cellBorders->getBottom()->getHashCode() == $cellBorders->getLeft()->getHashCode()
1020 6
                    && $cellBorders->getBottom()->getHashCode() == $cellBorders->getRight()->getHashCode()) {
1021 6
                    $lineStyle = 'none';
1022 6
                    $lineWidth = Text::numberFormat($cellBorders->getBottom()->getLineWidth() / 1.75, 2);
1023 6
                    $lineColor = $cellBorders->getBottom()->getColor()->getRGB();
1024 6
                    switch ($cellBorders->getBottom()->getLineStyle()) {
1025 6
                        case Border::LINE_SINGLE:
1026 6
                            $lineStyle = 'solid';
1027 6
                    }
1028 6
                    $objWriter->writeAttribute('fo:border', $lineWidth.'pt '.$lineStyle.' #'.$lineColor);
1029 6
                } else {
1030
                    $lineStyle = 'none';
1031
                    $lineWidth = Text::numberFormat($cellBorders->getBottom()->getLineWidth() / 1.75, 2);
1032
                    $lineColor = $cellBorders->getBottom()->getColor()->getRGB();
1033
                    switch ($cellBorders->getBottom()->getLineStyle()) {
1034
                        case Border::LINE_SINGLE:
1035
                            $lineStyle = 'solid';
1036
                    }
1037
                    $objWriter->writeAttribute('fo:border-bottom', $lineWidth.'pt '.$lineStyle.' #'.$lineColor);
1038
                    // TOP
1039
                    $lineStyle = 'none';
1040
                    $lineWidth = Text::numberFormat($cellBorders->getTop()->getLineWidth() / 1.75, 2);
1041
                    $lineColor = $cellBorders->getTop()->getColor()->getRGB();
1042
                    switch ($cellBorders->getTop()->getLineStyle()) {
1043
                        case Border::LINE_SINGLE:
1044
                            $lineStyle = 'solid';
1045
                    }
1046
                    $objWriter->writeAttribute('fo:border-top', $lineWidth.'pt '.$lineStyle.' #'.$lineColor);
1047
                    // RIGHT
1048
                    $lineStyle = 'none';
1049
                    $lineWidth = Text::numberFormat($cellBorders->getRight()->getLineWidth() / 1.75, 2);
1050
                    $lineColor = $cellBorders->getRight()->getColor()->getRGB();
1051
                    switch ($cellBorders->getRight()->getLineStyle()) {
1052
                        case Border::LINE_SINGLE:
1053
                            $lineStyle = 'solid';
1054
                    }
1055
                    $objWriter->writeAttribute('fo:border-right', $lineWidth.'pt '.$lineStyle.' #'.$lineColor);
1056
                    // LEFT
1057
                    $lineStyle = 'none';
1058
                    $lineWidth = Text::numberFormat($cellBorders->getLeft()->getLineWidth() / 1.75, 2);
1059
                    $lineColor = $cellBorders->getLeft()->getColor()->getRGB();
1060
                    switch ($cellBorders->getLeft()->getLineStyle()) {
1061
                        case Border::LINE_SINGLE:
1062
                            $lineStyle = 'solid';
1063
                    }
1064
                    $objWriter->writeAttribute('fo:border-left', $lineWidth.'pt '.$lineStyle.' #'.$lineColor);
1065
                }
1066 6
                $objWriter->endElement();
1067
1068 6
                $objWriter->endElement();
1069
1070 6
                foreach ($shapeCell->getParagraphs() as $shapeParagraph) {
1071 6
                    foreach ($shapeParagraph->getRichTextElements() as $shapeRichText) {
1072 2
                        if ($shapeRichText instanceof Run) {
1073
                            // Style des font text
1074 2
                            if (!isset($this->arrStyleTextFont[$shapeRichText->getHashCode()])) {
1075 2
                                $this->arrStyleTextFont[$shapeRichText->getHashCode()] = $shapeRichText;
1076 2
                            }
1077 2
                        }
1078 6
                    }
1079 6
                }
1080 6
            }
1081 7
        }
1082 7
    }
1083
1084
    /**
1085
     * Write the slide note
1086
     * @param XMLWriter $objWriter
1087
     * @param \PhpOffice\PhpPresentation\Slide\Note $note
1088
     */
1089 59
    public function writeSlideNote(XMLWriter $objWriter, Note $note)
1090
    {
1091 59
        $shapesNote = $note->getShapeCollection();
1092 59
        if (count($shapesNote) > 0) {
1093 1
            $objWriter->startElement('presentation:notes');
1094
1095 1
            foreach ($shapesNote as $shape) {
1096
                // Increment $this->shapeId
1097 1
                ++$this->shapeId;
1098
1099 1
                if ($shape instanceof RichText) {
1100 1
                    $this->writeShapeTxt($objWriter, $shape);
1101 1
                }
1102 1
            }
1103
1104 1
            $objWriter->endElement();
1105 1
        }
1106 59
    }
1107
1108
    /**
1109
     * Write style of a slide
1110
     * @param XMLWriter $objWriter
1111
     * @param Slide $slide
1112
     * @param int $incPage
1113
     */
1114 59
    public function writeStyleSlide(XMLWriter $objWriter, Slide $slide, $incPage)
1115
    {
1116
        // style:style
1117 59
        $objWriter->startElement('style:style');
1118 59
        $objWriter->writeAttribute('style:family', 'drawing-page');
1119 59
        $objWriter->writeAttribute('style:name', 'stylePage'.$incPage);
1120
        // style:style/style:drawing-page-properties
1121 59
        $objWriter->startElement('style:drawing-page-properties');
1122 59
        $objWriter->writeAttributeIf(!$slide->isVisible(), 'presentation:visibility', 'hidden');
1123 59
        if (!is_null($oTransition = $slide->getTransition())) {
1124 1
            $objWriter->writeAttribute('presentation:duration', 'PT'.number_format($oTransition->getAdvanceTimeTrigger() / 1000, 6, '.', '').'S');
1125 1
            $objWriter->writeAttributeIf($oTransition->hasManualTrigger(), 'presentation:transition-type', 'manual');
1126 1
            $objWriter->writeAttributeIf($oTransition->hasTimeTrigger(), 'presentation:transition-type', 'automatic');
1127 1
            switch ($oTransition->getSpeed()) {
1128 1
                case Transition::SPEED_FAST:
1129 1
                    $objWriter->writeAttribute('presentation:transition-speed', 'fast');
1130 1
                    break;
1131 1
                case Transition::SPEED_MEDIUM:
1132 1
                    $objWriter->writeAttribute('presentation:transition-speed', 'medium');
1133 1
                    break;
1134 1
                case Transition::SPEED_SLOW:
1135 1
                    $objWriter->writeAttribute('presentation:transition-speed', 'slow');
1136 1
                    break;
1137 1
            }
1138
1139
            /**
1140
             * http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part1.html#property-presentation_transition-style
1141
             */
1142 1
            switch ($oTransition->getTransitionType()) {
1143 1
                case Transition::TRANSITION_BLINDS_HORIZONTAL:
1144 1
                    $objWriter->writeAttribute('presentation:transition-style', 'horizontal-stripes');
1145 1
                    break;
1146 1
                case Transition::TRANSITION_BLINDS_VERTICAL:
1147 1
                    $objWriter->writeAttribute('presentation:transition-style', 'vertical-stripes');
1148 1
                    break;
1149 1
                case Transition::TRANSITION_CHECKER_HORIZONTAL:
1150 1
                    $objWriter->writeAttribute('presentation:transition-style', 'horizontal-checkerboard');
1151 1
                    break;
1152 1
                case Transition::TRANSITION_CHECKER_VERTICAL:
1153 1
                    $objWriter->writeAttribute('presentation:transition-style', 'vertical-checkerboard');
1154 1
                    break;
1155 1
                case Transition::TRANSITION_CIRCLE_HORIZONTAL:
1156 1
                    $objWriter->writeAttribute('presentation:transition-style', 'none');
1157 1
                    break;
1158 1
                case Transition::TRANSITION_CIRCLE_VERTICAL:
1159 1
                    $objWriter->writeAttribute('presentation:transition-style', 'none');
1160 1
                    break;
1161 1
                case Transition::TRANSITION_COMB_HORIZONTAL:
1162 1
                    $objWriter->writeAttribute('presentation:transition-style', 'none');
1163 1
                    break;
1164 1
                case Transition::TRANSITION_COMB_VERTICAL:
1165 1
                    $objWriter->writeAttribute('presentation:transition-style', 'none');
1166 1
                    break;
1167 1
                case Transition::TRANSITION_COVER_DOWN:
1168 1
                    $objWriter->writeAttribute('presentation:transition-style', 'uncover-to-bottom');
1169 1
                    break;
1170 1
                case Transition::TRANSITION_COVER_LEFT:
1171 1
                    $objWriter->writeAttribute('presentation:transition-style', 'uncover-to-left');
1172 1
                    break;
1173 1
                case Transition::TRANSITION_COVER_LEFT_DOWN:
1174 1
                    $objWriter->writeAttribute('presentation:transition-style', 'uncover-to-lowerleft');
1175 1
                    break;
1176 1
                case Transition::TRANSITION_COVER_LEFT_UP:
1177 1
                    $objWriter->writeAttribute('presentation:transition-style', 'uncover-to-upperleft');
1178 1
                    break;
1179 1
                case Transition::TRANSITION_COVER_RIGHT:
1180 1
                    $objWriter->writeAttribute('presentation:transition-style', 'uncover-to-right');
1181 1
                    break;
1182 1
                case Transition::TRANSITION_COVER_RIGHT_DOWN:
1183 1
                    $objWriter->writeAttribute('presentation:transition-style', 'uncover-to-lowerright');
1184 1
                    break;
1185 1
                case Transition::TRANSITION_COVER_RIGHT_UP:
1186 1
                    $objWriter->writeAttribute('presentation:transition-style', 'uncover-to-upperright');
1187 1
                    break;
1188 1
                case Transition::TRANSITION_COVER_UP:
1189 1
                    $objWriter->writeAttribute('presentation:transition-style', 'uncover-to-top');
1190 1
                    break;
1191 1
                case Transition::TRANSITION_CUT:
1192 1
                    $objWriter->writeAttribute('presentation:transition-style', 'none');
1193 1
                    break;
1194 1
                case Transition::TRANSITION_DIAMOND:
1195 1
                    $objWriter->writeAttribute('presentation:transition-style', 'none');
1196 1
                    break;
1197 1
                case Transition::TRANSITION_DISSOLVE:
1198 1
                    $objWriter->writeAttribute('presentation:transition-style', 'dissolve');
1199 1
                    break;
1200 1
                case Transition::TRANSITION_FADE:
1201 1
                    $objWriter->writeAttribute('presentation:transition-style', 'fade-from-center');
1202 1
                    break;
1203 1
                case Transition::TRANSITION_NEWSFLASH:
1204 1
                    $objWriter->writeAttribute('presentation:transition-style', 'none');
1205 1
                    break;
1206 1
                case Transition::TRANSITION_PLUS:
1207 1
                    $objWriter->writeAttribute('presentation:transition-style', 'close');
1208 1
                    break;
1209 1
                case Transition::TRANSITION_PULL_DOWN:
1210 1
                    $objWriter->writeAttribute('presentation:transition-style', 'stretch-from-bottom');
1211 1
                    break;
1212 1
                case Transition::TRANSITION_PULL_LEFT:
1213 1
                    $objWriter->writeAttribute('presentation:transition-style', 'stretch-from-left');
1214 1
                    break;
1215 1
                case Transition::TRANSITION_PULL_RIGHT:
1216 1
                    $objWriter->writeAttribute('presentation:transition-style', 'stretch-from-right');
1217 1
                    break;
1218 1
                case Transition::TRANSITION_PULL_UP:
1219 1
                    $objWriter->writeAttribute('presentation:transition-style', 'stretch-from-top');
1220 1
                    break;
1221 1
                case Transition::TRANSITION_PUSH_DOWN:
1222 1
                    $objWriter->writeAttribute('presentation:transition-style', 'roll-from-bottom');
1223 1
                    break;
1224 1
                case Transition::TRANSITION_PUSH_LEFT:
1225 1
                    $objWriter->writeAttribute('presentation:transition-style', 'roll-from-left');
1226 1
                    break;
1227 1
                case Transition::TRANSITION_PUSH_RIGHT:
1228 1
                    $objWriter->writeAttribute('presentation:transition-style', 'roll-from-right');
1229 1
                    break;
1230 1
                case Transition::TRANSITION_PUSH_UP:
1231 1
                    $objWriter->writeAttribute('presentation:transition-style', 'roll-from-top');
1232 1
                    break;
1233 1
                case Transition::TRANSITION_RANDOM:
1234 1
                    $objWriter->writeAttribute('presentation:transition-style', 'random');
1235 1
                    break;
1236 1
                case Transition::TRANSITION_RANDOMBAR_HORIZONTAL:
1237 1
                    $objWriter->writeAttribute('presentation:transition-style', 'horizontal-lines');
1238 1
                    break;
1239 1
                case Transition::TRANSITION_RANDOMBAR_VERTICAL:
1240 1
                    $objWriter->writeAttribute('presentation:transition-style', 'vertical-lines');
1241 1
                    break;
1242 1
                case Transition::TRANSITION_SPLIT_IN_HORIZONTAL:
1243 1
                    $objWriter->writeAttribute('presentation:transition-style', 'close-horizontal');
1244 1
                    break;
1245 1
                case Transition::TRANSITION_SPLIT_OUT_HORIZONTAL:
1246 1
                    $objWriter->writeAttribute('presentation:transition-style', 'open-horizontal');
1247 1
                    break;
1248 1
                case Transition::TRANSITION_SPLIT_IN_VERTICAL:
1249 1
                    $objWriter->writeAttribute('presentation:transition-style', 'close-vertical');
1250 1
                    break;
1251 1
                case Transition::TRANSITION_SPLIT_OUT_VERTICAL:
1252 1
                    $objWriter->writeAttribute('presentation:transition-style', 'open-vertical');
1253 1
                    break;
1254 1
                case Transition::TRANSITION_STRIPS_LEFT_DOWN:
1255 1
                    $objWriter->writeAttribute('presentation:transition-style', 'none');
1256 1
                    break;
1257 1
                case Transition::TRANSITION_STRIPS_LEFT_UP:
1258 1
                    $objWriter->writeAttribute('presentation:transition-style', 'none');
1259 1
                    break;
1260 1
                case Transition::TRANSITION_STRIPS_RIGHT_DOWN:
1261 1
                    $objWriter->writeAttribute('presentation:transition-style', 'none');
1262 1
                    break;
1263 1
                case Transition::TRANSITION_STRIPS_RIGHT_UP:
1264 1
                    $objWriter->writeAttribute('presentation:transition-style', 'none');
1265 1
                    break;
1266 1
                case Transition::TRANSITION_WEDGE:
1267 1
                    $objWriter->writeAttribute('presentation:transition-style', 'none');
1268 1
                    break;
1269 1
                case Transition::TRANSITION_WIPE_DOWN:
1270 1
                    $objWriter->writeAttribute('presentation:transition-style', 'fade-from-bottom');
1271 1
                    break;
1272 1
                case Transition::TRANSITION_WIPE_LEFT:
1273 1
                    $objWriter->writeAttribute('presentation:transition-style', 'fade-from-left');
1274 1
                    break;
1275 1
                case Transition::TRANSITION_WIPE_RIGHT:
1276 1
                    $objWriter->writeAttribute('presentation:transition-style', 'fade-from-right');
1277 1
                    break;
1278 1
                case Transition::TRANSITION_WIPE_UP:
1279 1
                    $objWriter->writeAttribute('presentation:transition-style', 'fade-from-top');
1280 1
                    break;
1281 1
                case Transition::TRANSITION_ZOOM_IN:
1282 1
                    $objWriter->writeAttribute('presentation:transition-style', 'none');
1283 1
                    break;
1284 1
                case Transition::TRANSITION_ZOOM_OUT:
1285 1
                    $objWriter->writeAttribute('presentation:transition-style', 'none');
1286 1
                    break;
1287 1
            }
1288 1
        }
1289 59
        $oBackground = $slide->getBackground();
1290 59
        if ($oBackground instanceof Slide\AbstractBackground) {
1291 1
            $objWriter->writeAttribute('presentation:background-visible', 'true');
1292 1
            if ($oBackground instanceof Slide\Background\Color) {
1293
                $objWriter->writeAttribute('draw:fill', 'solid');
1294
                $objWriter->writeAttribute('draw:fill-color', '#' . $oBackground->getColor()->getRGB());
1295
            }
1296 1
            if ($oBackground instanceof Slide\Background\Image) {
1297 1
                $objWriter->writeAttribute('draw:fill', 'bitmap');
1298 1
                $objWriter->writeAttribute('draw:fill-image-name', 'background_'.$incPage);
1299 1
                $objWriter->writeAttribute('style:repeat', 'stretch');
1300 1
            }
1301 1
        }
1302 59
        $objWriter->endElement();
1303
        // > style:style
1304 59
        $objWriter->endElement();
1305 59
    }
1306
1307
1308
    /**
1309
     * @param XMLWriter $objWriter
1310
     * @param Shadow $oShadow
1311
     * @todo Improve for supporting any direction (https://sinepost.wordpress.com/2012/02/16/theyve-got-atan-you-want-atan2/)
1312
     */
1313 1
    protected function writeStylePartShadow(XMLWriter $objWriter, Shadow $oShadow)
1314
    {
1315 1
        $objWriter->writeAttribute('draw:shadow', 'visible');
1316 1
        $objWriter->writeAttribute('draw:shadow-color', '#' . $oShadow->getColor()->getRGB());
1317
1318 1
        $distanceCms = CommonDrawing::pixelsToCentimeters($oShadow->getDistance());
1319 1
        if ($oShadow->getDirection() == 0 || $oShadow->getDirection() == 360) {
1320 1
            $objWriter->writeAttribute('draw:shadow-offset-x', $distanceCms . 'cm');
1321 1
            $objWriter->writeAttribute('draw:shadow-offset-y', '0cm');
1322 1
        } elseif ($oShadow->getDirection() == 45) {
1323 1
            $objWriter->writeAttribute('draw:shadow-offset-x', $distanceCms . 'cm');
1324 1
            $objWriter->writeAttribute('draw:shadow-offset-y', $distanceCms . 'cm');
1325 1
        } elseif ($oShadow->getDirection() == 90) {
1326 1
            $objWriter->writeAttribute('draw:shadow-offset-x', '0cm');
1327 1
            $objWriter->writeAttribute('draw:shadow-offset-y', $distanceCms . 'cm');
1328 1
        } elseif ($oShadow->getDirection() == 135) {
1329 1
            $objWriter->writeAttribute('draw:shadow-offset-x', '-' . $distanceCms . 'cm');
1330 1
            $objWriter->writeAttribute('draw:shadow-offset-y', $distanceCms . 'cm');
1331 1
        } elseif ($oShadow->getDirection() == 180) {
1332 1
            $objWriter->writeAttribute('draw:shadow-offset-x', '-' . $distanceCms . 'cm');
1333 1
            $objWriter->writeAttribute('draw:shadow-offset-y', '0cm');
1334 1
        } elseif ($oShadow->getDirection() == 225) {
1335 1
            $objWriter->writeAttribute('draw:shadow-offset-x', '-' . $distanceCms . 'cm');
1336 1
            $objWriter->writeAttribute('draw:shadow-offset-y', '-' . $distanceCms . 'cm');
1337 1
        } elseif ($oShadow->getDirection() == 270) {
1338 1
            $objWriter->writeAttribute('draw:shadow-offset-x', '0cm');
1339 1
            $objWriter->writeAttribute('draw:shadow-offset-y', '-' . $distanceCms . 'cm');
1340 1
        } elseif ($oShadow->getDirection() == 315) {
1341 1
            $objWriter->writeAttribute('draw:shadow-offset-x', $distanceCms . 'cm');
1342 1
            $objWriter->writeAttribute('draw:shadow-offset-y', '-' . $distanceCms . 'cm');
1343 1
        }
1344 1
        $objWriter->writeAttribute('draw:shadow-opacity', (100 - $oShadow->getAlpha()) . '%');
1345 1
        $objWriter->writeAttribute('style:mirror', 'none');
1346 1
    }
1347
}
1348