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