BEGIN {
use
vars
qw(@ISA $VERSION)
;
@ISA
=
qw( PDF::API2::Resource::BaseFont )
;
(
$VERSION
) =
'$Revision: 1.8 $'
=~ /Revision: (\S+)\s/;
}
sub
encodeByData {
my
(
$self
,
$encoding
)=
@_
;
my
$data
=
undef
;
my
(
$firstChar
,
$lastChar
);
if
(
$self
->issymbol ||
$encoding
eq
'asis'
) {
$encoding
=
undef
;
}
if
(
defined
$encoding
) {
$self
->data->{e2u}=[
unpack
(
'U*'
,decode(
$encoding
,
pack
(
'C*'
,(0..255)))) ];
$self
->data->{e2n}=[
map
{ nameByUni(
$_
) ||
'.notdef'
} @{
$self
->data->{e2u}} ];
}
else
{
$self
->data->{e2u}=[ @{
$self
->data->{uni}} ];
$self
->data->{e2n}=[
map
{
$_
||
'.notdef'
} @{
$self
->data->{char}} ];
}
$self
->data->{u2c}={};
$self
->data->{u2e}={};
$self
->data->{u2n}={};
$self
->data->{n2c}={};
$self
->data->{n2e}={};
$self
->data->{n2u}={};
foreach
my
$n
(0..255) {
my
$xchar
=
undef
;
my
$xuni
=
undef
;
if
(
defined
$self
->data->{char}->[
$n
]) {
$xchar
=
$self
->data->{char}->[
$n
];
}
else
{
$xchar
=
'.notdef'
;
}
$self
->data->{n2c}->{
$xchar
}=
$n
unless
(
defined
$self
->data->{n2c}->{
$xchar
});
if
(
defined
$self
->data->{e2n}->[
$n
]) {
$xchar
=
$self
->data->{e2n}->[
$n
];
}
else
{
$xchar
=
'.notdef'
;
}
$self
->data->{n2e}->{
$xchar
}=
$n
unless
(
defined
$self
->data->{n2e}->{
$xchar
});
$self
->data->{n2u}->{
$xchar
}=
$self
->data->{e2u}->[
$n
]
unless
(
defined
$self
->data->{n2u}->{
$xchar
});
if
(
defined
$self
->data->{char}->[
$n
]) {
$xchar
=
$self
->data->{char}->[
$n
];
}
else
{
$xchar
=
'.notdef'
;
}
if
(
defined
$self
->data->{uni}->[
$n
]) {
$xuni
=
$self
->data->{uni}->[
$n
];
}
else
{
$xuni
=0;
}
$self
->data->{n2u}->{
$xchar
}=
$xuni
unless
(
defined
$self
->data->{n2u}->{
$xchar
});
$self
->data->{u2c}->{
$xuni
}||=
$n
unless
(
defined
$self
->data->{u2c}->{
$xuni
});
if
(
defined
$self
->data->{e2u}->[
$n
]) {
$xuni
=
$self
->data->{e2u}->[
$n
];
}
else
{
$xuni
=0;
}
$self
->data->{u2e}->{
$xuni
}||=
$n
unless
(
defined
$self
->data->{u2e}->{
$xuni
});
if
(
defined
$self
->data->{e2n}->[
$n
]) {
$xchar
=
$self
->data->{e2n}->[
$n
];
}
else
{
$xchar
=
'.notdef'
;
}
$self
->data->{u2n}->{
$xuni
}=
$xchar
unless
(
defined
$self
->data->{u2n}->{
$xuni
});
if
(
defined
$self
->data->{char}->[
$n
]) {
$xchar
=
$self
->data->{char}->[
$n
];
}
else
{
$xchar
=
'.notdef'
;
}
if
(
defined
$self
->data->{uni}->[
$n
]) {
$xuni
=
$self
->data->{uni}->[
$n
];
}
else
{
$xuni
=0;
}
$self
->data->{u2n}->{
$xuni
}=
$xchar
unless
(
defined
$self
->data->{u2n}->{
$xuni
});
}
my
$en
= PDFDict();
$self
->{Encoding}=
$en
;
$en
->{Type}=PDFName(
'Encoding'
);
$en
->{BaseEncoding}=PDFName(
'WinAnsiEncoding'
);
$en
->{Differences}=PDFArray(PDFNum(0));
foreach
my
$n
(0..255) {
$en
->{Differences}->add_elements( PDFName(
$self
->glyphByEnc(
$n
) ||
'.notdef'
) );
}
$self
->{
'FirstChar'
} = PDFNum(
$self
->data->{firstchar});
$self
->{
'LastChar'
} = PDFNum(
$self
->data->{lastchar});
$self
->{Widths}=PDFArray();
foreach
my
$n
(
$self
->data->{firstchar}..
$self
->data->{lastchar}) {
$self
->{Widths}->add_elements( PDFNum(
$self
->wxByEnc(
$n
)) );
}
return
(
$self
);
}
sub
text {
return
(
$_
[0]->textByStr(
$_
[1])); }
sub
automap {
my
(
$self
)=
@_
;
my
%gl
=
map
{
$_
=>defineName(
$_
) }
keys
%{
$self
->data->{wx}};
foreach
my
$n
(0..255) {
delete
$gl
{
$self
->data->{e2n}->[
$n
]};
}
my
@nm
=
sort
{
$gl
{
$a
}<=>
$gl
{
$b
} }
keys
%gl
;
my
@fnts
=();
my
$count
=0;
while
(
@glyphs
=
splice
(
@nm
,0,223)) {
my
$obj
=
$self
->SUPER::new(
$self
->{
' apipdf'
},
$self
->name.
'am'
.
$count
);
$obj
->{
' data'
}={ %{
$self
->data} };
$obj
->data->{firstchar}=32;
$obj
->data->{lastchar}=32+
scalar
(
@glyphs
);
push
@fnts
,
$obj
;
foreach
my
$key
(
qw( Subtype BaseFont FontDescriptor )
) {
$obj
->{
$key
}=
$self
->{
$key
}
if
(
defined
$self
->{
$key
});
}
$obj
->data->{char}=[];
$obj
->data->{uni}=[];
foreach
my
$n
(0..31) {
$obj
->data->{char}->[
$n
]=
'.notdef'
;
$obj
->data->{uni}->[
$n
]=0;
}
$obj
->data->{char}->[32]=
'space'
;
$obj
->data->{uni}->[32]=32;
foreach
my
$n
(33..
$obj
->data->{lastchar}) {
$obj
->data->{char}->[
$n
]=
$glyphs
[
$n
-33];
$obj
->data->{uni}->[
$n
]=
$gl
{
$glyphs
[
$n
-33]};
}
foreach
my
$n
((
$obj
->data->{lastchar}+1)..255) {
$obj
->data->{char}->[
$n
]=
'.notdef'
;
$obj
->data->{uni}->[
$n
]=0;
}
$obj
->encodeByData(
undef
);
$count
++;
}
return
(
@fnts
);
}
sub
remap {
my
(
$self
,
$enc
)=
@_
;
my
$obj
=
$self
->SUPER::new(
$self
->{
' apipdf'
},
$self
->name.
'rm'
.pdfkey());
$obj
->{
' data'
}={ %{
$self
->data} };
foreach
my
$key
(
qw( Subtype BaseFont FontDescriptor )
) {
$obj
->{
$key
}=
$self
->{
$key
}
if
(
defined
$self
->{
$key
});
}
$obj
->encodeByData(
$enc
);
return
(
$obj
);
}
1;