use
vars
qw(@EXPORT @ISA)
;
@ISA
=
qw(Exporter)
;
@EXPORT
=
qw(PDFBool PDFArray PDFDict PDFName PDFNum PDFStr
asPDFBool asPDFName asPDFNum asPDFStr)
;
sub
PDFBool
{ Text::PDF::Bool->new(
@_
); }
sub
PDFArray
{ Text::PDF::Array->new(
@_
); }
sub
PDFDict
{ Text::PDF::Dict->new(
@_
); }
sub
PDFName
{ Text::PDF::Name->new(
@_
); }
sub
PDFNum
{ Text::PDF::Number->new(
@_
); }
sub
PDFStr
{ Text::PDF::String->new(
@_
); }
sub
asPDFBool
{ Text::PDF::Bool->new(
@_
)->as_pdf; }
sub
asPDFStr
{ Text::PDF::String->new(
@_
)->as_pdf; }
sub
asPDFName
{ Text::PDF::Name->new(
@_
)->as_pdf; }
sub
asPDFNum
{
$_
[0]; }
sub
unpacku
{
my
(
$str
) =
@_
;
my
(
@res
);
return
(
unpack
(
"U*"
,
$str
))
if
($^V && $^V ge
'v5.6.0'
);
$str
=
"$str"
;
while
(
length
(
$str
))
{
$str
=~ s/^[\x80-\xBF]+//o;
if
(
$str
=~ s/^([\x00-\x7F]+)//o)
{
push
(
@res
,
unpack
(
"C*"
, $1)); }
elsif
(
$str
=~ s/^([\xC0-\xDF])([\x80-\xBF])//o)
{
push
(
@res
, ((
ord
($1) & 0x1F) << 6) | (
ord
($2) & 0x3F)); }
elsif
(
$str
=~ s/^([\0xE0-\xEF])([\x80-\xBF])([\x80-\xBF])//o)
{
push
(
@res
, ((
ord
($1) & 0x0F) << 12)
| ((
ord
($2) & 0x3F) << 6)
| (
ord
($3) & 0x3F)); }
elsif
(
$str
=~ s/^([\xF0-\xF7])([\x80-\xBF])([\x80-\xBF])([\x80-\xBF])//o)
{
my
(
$b1
,
$b2
,
$b3
,
$b4
) = (
ord
($1),
ord
($2),
ord
($3),
ord
($4));
push
(
@res
, (((
$b1
& 0x07) << 8) | ((
$b2
& 0x3F) << 2)
| ((
$b3
& 0x30) >> 4)) + 0xD600);
push
(
@res
, (((
$b3
& 0x0F) << 6) | (
$b4
& 0x3F)) + 0xDC00);
}
elsif
(
$str
=~ s/^[\xF8-\xFF][\x80-\xBF]*//o)
{ }
}
@res
;
}
1;