|
| 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 | + * ListItem element HTML writer. |
| 23 | + * |
| 24 | + * @since 0.10.0 |
| 25 | + */ |
| 26 | +class ListItemRun extends TextRun |
| 27 | +{ |
| 28 | + /** |
| 29 | + * Write list item. |
| 30 | + * |
| 31 | + * @return string |
| 32 | + */ |
| 33 | + public function write() |
| 34 | + { |
| 35 | + $element = $this->element; |
| 36 | + if (!$element instanceof \PhpOffice\PhpWord\Element\ListItemRun) { |
| 37 | + return ''; |
| 38 | + } |
| 39 | + |
| 40 | + $writer = new Container($this->parentWriter, $element); |
| 41 | + $this->getStyles(); |
| 42 | + |
| 43 | + $depth = (int) $element->getDepth(); |
| 44 | + $style = $element->getStyle(); |
| 45 | + |
| 46 | + $content = ''; |
| 47 | + $content .= $this->writeOpening(); |
| 48 | + if ($style instanceof \PhpOffice\PhpWord\Style\ListItem) { |
| 49 | + $numStyle = $style->getNumbering(); |
| 50 | + $levels = $numStyle->getLevels(); |
| 51 | + $content .= '\ilvl' . $element->getDepth(); |
| 52 | + $content .= '\ls' . $style->getNumId(); |
| 53 | + $content .= '\tx' . $levels[$depth]->getTabPos(); |
| 54 | + $hanging = $levels[$depth]->getLeft() + $levels[$depth]->getHanging(); |
| 55 | + $left = 0 - $levels[$depth]->getHanging(); |
| 56 | + $content .= '\fi' . $left; |
| 57 | + $content .= '\li' . $hanging; |
| 58 | + $content .= '\lin' . $hanging; |
| 59 | + } |
| 60 | + $content .= '{'; |
| 61 | + $content .= $writer->write(); |
| 62 | + $content .= '}'; |
| 63 | + $content .= $this->writeClosing(); |
| 64 | + |
| 65 | + return $content; |
| 66 | + } |
| 67 | +} |
0 commit comments