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