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