1 |
<?php |
2 |
/** |
3 |
* This file holds helper functions |
4 |
* for things related to SVG Tags |
5 |
* (Scalable Vector Graphics) |
6 |
* |
7 |
* $Id: svg_utils.inc,v 1.7 2002/11/08 21:56:12 hemna Exp $ |
8 |
* |
9 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
10 |
* @package phpHtmlLib |
11 |
* @link http://phphtmllib.newsblob.com |
12 |
*/ |
13 |
|
14 |
|
15 |
/** |
16 |
* This function is used to build an |
17 |
* SVG <a> tag |
18 |
* |
19 |
* @param string - the 'xlink:href' attribute |
20 |
* @param mixed - any N number of params for |
21 |
* content for the tag |
22 |
* @return Asvgtag object |
23 |
* @link http://www.w3.org/TR/SVG/linking.html#AElement |
24 |
*/ |
25 |
function svg_a($xlinkhref) { |
26 |
$tag = new Asvgtag( array("xlink:href" => $xlinkhref)); |
27 |
$num_args = func_num_args(); |
28 |
for ($i=1;$i<$num_args;$i++) { |
29 |
$tag->add(func_get_arg($i)); |
30 |
} |
31 |
return $tag; |
32 |
} |
33 |
|
34 |
/** |
35 |
* This function is used to build an |
36 |
* SVG <animate> tag |
37 |
* |
38 |
* @param string - the 'from' attribute |
39 |
* @param string - the 'to' attribute |
40 |
* @param string - the 'duration' attribute |
41 |
* @param string - the 'attributeName' attribute |
42 |
* @param string - the 'attributeType' attribute |
43 |
* @param string - the 'repeatCount' attribute |
44 |
* @param string - the 'fill' attribute |
45 |
* @return ANIMATEsvgtag object |
46 |
* @link http://www.w3.org/TR/SVG/animate.html#AnimateElement |
47 |
*/ |
48 |
function svg_animate($from, $to, $duration, $attributename, |
49 |
$attributetype, $repeatcount=NULL, $fill=NULL) { |
50 |
$tag = new ANIMATEsvgtag( array("from" => $from, "to" => $to, |
51 |
"duration" => $duration, |
52 |
"attributeName" => $attributename, |
53 |
"attributeType" => $attributetype)); |
54 |
if ($repeatcount) { |
55 |
$tag->set_tag_attribute("repeatCount", $repeatcount); |
56 |
} |
57 |
if ($fill) { |
58 |
$tag->set_tag_attribute("fill", $fill); |
59 |
} |
60 |
|
61 |
return $tag; |
62 |
} |
63 |
|
64 |
/** |
65 |
* This function is used to build an |
66 |
* SVG <circle> tag and its common |
67 |
* attributes |
68 |
* |
69 |
* @param int - the 'cx' attribute. The x-axis |
70 |
* coordinate of the center of the circle |
71 |
* @param int - the 'cy' attribute. The y-axis |
72 |
* coordinate of the center of the circle |
73 |
* @param string - the 'r' (radius) attribute |
74 |
* @param string - the 'fill' attribute |
75 |
* @param string - the 'stroke' attribute |
76 |
* @param string - the 'stroke-width' attribute |
77 |
* @param string - the 'style' attribyte |
78 |
* @return CIRCLEsvgtag object |
79 |
* @link http://www.w3.org/TR/SVG/shapes.html |
80 |
*/ |
81 |
function svg_circle($cx, $cy, $radius, $fill="none", |
82 |
$stroke=NULL, $strokewidth=NULL, $style=NULL) { |
83 |
$tag = new CIRCLEsvgtag( array("cx" => $cx, "cy" => $cy, |
84 |
"r" => $radius)); |
85 |
if ($fill) { |
86 |
$tag->set_tag_attribute("fill", $fill); |
87 |
} |
88 |
if ($stroke) { |
89 |
$tag->set_tag_attribute("stroke", $stroke); |
90 |
} |
91 |
if ($strokewidth) { |
92 |
$tag->set_tag_attribute("stroke-width", $strokewidth); |
93 |
} |
94 |
if ($style) { |
95 |
$tag->set_style($style); |
96 |
} |
97 |
return $tag; |
98 |
} |
99 |
|
100 |
|
101 |
/** |
102 |
* This function is used for building an |
103 |
* SVG <desc> tag |
104 |
* |
105 |
* @param mixed - any N number of params for |
106 |
* content for the tag |
107 |
* @return DESCsvgtag object |
108 |
*/ |
109 |
function svg_desc() { |
110 |
$tag = new DESCsvgtag; |
111 |
$args = func_get_args(); |
112 |
call_user_func_array( array(&$tag, "add"), $args); |
113 |
return $tag; |
114 |
} |
115 |
|
116 |
/** |
117 |
* This function is used to build an |
118 |
* SVG <ellipse> tag and its common |
119 |
* attributes |
120 |
* |
121 |
* @param int - the 'cx' attribute. The x-axis |
122 |
* coordinate of the center of the circle |
123 |
* @param int - the 'cy' attribute. The y-axis |
124 |
* coordinate of the center of the circle |
125 |
* @param int - the 'rx' attribute. The x-axis radius of |
126 |
* the ellipse. |
127 |
* @param int - the 'ry' attribute. The y-axis radius of |
128 |
* the ellipse. |
129 |
* @param string - the 'fill' attribute |
130 |
* @param string - the 'stroke' attribute |
131 |
* @param string - the 'stroke-width' attribute |
132 |
* @param string - the 'style' attribyte |
133 |
* @return ELLIPSEsvgtag object |
134 |
* @link http://www.w3.org/TR/SVG/shapes.html |
135 |
*/ |
136 |
function svg_ellipse($cx, $cy, $rx, $ry, $fill="none", |
137 |
$stroke=NULL, $strokewidth, $style=NULL) { |
138 |
$tag = new ELLIPSEsvgtag( array("cx" => $cx, "cy" => $cy, |
139 |
"rx" => $rx, "ry" => $ry)); |
140 |
if ($fill) { |
141 |
$tag->set_tag_attribute("fill", $fill); |
142 |
} |
143 |
if ($stroke) { |
144 |
$tag->set_tag_attribute("stroke", $stroke); |
145 |
} |
146 |
if ($strokewidth) { |
147 |
$tag->set_tag_attribute("stroke-width", $strokewidth); |
148 |
} |
149 |
if ($style) { |
150 |
$tag->set_style($style); |
151 |
} |
152 |
return $tag; |
153 |
} |
154 |
|
155 |
/** |
156 |
* this function builds an SVG |
157 |
* <font> tag |
158 |
* |
159 |
* @param string - the required 'horiz-adv-x' attribute |
160 |
* @return FONTsvgtag object |
161 |
*/ |
162 |
function svg_font( $horizadvx ) { |
163 |
$tag = new FONTsvgtag( array("horiz-adv-x" => |
164 |
$horizadvx)); |
165 |
$num_args = func_num_args(); |
166 |
for ($i=1;$i<$num_args;$i++) { |
167 |
$tag->add(func_get_arg($i)); |
168 |
} |
169 |
return $tag; |
170 |
} |
171 |
|
172 |
/** |
173 |
* This function builds an SVG |
174 |
* <g> tag |
175 |
* |
176 |
* @param string - the 'style' attribute |
177 |
* @param string - the 'transform' attribute |
178 |
* @return Gsvgtag object |
179 |
*/ |
180 |
function svg_g($style=NULL, $transform=NULL) { |
181 |
$tag = new Gsvgtag; |
182 |
if ($style) { |
183 |
$tag->set_style($style); |
184 |
} |
185 |
|
186 |
if ($transform) { |
187 |
$tag->set_transform( $transform ); |
188 |
} |
189 |
|
190 |
return $tag; |
191 |
} |
192 |
|
193 |
|
194 |
/** |
195 |
* This function is used for building an |
196 |
* SVG <line> tag |
197 |
* |
198 |
* @param int - the 'x1' attribute |
199 |
* @param int - the 'y1' attribute |
200 |
* @param int - the 'x2' attribute |
201 |
* @param int - the 'y2' attribute |
202 |
* @param string - the 'stroke' attribute |
203 |
* @param string - the 'stroke-width' attribute |
204 |
* @param string - the 'style' attribute |
205 |
* @return LINEsvgtag object |
206 |
* @link http://www.w3.org/TR/SVG/shapes.html |
207 |
*/ |
208 |
function svg_line($x1, $y1, $x2, $y2, $stroke=NULL, |
209 |
$strokewidth, $style=NULL) { |
210 |
$tag = new LINEsvgtag(array("x1" => $x1, "y1" => $y1, |
211 |
"x2" => $x2, "y2" => $y2)); |
212 |
if ($stroke) { |
213 |
$tag->set_tag_attribute("stroke", $stroke); |
214 |
} |
215 |
if ($strokewidth) { |
216 |
$tag->set_tag_attribute("stroke-width", $strokewidth); |
217 |
} |
218 |
if ($style) { |
219 |
$tag->set_style( $style ); |
220 |
} |
221 |
|
222 |
return $tag; |
223 |
} |
224 |
|
225 |
/** |
226 |
* This function is used for building an |
227 |
* SVG <marker> tag |
228 |
* |
229 |
* @param string - the 'refX' attribute |
230 |
* @param string - the 'refY' attribute |
231 |
* @param string - the 'markerUnits' attribute |
232 |
* @param string - the 'markerWidth' attribute |
233 |
* @param string - the 'markerHeight' attribute |
234 |
* @param string - the 'orient' attribute |
235 |
* @return MARKERsvgtag object |
236 |
* @link http://www.w3.org/TR/SVG/painting.html#MarkerElement |
237 |
*/ |
238 |
function svg_marker($refx, $refY, $markerunits=NULL, |
239 |
$markerwidth=NULL, $markerheight=NULL, |
240 |
$orient=NULL) { |
241 |
$tag = new MARKERsvgtag( array("refx" => $refx, |
242 |
"refy" => $refy)); |
243 |
|
244 |
if ($markerunits) { |
245 |
$this->set_tag_attribute("markerUnits", $markerunits ); |
246 |
} |
247 |
if ($markerwidth) { |
248 |
$this->set_tag_attribute("markerWidth", $markerwidth ); |
249 |
} |
250 |
if ($markerheight) { |
251 |
$this->set_tag_attribute("markerHeight", $markerheight ); |
252 |
} |
253 |
if ($orient) { |
254 |
$this->set_tag_attribute("orient", $orient ); |
255 |
} |
256 |
|
257 |
return $tag; |
258 |
} |
259 |
|
260 |
/** |
261 |
* This function is used for building an |
262 |
* SVG <polygon> tag |
263 |
* |
264 |
* @param int - the 'points' attribute |
265 |
* @param string - the 'fill' attribute |
266 |
* @param string - the 'stroke' attribute |
267 |
* @param string - the 'stroke-width' attribute |
268 |
* @param string - the 'style' attribute |
269 |
* @return POLYGONsvgtag object |
270 |
* @link http://www.w3.org/TR/SVG/shapes.html |
271 |
*/ |
272 |
function svg_polygon($points, $fill="none", $stroke=NULL, |
273 |
$strokewidth, $style=NULL) { |
274 |
$tag = new POLYGONsvgtag; |
275 |
|
276 |
if ($fill) { |
277 |
$tag->set_tag_attribute("fill", $fill); |
278 |
} |
279 |
if ($stroke) { |
280 |
$tag->set_tag_attribute("stroke", $stroke); |
281 |
} |
282 |
if ($strokewidth) { |
283 |
$tag->set_tag_attribute("stroke-width", $strokewidth); |
284 |
} |
285 |
if ($style) { |
286 |
$tag->set_style( $style ); |
287 |
} |
288 |
|
289 |
//do this instead of the constructor |
290 |
//because the output is easier to read. |
291 |
$tag->set_tag_attribute("points", $points); |
292 |
|
293 |
return $tag; |
294 |
} |
295 |
|
296 |
/** |
297 |
* This function is used for building an |
298 |
* SVG <polyline> tag |
299 |
* |
300 |
* @param int - the 'points' attribute |
301 |
* @param string - the 'fill' attribute |
302 |
* @param string - the 'stroke' attribute |
303 |
* @param string - the 'stroke-width' attribute |
304 |
* @param string - the 'style' attribute |
305 |
* @return POLYLINEsvgtag object |
306 |
* @link http://www.w3.org/TR/SVG/shapes.html |
307 |
*/ |
308 |
function svg_polyline($points, $fill="none", $stroke=NULL, |
309 |
$strokewidth, $style=NULL) { |
310 |
$tag = new POLYLINEsvgtag; |
311 |
|
312 |
if ($fill) { |
313 |
$tag->set_tag_attribute("fill", $fill); |
314 |
} |
315 |
if ($stroke) { |
316 |
$tag->set_tag_attribute("stroke", $stroke); |
317 |
} |
318 |
if ($strokewidth) { |
319 |
$tag->set_tag_attribute("stroke-width", $strokewidth); |
320 |
} |
321 |
if ($style) { |
322 |
$tag->set_style( $style ); |
323 |
} |
324 |
|
325 |
//do this instead of the constructor |
326 |
//because the output is easier to read. |
327 |
$tag->set_tag_attribute("points", $points); |
328 |
|
329 |
return $tag; |
330 |
} |
331 |
|
332 |
|
333 |
/** |
334 |
* This function creates a <script> |
335 |
* tag and wraps the javascript in the |
336 |
* appropriate <![CDATA[ JAVASCRIPT ]]> |
337 |
* that is required for svg. |
338 |
* |
339 |
* @param string the 'type' attribute |
340 |
* @param mixed - any N number of params for |
341 |
* content for the tag |
342 |
* @return SCRIPTsvgtag object |
343 |
*/ |
344 |
function svg_script( $type="text/javascript" ) { |
345 |
$tag = new SCRIPTsvgtag(array("type" => $type)); |
346 |
$num_args = func_num_args(); |
347 |
for ($i=1;$i<$num_args;$i++) { |
348 |
$tag->add(func_get_arg($i)); |
349 |
} |
350 |
return $tag; |
351 |
} |
352 |
|
353 |
/** |
354 |
* This function creates a <script> |
355 |
* tag and wraps the javascript in the |
356 |
* appropriate <![CDATA[ JAVASCRIPT ]]> |
357 |
* that is required for svg. |
358 |
* |
359 |
* @param string the 'type' attribute |
360 |
* @param mixed - any N number of params for |
361 |
* content for the tag |
362 |
* @return SCRIPTsvgtag object |
363 |
*/ |
364 |
function svg_style( $type="text/css" ) { |
365 |
$tag = new STYLEsvgtag(array("type" => $type)); |
366 |
$num_args = func_num_args(); |
367 |
for ($i=1;$i<$num_args;$i++) { |
368 |
$tag->add(func_get_arg($i)); |
369 |
} |
370 |
return $tag; |
371 |
} |
372 |
|
373 |
|
374 |
/** |
375 |
* This function is used to build an |
376 |
* SVG <rect> tag and its common |
377 |
* attributes |
378 |
* |
379 |
* @param int - the 'x' attribute |
380 |
* @param int - the 'y' attribute |
381 |
* @param string - the 'width' attribute |
382 |
* @param string - the 'height' attribute |
383 |
* @param string - the 'fill' attribute |
384 |
* @param string - the 'stroke' attribute |
385 |
* @param string - the 'stroke-width' attribyte |
386 |
* @param string - the 'style' attribyte |
387 |
* @return RECTsvgtag object |
388 |
* @link http://www.w3.org/TR/SVG/shapes.html |
389 |
*/ |
390 |
function svg_rect($x, $y, $width, $height, $fill=NULL, |
391 |
$stroke=NULL, $strokewidth=NULL, $style=NULL) { |
392 |
$tag = new RECTsvgtag( array("x" => $x, "y" => $y, |
393 |
"width" => $width, |
394 |
"height" => $height)); |
395 |
if ($fill) { |
396 |
$tag->set_tag_attribute("fill", $fill); |
397 |
} |
398 |
if ($stroke) { |
399 |
$tag->set_tag_attribute("stroke", $stroke); |
400 |
} |
401 |
if ($strokewidth) { |
402 |
$tag->set_tag_attribute("stroke-width", $strokewidth); |
403 |
} |
404 |
|
405 |
if ($style) { |
406 |
$tag->set_style($style); |
407 |
} |
408 |
return $tag; |
409 |
} |
410 |
|
411 |
/** |
412 |
* This function is used to build an |
413 |
* SVG <text> tag |
414 |
* |
415 |
* @param int - the 'x' attribute |
416 |
* @param int - the 'y' attribute |
417 |
* @param string - the 'rotate' attribute |
418 |
* @param style - the 'class' attribute |
419 |
* @param mixed - any N number of params for |
420 |
* content for the tag |
421 |
* @return TEXTsvgtag object. |
422 |
* @link http://www.w3.org/TR/SVG/text.html |
423 |
*/ |
424 |
function svg_text($x, $y, $rotate=NULL, $class=NULL) { |
425 |
$tag = new TEXTsvgtag( array("x" => $x, "y" => $y)); |
426 |
if ($rotate) { |
427 |
$tag->set_tag_attribute( "rotate", $rotate ); |
428 |
} |
429 |
if ($class) { |
430 |
$tag->set_class( $class ); |
431 |
} |
432 |
$num_args = func_num_args(); |
433 |
for ($i=4;$i<$num_args;$i++) { |
434 |
$tag->add(func_get_arg($i)); |
435 |
} |
436 |
return $tag; |
437 |
} |
438 |
|
439 |
/** |
440 |
* This function is used to build an |
441 |
* SVG <textpath> tag. |
442 |
* |
443 |
* @param string - the 'xlink:href' attribute |
444 |
* @param string - the 'class' attribute |
445 |
* @param mixed - any N number of params for |
446 |
* content for the tag |
447 |
* @return TEXTPATHsvgtag object. |
448 |
* @link http://www.w3.org/TR/SVG/text.html#TextPathElement |
449 |
*/ |
450 |
function svg_textpath($xlinkhref, $class=NULL) { |
451 |
$tag = new TEXTPATHsvgtag( array("xlink:href" => $xlinkhref)); |
452 |
if ($class) { |
453 |
$tag->set_class( $class ); |
454 |
} |
455 |
$num_args = func_num_args(); |
456 |
for ($i=2;$i<$num_args;$i++) { |
457 |
$tag->add(func_get_arg($i)); |
458 |
} |
459 |
return $tag; |
460 |
} |
461 |
|
462 |
/** |
463 |
* This function is used to build an |
464 |
* SVG <tref> tag |
465 |
* |
466 |
* @param string - the 'xlink:href' required attribute |
467 |
* @param string - the 'class' attribute |
468 |
* @param mixed - any N number of params for |
469 |
* content for the tag |
470 |
* @return TREFsvgtag object. |
471 |
* @link http://www.w3.org/TR/SVG/text.html |
472 |
*/ |
473 |
function svg_tref($xlinkhref, $class=NULL) { |
474 |
$tag = new TREFsvgtag( array("xlink:href" => $xlinkhref)); |
475 |
if ($class) { |
476 |
$tag->set_class( $class ); |
477 |
} |
478 |
$num_args = func_num_args(); |
479 |
for ($i=2;$i<$num_args;$i++) { |
480 |
$tag->add(func_get_arg($i)); |
481 |
} |
482 |
return $tag; |
483 |
} |
484 |
|
485 |
/** |
486 |
* This function is used to build an |
487 |
* SVG <tref> tag. |
488 |
* |
489 |
* @param string - the 'x' attribute |
490 |
* @param string - the 'y' attribute |
491 |
* @param string - the 'class' attribute |
492 |
* @return TSPANsvgtag object. |
493 |
* @link http://www.w3.org/TR/SVG/text.html |
494 |
*/ |
495 |
function svg_tspan($x, $y, $class=NULL) { |
496 |
$tag = new TSPANsvgtag( array("x" => $x, |
497 |
"y" => $y)); |
498 |
if ($class) { |
499 |
$tag->set_class( $class ); |
500 |
} |
501 |
return $tag; |
502 |
} |
503 |
|
504 |
|
505 |
?> |