1 | <?php |
||
26 | class SVG extends Base implements ContainerInterface, ElementFactoryInterface, SVGOutputInterface |
||
27 | { |
||
28 | use ElementTrait, ChildTrait; |
||
29 | |||
30 | /** |
||
31 | * @var XMLDocumentInterface |
||
32 | */ |
||
33 | private $svg; |
||
34 | |||
35 | /** |
||
36 | * @var OutputInterface |
||
37 | */ |
||
38 | private $outputImpl; |
||
39 | |||
40 | 149 | public function __construct($width = 640, $height = 480, XMLDocumentInterface $dom = null) |
|
62 | |||
63 | /** |
||
64 | * @param array $assoc |
||
65 | * |
||
66 | * @return SVG |
||
67 | */ |
||
68 | 149 | public function apply(array $assoc) |
|
74 | |||
75 | /** |
||
76 | * @param $width |
||
77 | * @param $height |
||
78 | * @param XMLDocumentInterface|null $dom |
||
79 | * |
||
80 | * @return SVG |
||
81 | */ |
||
82 | public static function create($width, $height, XMLDocumentInterface $dom = null) |
||
83 | { |
||
84 | return new SVG($width, $height, $dom); |
||
85 | } |
||
86 | |||
87 | 3 | public function getRoot() |
|
91 | |||
92 | 3 | public function getName() |
|
96 | |||
97 | /** |
||
98 | * @return DOMElement |
||
99 | */ |
||
100 | 149 | public function getElement() |
|
101 | { |
||
102 | 149 | return $this->svg->getElement(); |
|
103 | } |
||
104 | |||
105 | 149 | public function createElement($name, $value = null, $attributes = []) |
|
106 | { |
||
107 | 149 | $element = $this->domImpl->createElement($name, $value); |
|
108 | |||
109 | 149 | KeyValueWriter::apply($element, $attributes); |
|
110 | |||
111 | 149 | return $element; |
|
112 | } |
||
113 | |||
114 | 1 | public function __toString() |
|
118 | |||
119 | 61 | public function draw() |
|
120 | { |
||
121 | 61 | return $this->domImpl->saveHTML(); |
|
122 | } |
||
123 | |||
124 | /** |
||
125 | * @inheritdoc |
||
126 | */ |
||
127 | 1 | public function copy(array $apply = [], array $ignore = [], ContainerInterface $parent = null) |
|
128 | { |
||
129 | 1 | throw new \BadMethodCallException("You cannot copy SVG element."); |
|
130 | } |
||
131 | |||
132 | /** |
||
133 | * Returns escaped svg as plain text. |
||
134 | * |
||
135 | * @return string |
||
136 | */ |
||
137 | 1 | public function asString() |
|
138 | { |
||
139 | 1 | return htmlspecialchars($this->draw()); |
|
140 | } |
||
141 | |||
142 | /** |
||
143 | * @inheritdoc |
||
144 | */ |
||
145 | 1 | public function asSVG() |
|
149 | |||
150 | /** |
||
151 | * @inheritdoc |
||
152 | */ |
||
153 | 2 | public function asSVGZ($sendHeader = false) |
|
154 | { |
||
155 | 2 | if ($sendHeader && !headers_sent()) { |
|
156 | 1 | header("Content-Encoding: gzip"); |
|
157 | 1 | } |
|
158 | |||
159 | 2 | return gzencode($this->draw(), 9); |
|
160 | } |
||
161 | |||
162 | /** |
||
163 | * @inheritdoc |
||
164 | */ |
||
165 | 1 | public function asDataUriBase64() |
|
172 | |||
173 | /** |
||
174 | * @inheritdoc |
||
175 | */ |
||
176 | 2 | public function asFile($name, $prettyPrint = false, $override = false) |
|
177 | { |
||
178 | 2 | return $this->outputImpl->file( |
|
179 | 2 | $name, |
|
184 | |||
185 | /** |
||
186 | * @inheritdoc |
||
187 | */ |
||
188 | public function asImageFile($name, $format = IOFormat::PNG, $override = false) |
||
197 | |||
198 | /** |
||
199 | * @inheritdoc |
||
200 | */ |
||
201 | public function asImage($format = IOFormat::PNG, $sendHeader = false) |
||
209 | |||
210 | public static function fromString($svgString) |
||
214 | } |
||
215 |