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