Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
102 / 102
100.00% covered (success)
100.00%
35 / 35
CRAP
100.00% covered (success)
100.00%
1 / 1
Frame
100.00% covered (success)
100.00%
102 / 102
100.00% covered (success)
100.00%
35 / 35
36
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getAlignment
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setAlignment
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 getUnit
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setUnit
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getWidth
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setWidth
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getHeight
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setHeight
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getLeft
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setLeft
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getTop
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setTop
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getPos
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setPos
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 getHPos
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setHPos
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
1
 getVPos
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setVPos
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
1
 getHPosRelTo
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setHPosRelTo
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
1
 getVPosRelTo
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setVPosRelTo
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
1
 getWrap
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setWrap
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
1
 getWrapDistanceTop
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setWrapDistanceTop
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getWrapDistanceBottom
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setWrapDistanceBottom
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getWrapDistanceLeft
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setWrapDistanceLeft
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getWrapDistanceRight
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setWrapDistanceRight
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getPosition
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setPosition
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2/**
3 * This file is part of PHPWord - A pure PHP library for reading and writing
4 * word processing documents.
5 *
6 * PHPWord is free software distributed under the terms of the GNU Lesser
7 * General Public License version 3 as published by the Free Software Foundation.
8 *
9 * For the full copyright and license information, please read the LICENSE
10 * file that was distributed with this source code. For the full list of
11 * contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
12 *
13 * @see         https://github.com/PHPOffice/PHPWord
14 *
15 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16 */
17
18namespace PhpOffice\PhpWord\Style;
19
20use PhpOffice\PhpWord\SimpleType\Jc;
21
22/**
23 * Frame defines the size and position of an object.
24 *
25 * Width, height, left/hpos, top/vpos, hrel, vrel, wrap, zindex
26 *
27 * @since 0.12.0
28 *
29 * @todo Make existing style (image, textbox, etc) use this style
30 */
31class Frame extends AbstractStyle
32{
33    /**
34     * Length unit.
35     *
36     * @const string
37     */
38    const UNIT_PT = 'pt'; // Mostly for shapes
39    const UNIT_PX = 'px'; // Mostly for images
40
41    /**
42     * General positioning options.
43     *
44     * @const string
45     */
46    const POS_ABSOLUTE = 'absolute';
47    const POS_RELATIVE = 'relative';
48
49    /**
50     * Horizontal/vertical value.
51     *
52     * @const string
53     */
54    const POS_CENTER = 'center';
55    const POS_LEFT = 'left';
56    const POS_RIGHT = 'right';
57    const POS_TOP = 'top';
58    const POS_BOTTOM = 'bottom';
59    const POS_INSIDE = 'inside';
60    const POS_OUTSIDE = 'outside';
61
62    /**
63     * Position relative to.
64     *
65     * @const string
66     */
67    const POS_RELTO_MARGIN = 'margin';
68    const POS_RELTO_PAGE = 'page';
69    const POS_RELTO_COLUMN = 'column'; // horizontal only
70    const POS_RELTO_CHAR = 'char'; // horizontal only
71    const POS_RELTO_TEXT = 'text'; // vertical only
72    const POS_RELTO_LINE = 'line'; // vertical only
73    const POS_RELTO_LMARGIN = 'left-margin-area'; // horizontal only
74    const POS_RELTO_RMARGIN = 'right-margin-area'; // horizontal only
75    const POS_RELTO_TMARGIN = 'top-margin-area'; // vertical only
76    const POS_RELTO_BMARGIN = 'bottom-margin-area'; // vertical only
77    const POS_RELTO_IMARGIN = 'inner-margin-area';
78    const POS_RELTO_OMARGIN = 'outer-margin-area';
79
80    /**
81     * Wrap type.
82     *
83     * @const string
84     */
85    const WRAP_INLINE = 'inline';
86    const WRAP_SQUARE = 'square';
87    const WRAP_TIGHT = 'tight';
88    const WRAP_THROUGH = 'through';
89    const WRAP_TOPBOTTOM = 'topAndBottom';
90    const WRAP_BEHIND = 'behind';
91    const WRAP_INFRONT = 'infront';
92
93    /**
94     * @var string
95     */
96    private $alignment = '';
97
98    /**
99     * Unit.
100     *
101     * @var string
102     */
103    private $unit = 'pt';
104
105    /**
106     * Width.
107     *
108     * @var float|int
109     */
110    private $width;
111
112    /**
113     * Height.
114     *
115     * @var float|int
116     */
117    private $height;
118
119    /**
120     * Leftmost (horizontal) position.
121     *
122     * @var float|int
123     */
124    private $left = 0;
125
126    /**
127     * Topmost (vertical) position.
128     *
129     * @var float|int
130     */
131    private $top = 0;
132
133    /**
134     * Position type: absolute|relative.
135     *
136     * @var string
137     */
138    private $pos;
139
140    /**
141     * Horizontal position.
142     *
143     * @var string
144     */
145    private $hPos;
146
147    /**
148     * Horizontal position relative to.
149     *
150     * @var string
151     */
152    private $hPosRelTo;
153
154    /**
155     * Vertical position.
156     *
157     * @var string
158     */
159    private $vPos;
160
161    /**
162     * Vertical position relative to.
163     *
164     * @var string
165     */
166    private $vPosRelTo;
167
168    /**
169     * Wrap type.
170     *
171     * @var string
172     */
173    private $wrap;
174
175    /**
176     * Top wrap distance.
177     *
178     * @var float
179     */
180    private $wrapDistanceTop;
181
182    /**
183     * Bottom wrap distance.
184     *
185     * @var float
186     */
187    private $wrapDistanceBottom;
188
189    /**
190     * Left wrap distance.
191     *
192     * @var float
193     */
194    private $wrapDistanceLeft;
195
196    /**
197     * Right wrap distance.
198     *
199     * @var float
200     */
201    private $wrapDistanceRight;
202
203    /**
204     * Vertically raised or lowered text.
205     *
206     * @var int
207     *
208     * @see http://www.datypic.com/sc/ooxml/e-w_position-1.html
209     */
210    private $position;
211
212    /**
213     * Create a new instance.
214     *
215     * @param array $style
216     */
217    public function __construct($style = [])
218    {
219        $this->setStyleByArray($style);
220    }
221
222    /**
223     * @since 0.13.0
224     *
225     * @return string
226     */
227    public function getAlignment()
228    {
229        return $this->alignment;
230    }
231
232    /**
233     * @since 0.13.0
234     *
235     * @param string $value
236     *
237     * @return self
238     */
239    public function setAlignment($value)
240    {
241        if (Jc::isValid($value)) {
242            $this->alignment = $value;
243        }
244
245        return $this;
246    }
247
248    /**
249     * Get unit.
250     *
251     * @return string
252     */
253    public function getUnit()
254    {
255        return $this->unit;
256    }
257
258    /**
259     * Set unit.
260     *
261     * @param string $value
262     *
263     * @return self
264     */
265    public function setUnit($value)
266    {
267        $this->unit = $value;
268
269        return $this;
270    }
271
272    /**
273     * Get width.
274     *
275     * @return float|int
276     */
277    public function getWidth()
278    {
279        return $this->width;
280    }
281
282    /**
283     * Set width.
284     *
285     * @param float|int $value
286     *
287     * @return self
288     */
289    public function setWidth($value = null)
290    {
291        $this->width = $this->setNumericVal($value, null);
292
293        return $this;
294    }
295
296    /**
297     * Get height.
298     *
299     * @return float|int
300     */
301    public function getHeight()
302    {
303        return $this->height;
304    }
305
306    /**
307     * Set height.
308     *
309     * @param float|int $value
310     *
311     * @return self
312     */
313    public function setHeight($value = null)
314    {
315        $this->height = $this->setNumericVal($value, null);
316
317        return $this;
318    }
319
320    /**
321     * Get left.
322     *
323     * @return float|int
324     */
325    public function getLeft()
326    {
327        return $this->left;
328    }
329
330    /**
331     * Set left.
332     *
333     * @param float|int $value
334     *
335     * @return self
336     */
337    public function setLeft($value = 0)
338    {
339        $this->left = $this->setNumericVal($value, 0);
340
341        return $this;
342    }
343
344    /**
345     * Get topmost position.
346     *
347     * @return float|int
348     */
349    public function getTop()
350    {
351        return $this->top;
352    }
353
354    /**
355     * Set topmost position.
356     *
357     * @param float|int $value
358     *
359     * @return self
360     */
361    public function setTop($value = 0)
362    {
363        $this->top = $this->setNumericVal($value, 0);
364
365        return $this;
366    }
367
368    /**
369     * Get position type.
370     *
371     * @return string
372     */
373    public function getPos()
374    {
375        return $this->pos;
376    }
377
378    /**
379     * Set position type.
380     *
381     * @param string $value
382     *
383     * @return self
384     */
385    public function setPos($value)
386    {
387        $enum = [
388            self::POS_ABSOLUTE,
389            self::POS_RELATIVE,
390        ];
391        $this->pos = $this->setEnumVal($value, $enum, $this->pos);
392
393        return $this;
394    }
395
396    /**
397     * Get horizontal position.
398     *
399     * @return string
400     */
401    public function getHPos()
402    {
403        return $this->hPos;
404    }
405
406    /**
407     * Set horizontal position.
408     *
409     * @since 0.12.0 "absolute" option is available.
410     *
411     * @param string $value
412     *
413     * @return self
414     */
415    public function setHPos($value)
416    {
417        $enum = [
418            self::POS_ABSOLUTE,
419            self::POS_LEFT,
420            self::POS_CENTER,
421            self::POS_RIGHT,
422            self::POS_INSIDE,
423            self::POS_OUTSIDE,
424        ];
425        $this->hPos = $this->setEnumVal($value, $enum, $this->hPos);
426
427        return $this;
428    }
429
430    /**
431     * Get vertical position.
432     *
433     * @return string
434     */
435    public function getVPos()
436    {
437        return $this->vPos;
438    }
439
440    /**
441     * Set vertical position.
442     *
443     * @since 0.12.0 "absolute" option is available.
444     *
445     * @param string $value
446     *
447     * @return self
448     */
449    public function setVPos($value)
450    {
451        $enum = [
452            self::POS_ABSOLUTE,
453            self::POS_TOP,
454            self::POS_CENTER,
455            self::POS_BOTTOM,
456            self::POS_INSIDE,
457            self::POS_OUTSIDE,
458        ];
459        $this->vPos = $this->setEnumVal($value, $enum, $this->vPos);
460
461        return $this;
462    }
463
464    /**
465     * Get horizontal position relative to.
466     *
467     * @return string
468     */
469    public function getHPosRelTo()
470    {
471        return $this->hPosRelTo;
472    }
473
474    /**
475     * Set horizontal position relative to.
476     *
477     * @param string $value
478     *
479     * @return self
480     */
481    public function setHPosRelTo($value)
482    {
483        $enum = [
484            self::POS_RELTO_MARGIN,
485            self::POS_RELTO_PAGE,
486            self::POS_RELTO_COLUMN,
487            self::POS_RELTO_CHAR,
488            self::POS_RELTO_LMARGIN,
489            self::POS_RELTO_RMARGIN,
490            self::POS_RELTO_IMARGIN,
491            self::POS_RELTO_OMARGIN,
492        ];
493        $this->hPosRelTo = $this->setEnumVal($value, $enum, $this->hPosRelTo);
494
495        return $this;
496    }
497
498    /**
499     * Get vertical position relative to.
500     *
501     * @return string
502     */
503    public function getVPosRelTo()
504    {
505        return $this->vPosRelTo;
506    }
507
508    /**
509     * Set vertical position relative to.
510     *
511     * @param string $value
512     *
513     * @return self
514     */
515    public function setVPosRelTo($value)
516    {
517        $enum = [
518            self::POS_RELTO_MARGIN,
519            self::POS_RELTO_PAGE,
520            self::POS_RELTO_TEXT,
521            self::POS_RELTO_LINE,
522            self::POS_RELTO_TMARGIN,
523            self::POS_RELTO_BMARGIN,
524            self::POS_RELTO_IMARGIN,
525            self::POS_RELTO_OMARGIN,
526        ];
527        $this->vPosRelTo = $this->setEnumVal($value, $enum, $this->vPosRelTo);
528
529        return $this;
530    }
531
532    /**
533     * Get wrap type.
534     *
535     * @return string
536     */
537    public function getWrap()
538    {
539        return $this->wrap;
540    }
541
542    /**
543     * Set wrap type.
544     *
545     * @param string $value
546     *
547     * @return self
548     */
549    public function setWrap($value)
550    {
551        $enum = [
552            self::WRAP_INLINE,
553            self::WRAP_SQUARE,
554            self::WRAP_TIGHT,
555            self::WRAP_THROUGH,
556            self::WRAP_TOPBOTTOM,
557            self::WRAP_BEHIND,
558            self::WRAP_INFRONT,
559        ];
560        $this->wrap = $this->setEnumVal($value, $enum, $this->wrap);
561
562        return $this;
563    }
564
565    /**
566     * Get top distance from text wrap.
567     *
568     * @return float
569     */
570    public function getWrapDistanceTop()
571    {
572        return $this->wrapDistanceTop;
573    }
574
575    /**
576     * Set top distance from text wrap.
577     *
578     * @param int $value
579     *
580     * @return self
581     */
582    public function setWrapDistanceTop($value = null)
583    {
584        $this->wrapDistanceTop = $this->setFloatVal($value, null);
585
586        return $this;
587    }
588
589    /**
590     * Get bottom distance from text wrap.
591     *
592     * @return float
593     */
594    public function getWrapDistanceBottom()
595    {
596        return $this->wrapDistanceBottom;
597    }
598
599    /**
600     * Set bottom distance from text wrap.
601     *
602     * @param float $value
603     *
604     * @return self
605     */
606    public function setWrapDistanceBottom($value = null)
607    {
608        $this->wrapDistanceBottom = $this->setFloatVal($value, null);
609
610        return $this;
611    }
612
613    /**
614     * Get left distance from text wrap.
615     *
616     * @return float
617     */
618    public function getWrapDistanceLeft()
619    {
620        return $this->wrapDistanceLeft;
621    }
622
623    /**
624     * Set left distance from text wrap.
625     *
626     * @param float $value
627     *
628     * @return self
629     */
630    public function setWrapDistanceLeft($value = null)
631    {
632        $this->wrapDistanceLeft = $this->setFloatVal($value, null);
633
634        return $this;
635    }
636
637    /**
638     * Get right distance from text wrap.
639     *
640     * @return float
641     */
642    public function getWrapDistanceRight()
643    {
644        return $this->wrapDistanceRight;
645    }
646
647    /**
648     * Set right distance from text wrap.
649     *
650     * @param float $value
651     *
652     * @return self
653     */
654    public function setWrapDistanceRight($value = null)
655    {
656        $this->wrapDistanceRight = $this->setFloatVal($value, null);
657
658        return $this;
659    }
660
661    /**
662     * Get position.
663     *
664     * @return int
665     */
666    public function getPosition()
667    {
668        return $this->position;
669    }
670
671    /**
672     * Set position.
673     *
674     * @param int $value
675     *
676     * @return self
677     */
678    public function setPosition($value = null)
679    {
680        $this->position = $this->setIntVal($value, null);
681
682        return $this;
683    }
684}