| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# -*- perl -*- |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# Author: Slaven Rezic |
|
5
|
|
|
|
|
|
|
# |
|
6
|
|
|
|
|
|
|
# Copyright (C) 2009,2011,2016,2017 Slaven Rezic. All rights reserved. |
|
7
|
|
|
|
|
|
|
# This package is free software; you can redistribute it and/or |
|
8
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
|
9
|
|
|
|
|
|
|
# |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
package Image::Info::SVG; |
|
12
|
|
|
|
|
|
|
|
|
13
|
3
|
|
|
3
|
|
2898
|
use strict; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
409
|
|
|
14
|
|
|
|
|
|
|
our (@PREFER_MODULE, $USING_MODULE); |
|
15
|
|
|
|
|
|
|
our $VERSION = '2.05'; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
@PREFER_MODULE = qw(Image::Info::SVG::XMLLibXMLReader |
|
18
|
|
|
|
|
|
|
Image::Info::SVG::XMLSimple |
|
19
|
|
|
|
|
|
|
) |
|
20
|
|
|
|
|
|
|
if !@PREFER_MODULE; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
TRY_MODULE: { |
|
23
|
|
|
|
|
|
|
for my $try_module (@PREFER_MODULE) { |
|
24
|
|
|
|
|
|
|
if (eval qq{ require $try_module; 1 }) { |
|
25
|
|
|
|
|
|
|
my $sub = $try_module . '::process_file'; |
|
26
|
3
|
|
|
3
|
|
19
|
no strict 'refs'; |
|
|
3
|
|
|
|
|
8
|
|
|
|
3
|
|
|
|
|
465
|
|
|
27
|
|
|
|
|
|
|
*process_file = \&{$sub}; |
|
28
|
|
|
|
|
|
|
$USING_MODULE = $try_module; |
|
29
|
|
|
|
|
|
|
last TRY_MODULE; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
die "Cannot require any of @PREFER_MODULE...\n"; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
1; |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
__END__ |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=pod |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 NAME |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Image::Info::SVG - SVG support for Image::Info |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
use Image::Info qw(image_info dim); |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
my $info = image_info("image.svg"); |
|
50
|
|
|
|
|
|
|
if (my $error = $info->{error}) { |
|
51
|
|
|
|
|
|
|
die "Can't parse image info: $error\n"; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
my $title = $info->{SVG_Title}; |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
my($w, $h) = dim($info); |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
This modules supplies the standard key names except for |
|
60
|
|
|
|
|
|
|
BitsPerSample, Compression, Gamma, Interlace, LastModificationTime, as well as: |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=over |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=item ImageDescription |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
The image description, corresponds to <desc>. |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=item SVG_Image |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
A scalar or reference to an array of scalars containing the URI's of |
|
71
|
|
|
|
|
|
|
embedded images (JPG or PNG) that are embedded in the image. |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=item SVG_StandAlone |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Whether or not the image is standalone. |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item SVG_Title |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
The image title, corresponds to <title> |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item SVG_Version |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
The URI of the DTD the image conforms to. |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=back |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 METHODS |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 process_file() |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$info->process_file($source, $options); |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Processes one file and sets the found info fields in the C<$info> object. |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 FILES |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
This module requires either L<XML::LibXML::Reader> or L<XML::Simple>. |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 COMPATIBILITY |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Previous versions (until Image-Info-1.28) used L<XML::Simple> as the |
|
102
|
|
|
|
|
|
|
underlying parser. Since Image-Info-1.29 the default parser is |
|
103
|
|
|
|
|
|
|
L<XML::LibXML::Reader> which is much more faster, memory-efficient, |
|
104
|
|
|
|
|
|
|
and does not rely on regular expressions for some aspects of XML |
|
105
|
|
|
|
|
|
|
parsing. If for some reason you need the old parser, you can force it |
|
106
|
|
|
|
|
|
|
by setting the variable C<@Image::Info::SVG::PREFER_MODULE> as early |
|
107
|
|
|
|
|
|
|
as possible: |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
use Image::Info; |
|
110
|
|
|
|
|
|
|
@Image::Info::SVG::PREFER_MODULE = qw(Image::Info::SVG::XMLSimple Image::Info::SVG::XMLLibXMLReader); |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
The variable C<$Image::Info::SVG::USING_MODULE> can be queried to see |
|
113
|
|
|
|
|
|
|
which parser is in use (after B<Image::Info::SVG> is required). |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Since 1.38_50 processing of XML external entities (XXE) is not done |
|
116
|
|
|
|
|
|
|
anymore for security reasons in both backends |
|
117
|
|
|
|
|
|
|
(B<Image::Info::SVG::XMLLibXMLReader> and |
|
118
|
|
|
|
|
|
|
B<Image::Info::SVG::XMLSimple>). Controlling XXE processing behavior |
|
119
|
|
|
|
|
|
|
in B<XML::Simple> is not really possible (see |
|
120
|
|
|
|
|
|
|
L<https://rt.cpan.org/Ticket/Display.html?id=83794>), so as a |
|
121
|
|
|
|
|
|
|
workaround the underlying SAX parser is fixed to L<XML::SAX::PurePerl> |
|
122
|
|
|
|
|
|
|
which is uncapable of processing external entities E<0x2014> but |
|
123
|
|
|
|
|
|
|
unfortunately it is also a slow parser. |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
L<Image::Info>, L<XML::LibXML::Reader>, L<XML::Simple>, L<XML::SAX::PurePerl> |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 NOTES |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
For more information about SVG see L<http://www.w3.org/Graphics/SVG/> |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Random notes: |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Colors |
|
136
|
|
|
|
|
|
|
# iterate over polygon,rect,circle,ellipse,line,polyline,text for style->stroke: style->fill:? |
|
137
|
|
|
|
|
|
|
# and iterate over each of these within <g> too?! and recurse?! |
|
138
|
|
|
|
|
|
|
# append <color>'s |
|
139
|
|
|
|
|
|
|
# perhaps even deep recursion through <svg>'s? |
|
140
|
|
|
|
|
|
|
ColorProfile <color-profile> |
|
141
|
|
|
|
|
|
|
RenderingIntent ? |
|
142
|
|
|
|
|
|
|
requiredFeatures |
|
143
|
|
|
|
|
|
|
requiredExtensions |
|
144
|
|
|
|
|
|
|
systemLanguage |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 AUTHOR |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Jerrad Pierce <belg4mit@mit.edu>/<webmaster@pthbb.org> wrote the original code based on L<XML::Simple> |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Slaven Rezic <srezic@cpan.org> wrote the code using L<XML::LibXML::Reader> |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or |
|
153
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=begin register |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
MAGIC: /^(<\?xml|[\012\015\t ]*<svg\b)/ |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Provides a plethora of attributes and metadata of an SVG vector graphic. |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=end register |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=cut |