1SVG::Manual(3)        User Contributed Perl Documentation       SVG::Manual(3)
2
3
4

NAME

6       SVG - Perl extension for generating Scalable Vector Graphics (SVG) doc‐
7       uments
8
9       VERSION
10
11       Covers SVG-2.44 distribution, April 2008
12

SYNOPSIS

14           #!/usr/bin/perl -w
15           use strict;
16           use SVG;
17
18           # create an SVG object
19           my $svg= SVG->new(width=>200,height=>200);
20           #or
21           my $svg= SVG->new(width=>200,height=>200);
22
23           # use explicit element constructor to generate a group element
24           my $y=$svg->group(
25               id    => 'group_y',
26               style => { stroke=>'red', fill=>'green' }
27           );
28
29           # add a circle to the group
30           $y->circle(cx=>100, cy=>100, r=>50, id=>'circle_in_group_y');
31
32           # or, use the generic 'tag' method to generate a group element by name
33           my $z=$svg->tag('g',
34                           id    => 'group_z',
35                           style => {
36                               stroke => 'rgb(100,200,50)',
37                               fill   => 'rgb(10,100,150)'
38                           }
39                       );
40
41           # create and add a circle using the generic 'tag' method
42           $z->tag('circle', cx=>50, cy=>50, r=>100, id=>'circle_in_group_z');
43
44           # create an anchor on a rectangle within a group within the group z
45           my $k = $z->anchor(
46               id      => 'anchor_k',
47               -href   => 'http://test.hackmare.com/',
48               target => 'new_window_0'
49           )->rectangle(
50               x     => 20, y      => 50,
51               width => 20, height => 30,
52               rx    => 10, ry     => 5,
53               id    => 'rect_k_in_anchor_k_in_group_z'
54           );
55
56           # now render the SVG object, implicitly use svg namespace
57           print $svg->xmlify;
58
59           # or render a child node of the SVG object without rendering the entire object
60           print $k->xmlify; #renders the anchor $k above containing a rectangle, but does not
61                             #render any of the ancestor nodes of $k
62
63           # or, explicitly use svg namespace and generate a document with its own DTD
64           print $svg->xmlify(-namespace=>'svg');
65
66           # or, explicitly use svg namespace and generate an in-line docunent
67           print $svg->xmlify(
68               -namespace => "svg",
69               -pubid => "-//W3C//DTD SVG 1.0//EN",
70               -inline   => 1
71           );
72

DESCRIPTION

74       SVG is a 100% Perl module which generates a nested data structure con‐
75       taining the DOM representation of an SVG (Scalable Vector Graphics)
76       image. Using SVG, you can generate SVG objects, embed other SVG
77       instances into it, access the DOM object, create and access javascript,
78       and generate SMIL animation content.
79
80       General Steps to generating an SVG document
81
82       Generating SVG is a simple three step process:
83
84       1 The first step is to construct a new SVG object with "new".
85
86       2 The second step is to call element constructors to create SVG ele‐
87       ments. Examples of element constructors are "circle" and "path".
88
89       3 The third and last step is to render the SVG object into XML using
90       the "xmlify" method.
91
92       The "xmlify" method takes a number of optional arguments that control
93       how SVG renders the object into XML, and in particular determine
94       whether a stand-alone SVG document or an inline SVG document fragment
95       is generated:
96
97       -stand-alone
98
99       A complete SVG document with its own associated DTD. A namespace for
100       the SVG elements may be optionally specified.
101
102       -in-line
103
104       An in-line SVG document fragment with no DTD that be embedded within
105       other XML content. As with stand-alone documents, an alternate names‐
106       pace may be specified.
107
108       No XML content is generated until the third step is reached. Up until
109       this point, all constructed element definitions reside in a DOM-like
110       data structure from which they can be accessed and modified.
111
112       EXPORTS
113
114       None. However, SVG permits both options and additional element methods
115       to be specified in the import list. These options and elements are then
116       available for all SVG instances that are created with the "new" con‐
117       structor. For example, to change the indent string to two spaces per
118       level:
119
120           use SVG (-indent => "  ");
121
122       With the exception of -auto, all options may also be specified to the
123       "new" constructor. The currently supported options and their default
124       value are:
125
126           # processing options
127           -auto       => 0,       # permit arbitrary autoloading of all unrecognised elements
128           -printerror => 1,       # print error messages to STDERR
129           -raiseerror => 1,       # die on errors (implies -printerror)
130
131           # rendering options
132           -indent     => "\t",    # what to indent with
133           -elsep      => "\n",    # element line (vertical) separator
134                                   #     (note that not all agents ignor trailing blanks)
135           -nocredits  => 0,       # enable/disable credit note comment
136           -namespace  => '',      # The root element's (and it's children's) namespace prefix
137
138           # XML and Doctype declarations
139           -inline     => 0,       # inline or stand alone
140           -docroot    => 'svg',   # The document's root element
141           -version    => '1.0',
142           -extension  => '',
143           -encoding   => 'UTF-8',
144           -xml_svg    => 'http://www.w3.org/2000/svg',   # the svg xmlns attribute
145           -xml_xlink  => 'http://www.w3.org/1999/xlink', # the svg tag xmlns:xlink attribute
146           -standalone => 'yes',
147           -pubid      => "-//W3C//DTD SVG 1.0//EN",      # formerly -identifier
148           -sysid      => 'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd', # the system id
149
150       SVG also allows additional element generation methods to be specified
151       in the import list. For example to generate 'star' and 'planet' element
152       methods:
153
154           use SVG qw(star planet);
155
156       or:
157
158           use SVG ("star","planet");
159
160       This will add 'star' to the list of elements supported by SVG.pm (but
161       not of course other SVG parsers...). Alternatively the '-auto' option
162       will allow any unknown method call to generate an element of the same
163       name:
164
165           use SVG (-auto => 1, "star", "planet");
166
167       Any elements specified explicitly (as 'star' and 'planet' are here) are
168       predeclared; other elements are defined as and when they are seen by
169       Perl. Note that enabling '-auto' effectively disables compile-time syn‐
170       tax checking for valid method names.
171
172       Example:
173
174           use SVG (
175               -auto       => 0,
176               -indent     => "  ",
177               -raiserror  => 0,
178               -printerror => 1,
179               "star", "planet", "moon"
180           );
181
182       Default SVG tag
183
184       The Default SVG tag will generate the following XML:
185
186        $svg = new SVG;
187        $svg->xmlify;
188
189        resulting XML snippet:
190
191        <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
192        <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
193        <svg height="100%" width="100%" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
194               <defs  /><!--
195               Generated using the Perl SVG Module V2.44
196               by Ronan Oger
197               Info: http://www.roitsystems.com/
198         -->
199        </svg>
200

SEE ALSO

202       perl(1), SVG::XML, SVG::Element, SVG::DOM, SVG::Parser
203       <http://www.roitsystems.com/>ROIT Systems: Commercial SVG perl solu‐
204       tions <http://www.w3c.org/Graphics/SVG/>SVG at the W3C
205

AUTHOR

207       Ronan Oger, RO IT Systems GmbH, cpan@roitsystems.com
208

CREDITS

210       Peter Wainwright, Excellent ideas, beta-testing, writing SVG::Parser
211       and much of SVG::DOM.  Fredo, http://www.penguin.at0.net/~fredo/ - pro‐
212       vided example code and initial feedback for early SVG.pm versions and
213       the idea of a simplified svg generator.  Adam Schneider, Brial Pilpré,
214       Ian Hickson Martin Owens - SVG::DOM improvements in version 3.34
215

EXAMPLES

217       http://wiki.roitsystems.com/
218
219       See also the examples directory in this distribution which contain sev‐
220       eral fully documented examples.
221

METHODS

223       SVG provides both explicit and generic element constructor methods.
224       Explicit generators are generally (with a few exceptions) named for the
225       element they generate. If a tag method is required for a tag containing
226       hyphens, the method name replaces the hyphen with an underscore. ie: to
227       generate tag <column-heading id="new"> you would use method $svg->col‐
228       umn_heading(id=>'new').
229
230       All element constructors take a hash of element attributes and options;
231       element attributes such as 'id' or 'border' are passed by name, while
232       options for the method (such as the type of an element that supports
233       multiple alternate forms) are passed preceded by a hyphen, e.g '-type'.
234       Both types may be freely intermixed; see the "fe" method and code exam‐
235       ples througout the documentation for more examples.
236
237       new (constructor)
238
239       $svg = SVG->new(%attributes)
240
241       Creates a new SVG object. Attributes of the document SVG element be
242       passed as an optional list of key value pairs. Additionally, SVG
243       options (prefixed with a hyphen) may be set on a per object basis:
244
245       Example:
246
247           my $svg1=new SVG;
248
249           my $svg2=new SVG(id => 'document_element');
250
251           my $svg3=new SVG(s
252               -printerror => 1,
253               -raiseerror => 0,
254               -indent     => '  ',
255               -docroot => 'svg', #default document root element (SVG specification assumes svg). Defaults to 'svg' if undefined
256               -sysid      => 'abc', #optional system identifyer
257               -pubid      => "-//W3C//DTD SVG 1.0//EN", #public identifyer default value is "-//W3C//DTD SVG 1.0//EN" if undefined
258               -namespace => 'mysvg',
259               -inline   => 1
260               id          => 'document_element',
261               width       => 300,
262               height      => 200,
263           );
264
265       Default SVG options may also be set in the import list. See "EXPORTS"
266       above for more on the available options.
267
268       Furthermore, the following options:
269
270           -version
271           -encoding
272           -standalone
273           -namespace Defines the document or element level namespace. The order of assignment priority is element,document .
274           -inline
275           -identifier
276           -nostub
277           -dtd (standalone)
278
279       may also be set in xmlify, overriding any corresponding values set in
280       the SVG->new declaration
281
282       xmlify (alias: to_xml render serialise serialize)
283
284       $string = $svg->xmlify(%attributes);
285
286       Returns xml representation of svg document.
287
288       XML Declaration
289
290           Name               Default Value
291           -version           '1.0'
292           -encoding          'UTF-8'
293           -standalone        'yes'
294           -namespace         'svg'                - namespace for elements
295           -inline            '0' - If '1', then this is an inline document.
296           -pubid             '-//W3C//DTD SVG 1.0//EN';
297           -dtd (standalone)  'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'
298
299       tag (alias: element)
300
301       $tag = $svg->tag($name, %attributes)
302
303       Generic element generator. Creates the element named $name with the
304       attributes specified in %attributes. This method is the basis of most
305       of the explicit element generators.
306
307       Example:
308
309           my $tag = $svg->tag('g', transform=>'rotate(-45)');
310
311       anchor
312
313       $tag = $svg->anchor(%attributes)
314
315       Generate an anchor element. Anchors are put around objects to make them
316       'live' (i.e. clickable). It therefore requires a drawn object or group
317       element as a child.
318
319       Example:
320
321           # generate an anchor
322           $tag = $svg->anchor(
323               -href=>'http://here.com/some/simpler/svg.svg'
324           );
325           # add a circle to the anchor. The circle can be clicked on.
326           $tag->circle(cx=>10,cy=>10,r=>1);
327
328           # more complex anchor with both URL and target
329           $tag = $svg->anchor(
330                     -href   => 'http://somewhere.org/some/other/page.html',
331                     target => 'new_window'
332           );
333
334       circle
335
336       $tag = $svg->circle(%attributes)
337
338       Draw a circle at (cx,cy) with radius r.
339
340       Example:
341
342           my $tag = $svg->circle(cx=>4, cy=>2, r=>1);
343
344       ellipse
345
346       $tag = $svg->ellipse(%attributes)
347
348       Draw an ellipse at (cx,cy) with radii rx,ry.
349
350       Example:
351
352           my $tag = $svg->ellipse(
353               cx=>10, cy=>10,
354               rx=>5, ry=>7,
355               id=>'ellipse',
356               style=>{
357                   'stroke'=>'red',
358                   'fill'=>'green',
359                   'stroke-width'=>'4',
360                   'stroke-opacity'=>'0.5',
361                   'fill-opacity'=>'0.2'
362               }
363           );
364
365       rectangle (alias: rect)
366
367       $tag = $svg->rectangle(%attributes)
368
369       Draw a rectangle at (x,y) with width 'width' and height 'height' and
370       side radii 'rx' and 'ry'.
371
372       Example:
373
374           $tag = $svg->rectangle(
375               x=>10, y=>20,
376               width=>4, height=>5,
377               rx=>5.2, ry=>2.4,
378               id=>'rect_1'
379           );
380
381       image
382
383        $tag = $svg->image(%attributes)
384
385       Draw an image at (x,y) with width 'width' and height 'height' linked to
386       image resource '-href'. See also "use".
387
388       Example:
389
390           $tag = $svg->image(
391               x=>100, y=>100,
392               width=>300, height=>200,
393               '-href'=>"image.png", #may also embed SVG, e.g. "image.svg"
394               id=>'image_1'
395           );
396
397       Output:
398
399           <image xlink:href="image.png" x="100" y="100" width="300" height="200"/>
400
401       use
402
403       $tag = $svg->use(%attributes)
404
405       Retrieve the content from an entity within an SVG document and apply it
406       at (x,y) with width 'width' and height 'height' linked to image
407       resource '-href'.
408
409       Example:
410
411           $tag = $svg->use(
412               x=>100, y=>100,
413               width=>300, height=>200,
414               '-href'=>"pic.svg#image_1",
415               id=>'image_1'
416           );
417
418       Output:
419
420           <use xlink:href="pic.svg#image_1" x="100" y="100" width="300" height="200"/>
421
422       According to the SVG specification, the 'use' element in SVG can point
423       to a single element within an external SVG file.
424
425       polygon
426
427       $tag = $svg->polygon(%attributes)
428
429       Draw an n-sided polygon with vertices at points defined by a string of
430       the form 'x1,y1,x2,y2,x3,y3,... xy,yn'. The "get_path" method is pro‐
431       vided as a convenience to generate a suitable string from coordinate
432       data.
433
434       Example:
435
436           # a five-sided polygon
437           my $xv = [0,2,4,5,1];
438           my $yv = [0,0,2,7,5];
439
440           $points = $a->get_path(
441               x=>$xv, y=>$yv,
442               -type=>'polygon'
443           );
444
445           $c = $a->polygon(
446               %$points,
447               id=>'pgon1',
448               style=>\%polygon_style
449           );
450
451       SEE ALSO:
452
453       "polyline", "path", "get_path".
454
455       polyline
456
457       $tag = $svg->polyline(%attributes)
458
459       Draw an n-point polyline with points defined by a string of the form
460       'x1,y1,x2,y2,x3,y3,... xy,yn'. The "get_path" method is provided as a
461       convenience to generate a suitable string from coordinate data.
462
463       Example:
464
465           # a 10-pointsaw-tooth pattern
466           my $xv = [0,1,2,3,4,5,6,7,8,9];
467           my $yv = [0,1,0,1,0,1,0,1,0,1];
468
469           $points = $a->get_path(
470               x=>$xv, y=>$yv,
471               -type=>'polyline',
472               -closed=>'true' #specify that the polyline is closed.
473           );
474
475           my $tag = $a->polyline (
476               %$points,
477               id=>'pline_1',
478               style=>{
479                   'fill-opacity'=>0,
480                   'stroke-color'=>'rgb(250,123,23)'
481               }
482           );
483
484       line
485
486       $tag = $svg->line(%attributes)
487
488       Draw a straight line between two points (x1,y1) and (x2,y2).
489
490       Example:
491
492           my $tag = $svg->line(
493               id=>'l1',
494               x1=>0, y1=>10,
495               x2=>10, y2=>0
496           );
497
498       To draw multiple connected lines, use "polyline".
499
500       text
501
502       $text = $svg->text(%attributes)->cdata();
503
504       $text_path = $svg->text(-type=>'path'); $text_span =
505       $text_path->text(-type=>'span')->cdata('A'); $text_span =
506       $text_path->text(-type=>'span')->cdata('B'); $text_span =
507       $text_path->text(-type=>'span')->cdata('C');
508
509       define the container for a text string to be drawn in the image.
510
511       Input:
512           -type     = path type (path ⎪ polyline ⎪ polygon)
513           -type     = text element type  (path ⎪ span ⎪ normal [default])
514
515       Example:
516
517           my $text1 = $svg->text(
518               id=>'l1', x=>10, y=>10
519           )->cdata('hello, world');
520
521           my $text2 = $svg->text(
522               id=>'l1', x=>10, y=>10, -cdata=>'hello, world');
523
524           my $text = $svg->text(
525               id=>'tp', x=>10, y=>10 -type=>path)
526               ->text(id=>'ts' -type=>'span')
527               ->cdata('hello, world');
528
529       SEE ALSO:
530
531           L<"desc">, L<"cdata">.
532
533       title
534
535       $tag = $svg->title(%attributes)
536
537       Generate the title of the image.
538
539       Example:
540
541           my $tag = $svg->title(id=>'document-title')->cdata('This is the title');
542
543       desc
544
545       $tag = $svg->desc(%attributes)
546
547       Generate the description of the image.
548
549       Example:
550
551           my $tag = $svg->desc(id=>'document-desc')->cdata('This is a description');
552
553       comment
554
555       $tag = $svg->comment(@comments)
556
557       Generate the description of the image.
558
559       Example:
560
561           my $tag = $svg->comment('comment 1','comment 2','comment 3');
562
563       pi (Processing Instruction)
564
565       $tag = $svg->pi(@pi)
566
567       Generate a set of processing instructions
568
569       Example:
570
571           my $tag = $svg->pi('instruction one','instruction two','instruction three');
572
573           returns:
574             <lt>?instruction one?<gt>
575             <lt>?instruction two?<gt>
576             <lt>?instruction three?<gt>
577
578       script
579
580       $tag = $svg->script(%attributes)
581
582       Generate a script container for dynamic (client-side) scripting using
583       ECMAscript, Javascript or other compatible scripting language.
584
585       Example:
586
587           my $tag = $svg->script(-type=>"text/ecmascript");
588           #or my $tag = $svg->script();
589           #note that type ecmascript is not Mozilla compliant
590
591           # populate the script tag with cdata
592           # be careful to manage the javascript line ends.
593           # qq⎪text⎪ or qq§text§ where text is the script
594           # works well for this.
595           #make sure to use the CAPITAL CDATA to poulate the script.
596           $tag->CDATA(qq⎪function d(){
597               //simple display function
598               for(cnt = 0; cnt < d.length; cnt++)
599                   document.write(d[cnt]);//end for loop
600               document.write("<BR>");//write a line break
601             }⎪
602           );
603
604       path
605
606       $tag = $svg->path(%attributes)
607
608       Draw a path element. The path vertices may be imputed as a parameter or
609       calculated usingthe "get_path" method.
610
611       Example:
612
613           # a 10-pointsaw-tooth pattern drawn with a path definition
614           my $xv = [0,1,2,3,4,5,6,7,8,9];
615           my $yv = [0,1,0,1,0,1,0,1,0,1];
616
617           $points = $a->get_path(
618               x => $xv,
619               y => $yv,
620               -type   => 'path',
621               -closed => 'true'  #specify that the polyline is closed
622           );
623
624           $tag = $svg->path(
625               %$points,
626               id    => 'pline_1',
627               style => {
628                   'fill-opacity' => 0,
629                   'fill-color'   => 'green',
630                   'stroke-color' => 'rgb(250,123,23)'
631               }
632           );
633
634       SEE ALSO:
635
636       "get_path".
637
638       get_path
639
640       $path = $svg->get_path(%attributes)
641
642       Returns the text string of points correctly formatted to be incorpo‐
643       rated into the multi-point SVG drawing object definitions (path, poly‐
644       line, polygon)
645
646       Input: attributes including:
647
648           -type     = path type (path ⎪ polyline ⎪ polygon)
649           x         = reference to array of x coordinates
650           y         = reference to array of y coordinates
651
652       Output: a hash reference consisting of the following key-value pair:
653
654           points    = the appropriate points-definition string
655           -type     = path⎪polygon⎪polyline
656           -relative = 1 (define relative position rather than absolute position)
657           -closed   = 1 (close the curve - path and polygon only)
658
659       Example:
660
661           #generate an open path definition for a path.
662           my ($points,$p);
663           $points = $svg->get_path(x=&gt\@x,y=&gt\@y,-relative=&gt1,-type=&gt'path');
664
665           #add the path to the SVG document
666           my $p = $svg->path(%$path, style=>\%style_definition);
667
668           #generate an closed path definition for a a polyline.
669           $points = $svg->get_path(
670               x=>\@x,
671               y=>\@y,
672               -relative=>1,
673               -type=>'polyline',
674               -closed=>1
675           ); # generate a closed path definition for a polyline
676
677           # add the polyline to the SVG document
678           $p = $svg->polyline(%$points, id=>'pline1');
679
680       Aliases: get_path set_path
681
682       animate
683
684       $tag = $svg->animate(%attributes)
685
686       Generate an SMIL animation tag. This is allowed within any nonempty
687       tag. Refer\ to the W3C for detailed information on the subtleties of
688       the animate SMIL commands.
689
690       Inputs: -method = Transform ⎪ Motion ⎪ Color
691
692         my $an_ellipse = $svg->ellipse(
693             cx=>30,cy=>150,rx=>10,ry=>10,id=>'an_ellipse',
694             stroke=>'rgb(130,220,70)',fill=>'rgb(30,20,50)');
695
696         $an_ellipse-> animate(
697             attributeName=>"cx",values=>"20; 200; 20",dur=>"10s", repeatDur=>'indefinite');
698
699         $an_ellipse-> animate(
700             attributeName=>"rx",values=>"10;30;20;100;50",
701             dur=>"10s", repeatDur=>'indefinite');
702
703         $an_ellipse-> animate(
704             attributeName=>"ry",values=>"30;50;10;20;70;150",
705             dur=>"15s", repeatDur=>'indefinite');
706
707         $an_ellipse-> animate(
708             attributeName=>"rx",values=>"30;75;10;100;20;20;150",
709             dur=>"20s", repeatDur=>'indefinite');
710
711         $an_ellipse-> animate(
712             attributeName=>"fill",values=>"red;green;blue;cyan;yellow",
713             dur=>"5s", repeatDur=>'indefinite');
714
715         $an_ellipse-> animate(
716             attributeName=>"fill-opacity",values=>"0;1;0.5;0.75;1",
717             dur=>"20s",repeatDur=>'indefinite');
718
719         $an_ellipse-> animate(
720             attributeName=>"stroke-width",values=>"1;3;2;10;5",
721             dur=>"20s",repeatDur=>'indefinite');
722
723       group
724
725       $tag = $svg->group(%attributes)
726
727       Define a group of objects with common properties. groups can have
728       style, animation, filters, transformations, and mouse actions assigned
729       to them.
730
731       Example:
732
733           $tag = $svg->group(
734               id        => 'xvs000248',
735               style     => {
736                   'font'      => [ qw( Arial Helvetica sans ) ],
737                   'font-size' => 10,
738                   'fill'      => 'red',
739               },
740               transform => 'rotate(-45)'
741           );
742
743       defs
744
745       $tag = $svg->defs(%attributes)
746
747       define a definition segment. A Defs requires children when defined
748       using SVG.pm Example:
749
750           $tag = $svg->defs(id  =>  'def_con_one',);
751
752       style
753
754       $svg->tag('style', %styledef);
755
756       Sets/Adds style-definition for the following objects being created.
757
758       Style definitions apply to an object and all its children for all prop‐
759       erties for which the value of the property is not redefined by the
760       child.
761
762       mouseaction
763
764       $svg->mouseaction(%attributes)
765
766       Sets/Adds mouse action definitions for tag
767
768       $svg->attrib($name, $value)
769
770       Sets/Adds mouse action definitions.
771
772       $svg->attrib $name, $value
773
774       $svg->attrib $name, \@value
775
776       $svg->attrib $name, \%value
777
778       Sets/Replaces attributes for a tag.
779
780       cdata
781
782       $svg->cdata($text)
783
784       Sets cdata to $text. SVG.pm allows you to set cdata for any tag. If the
785       tag is meant to be an empty tag, SVG.pm will not complain, but the ren‐
786       dering agent will fail. In the SVG DTD, cdata is generally only meant
787       for adding text or script content.
788
789       Example:
790
791           $svg->text(
792               style => {
793                   'font'      => 'Arial',
794                   'font-size' => 20
795               })->cdata('SVG.pm is a perl module on CPAN!');
796
797           my $text = $svg->text(style=>{'font'=>'Arial','font-size'=>20});
798           $text->cdata('SVG.pm is a perl module on CPAN!');
799
800       Result:
801
802           E<lt>text style="font: Arial; font-size: 20" E<gt>SVG.pm is a perl module on CPAN!E<lt>/text E<gt>
803
804       SEE ALSO:
805
806         L<"CDATA"> L<"desc">, L<"title">, L<"text">, L<"script">.
807
808       cdata_noxmlesc
809
810        $script = $svg->script();
811        $script->cdata_noxmlesc($text);
812
813       Generates cdata content for text and similar tags which do not get
814       xml-escaped.  In othe words, does not parse the content and inserts the
815       exact string into the cdata location.
816
817       CDATA
818
819        $script = $svg->script();
820        $script->CDATA($text);
821
822       Generates a <![CDATA[ ... ]]> tag with the contents of $text rendered
823       exactly as supplied. SVG.pm allows you to set cdata for any tag. If the
824       tag is meant to be an empty tag, SVG.pm will not complain, but the ren‐
825       dering agent will fail. In the SVG DTD, cdata is generally only meant
826       for adding text or script content.
827
828       Example:
829
830             my $text = qq§
831               var SVGDoc;
832               var groups = new Array();
833               var last_group;
834
835               /*****
836               *
837               *   init
838               *
839               *   Find this SVG's document element
840               *   Define members of each group by id
841               *
842               *****/
843               function init(e) {
844                   SVGDoc = e.getTarget().getOwnerDocument();
845                   append_group(1, 4, 6); // group 0
846                   append_group(5, 4, 3); // group 1
847                   append_group(2, 3);    // group 2
848               }§;
849               $svg->script()->CDATA($text);
850
851       Result:
852
853           E<lt>script E<gt>
854             <gt>![CDATA[
855               var SVGDoc;
856               var groups = new Array();
857               var last_group;
858
859               /*****
860               *
861               *   init
862               *
863               *   Find this SVG's document element
864               *   Define members of each group by id
865               *
866               *****/
867               function init(e) {
868                   SVGDoc = e.getTarget().getOwnerDocument();
869                   append_group(1, 4, 6); // group 0
870                   append_group(5, 4, 3); // group 1
871                   append_group(2, 3);    // group 2
872               }
873               ]]E<gt>
874
875       SEE ALSO:
876
877         L<"cdata">, L<"script">.
878
879       xmlescp and xmlescape
880
881       $string = SVG::xmlescp($string) $string = SVG::xmlesc($string) $string
882       = SVG::xmlescape($string)
883
884       SVG module does not xml-escape characters that are incompatible with
885       the XML specification. xmlescp and xmlescape provides this functional‐
886       ity. It is a helper function which Generates an XML-escaped string for
887       reserved characters such as ampersand, open and close brackets,
888       etcetera.
889
890       The behaviour of xmlesc is to apply the following transformation to the
891       input string $s:
892
893           $s = '0' unless defined $s;
894           $s=join(', ',@{$s}) if(ref($s) eq 'ARRAY');
895               $s=~s/&(?!#(x\w\w⎪\d+?);)/&amp;/g;
896           $s=~s/>/&gt;/g;
897           $s=~s/</&lt;/g;
898           $s=~s/\"/&quot;/g;
899           $s=~s/\'/&apos;/g;
900           $s=~s/\`/&apos;/g;
901           $s=~s/([\x00-\x1f])/sprintf('&#x%02X;',chr($1))/eg;
902               #per suggestion from Adam Schneider
903               $s=~s/([\200-\377])/'&#'.ord($1).';'/ge;
904
905       filter
906
907       $tag = $svg->filter(%attributes)
908
909       Generate a filter. Filter elements contain "fe" filter sub-elements.
910
911       Example:
912
913           my $filter = $svg->filter(
914               filterUnits=>"objectBoundingBox",
915               x=>"-10%",
916               y=>"-10%",
917               width=>"150%",
918               height=>"150%",
919               filterUnits=>'objectBoundingBox'
920           );
921
922           $filter->fe();
923
924       SEE ALSO:
925
926       "fe".
927
928       fe
929
930       $tag = $svg->fe(-type=>'type', %attributes)
931
932       Generate a filter sub-element. Must be a child of a "filter" element.
933
934       Example:
935
936           my $fe = $svg->fe(
937               -type     => 'DiffuseLighting'  # required - element name omiting 'fe'
938               id        => 'filter_1',
939               style     => {
940                   'font'      => [ qw(Arial Helvetica sans) ],
941                   'font-size' => 10,
942                   'fill'      => 'red',
943               },
944               transform => 'rotate(-45)'
945           );
946
947       Note that the following filter elements are currently supported:
948
949       * feBlend
950
951       * feColorMatrix
952
953       * feComponentTransfer
954
955       * feComposite
956
957       * feConvolveMatrix
958
959       * feDiffuseLighting
960
961       * feDisplacementMap
962
963       * feDistantLight
964
965       * feFlood
966
967       * feFuncA
968
969       * feFuncB
970
971       * feFuncG
972
973       * feFuncR
974
975       * feGaussianBlur
976
977       * feImage
978
979       * feMerge
980
981       * feMergeNode
982
983       * feMorphology
984
985       * feOffset
986
987       * fePointLight
988
989       * feSpecularLighting
990
991       * feSpotLight
992
993       * feTile
994
995       * feTurbulence
996
997       SEE ALSO:
998
999       "filter".
1000
1001       pattern
1002
1003       $tag = $svg->pattern(%attributes)
1004
1005       Define a pattern for later reference by url.
1006
1007       Example:
1008
1009           my $pattern = $svg->pattern(
1010               id     => "Argyle_1",
1011               width  => "50",
1012               height => "50",
1013               patternUnits        => "userSpaceOnUse",
1014               patternContentUnits => "userSpaceOnUse"
1015           );
1016
1017       set
1018
1019       $tag = $svg->set(%attributes)
1020
1021       Set a definition for an SVG object in one section, to be referenced in
1022       other sections as needed.
1023
1024       Example:
1025
1026           my $set = $svg->set(
1027               id     => "Argyle_1",
1028               width  => "50",
1029               height => "50",
1030               patternUnits        => "userSpaceOnUse",
1031               patternContentUnits => "userSpaceOnUse"
1032           );
1033
1034       stop
1035
1036       $tag = $svg->stop(%attributes)
1037
1038       Define a stop boundary for "gradient"
1039
1040       Example:
1041
1042          my $pattern = $svg->stop(
1043              id     => "Argyle_1",
1044              width  => "50",
1045              height => "50",
1046              patternUnits        => "userSpaceOnUse",
1047              patternContentUnits => "userSpaceOnUse"
1048          );
1049
1050       $tag = $svg->gradient(%attributes)
1051
1052       Define a color gradient. Can be of type linear or radial
1053
1054       Example:
1055
1056           my $gradient = $svg->gradient(
1057               -type => "linear",
1058               id    => "gradient_1"
1059           );
1060

GENERIC ELEMENT METHODS

1062       The following elements are generically supported by SVG:
1063
1064       * altGlyph
1065
1066       * altGlyphDef
1067
1068       * altGlyphItem
1069
1070       * clipPath
1071
1072       * color-profile
1073
1074       * cursor
1075
1076       * definition-src
1077
1078       * font-face-format
1079
1080       * font-face-name
1081
1082       * font-face-src
1083
1084       * font-face-url
1085
1086       * foreignObject
1087
1088       * glyph
1089
1090       * glyphRef
1091
1092       * hkern
1093
1094       * marker
1095
1096       * mask
1097
1098       * metadata
1099
1100       * missing-glyph
1101
1102       * mpath
1103
1104       * switch
1105
1106       * symbol
1107
1108       * tref
1109
1110       * view
1111
1112       * vkern
1113
1114       See e.g. "pattern" for an example of the use of these methods.
1115

METHODS IMPORTED BY SVG::DOM

1117       The following SVG::DOM elements are accessible through SVG:
1118
1119       * getChildren
1120
1121       * getFirstChild
1122
1123       * getNextChild
1124
1125       * getLastChild
1126
1127       * getParent
1128
1129       * getParentElement
1130
1131       * getSiblings
1132
1133       * getElementByID
1134
1135       * getElementID
1136
1137       * getElements
1138
1139       * getElementName
1140
1141       * getType
1142
1143       * getAttributes
1144
1145       * getAttribute
1146
1147       * setAttributes
1148
1149       * setAttribute
1150
1151       * insertBefore
1152
1153       * insertAfter
1154
1155       * insertSiblingBefore
1156
1157       * insertSiblingAfter
1158
1159       * replaceChild
1160
1161       * removeChild
1162
1163       * cloneNode
1164

LICENSE

1166       SVG.pl is distributed under the same license as Perl itself. It is pro‐
1167       vided free of warranty and may be re-used freely.
1168

SEE ALSO

1170       perl(1), SVG, SVG::DOM, SVG::XML, SVG::Element, SVG::Parser, SVG::Man‐
1171       ual, SVG::Extension Serverside SVG Portal - Perl focused SVG site with
1172       discussion board and examples: <http://www.roitsystems.com/>
1173       <http://www.perlsvg.com/> SVG at the W3C: <http://www.w3c.org/Graph
1174       ics/SVG/> For Commercial Perl/SVG development, refer to the following
1175       sites: RO IT Systems: <http://www.roitsystems.com/>
1176
1177
1178
1179perl v5.8.8                       2008-04-21                    SVG::Manual(3)
Impressum