Skip to content

Commit 1accec2

Browse files
committed
Refactor styles: Inherit Image and Line from Frame
1 parent 2328e34 commit 1accec2

File tree

14 files changed

+579
-528
lines changed

14 files changed

+579
-528
lines changed

src/PhpWord/Style/Frame.php

Lines changed: 316 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,80 @@
2727
*/
2828
class Frame extends AbstractStyle
2929
{
30+
/**
31+
* Length unit
32+
*
33+
* @const string
34+
*/
35+
const UNIT_PT = 'pt'; // Mostly for shapes
36+
const UNIT_PX = 'px'; // Mostly for images
37+
38+
/**
39+
* Position type, relative/absolute
40+
*
41+
* @const string
42+
*/
43+
const POS_ABSOLUTE = 'absolute';
44+
const POS_RELATIVE = 'relative';
45+
46+
/**
47+
* Horizontal/vertical value
48+
*
49+
* @const string
50+
*/
51+
const POS_CENTER = 'center';
52+
const POS_LEFT = 'left';
53+
const POS_RIGHT = 'right';
54+
const POS_TOP = 'top';
55+
const POS_BOTTOM = 'bottom';
56+
const POS_INSIDE = 'inside';
57+
const POS_OUTSIDE = 'outside';
58+
59+
/**
60+
* Position relative to
61+
*
62+
* @const string
63+
*/
64+
const POS_RELTO_MARGIN = 'margin';
65+
const POS_RELTO_PAGE = 'page';
66+
const POS_RELTO_COLUMN = 'column'; // horizontal only
67+
const POS_RELTO_CHAR = 'char'; // horizontal only
68+
const POS_RELTO_TEXT = 'text'; // vertical only
69+
const POS_RELTO_LINE = 'line'; // vertical only
70+
const POS_RELTO_LMARGIN = 'left-margin-area'; // horizontal only
71+
const POS_RELTO_RMARGIN = 'right-margin-area'; // horizontal only
72+
const POS_RELTO_TMARGIN = 'top-margin-area'; // vertical only
73+
const POS_RELTO_BMARGIN = 'bottom-margin-area'; // vertical only
74+
const POS_RELTO_IMARGIN = 'inner-margin-area';
75+
const POS_RELTO_OMARGIN = 'outer-margin-area';
76+
77+
/**
78+
* Wrap type
79+
*
80+
* @const string
81+
*/
82+
const WRAP_INLINE = 'inline';
83+
const WRAP_SQUARE = 'square';
84+
const WRAP_TIGHT = 'tight';
85+
const WRAP_THROUGH = 'through';
86+
const WRAP_TOPBOTTOM = 'topAndBottom';
87+
const WRAP_BEHIND = 'behind';
88+
const WRAP_INFRONT = 'infront';
89+
90+
/**
91+
* Alignment
92+
*
93+
* @var \PhpOffice\PhpWord\Style\Alignment
94+
*/
95+
private $alignment;
96+
97+
/**
98+
* Unit
99+
*
100+
* @var string
101+
*/
102+
private $unit = 'pt';
103+
30104
/**
31105
* Width
32106
*
@@ -55,16 +129,105 @@ class Frame extends AbstractStyle
55129
*/
56130
private $top = 0;
57131

132+
/**
133+
* Position type: absolute|relative
134+
*
135+
* @var string
136+
*/
137+
private $pos;
138+
139+
/**
140+
* Horizontal position
141+
*
142+
* @var string
143+
*/
144+
private $hPos;
145+
146+
/**
147+
* Horizontal position relative to
148+
*
149+
* @var string
150+
*/
151+
private $hPosRelTo;
152+
153+
/**
154+
* Vertical position
155+
*
156+
* @var string
157+
*/
158+
private $vPos;
159+
160+
/**
161+
* Vertical position relative to
162+
*
163+
* @var string
164+
*/
165+
private $vPosRelTo;
166+
167+
/**
168+
* Wrap type
169+
*
170+
* @var string
171+
*/
172+
private $wrap;
173+
58174
/**
59175
* Create a new instance
60176
*
61177
* @param array $style
62178
*/
63179
public function __construct($style = array())
64180
{
181+
$this->alignment = new Alignment();
65182
$this->setStyleByArray($style);
66183
}
67184

185+
/**
186+
* Get alignment
187+
*
188+
* @return string
189+
*/
190+
public function getAlign()
191+
{
192+
return $this->alignment->getValue();
193+
}
194+
195+
/**
196+
* Set alignment
197+
*
198+
* @param string $value
199+
* @return self
200+
*/
201+
public function setAlign($value = null)
202+
{
203+
$this->alignment->setValue($value);
204+
205+
return $this;
206+
}
207+
208+
/**
209+
* Get unit
210+
*
211+
* @return string
212+
*/
213+
public function getUnit()
214+
{
215+
return $this->unit;
216+
}
217+
218+
/**
219+
* Set unit
220+
*
221+
* @param string $value
222+
* @return self
223+
*/
224+
public function setUnit($value)
225+
{
226+
$this->unit = $value;
227+
228+
return $this;
229+
}
230+
68231
/**
69232
* Get width
70233
*
@@ -156,4 +319,157 @@ public function setTop($value = 0)
156319

157320
return $this;
158321
}
322+
323+
/**
324+
* Get position type
325+
*
326+
* @return string
327+
*/
328+
public function getPos()
329+
{
330+
return $this->pos;
331+
}
332+
333+
/**
334+
* Set position type
335+
*
336+
* @param string $value
337+
* @return self
338+
*/
339+
public function setPos($value)
340+
{
341+
$enum = array(self::POS_RELATIVE, self::POS_ABSOLUTE);
342+
$this->pos = $this->setEnumVal($value, $enum, $this->pos);
343+
344+
return $this;
345+
}
346+
347+
/**
348+
* Get horizontal position
349+
*
350+
* @return string
351+
*/
352+
public function getHPos()
353+
{
354+
return $this->hPos;
355+
}
356+
357+
/**
358+
* Set horizontal position
359+
*
360+
* @param string $value
361+
* @return self
362+
*/
363+
public function setHPos($value)
364+
{
365+
$enum = array(self::POS_LEFT, self::POS_CENTER, self::POS_RIGHT, self::POS_INSIDE, self::POS_OUTSIDE);
366+
$this->hPos = $this->setEnumVal($value, $enum, $this->hPos);
367+
368+
return $this;
369+
}
370+
371+
/**
372+
* Get vertical position
373+
*
374+
* @return string
375+
*/
376+
public function getVPos()
377+
{
378+
return $this->vPos;
379+
}
380+
381+
/**
382+
* Set vertical position
383+
*
384+
* @param string $value
385+
* @return self
386+
*/
387+
public function setVPos($value)
388+
{
389+
$enum = array(self::POS_TOP, self::POS_CENTER, self::POS_BOTTOM, self::POS_INSIDE, self::POS_OUTSIDE);
390+
$this->vPos = $this->setEnumVal($value, $enum, $this->vPos);
391+
392+
return $this;
393+
}
394+
395+
/**
396+
* Get horizontal position relative to
397+
*
398+
* @return string
399+
*/
400+
public function getHPosRelTo()
401+
{
402+
return $this->hPosRelTo;
403+
}
404+
405+
/**
406+
* Set horizontal position relative to
407+
*
408+
* @param string $value
409+
* @return self
410+
*/
411+
public function setHPosRelTo($value)
412+
{
413+
$enum = array(
414+
self::POS_RELTO_MARGIN, self::POS_RELTO_PAGE, self::POS_RELTO_COLUMN, self::POS_RELTO_CHAR,
415+
self::POS_RELTO_LMARGIN, self::POS_RELTO_RMARGIN, self::POS_RELTO_IMARGIN, self::POS_RELTO_OMARGIN,
416+
);
417+
$this->hPosRelTo = $this->setEnumVal($value, $enum, $this->hPosRelTo);
418+
419+
return $this;
420+
}
421+
422+
/**
423+
* Get vertical position relative to
424+
*
425+
* @return string
426+
*/
427+
public function getVPosRelTo()
428+
{
429+
return $this->vPosRelTo;
430+
}
431+
432+
/**
433+
* Set vertical position relative to
434+
*
435+
* @param string $value
436+
* @return self
437+
*/
438+
public function setVPosRelTo($value)
439+
{
440+
$enum = array(
441+
self::POS_RELTO_MARGIN, self::POS_RELTO_PAGE, self::POS_RELTO_TEXT, self::POS_RELTO_LINE,
442+
self::POS_RELTO_TMARGIN, self::POS_RELTO_BMARGIN, self::POS_RELTO_IMARGIN, self::POS_RELTO_OMARGIN,
443+
);
444+
$this->vPosRelTo = $this->setEnumVal($value, $enum, $this->vPosRelTo);
445+
446+
return $this;
447+
}
448+
449+
/**
450+
* Get wrap type
451+
*
452+
* @return string
453+
*/
454+
public function getWrap()
455+
{
456+
return $this->wrap;
457+
}
458+
459+
/**
460+
* Set wrap type
461+
*
462+
* @param string $value
463+
* @return self
464+
*/
465+
public function setWrap($value)
466+
{
467+
$enum = array(
468+
self::WRAP_INLINE, self::WRAP_SQUARE, self::WRAP_TIGHT, self::WRAP_THROUGH,
469+
self::WRAP_TOPBOTTOM, self::WRAP_BEHIND, self::WRAP_INFRONT
470+
);
471+
$this->wrap = $this->setEnumVal($value, $enum, $this->wrap);
472+
473+
return $this;
474+
}
159475
}

0 commit comments

Comments
 (0)