Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| Graphic | |
100.00% |
15 / 15 |
|
100.00% |
2 / 2 |
9 | |
100.00% |
1 / 1 |
| writeFrameProperties | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
4 | |||
| writeFillAndStroke | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
5 | |||
| 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 as published by the Free Software Foundation. |
| 9 | */ |
| 10 | |
| 11 | namespace PhpOffice\PhpWord\Writer\ODText\Style; |
| 12 | |
| 13 | use PhpOffice\PhpWord\Shared\Converter; |
| 14 | use PhpOffice\PhpWord\Shared\XMLWriter; |
| 15 | use PhpOffice\PhpWord\Style\Fill; |
| 16 | use PhpOffice\PhpWord\Style\Frame; |
| 17 | use PhpOffice\PhpWord\Style\Outline; |
| 18 | |
| 19 | /** |
| 20 | * Shared ODF graphic property helpers. |
| 21 | */ |
| 22 | class Graphic |
| 23 | { |
| 24 | /** |
| 25 | * Write the ODF geometry for a frame-like element. |
| 26 | */ |
| 27 | public static function writeFrameProperties(XMLWriter $xmlWriter, Frame $style): void |
| 28 | { |
| 29 | $unit = $style->getUnit(); |
| 30 | $convert = $unit === Frame::UNIT_PX ? 'pixelToCm' : 'pointToCm'; |
| 31 | $xmlWriter->writeAttributeIf($style->getWidth() !== null, 'svg:width', Converter::$convert($style->getWidth()) . 'cm'); |
| 32 | $xmlWriter->writeAttributeIf($style->getHeight() !== null, 'svg:height', Converter::$convert($style->getHeight()) . 'cm'); |
| 33 | $xmlWriter->writeAttributeIf($style->getLeft() !== null && $style->getLeft() != 0, 'svg:x', Converter::$convert($style->getLeft()) . 'cm'); |
| 34 | $xmlWriter->writeAttributeIf($style->getTop() !== null && $style->getTop() != 0, 'svg:y', Converter::$convert($style->getTop()) . 'cm'); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Write standard ODF fill and stroke properties. |
| 39 | */ |
| 40 | public static function writeFillAndStroke(XMLWriter $xmlWriter, ?Fill $fill = null, ?Outline $outline = null): void |
| 41 | { |
| 42 | if ($fill !== null && $fill->getColor() !== null) { |
| 43 | $xmlWriter->writeAttribute('draw:fill', 'solid'); |
| 44 | $xmlWriter->writeAttribute('draw:fill-color', '#' . ltrim($fill->getColor(), '#')); |
| 45 | } else { |
| 46 | $xmlWriter->writeAttribute('draw:fill', 'none'); |
| 47 | } |
| 48 | |
| 49 | if ($outline !== null && $outline->getColor() !== null) { |
| 50 | $xmlWriter->writeAttribute('draw:stroke', 'solid'); |
| 51 | $xmlWriter->writeAttribute('svg:stroke-color', '#' . ltrim($outline->getColor(), '#')); |
| 52 | $xmlWriter->writeAttributeIf($outline->getWeight() !== null, 'svg:stroke-width', $outline->getWeight() . $outline->getUnit()); |
| 53 | } else { |
| 54 | $xmlWriter->writeAttribute('draw:stroke', 'none'); |
| 55 | } |
| 56 | } |
| 57 | } |