Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
27 / 27 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
MarginBorder | |
100.00% |
27 / 27 |
|
100.00% |
6 / 6 |
15 | |
100.00% |
1 / 1 |
write | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
4 | |||
writeSide | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
7 | |||
setSizes | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setColors | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setStyles | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setAttributes | |
100.00% |
1 / 1 |
|
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 | |
18 | namespace PhpOffice\PhpWord\Writer\Word2007\Style; |
19 | |
20 | use PhpOffice\PhpWord\Shared\XMLWriter; |
21 | |
22 | /** |
23 | * Margin border style writer. |
24 | * |
25 | * @since 0.10.0 |
26 | */ |
27 | class MarginBorder extends AbstractStyle |
28 | { |
29 | /** |
30 | * Sizes. |
31 | * |
32 | * @var int[] |
33 | */ |
34 | private $sizes = []; |
35 | |
36 | /** |
37 | * Colors. |
38 | * |
39 | * @var string[] |
40 | */ |
41 | private $colors = []; |
42 | |
43 | /** |
44 | * Border styles. |
45 | * |
46 | * @var string[] |
47 | */ |
48 | private $styles = []; |
49 | |
50 | /** |
51 | * Other attributes. |
52 | * |
53 | * @var array |
54 | */ |
55 | private $attributes = []; |
56 | |
57 | /** |
58 | * Write style. |
59 | */ |
60 | public function write(): void |
61 | { |
62 | $xmlWriter = $this->getXmlWriter(); |
63 | |
64 | $sides = ['top', 'left', 'right', 'bottom', 'insideH', 'insideV']; |
65 | |
66 | foreach ($this->sizes as $i => $size) { |
67 | if ($size !== null) { |
68 | $color = null; |
69 | if (isset($this->colors[$i])) { |
70 | $color = $this->colors[$i]; |
71 | } |
72 | $style = $this->styles[$i] ?? 'single'; |
73 | $this->writeSide($xmlWriter, $sides[$i], $this->sizes[$i], $color, $style); |
74 | } |
75 | } |
76 | } |
77 | |
78 | /** |
79 | * Write side. |
80 | * |
81 | * @param string $side |
82 | * @param int $width |
83 | * @param string $color |
84 | * @param string $borderStyle |
85 | */ |
86 | private function writeSide(XMLWriter $xmlWriter, $side, $width, $color = null, $borderStyle = 'solid'): void |
87 | { |
88 | $xmlWriter->startElement('w:' . $side); |
89 | if (!empty($this->colors)) { |
90 | if ($color === null && !empty($this->attributes)) { |
91 | if (isset($this->attributes['defaultColor'])) { |
92 | $color = $this->attributes['defaultColor']; |
93 | } |
94 | } |
95 | $xmlWriter->writeAttribute('w:val', $borderStyle); |
96 | $xmlWriter->writeAttribute('w:sz', $width); |
97 | $xmlWriter->writeAttributeIf($color != null, 'w:color', $color); |
98 | if (!empty($this->attributes)) { |
99 | if (isset($this->attributes['space'])) { |
100 | $xmlWriter->writeAttribute('w:space', $this->attributes['space']); |
101 | } |
102 | } |
103 | } else { |
104 | $xmlWriter->writeAttribute('w:w', $width); |
105 | $xmlWriter->writeAttribute('w:type', 'dxa'); |
106 | } |
107 | $xmlWriter->endElement(); |
108 | } |
109 | |
110 | /** |
111 | * Set sizes. |
112 | * |
113 | * @param int[] $value |
114 | */ |
115 | public function setSizes($value): void |
116 | { |
117 | $this->sizes = $value; |
118 | } |
119 | |
120 | /** |
121 | * Set colors. |
122 | * |
123 | * @param array<null|string> $value |
124 | */ |
125 | public function setColors($value): void |
126 | { |
127 | $this->colors = $value; |
128 | } |
129 | |
130 | /** |
131 | * Set border styles. |
132 | * |
133 | * @param string[] $value |
134 | */ |
135 | public function setStyles($value): void |
136 | { |
137 | $this->styles = $value; |
138 | } |
139 | |
140 | /** |
141 | * Set attributes. |
142 | * |
143 | * @param array $value |
144 | */ |
145 | public function setAttributes($value): void |
146 | { |
147 | $this->attributes = $value; |
148 | } |
149 | } |