Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
96.88% |
31 / 32 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| Numbering | |
96.88% |
31 / 32 |
|
0.00% |
0 / 1 |
3 | |
0.00% |
0 / 1 |
| write | |
96.88% |
31 / 32 |
|
0.00% |
0 / 1 |
3 | |||
| 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\Style; |
| 20 | |
| 21 | use PhpOffice\PhpWord\Shared\Converter; |
| 22 | use PhpOffice\PhpWord\Style\Numbering as StyleNumbering; |
| 23 | |
| 24 | /** |
| 25 | * Numbering style writer. |
| 26 | */ |
| 27 | class Numbering extends AbstractStyle |
| 28 | { |
| 29 | /** |
| 30 | * Write style. |
| 31 | */ |
| 32 | public function write(): void |
| 33 | { |
| 34 | /** @var StyleNumbering $style Type hint */ |
| 35 | $style = $this->getStyle(); |
| 36 | if (!$style instanceof StyleNumbering) { |
| 37 | return; |
| 38 | } |
| 39 | $xmlWriter = $this->getXmlWriter(); |
| 40 | |
| 41 | $xmlWriter->startElement('text:list-style'); |
| 42 | $xmlWriter->writeAttribute('style:name', $style->getStyleName()); |
| 43 | |
| 44 | foreach ($style->getLevels() as $styleLevel) { |
| 45 | $numLevel = $styleLevel->getLevel() + 1; |
| 46 | |
| 47 | // In Twips |
| 48 | $tabPos = $styleLevel->getTabPos(); |
| 49 | // In Inches |
| 50 | $tabPos /= Converter::INCH_TO_TWIP; |
| 51 | // In Centimeters |
| 52 | $tabPos *= Converter::INCH_TO_CM; |
| 53 | |
| 54 | // In Twips |
| 55 | $hanging = $styleLevel->getHanging(); |
| 56 | // In Inches |
| 57 | $hanging /= Converter::INCH_TO_TWIP; |
| 58 | // In Centimeters |
| 59 | $hanging *= Converter::INCH_TO_CM; |
| 60 | |
| 61 | $xmlWriter->startElement('text:list-level-style-bullet'); |
| 62 | $xmlWriter->writeAttribute('text:level', $numLevel); |
| 63 | $xmlWriter->writeAttribute('text:style-name', $style->getStyleName() . '_' . $numLevel); |
| 64 | $xmlWriter->writeAttribute('text:bullet-char', $styleLevel->getText()); |
| 65 | |
| 66 | $xmlWriter->startElement('style:list-level-properties'); |
| 67 | $xmlWriter->writeAttribute('text:list-level-position-and-space-mode', 'label-alignment'); |
| 68 | |
| 69 | $xmlWriter->startElement('style:list-level-label-alignment'); |
| 70 | $xmlWriter->writeAttribute('text:label-followed-by', 'listtab'); |
| 71 | $xmlWriter->writeAttribute('text:list-tab-stop-position', number_format($tabPos, 2, '.', '') . 'cm'); |
| 72 | $xmlWriter->writeAttribute('fo:text-indent', '-' . number_format($hanging, 2, '.', '') . 'cm'); |
| 73 | $xmlWriter->writeAttribute('fo:margin-left', number_format($tabPos, 2, '.', '') . 'cm'); |
| 74 | |
| 75 | $xmlWriter->endElement(); // style:list-level-label-alignment |
| 76 | $xmlWriter->endElement(); // style:list-level-properties |
| 77 | |
| 78 | $xmlWriter->startElement('style:text-properties'); |
| 79 | $xmlWriter->writeAttribute('style:font-name', $styleLevel->getFont()); |
| 80 | $xmlWriter->endElement(); // style:text-properties |
| 81 | |
| 82 | $xmlWriter->endElement(); // text:list-level-style-bullet |
| 83 | } |
| 84 | |
| 85 | $xmlWriter->endElement(); // text:list-style |
| 86 | } |
| 87 | } |