Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
79.17% |
19 / 24 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
Section | |
79.17% |
19 / 24 |
|
0.00% |
0 / 1 |
3.08 | |
0.00% |
0 / 1 |
write | |
79.17% |
19 / 24 |
|
0.00% |
0 / 1 |
3.08 |
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\RTF\Style; |
19 | |
20 | use PhpOffice\PhpWord\Style\Section as SectionStyle; |
21 | |
22 | /** |
23 | * RTF section style writer. |
24 | * |
25 | * @since 0.12.0 |
26 | */ |
27 | class Section extends AbstractStyle |
28 | { |
29 | /** |
30 | * Write style. |
31 | * |
32 | * @return string |
33 | */ |
34 | public function write() |
35 | { |
36 | $style = $this->getStyle(); |
37 | if (!$style instanceof SectionStyle) { |
38 | return ''; |
39 | } |
40 | |
41 | $content = ''; |
42 | |
43 | $content .= '\sectd '; |
44 | |
45 | // Size & margin |
46 | $content .= $this->getValueIf($style->getPageSizeW() !== null, '\pgwsxn' . round($style->getPageSizeW())); |
47 | $content .= $this->getValueIf($style->getPageSizeH() !== null, '\pghsxn' . round($style->getPageSizeH())); |
48 | $content .= ' '; |
49 | $content .= $this->getValueIf($style->getMarginTop() !== null, '\margtsxn' . round($style->getMarginTop())); |
50 | $content .= $this->getValueIf($style->getMarginRight() !== null, '\margrsxn' . round($style->getMarginRight())); |
51 | $content .= $this->getValueIf($style->getMarginBottom() !== null, '\margbsxn' . round($style->getMarginBottom())); |
52 | $content .= $this->getValueIf($style->getMarginLeft() !== null, '\marglsxn' . round($style->getMarginLeft())); |
53 | $content .= $this->getValueIf($style->getHeaderHeight() !== null, '\headery' . round($style->getHeaderHeight())); |
54 | $content .= $this->getValueIf($style->getFooterHeight() !== null, '\footery' . round($style->getFooterHeight())); |
55 | $content .= $this->getValueIf($style->getGutter() !== null, '\guttersxn' . round($style->getGutter())); |
56 | $content .= $this->getValueIf($style->getPageNumberingStart() !== null, '\pgnstarts' . $style->getPageNumberingStart() . '\pgnrestart'); |
57 | $content .= ' '; |
58 | |
59 | // Borders |
60 | if ($style->hasBorder()) { |
61 | $styleWriter = new Border($style); |
62 | $styleWriter->setParentWriter($this->getParentWriter()); |
63 | $styleWriter->setSizes($style->getBorderSize()); |
64 | $styleWriter->setColors($style->getBorderColor()); |
65 | $content .= $styleWriter->write(); |
66 | } |
67 | |
68 | return $content . PHP_EOL; |
69 | } |
70 | } |