[347] | 1 | <?php
|
---|
| 2 | /**
|
---|
| 3 | * Html2Pdf Library - Tag class
|
---|
| 4 | *
|
---|
| 5 | * HTML => PDF converter
|
---|
| 6 | * distributed under the OSL-3.0 License
|
---|
| 7 | *
|
---|
| 8 | * @package Html2pdf
|
---|
| 9 | * @author Laurent MINGUET <webmaster@html2pdf.fr>
|
---|
| 10 | * @copyright 2017 Laurent MINGUET
|
---|
| 11 | */
|
---|
| 12 | namespace Spipu\Html2Pdf\Tag;
|
---|
| 13 |
|
---|
| 14 | use Spipu\Html2Pdf\Exception\HtmlParsingException;
|
---|
| 15 | use Spipu\Html2Pdf\SvgDrawer;
|
---|
| 16 |
|
---|
| 17 | /**
|
---|
| 18 | * Abstract Default Tag
|
---|
| 19 | * used by all the svg tags
|
---|
| 20 | */
|
---|
| 21 | abstract class AbstractSvgTag extends AbstractTag
|
---|
| 22 | {
|
---|
| 23 | /**
|
---|
| 24 | * @var SvgDrawer
|
---|
| 25 | */
|
---|
| 26 | protected $svgDrawer;
|
---|
| 27 |
|
---|
| 28 | /**
|
---|
| 29 | * AbstractSvgTag constructor.
|
---|
| 30 | *
|
---|
| 31 | * @param SvgDrawer $svgDrawer
|
---|
| 32 | */
|
---|
| 33 | public function __construct(SvgDrawer $svgDrawer)
|
---|
| 34 | {
|
---|
| 35 | parent::__construct();
|
---|
| 36 |
|
---|
| 37 | $this->svgDrawer = $svgDrawer;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | /**
|
---|
| 41 | * @inheritdoc
|
---|
| 42 | */
|
---|
| 43 | public function open($properties)
|
---|
| 44 | {
|
---|
| 45 | $this->openSvg($properties);
|
---|
| 46 | $this->drawSvg($properties);
|
---|
| 47 | $this->closeSvg();
|
---|
| 48 | return true;
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | /**
|
---|
| 52 | * @inheritdoc
|
---|
| 53 | */
|
---|
| 54 | public function close($properties)
|
---|
| 55 | {
|
---|
| 56 | return true;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | /**
|
---|
| 60 | * Open the SVG tag
|
---|
| 61 | *
|
---|
| 62 | * @param array $properties
|
---|
| 63 | * @throws HtmlParsingException
|
---|
| 64 | */
|
---|
| 65 | protected function openSvg($properties)
|
---|
| 66 | {
|
---|
| 67 | if (!$this->svgDrawer->isDrawing()) {
|
---|
| 68 | $e = new HtmlParsingException('The asked ['.$this->getName().'] tag is not in a [DRAW] tag');
|
---|
| 69 | $e->setInvalidTag($this->getName());
|
---|
| 70 | throw $e;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | $transform = null;
|
---|
| 74 | if (array_key_exists('transform', $properties)) {
|
---|
| 75 | $transform = $this->svgDrawer->prepareTransform($properties['transform']);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | $this->pdf->doTransform($transform);
|
---|
| 79 | $this->parsingCss->save();
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | /**
|
---|
| 83 | * Close the SVG tag
|
---|
| 84 | */
|
---|
| 85 | protected function closeSvg()
|
---|
| 86 | {
|
---|
| 87 | $this->pdf->undoTransform();
|
---|
| 88 |
|
---|
| 89 | $this->parsingCss->load();
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | /**
|
---|
| 93 | * Draw the SVG tag
|
---|
| 94 | *
|
---|
| 95 | * @param array $properties
|
---|
| 96 | *
|
---|
| 97 | * @return void
|
---|
| 98 | */
|
---|
| 99 | abstract protected function drawSvg($properties);
|
---|
| 100 | }
|
---|