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