| Code Coverage | ||||||||||
| Lines | Functions and Methods | Classes and Traits | ||||||||
| Total |  | 73.68% | 14 / 19 |  | 0.00% | 0 / 1 | CRAP |  | 0.00% | 0 / 1 | 
| Ruby |  | 73.68% | 14 / 19 |  | 0.00% | 0 / 1 | 9.17 |  | 0.00% | 0 / 1 | 
| write |  | 73.68% | 14 / 19 |  | 0.00% | 0 / 1 | 9.17 | |||
| 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\ODText\Element; | 
| 20 | |
| 21 | /** | 
| 22 | * Ruby element writer. | 
| 23 | * NOTE: This class will write out a Ruby element in the format {baseText} ({rubyText}) | 
| 24 | * just like RTF; however, ODT files natively support Ruby text elements. | 
| 25 | * This implementation should be changed in the future to support ODT's native | 
| 26 | * Ruby elements and usage. | 
| 27 | */ | 
| 28 | class Ruby extends AbstractElement | 
| 29 | { | 
| 30 | /** | 
| 31 | * Write element. | 
| 32 | */ | 
| 33 | public function write(): void | 
| 34 | { | 
| 35 | $xmlWriter = $this->getXmlWriter(); | 
| 36 | $element = $this->getElement(); | 
| 37 | if (!$element instanceof \PhpOffice\PhpWord\Element\Ruby) { | 
| 38 | return; | 
| 39 | } | 
| 40 | $paragraphStyle = $element->getBaseTextRun()->getParagraphStyle(); | 
| 41 | |
| 42 | if (!$this->withoutP) { | 
| 43 | $xmlWriter->startElement('text:p'); // text:p | 
| 44 | } | 
| 45 | if (empty($paragraphStyle)) { | 
| 46 | if (!$this->withoutP) { | 
| 47 | $xmlWriter->writeAttribute('text:style-name', 'Normal'); | 
| 48 | } | 
| 49 | } elseif (is_string($paragraphStyle)) { | 
| 50 | if (!$this->withoutP) { | 
| 51 | $xmlWriter->writeAttribute('text:style-name', $paragraphStyle); | 
| 52 | } | 
| 53 | } | 
| 54 | |
| 55 | $this->replaceTabs($element->getBaseTextRun()->getText(), $xmlWriter); | 
| 56 | $this->writeText(' ('); | 
| 57 | $this->replaceTabs($element->getRubyTextRun()->getText(), $xmlWriter); | 
| 58 | $this->writeText(')'); | 
| 59 | |
| 60 | if (!$this->withoutP) { | 
| 61 | $xmlWriter->endElement(); // text:p | 
| 62 | } | 
| 63 | } | 
| 64 | } |