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