line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::PDF::String; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Text::PDF::String - PDF String type objects and superclass for simple objects |
6
|
|
|
|
|
|
|
that are basically stringlike (Number, Name, etc.) |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 METHODS |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=cut |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
13
|
1
|
|
|
1
|
|
3
|
use vars qw(@ISA %trans %out_trans); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
40
|
|
14
|
|
|
|
|
|
|
# no warnings qw(uninitialized); |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
3
|
use Text::PDF::Objind; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
526
|
|
17
|
|
|
|
|
|
|
@ISA = qw(Text::PDF::Objind); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
%trans = ( |
20
|
|
|
|
|
|
|
"n" => "\n", |
21
|
|
|
|
|
|
|
"r" => "\r", |
22
|
|
|
|
|
|
|
"t" => "\t", |
23
|
|
|
|
|
|
|
"b" => "\b", |
24
|
|
|
|
|
|
|
"f" => "\f", |
25
|
|
|
|
|
|
|
"\\" => "\\", |
26
|
|
|
|
|
|
|
"(" => "(", |
27
|
|
|
|
|
|
|
")" => ")" |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
%out_trans = ( |
31
|
|
|
|
|
|
|
"\n" => "n", |
32
|
|
|
|
|
|
|
"\r" => "r", |
33
|
|
|
|
|
|
|
"\t" => "t", |
34
|
|
|
|
|
|
|
"\b" => "b", |
35
|
|
|
|
|
|
|
"\f" => "f", |
36
|
|
|
|
|
|
|
"\\" => "\\", |
37
|
|
|
|
|
|
|
"(" => "(", |
38
|
|
|
|
|
|
|
")" => ")" |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 Text::PDF::String->from_pdf($string) |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Creates a new string object (not a full object yet) from a given string. |
45
|
|
|
|
|
|
|
The string is parsed according to input criteria with escaping working. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub from_pdf |
50
|
|
|
|
|
|
|
{ |
51
|
2
|
|
|
2
|
1
|
2
|
my ($class, $str) = @_; |
52
|
2
|
|
|
|
|
3
|
my ($self) = {}; |
53
|
|
|
|
|
|
|
|
54
|
2
|
|
|
|
|
3
|
bless $self, $class; |
55
|
2
|
|
|
|
|
5
|
$self->{'val'} = $self->convert($str); |
56
|
2
|
|
|
|
|
2
|
$self->{' realised'} = 1; |
57
|
2
|
|
|
|
|
3
|
return $self; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 Text::PDF::String->new($string) |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Creates a new string object (not a full object yet) from a given string. |
64
|
|
|
|
|
|
|
The string is parsed according to input criteria with escaping working. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub new |
69
|
|
|
|
|
|
|
{ |
70
|
19
|
|
|
19
|
1
|
19
|
my ($class, $str) = @_; |
71
|
19
|
|
|
|
|
17
|
my ($self) = {}; |
72
|
|
|
|
|
|
|
|
73
|
19
|
|
|
|
|
18
|
bless $self, $class; |
74
|
19
|
|
|
|
|
24
|
$self->{'val'} = $str; |
75
|
19
|
|
|
|
|
16
|
$self->{' realised'} = 1; |
76
|
19
|
|
|
|
|
37
|
return $self; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 $s->convert($str) |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Returns $str converted as per criteria for input from PDF file |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub convert |
87
|
|
|
|
|
|
|
{ |
88
|
0
|
|
|
0
|
1
|
0
|
my ($self, $str) = @_; |
89
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
0
|
$str =~ s/\\([nrtbf\\()]|[0-7]+)/defined $trans{$1} ? $trans{$1} : chr(oct($1))/oegi; |
|
0
|
|
|
|
|
0
|
|
91
|
|
|
|
|
|
|
# $str =~ s/\\([0-7]+)/chr(oct($1))/oeg; # thanks to kundrat@kundrat.sk |
92
|
0
|
|
|
|
|
0
|
1 while $str =~ s/\<([0-9a-f]{2})[\r\n]*/chr(hex($1))."\<"/oige; |
|
0
|
|
|
|
|
0
|
|
93
|
0
|
|
|
|
|
0
|
$str =~ s/\<([0-9a-f]?)\>/chr(hex($1."0"))/oige; |
|
0
|
|
|
|
|
0
|
|
94
|
0
|
|
|
|
|
0
|
$str =~ s/\<\>//og; |
95
|
0
|
|
|
|
|
0
|
return $str; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 $s->val |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Returns the value of this string (the string itself). |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub val |
106
|
6
|
|
|
6
|
1
|
16
|
{ $_[0]->{'val'}; } |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 $->as_pdf |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Returns the string formatted for output as PDF for PDF File object $pdf. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub as_pdf |
116
|
|
|
|
|
|
|
{ |
117
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
118
|
0
|
|
|
|
|
0
|
my ($str) = $self->{'val'}; |
119
|
|
|
|
|
|
|
|
120
|
0
|
0
|
|
|
|
0
|
if ($str =~ m/[^\n\r\t\b\f\040-\176\200-\377]/oi) |
121
|
|
|
|
|
|
|
{ |
122
|
0
|
|
|
|
|
0
|
$str =~ s/(.)/sprintf("%02X", ord($1))/oge; |
|
0
|
|
|
|
|
0
|
|
123
|
0
|
|
|
|
|
0
|
return "<$str>"; |
124
|
|
|
|
|
|
|
} else |
125
|
|
|
|
|
|
|
{ |
126
|
0
|
|
|
|
|
0
|
$str =~ s/([\n\r\t\b\f\\()])/\\$out_trans{$1}/ogi; |
127
|
0
|
|
|
|
|
0
|
return "($str)"; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head2 $s->outobjdeep |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Outputs the string in PDF format, complete with necessary conversions |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub outobjdeep |
138
|
|
|
|
|
|
|
{ |
139
|
16
|
|
|
16
|
1
|
19
|
my ($self, $fh, $pdf, %opts) = @_; |
140
|
|
|
|
|
|
|
|
141
|
16
|
|
|
|
|
33
|
$fh->print($self->as_pdf ($pdf)); |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 $s->copy($inpdf, $res, $unique, $outpdf, %opts) |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Copies an object. See Text::PDF::Objind::Copy() for details |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub copy |
152
|
|
|
|
|
|
|
{ |
153
|
0
|
|
|
0
|
1
|
|
my ($self, $inpdf, $res, $unique, $outpdf, %opts) = @_; |
154
|
0
|
|
|
|
|
|
my ($i); |
155
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
$res = $self->SUPER::copy($inpdf, $res, $unique, $outpdf, %opts); |
157
|
0
|
|
|
|
|
|
$res->{'val'} = $self->{'val'}; |
158
|
0
|
|
|
|
|
|
$res->{' realised'} = 1; |
159
|
0
|
|
|
|
|
|
$res; |
160
|
|
|
|
|
|
|
} |