| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#! perl |
|
2
|
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
372004
|
use v5.26; |
|
|
5
|
|
|
|
|
18
|
|
|
4
|
5
|
|
|
5
|
|
2103
|
use Object::Pad; |
|
|
5
|
|
|
|
|
42495
|
|
|
|
5
|
|
|
|
|
32
|
|
|
5
|
5
|
|
|
5
|
|
1772
|
use utf8; |
|
|
5
|
|
|
|
|
836
|
|
|
|
5
|
|
|
|
|
44
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# SVG Parser, based on a modified version of XML::Tiny. |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
class SVGPDF::Parser; |
|
10
|
|
|
|
|
|
|
|
|
11
|
5
|
|
|
5
|
|
4519
|
use File::LoadLines; |
|
|
5
|
|
|
|
|
129176
|
|
|
|
5
|
|
|
|
|
718
|
|
|
12
|
5
|
|
|
5
|
|
53
|
use Carp; |
|
|
5
|
|
|
|
|
10
|
|
|
|
5
|
|
|
|
|
29601
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
field $debug; |
|
15
|
|
|
|
|
|
|
|
|
16
|
32
|
|
|
32
|
0
|
73
|
method parse_file ( $fname, %args ) { |
|
|
32
|
|
|
|
|
82
|
|
|
|
32
|
|
|
|
|
109
|
|
|
|
32
|
|
|
|
|
114
|
|
|
|
32
|
|
|
|
|
57
|
|
|
17
|
32
|
50
|
|
|
|
135
|
$debug = $args{debug} if defined $args{debug}; |
|
18
|
32
|
|
|
|
|
264
|
my $data = loadlines( $fname, { split => 0, chomp => 0 } ); |
|
19
|
32
|
|
|
|
|
10520
|
$self->parse( $data, %args ); |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
|
|
22
|
35
|
|
|
35
|
0
|
590
|
method parse ( $data, %args ) { |
|
|
35
|
|
|
|
|
157
|
|
|
|
35
|
|
|
|
|
90
|
|
|
|
35
|
|
|
|
|
96
|
|
|
|
35
|
|
|
|
|
123
|
|
|
23
|
35
|
50
|
|
|
|
148
|
if ( $debug ) { |
|
24
|
|
|
|
|
|
|
# Make it easier to read/write long lines and disable parts. |
|
25
|
0
|
|
|
|
|
0
|
$data =~ s/^#.*//mg; |
|
26
|
0
|
|
|
|
|
0
|
$data =~ s/\\[\n\r]+\s*//g; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
35
|
|
|
|
|
212
|
$self->_parse( $data, %args ); |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# The _parse method is a modified version of XML::Tiny. All comments |
|
32
|
|
|
|
|
|
|
# and restrictions of L are applicable. |
|
33
|
|
|
|
|
|
|
# Main modification is to allow whitespace elements in elements. |
|
34
|
|
|
|
|
|
|
# These are significant in SVG. |
|
35
|
|
|
|
|
|
|
# Since we're aiming at SVG parsing, and SVG is strict XML but often |
|
36
|
|
|
|
|
|
|
# wrapped in an (X)HTML document, the parser functionality is set |
|
37
|
|
|
|
|
|
|
# to no fatal_declarations and strict_entity_parsing. |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
field $re_name; |
|
40
|
|
|
|
|
|
|
field %emap; |
|
41
|
|
|
|
|
|
|
|
|
42
|
43
|
|
|
43
|
|
1168
|
method _parse ( $data, %params) { |
|
|
43
|
|
|
|
|
136
|
|
|
|
43
|
|
|
|
|
94
|
|
|
|
43
|
|
|
|
|
92
|
|
|
|
43
|
|
|
|
|
73
|
|
|
43
|
43
|
|
|
|
|
168
|
my $elem = { content => [] }; |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# TODO: Accept whitespace tokens by default within elements. |
|
46
|
43
|
|
|
|
|
116
|
my $whitespace_tokens = $params{whitespace_tokens}; |
|
47
|
|
|
|
|
|
|
|
|
48
|
43
|
|
100
|
|
|
259
|
$re_name //= '[:_a-z][\\w:\\.-]*'; |
|
49
|
43
|
|
|
|
|
362
|
%emap = qw( lt < gt > amp & quot " apos ' ); |
|
50
|
|
|
|
|
|
|
|
|
51
|
852
|
|
|
852
|
|
1242
|
my $fixent = sub ( $e ) { |
|
|
852
|
|
|
|
|
1297
|
|
|
|
852
|
|
|
|
|
1133
|
|
|
52
|
852
|
100
|
|
|
|
1900
|
$e =~ s/(\d+);/chr($1)/ge && return $e; |
|
|
2
|
|
|
|
|
24
|
|
|
53
|
850
|
100
|
|
|
|
1671
|
$e =~ s/(x[0-9a-f]+);/chr(hex($1))/gie && return $e; |
|
|
2
|
|
|
|
|
20
|
|
|
54
|
848
|
100
|
|
|
|
1836
|
$e =~ s/&(lt|gt|quot|apos|amp);/$emap{$1}/ge && return $e; |
|
|
5
|
|
|
|
|
29
|
|
|
55
|
847
|
100
|
|
|
|
2324
|
croak( "SVG Parser: Illegal ampersand or entity \"$1\"" ) |
|
56
|
|
|
|
|
|
|
if $e =~ /(&[^;]{0,10})/; |
|
57
|
845
|
|
|
|
|
2239
|
$e; |
|
58
|
43
|
|
|
|
|
324
|
}; |
|
59
|
|
|
|
|
|
|
|
|
60
|
43
|
50
|
33
|
|
|
395
|
croak( "SVG Parser: No elements" ) if !defined($data) || $data !~ /\S/; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Illegal low-ASCII chars. |
|
63
|
43
|
50
|
|
|
|
1279
|
croak( "SVG Parser: Not well-formed (illegal low-ASCII chars)" ) |
|
64
|
|
|
|
|
|
|
if $data =~ /[\x00-\x08\x0b\x0c\x0e-\x1f]/; |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Turn CDATA into PCDATA. |
|
67
|
43
|
|
|
|
|
190
|
$data =~ s{}{ |
|
68
|
1
|
|
|
|
|
36
|
$_ = $1.chr(0); # this makes sure that empty CDATAs become |
|
69
|
1
|
|
|
|
|
8
|
s/([&<>'"])/ # the empty string and aren't just thrown away. |
|
70
|
0
|
0
|
|
|
|
0
|
$1 eq '&' ? '&' : |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
$1 eq '<' ? '<' : |
|
72
|
|
|
|
|
|
|
$1 eq '"' ? '"' : |
|
73
|
|
|
|
|
|
|
$1 eq "'" ? ''' : |
|
74
|
|
|
|
|
|
|
'>' |
|
75
|
|
|
|
|
|
|
/eg; |
|
76
|
1
|
|
|
|
|
7
|
$_; |
|
77
|
|
|
|
|
|
|
}egs; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
croak( "SVG Parser: Not well-formed (CDATA not delimited or bad comment)" ) |
|
80
|
|
|
|
|
|
|
if $data =~ /]]>/ # ]]> not delimiting CDATA |
|
81
|
|
|
|
|
|
|
|| $data =~ //s # ---> can't end a comment |
|
82
|
43
|
100
|
33
|
|
|
13985
|
|| grep { $_ && /--/ } |
|
|
42
|
50
|
33
|
|
|
298
|
|
|
83
|
|
|
|
|
|
|
( $data =~ /^\s+||\s+$/gs); # -- in comm |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# Strip leading/trailing whitespace and comments (which don't nest - phew!). |
|
86
|
43
|
|
|
|
|
14023
|
$data =~ s/^\s+||\s+$//gs; |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# Turn quoted > in attribs into >. |
|
89
|
|
|
|
|
|
|
# Double- and single-quoted attrib values get done seperately. |
|
90
|
43
|
|
|
|
|
91093
|
while ( $data =~ s/($re_name\s*=\s*"[^"]*)>([^"]*")/$1>$2/gsi ) {} |
|
91
|
43
|
|
|
|
|
72618
|
while ( $data =~ s/($re_name\s*=\s*'[^']*)>([^']*')/$1>$2/gsi ) {} |
|
92
|
|
|
|
|
|
|
|
|
93
|
43
|
50
|
33
|
|
|
227
|
if ( $params{fatal_declarations} && $data =~ /
|
|
94
|
0
|
|
|
|
|
0
|
croak( "SVG Parser: Unexpected \"$1\"" ); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# The abc2svg generator forgets the close the body. Fix it. |
|
98
|
43
|
50
|
|
|
|
212
|
if ( $data =~ /\
|
|
99
|
0
|
|
|
|
|
0
|
$data =~ s;\s* |