| 1 | package SVG::DOM2; | ||
| 2 | |||
| 3 | =pod | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | SVG::DOM2 - SVG extention to the popular XML::DOM2 | ||
| 8 | |||
| 9 | =head2 VERSION | ||
| 10 | |||
| 11 | Version 1.00, 08 May, 2006 | ||
| 12 | |||
| 13 | =head1 DESCRIPTION | ||
| 14 | |||
| 15 | An SVG Extention of XML::DOM2, this should provide for all features of the svg specification upto 1.1. | ||
| 16 | |||
| 17 | =head1 METHODS | ||
| 18 | |||
| 19 | =cut | ||
| 20 | |||
| 21 | 2 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 22 | 2 | ▶ | use vars qw($VERSION); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 23 | |||
| 24 | 2 | ▶ | use base "XML::DOM2"; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 25 | use Carp; | ||
| 26 | |||
| 27 | # Basic Element Types | ||
| 28 | use SVG::DOM2::Element::Rect; | ||
| 29 | use SVG::DOM2::Element::Text; | ||
| 30 | use SVG::DOM2::Element::Path; | ||
| 31 | use SVG::DOM2::Element::Group; | ||
| 32 | use SVG::DOM2::Element::Line; | ||
| 33 | use SVG::DOM2::Element::Document; | ||
| 34 | use SVG::DOM2::Element::MetaData; | ||
| 35 | |||
| 36 | $VERSION = "1.00"; | ||
| 37 | |||
| 38 | =head2 new | ||
| 39 | |||
| 40 | $svg = SVG::DOM2->new( | ||
| 41 | -file = [svgfilename], | ||
| 42 | -data = [svgdata], | ||
| 43 | %options | ||
| 44 | ); | ||
| 45 | |||
| 46 | Create a new svg object, it will parse a file or data if required or will await creation of nodes. | ||
| 47 | |||
| 48 | =cut | ||
| 49 | sub new | ||
| 50 | { | ||
| 51 | my ($proto, %options) = @_; | ||
| 52 | return $proto->SUPER::new(%options); | ||
| 53 | } | ||
| 54 | |||
| 55 | =head2 _element_handle | ||
| 56 | |||
| 57 | This is the XML::DOM2 handel for all the elements that | ||
| 58 | svg documents can handle. | ||
| 59 | |||
| 60 | =cut | ||
| 61 | sub _element_handle | ||
| 62 | { | ||
| 63 | my ($self, $type, %opts) = @_; | ||
| 64 | return SVG::DOM2::Element::Rect->new(%opts) if $type eq 'rect'; | ||
| 65 | return SVG::DOM2::Element::Text->new(%opts) if $type eq 'text' or $type eq 'tspan'; | ||
| 66 | return SVG::DOM2::Element::Path->new(%opts) if $type eq 'path'; | ||
| 67 | return SVG::DOM2::Element::Group->new(%opts) if $type eq 'g'; | ||
| 68 | return SVG::DOM2::Element::Line->new(%opts) if $type eq 'line'; | ||
| 69 | return SVG::DOM2::Element::MetaData->new(%opts) if $type eq 'metadata'; | ||
| 70 | if($type eq '#document' or $type eq 'svg') { | ||
| 71 | $opts{'documentTag'} = $type if $type ne '#document'; | ||
| 72 | return SVG::DOM2::Element::Document->new(%opts); | ||
| 73 | } | ||
| 74 | return $self->SUPER::_element_handle($type, %opts); | ||
| 75 | } | ||
| 76 | |||
| 77 | sub _document_name { 'svg' } | ||
| 78 | sub default_unit { 'px' } | ||
| 79 | |||
| 80 | sub dpi | ||
| 81 | { | ||
| 82 | my ($self) = @_; | ||
| 83 | return $self->{'dpi'} || '90'; | ||
| 84 | } | ||
| 85 | |||
| 86 | sub out_dpi | ||
| 87 | { | ||
| 88 | my ($self) = @_; | ||
| 89 | return $self->{'out_dpi'} || $self->dpi; | ||
| 90 | } | ||
| 91 | |||
| 92 | sub SVGMetadataElement | ||
| 93 | { | ||
| 94 | my ($self) = @_; | ||
| 95 | return $self->documentElement->getChildrenByName('metadata'); | ||
| 96 | } | ||
| 97 | |||
| 98 | =head1 AUTHOR | ||
| 99 | |||
| 100 | Martin Owens, doctormo@cpan.org | ||
| 101 | |||
| 102 | =head1 SEE ALSO | ||
| 103 | |||
| 104 | perl(1),L<XML::DOM2>,L<XML::DOM2::Parser> | ||
| 105 | L<http://www.w3c.org/Graphics/SVG/> SVG at the W3C | ||
| 106 | |||
| 107 | =cut | ||
| 108 | |||
| 109 | return 1; | ||