Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
94.44% |
17 / 18 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
Ruby | |
94.44% |
17 / 18 |
|
0.00% |
0 / 1 |
4.00 | |
0.00% |
0 / 1 |
write | |
94.44% |
17 / 18 |
|
0.00% |
0 / 1 |
4.00 |
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\Element; |
20 | |
21 | /** |
22 | * Ruby element RTF writer. Writes {baseText} ({rubyText}) in current paragraph style |
23 | * because RTF does not natively support ruby text. |
24 | */ |
25 | class Ruby extends AbstractElement |
26 | { |
27 | /** |
28 | * Write element. |
29 | * |
30 | * @return string |
31 | */ |
32 | public function write() |
33 | { |
34 | /** @var \PhpOffice\PhpWord\Element\Ruby $element */ |
35 | $element = $this->element; |
36 | $elementClass = str_replace('\\Writer\\RTF', '', static::class); |
37 | if (!$element instanceof $elementClass || !is_string($element->getBaseTextRun()->getText())) { |
38 | return ''; |
39 | } |
40 | |
41 | $this->getStyles(); |
42 | |
43 | $content = ''; |
44 | $content .= $this->writeOpening(); |
45 | $content .= '{'; |
46 | $content .= $this->writeFontStyle(); |
47 | $content .= $this->writeText($element->getBaseTextRun()->getText()); |
48 | $rubyText = $element->getRubyTextRun()->getText(); |
49 | if ($rubyText !== '') { |
50 | $content .= ' ('; |
51 | $content .= $this->writeText($rubyText); |
52 | $content .= ')'; |
53 | } |
54 | $content .= '}'; |
55 | $content .= $this->writeClosing(); |
56 | |
57 | return $content; |
58 | } |
59 | } |