Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
20 / 20
100.00% covered (success)
100.00%
7 / 7
CRAP
100.00% covered (success)
100.00%
1 / 1
RTF
100.00% covered (success)
100.00%
20 / 20
100.00% covered (success)
100.00%
7 / 7
9
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
3
 save
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getContent
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 getFontTable
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getColorTable
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLastParagraphStyle
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setLastParagraphStyle
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
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
18namespace PhpOffice\PhpWord\Writer;
19
20use PhpOffice\PhpWord\PhpWord;
21
22/**
23 * RTF writer.
24 *
25 * @since 0.7.0
26 */
27class RTF extends AbstractWriter implements WriterInterface
28{
29    /**
30     * Last paragraph style.
31     *
32     * @var mixed
33     */
34    private $lastParagraphStyle;
35
36    /**
37     * Create new instance.
38     */
39    public function __construct(?PhpWord $phpWord = null)
40    {
41        $this->setPhpWord($phpWord);
42
43        $this->parts = ['Header', 'Document'];
44        foreach ($this->parts as $partName) {
45            $partClass = static::class . '\\Part\\' . $partName;
46            if (class_exists($partClass)) {
47                /** @var \PhpOffice\PhpWord\Writer\RTF\Part\AbstractPart $part Type hint */
48                $part = new $partClass();
49                $part->setParentWriter($this);
50                $this->writerParts[strtolower($partName)] = $part;
51            }
52        }
53    }
54
55    /**
56     * Save content to file.
57     */
58    public function save(string $filename): void
59    {
60        $this->writeFile($this->openFile($filename), $this->getContent());
61    }
62
63    /**
64     * Get content.
65     *
66     * @return string
67     *
68     * @since 0.11.0
69     */
70    private function getContent()
71    {
72        $content = '';
73
74        $content .= '{';
75        $content .= '\rtf1' . PHP_EOL;
76        $content .= $this->getWriterPart('Header')->write();
77        $content .= $this->getWriterPart('Document')->write();
78        $content .= '}';
79
80        return $content;
81    }
82
83    /**
84     * Get font table.
85     *
86     * @return array
87     */
88    public function getFontTable()
89    {
90        return $this->getWriterPart('Header')->getFontTable();
91    }
92
93    /**
94     * Get color table.
95     *
96     * @return array
97     */
98    public function getColorTable()
99    {
100        return $this->getWriterPart('Header')->getColorTable();
101    }
102
103    /**
104     * Get last paragraph style.
105     *
106     * @return mixed
107     */
108    public function getLastParagraphStyle()
109    {
110        return $this->lastParagraphStyle;
111    }
112
113    /**
114     * Set last paragraph style.
115     *
116     * @param mixed $value
117     */
118    public function setLastParagraphStyle($value = ''): void
119    {
120        $this->lastParagraphStyle = $value;
121    }
122}