diff svgExample.pl @ 39:8b3b5753ad41 laserkard

[svn r40] created succesuful interface to corel Draw :)
author rlm
date Sun, 24 Jan 2010 15:06:22 -0500
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/svgExample.pl	Sun Jan 24 15:06:22 2010 -0500
     1.3 @@ -0,0 +1,59 @@
     1.4 +    #!/usr/bin/perl -w
     1.5 +    use strict;
     1.6 +    use SVG;
     1.7 +
     1.8 +    # create an SVG object
     1.9 +    my $svg= SVG->new(width=>200,height=>200);
    1.10 +    #or
    1.11 +    my $svg= SVG->new(width=>200,height=>200);
    1.12 +
    1.13 +    # use explicit element constructor to generate a group element
    1.14 +    my $y=$svg->group(
    1.15 +        id    => 'group_y',
    1.16 +        style => { stroke=>'red', fill=>'green' }
    1.17 +    );
    1.18 +
    1.19 +    # add a circle to the group
    1.20 +    $y->circle(cx=>100, cy=>100, r=>50, id=>'circle_in_group_y');
    1.21 +
    1.22 +    # or, use the generic 'tag' method to generate a group element by name
    1.23 +    my $z=$svg->tag('g',
    1.24 +                    id    => 'group_z',
    1.25 +                    style => {
    1.26 +                        stroke => 'rgb(100,200,50)',
    1.27 +                        fill   => 'rgb(10,100,150)'
    1.28 +                    }
    1.29 +                );
    1.30 +
    1.31 +    # create and add a circle using the generic 'tag' method
    1.32 +    $z->tag('circle', cx=>50, cy=>50, r=>100, id=>'circle_in_group_z');
    1.33 +
    1.34 +    # create an anchor on a rectangle within a group within the group z
    1.35 +    my $k = $z->anchor(
    1.36 +        id      => 'anchor_k',
    1.37 +        -href   => 'http://test.hackmare.com/',
    1.38 +        target => 'new_window_0'
    1.39 +    )->rectangle(
    1.40 +        x     => 20, y      => 50,
    1.41 +        width => 20, height => 30,
    1.42 +        rx    => 10, ry     => 5,
    1.43 +        id    => 'rect_k_in_anchor_k_in_group_z'
    1.44 +    );
    1.45 +
    1.46 +    # now render the SVG object, implicitly use svg namespace
    1.47 +    print $svg->xmlify;
    1.48 +
    1.49 +    # or render a child node of the SVG object without rendering the entire object
    1.50 +    print $k->xmlify; #renders the anchor $k above containing a rectangle, but does not
    1.51 +                      #render any of the ancestor nodes of $k
    1.52 +
    1.53 +
    1.54 +    # or, explicitly use svg namespace and generate a document with its own DTD
    1.55 +    print $svg->xmlify(-namespace=>'svg');
    1.56 +
    1.57 +    # or, explicitly use svg namespace and generate an in-line docunent
    1.58 +    print $svg->xmlify(
    1.59 +        -namespace => "svg",
    1.60 +        -pubid => "-//W3C//DTD SVG 1.0//EN",
    1.61 +        -inline   => 1
    1.62 +    );
    1.63 \ No newline at end of file