Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
90.91% |
20 / 22 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Row | |
90.91% |
20 / 22 |
|
50.00% |
1 / 2 |
8.05 | |
0.00% |
0 / 1 |
| write | |
89.47% |
17 / 19 |
|
0.00% |
0 / 1 |
6.04 | |||
| convertHeight | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace PhpOffice\PhpWord\Writer\ODText\Style; |
| 4 | |
| 5 | use PhpOffice\PhpWord\Shared\Converter; |
| 6 | |
| 7 | /** |
| 8 | * Table row style writer. |
| 9 | */ |
| 10 | class Row extends AbstractStyle |
| 11 | { |
| 12 | public function write(): void |
| 13 | { |
| 14 | $style = $this->getStyle(); |
| 15 | if ($style instanceof \PhpOffice\PhpWord\Element\Row) { |
| 16 | $height = $style->getHeight(); |
| 17 | $style = $style->getStyle(); |
| 18 | } else { |
| 19 | $height = null; |
| 20 | } |
| 21 | if (!$style instanceof \PhpOffice\PhpWord\Style\Row) { |
| 22 | return; |
| 23 | } |
| 24 | |
| 25 | $xmlWriter = $this->getXmlWriter(); |
| 26 | $xmlWriter->startElement('style:style'); |
| 27 | $xmlWriter->writeAttribute('style:name', $style->getStyleName()); |
| 28 | $xmlWriter->writeAttribute('style:family', 'table-row'); |
| 29 | $xmlWriter->startElement('style:table-row-properties'); |
| 30 | |
| 31 | if ($height !== null) { |
| 32 | $attribute = $style->isExactHeight() ? 'style:row-height' : 'style:min-row-height'; |
| 33 | $xmlWriter->writeAttribute($attribute, $this->convertHeight($height)); |
| 34 | if ($style->isExactHeight()) { |
| 35 | $xmlWriter->writeAttribute('style:use-optimal-row-height', 'false'); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | $xmlWriter->endElement(); // style:table-row-properties |
| 40 | $xmlWriter->endElement(); // style:style |
| 41 | } |
| 42 | |
| 43 | private function convertHeight(int $height): string |
| 44 | { |
| 45 | $inches = (string) ($height / Converter::INCH_TO_TWIP) . 'in'; |
| 46 | $centimeters = (string) ($height * Converter::INCH_TO_CM / Converter::INCH_TO_TWIP) . 'cm'; |
| 47 | |
| 48 | return strlen($inches) < strlen($centimeters) ? $inches : $centimeters; |
| 49 | } |
| 50 | } |