Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
93.94% |
31 / 33 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
Table | |
93.94% |
31 / 33 |
|
0.00% |
0 / 1 |
22.11 | |
0.00% |
0 / 1 |
write | |
93.94% |
31 / 33 |
|
0.00% |
0 / 1 |
22.11 |
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 | declare(strict_types=1); |
19 | |
20 | namespace PhpOffice\PhpWord\Writer\HTML\Style; |
21 | |
22 | use PhpOffice\PhpWord\Style\Cell as StyleCell; |
23 | use PhpOffice\PhpWord\Style\Table as StyleTable; |
24 | |
25 | class Table extends AbstractStyle |
26 | { |
27 | /** |
28 | * @return string |
29 | */ |
30 | public function write() |
31 | { |
32 | $style = $this->getStyle(); |
33 | if (!$style instanceof StyleTable && !$style instanceof StyleCell) { |
34 | return ''; |
35 | } |
36 | |
37 | $css = []; |
38 | if (is_object($style) && method_exists($style, 'getLayout')) { |
39 | if ($style->getLayout() == StyleTable::LAYOUT_FIXED) { |
40 | $css['table-layout'] = 'fixed'; |
41 | } elseif ($style->getLayout() == StyleTable::LAYOUT_AUTO) { |
42 | $css['table-layout'] = 'auto'; |
43 | } |
44 | } |
45 | if (is_object($style) && method_exists($style, 'isBidiVisual')) { |
46 | if ($style->isBidiVisual()) { |
47 | $css['direction'] = 'rtl'; |
48 | } |
49 | } |
50 | if (is_object($style) && method_exists($style, 'getVAlign')) { |
51 | $css['vertical-align'] = $style->getVAlign(); |
52 | } |
53 | |
54 | foreach (['Top', 'Left', 'Bottom', 'Right'] as $direction) { |
55 | $method = 'getBorder' . $direction . 'Style'; |
56 | if (method_exists($style, $method)) { |
57 | $outval = $style->{$method}(); |
58 | if ($outval === 'single') { |
59 | $outval = 'solid'; |
60 | } |
61 | if (is_string($outval) && 1 == preg_match('/^[a-z]+$/', $outval)) { |
62 | $css['border-' . lcfirst($direction) . '-style'] = $outval; |
63 | } |
64 | } |
65 | |
66 | $method = 'getBorder' . $direction . 'Color'; |
67 | if (method_exists($style, $method)) { |
68 | $outval = $style->{$method}(); |
69 | if (is_string($outval) && 1 == preg_match('/^[a-z]+$/', $outval)) { |
70 | $css['border-' . lcfirst($direction) . '-color'] = $outval; |
71 | } |
72 | } |
73 | |
74 | $method = 'getBorder' . $direction . 'Size'; |
75 | if (method_exists($style, $method)) { |
76 | $outval = $style->{$method}(); |
77 | if (is_numeric($outval)) { |
78 | // size is in twips - divide by 20 to get points |
79 | $css['border-' . lcfirst($direction) . '-width'] = ((string) ($outval / 20)) . 'pt'; |
80 | } |
81 | } |
82 | } |
83 | |
84 | return $this->assembleCss($css); |
85 | } |
86 | } |