line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Text::PDF::Utils; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Text::PDF::Utils - Utility functions for PDF library |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 DESCRIPTION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
A set of utility functions to save the fingers of the PDF library users! |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 FUNCTIONS |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=cut |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
303
|
use Text::PDF::Array; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
21
|
|
18
|
1
|
|
|
1
|
|
343
|
use Text::PDF::Bool; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
19
|
1
|
|
|
1
|
|
374
|
use Text::PDF::Dict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
20
|
1
|
|
|
1
|
|
343
|
use Text::PDF::Name; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
21
|
1
|
|
|
1
|
|
360
|
use Text::PDF::Number; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
22
|
1
|
|
|
1
|
|
3
|
use Text::PDF::String; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
12
|
|
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
1
|
|
2
|
use Exporter; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
27
|
|
25
|
1
|
|
|
1
|
|
3
|
use vars qw(@EXPORT @ISA); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
469
|
|
26
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
27
|
|
|
|
|
|
|
@EXPORT = qw(PDFBool PDFArray PDFDict PDFName PDFNum PDFStr |
28
|
|
|
|
|
|
|
asPDFBool asPDFName asPDFNum asPDFStr); |
29
|
|
|
|
|
|
|
# no warnings qw(uninitialized); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head2 PDFBool |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Creates a Bool via Text::PDF::Bool->new |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub PDFBool |
39
|
0
|
|
|
0
|
1
|
0
|
{ Text::PDF::Bool->new(@_); } |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head2 PDFArray |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Creates an array via Text::PDF::Array->new |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub PDFArray |
49
|
2
|
|
|
2
|
1
|
4
|
{ Text::PDF::Array->new(@_); } |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 PDFDict |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Creates a dict via Text::PDF::Dict->new |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub PDFDict |
59
|
6
|
|
|
6
|
1
|
21
|
{ Text::PDF::Dict->new(@_); } |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 PDFName |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Creates a name via Text::PDF::Name->new |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=cut |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub PDFName |
69
|
10
|
|
|
10
|
1
|
22
|
{ Text::PDF::Name->new(@_); } |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head2 PDFNum |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Creates a number via Text::PDF::Number->new |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub PDFNum |
79
|
8
|
|
|
8
|
1
|
19
|
{ Text::PDF::Number->new(@_); } |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 PDFStr |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Creates a string via Text::PDF::String->new |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=cut |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub PDFStr |
89
|
0
|
|
|
0
|
1
|
|
{ Text::PDF::String->new(@_); } |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 asPDFBool |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Returns a boolean value in PDF output form |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub asPDFBool |
99
|
0
|
|
|
0
|
1
|
|
{ Text::PDF::Bool->new(@_)->as_pdf; } |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 asPDFStr |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Returns a string in PDF output form (including () or <>) |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub asPDFStr |
109
|
0
|
|
|
0
|
1
|
|
{ Text::PDF::String->new(@_)->as_pdf; } |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 asPDFName |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Returns a Name in PDF Output form (including /) |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub asPDFName |
119
|
0
|
|
|
0
|
1
|
|
{ Text::PDF::Name->new(@_)->as_pdf (@_); } |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 asPDFNum |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Returns a number in PDF output form |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub asPDFNum |
129
|
0
|
|
|
0
|
1
|
|
{ $_[0]; } # no translation needed |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 unpacku($str) |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Returns a list of unicode values for the given UTF8 string |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub unpacku |
139
|
|
|
|
|
|
|
{ |
140
|
0
|
|
|
0
|
1
|
|
my ($str) = @_; |
141
|
0
|
|
|
|
|
|
my (@res); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# return (unpack("U*", $str)) if ($^V && $^V ge v5.6.0); |
144
|
0
|
0
|
|
|
|
|
return (unpack("U*", $str)) if ($] >= 5.006); # so much for $^V! |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
$str = "$str"; # copy $str |
147
|
0
|
|
|
|
|
|
while (length($str)) # Thanks to Gisle Aas for some of his old code |
148
|
|
|
|
|
|
|
{ |
149
|
0
|
|
|
|
|
|
$str =~ s/^[\x80-\xBF]+//o; |
150
|
0
|
0
|
|
|
|
|
if ($str =~ s/^([\x00-\x7F]+)//o) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
{ push(@res, unpack("C*", $1)); } |
152
|
|
|
|
|
|
|
elsif ($str =~ s/^([\xC0-\xDF])([\x80-\xBF])//o) |
153
|
0
|
|
|
|
|
|
{ push(@res, ((ord($1) & 0x1F) << 6) | (ord($2) & 0x3F)); } |
154
|
|
|
|
|
|
|
elsif ($str =~ s/^([\0xE0-\xEF])([\x80-\xBF])([\x80-\xBF])//o) |
155
|
0
|
|
|
|
|
|
{ push(@res, ((ord($1) & 0x0F) << 12) |
156
|
|
|
|
|
|
|
| ((ord($2) & 0x3F) << 6) |
157
|
|
|
|
|
|
|
| (ord($3) & 0x3F)); } |
158
|
|
|
|
|
|
|
elsif ($str =~ s/^([\xF0-\xF7])([\x80-\xBF])([\x80-\xBF])([\x80-\xBF])//o) |
159
|
|
|
|
|
|
|
{ |
160
|
0
|
|
|
|
|
|
my ($b1, $b2, $b3, $b4) = (ord($1), ord($2), ord($3), ord($4)); |
161
|
0
|
|
|
|
|
|
push(@res, ((($b1 & 0x07) << 8) | (($b2 & 0x3F) << 2) |
162
|
|
|
|
|
|
|
| (($b3 & 0x30) >> 4)) + 0xD600); # account for offset |
163
|
0
|
|
|
|
|
|
push(@res, ((($b3 & 0x0F) << 6) | ($b4 & 0x3F)) + 0xDC00); |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
elsif ($str =~ s/^[\xF8-\xFF][\x80-\xBF]*//o) |
166
|
|
|
|
|
|
|
{ } |
167
|
|
|
|
|
|
|
} |
168
|
0
|
|
|
|
|
|
@res; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
1; |
173
|
|
|
|
|
|
|
|