| 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 | ▶ | use strict; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Text::PDF::Array; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 18 | 1 | ▶ | use Text::PDF::Bool; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 19 | 1 | ▶ | use Text::PDF::Dict; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 20 | 1 | ▶ | use Text::PDF::Name; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 21 | 1 | ▶ | use Text::PDF::Number; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 22 | 1 | ▶ | use Text::PDF::String; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||
| 24 | 1 | ▶ | use Exporter; | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 25 | 1 | ▶ | use vars qw(@EXPORT @ISA); | ||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||
| 26 | 1 | @ISA = qw(Exporter); | |||||||||||||||||||||||||
| 27 | 1 | @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 | ▶ | { Text::PDF::Bool->new(@_); } | ||||||||||||||||||||||||
|
Subroutine
PDFBool: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||
| 42 | =head2 PDFArray | ||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||
| 44 | Creates an array via Text::PDF::Array->new | ||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||
| 46 | =cut | ||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||
| 48 | sub PDFArray | ||||||||||||||||||||||||||
| 49 | 2 | ▶ | { Text::PDF::Array->new(@_); } | ||||||||||||||||||||||||
|
Subroutine
PDFArray: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||
| 52 | =head2 PDFDict | ||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||
| 54 | Creates a dict via Text::PDF::Dict->new | ||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||
| 56 | =cut | ||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||
| 58 | sub PDFDict | ||||||||||||||||||||||||||
| 59 | 6 | ▶ | { Text::PDF::Dict->new(@_); } | ||||||||||||||||||||||||
|
Subroutine
PDFDict: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||
| 62 | =head2 PDFName | ||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||
| 64 | Creates a name via Text::PDF::Name->new | ||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||
| 66 | =cut | ||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||
| 68 | sub PDFName | ||||||||||||||||||||||||||
| 69 | 10 | ▶ | { Text::PDF::Name->new(@_); } | ||||||||||||||||||||||||
|
Subroutine
PDFName: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||
| 72 | =head2 PDFNum | ||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||
| 74 | Creates a number via Text::PDF::Number->new | ||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||
| 76 | =cut | ||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||
| 78 | sub PDFNum | ||||||||||||||||||||||||||
| 79 | 8 | ▶ | { Text::PDF::Number->new(@_); } | ||||||||||||||||||||||||
|
Subroutine
PDFNum: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||
| 82 | =head2 PDFStr | ||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||
| 84 | Creates a string via Text::PDF::String->new | ||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||
| 86 | =cut | ||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||
| 88 | sub PDFStr | ||||||||||||||||||||||||||
| 89 | 0 | ▶ | { Text::PDF::String->new(@_); } | ||||||||||||||||||||||||
|
Subroutine
PDFStr: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||
| 92 | =head2 asPDFBool | ||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||
| 94 | Returns a boolean value in PDF output form | ||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||
| 96 | =cut | ||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||
| 98 | sub asPDFBool | ||||||||||||||||||||||||||
| 99 | 0 | ▶ | { Text::PDF::Bool->new(@_)->as_pdf; } | ||||||||||||||||||||||||
|
Subroutine
asPDFBool: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 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 | ▶ | { Text::PDF::String->new(@_)->as_pdf; } | ||||||||||||||||||||||||
|
Subroutine
asPDFStr: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||
| 112 | =head2 asPDFName | ||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||
| 114 | Returns a Name in PDF Output form (including /) | ||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||
| 116 | =cut | ||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||
| 118 | sub asPDFName | ||||||||||||||||||||||||||
| 119 | 0 | ▶ | { Text::PDF::Name->new(@_)->as_pdf (@_); } | ||||||||||||||||||||||||
|
Subroutine
asPDFName: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||
| 122 | =head2 asPDFNum | ||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||
| 124 | Returns a number in PDF output form | ||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||
| 126 | =cut | ||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||
| 128 | sub asPDFNum | ||||||||||||||||||||||||||
| 129 | 0 | ▶ | { $_[0]; } # no translation needed | ||||||||||||||||||||||||
|
Subroutine
asPDFNum: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||
| 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 | ▶ | my ($str) = @_; | ||||||||||||||||||||||||
|
Subroutine
unpacku: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||
| 141 | 0 | my (@res); | |||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||
| 143 | # return (unpack("U*", $str)) if ($^V && $^V ge v5.6.0); | ||||||||||||||||||||||||||
| 144 | 0 | ▶ | return (unpack("U*", $str)) if ($] >= 5.006); # so much for $^V! | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||
| 146 | 0 | $str = "$str"; # copy $str | |||||||||||||||||||||||||
| 147 | 0 | ▶ | while (length($str)) # Thanks to Gisle Aas for some of his old code | ||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||
| 148 | { | ||||||||||||||||||||||||||
| 149 | 0 | $str =~ s/^[\x80-\xBF]+//o; | |||||||||||||||||||||||||
| 150 | 0 | ▶ | if ($str =~ s/^([\x00-\x7F]+)//o) | ||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||
| 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 | 1; | |||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||