NAME

SVG - perl extention for generating SVG (scalable-vector-graphics)

SYNOPSIS

  use SVG;
  use strict;

  my $svg= SVG->new(width=>200,height=>200); 

  my $y=$svg->group( id     =>  'group_y',
                     style  =>  {stroke=>'red', fill=>'green'} );

  my $z=$svg->tag('g',  id=>'group_z',
                        style=>{ stroke=>'rgb(100,200,50)', 
                                 fill=>'rgb(10,100,150)'} );

 
  $y->circle(cx=>100,
             cy=>100,
             r=>50, 
             id=>'circle_y',);

  $z->tag('circle',cx=>50,
             cy=>50,
             r=>100, 
             id=>'circle_z',);
  
  # an anchor with a rectangle within group within group z

  $z -> anchor(
		     -href   => 'http://somewhere.org/some/line.html',
		     -target => 'new_window_0') -> 
                      $y->rectangle ( x=>20,
                                      y=>50,
                                      width=>20,
                                      height=>30,
                                      rx=>10,
                                      ry=>5,
                                      id=>'rect_z',);

 
  print $svg->xmlify;

DESCRIPTION

SVG is a 100% perl module which generates a nested data structure which contains the DOM representation of an SVG image. Using SV, You can generate SVG objects, embed other SVG instances within it, access the DOM object, create and access javascript, and generate SMIL animation content.

EXPORT

None

AUTHOR

Ronan Oger, ronan@roasp.com

SEE ALSO

perl(1). SVG::Utils. http://roasp.com/

SVG

$svg = SVG->new %properties

Creates a new svg object.

$xmlstring = $svg->xmlify

Returns xml representation of svg document.

$tag = $svg->tag $name, %properties

Creates element $name with %properties.

Example:

$tag = $svg->tag('g', transform=>'rotate(-45)');
$tag = $svg->anchor %properties

create a url anchor tag. requires a child drawn object or group element.

Example: # a complete anchor with a child tag $tag = $svg->anchor( -href=>'http://here.com/some/simpler/svg.svg' ); $tag->circle(cx=>10,cy=>10,r=>1);

# alternate tag definitions
$tag = $svg->anchor(
	-href   => 'http://somewhere.org/some/other/page.html',
	-target => 'new_window'
);

$tag = $svg->anchor(
	-href   => 'http://someotherwhere.net',
	-target => '_top'
);
$tag = $svg->circle %properties

draw a circle at cx,xy with radius r

Example:

	$tag = $svg->circle(	cx=>4
                      		cy=>2
                      		r=>1,);
$tag = $svg->ellipse %properties

draw an ellipse at cx,cy with radii rx,ry

Example:

	$tag = $svg->ellipse(cx=>10
                      cy=>10
                      rx=>5
                      ry=>7
                      id=>'ellipse',
                      style=>{'stroke'=>'red',
                              'fill'=>'green'
                              'stroke-width'=>'4'
                              'stroke-opacity'=>'0.5',
                              'fill-opacity'=>'0.2'});
$tag = $svg->rectangle %properties

draw a rectangle at (x,y) with width 'width' and height 'height' and side radii 'rx' and 'ry'

Example:

	$tag = $svg->rectangle(	x=>10,
                         	y=>20,
                         	width=>4,
                         	height=>5,
                         	rx=>5.2,
                         	ry=>2.4,
                         	id=>'rect_1',);
$tag = $svg->polygon %properties

draw an n-sided polygon with vertices at points defined by string 'x1 y1,x2 y2,x3 y3,...xy yn'. use method get_path to generate the string.

Example:

# a five-sided polygon

my $xv = [0,2,4,5,1];

my $yv = [0,0,2,7,5];

$points = $a->get_path(x=>$xv,
                        y=>$yv,
                      -type=>'polygon',);

$c = $a->polygon (%$points,
                  id=>'pgon1',
                  style=>\%polygon_style);
$tag = $svg->polyline %properties

draw an n-point polyline with points defined by string 'x1 y1,x2 y2,...xn yn'. use method get_path to generate the vertices from two array references.

Example:

# a 10-pointsaw-tooth pattern

my $xv = [0,1,2,3,4,5,6,7,8,9];

my $yv = [0,1,0,1,0,1,0,1,0,1];

$points = $a->get_path(x=>$xv,
                        y=>$yv,
                      -type=>'polyline',
                      -closed=>'true'); #specify that the polyline is closed.

$c = $a->polyline (%$points,
                  id=>'pline_1',
                  style=>{'fill-opacity'=>0,
                          'stroke-color'=>'rgb(250,123,23)'}
                  );

SEE ALSO:

get_path.

$tag = $svg->line %properties

draw a straight line between two points (x1,y1),(x2,y2).

Example:

my $tag = $svg->line( id=>'l1',x1=>0
                      y1=>0,
                      x2=>10,
                      y2=>10,);
$text = $svg->text %properties

define the container for a text string to be drawn in the image.

Example:

my $text = $svg->text( id=>'l1',x=>10
                      y=>10,) -> cdata('hello, world');
$desc = $svg->desc %properties

generate the description of the image.

Example:

my $desc = $svg->desc( id=>'root-desc')->cdata('hello this is a description');
$script = $svg->script %properties

Example:

my $text = $svg->script(type=>"text/ecmascript");
$tag = $svg->path %properties

Example:

# a 10-pointsaw-tooth pattern

my $xv = [0,1,2,3,4,5,6,7,8,9];

my $yv = [0,1,0,1,0,1,0,1,0,1];

$points = $a->get_path(x=>$xv,
                        y=>$yv,
                      -type=>'path',
                      -closed=>'true'); #specify that the polyline is closed.

$tag = $svg->path (%$points,
                  id=>'pline_1',
                  style=>{'fill-opacity'=>0,
                          'fill-color'=>'green',
                          'stroke-color'=>'rgb(250,123,23)'}
                  );

SEE ALSO:

get_path.

$path = $svg->get_path %properties

A method which returns the text string of points correctly formatted to be incorporated into the multi-point SVG drawing object definitions (path, polyline, polygon)

input:

output: a hash reference consisting of the following key-value pair: points = the appropriate points-definition string type = path|polygon|polyline -relative = 1 (points define relative position rather than absolute position) -closed = 1 (close the curve - path and polygon only)

Example:

#generate an open path definition for a path.
my ($points,$p);
$points = $svg->get_path(x=>\@x,y=>\@y,-relative=>1,type=>'path');

#add the path to the SVG document 
my $p = $svg->path( %$path,
                 style=>\%style_definition); 

#generate an closed path definition for a a polyline.
$points = $svg->get_path( x=>\@x,
                       y=>\@y,
                       -relative=>1,
                       -type=>'polyline',
                       -closed=>1); # generate a closed path definition for a polyline

# add the polyline to the SVG document
$p = $svg->polyline (%$points,
                   id=>'pline1',);
animate(\%params)

Generate an SMIL animation tag. This is allowed within any of the nonempty tags. Refer to the W3C for detailed information on the subtleties of the animate SMIL commands.

inputs: -method = Transform | Motion | Color

$tag = $svg->group %properties

define a roup of objects with common properties. groups can have style, animation, filters, transformations, and mouse actions assigned to them.

Example:

$tag = $svg->group(
	id        => 'xvs000248',
	style     => {
		'font'      => [ qw( Arial Helvetica sans ) ],
		'font-size' => 10,
		'fill'      => 'red',
	},
	transform => 'rotate(-45)'
);
$svg->style %styledef

Sets/Adds style-definition.

$svg->mouseaction %styledef

Sets/Adds mouse action definitions for tag

$svg->mouseaction %styledef

Sets/Adds mouse action definitions.

$svg->attrib $name, $val
$svg->attrib $name, \@val
$svg->attrib $name, \%val

Sets attribute to val.

$svg->cdata $text

Sets cdata to $text.

Example:

	$svg->text(style=>{'font'=>'Arial','font-size'=>20})->cdata('SVG.pm is a perl module on CPAN!');

  my $text = $svg->text(style=>{'font'=>'Arial','font-size'=>20});
  $text->cdata('SVG.pm is a perl module on CPAN!');

Result:

E<lt>text style="font: Arial; font-size: 20" E<gt>SVG.pm is a perl module on CPAN!E<lt>/text E<gt>
$tag = $svg->fe %properties

Example:

	$tag = $svg->fe(
    -TYPE => 
		id        => 'xvs000248',
		style     => {
			'font'      => [ qw( Arial Helvetica sans ) ],
			'font-size' => 10,
			'fill'      => 'red',
		},
		transform => 'rotate(-45)'
	);

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 78:

'=item' outside of any '=over'

=over without closing =back

Around line 158:

=cut found outside a pod block. Skipping to next block.