line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#=======================================================================
|
2
|
|
|
|
|
|
|
# ____ ____ _____ _ ____ ___ ____
|
3
|
|
|
|
|
|
|
# | _ \| _ \| ___| _ _ / \ | _ \_ _| |___ \
|
4
|
|
|
|
|
|
|
# | |_) | | | | |_ (_) (_) / _ \ | |_) | | __) |
|
5
|
|
|
|
|
|
|
# | __/| |_| | _| _ _ / ___ \| __/| | / __/
|
6
|
|
|
|
|
|
|
# |_| |____/|_| (_) (_) /_/ \_\_| |___| |_____|
|
7
|
|
|
|
|
|
|
#
|
8
|
|
|
|
|
|
|
# A Perl Module Chain to faciliate the Creation and Modification
|
9
|
|
|
|
|
|
|
# of High-Quality "Portable Document Format (PDF)" Files.
|
10
|
|
|
|
|
|
|
#
|
11
|
|
|
|
|
|
|
# Copyright 1999-2005 Alfred Reibenschuh .
|
12
|
|
|
|
|
|
|
#
|
13
|
|
|
|
|
|
|
#=======================================================================
|
14
|
|
|
|
|
|
|
#
|
15
|
|
|
|
|
|
|
# This library is free software; you can redistribute it and/or
|
16
|
|
|
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
17
|
|
|
|
|
|
|
# License as published by the Free Software Foundation; either
|
18
|
|
|
|
|
|
|
# version 2 of the License, or (at your option) any later version.
|
19
|
|
|
|
|
|
|
#
|
20
|
|
|
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
21
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
23
|
|
|
|
|
|
|
# Lesser General Public License for more details.
|
24
|
|
|
|
|
|
|
#
|
25
|
|
|
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
26
|
|
|
|
|
|
|
# License along with this library; if not, write to the
|
27
|
|
|
|
|
|
|
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
28
|
|
|
|
|
|
|
# Boston, MA 02111-1307, USA.
|
29
|
|
|
|
|
|
|
#
|
30
|
|
|
|
|
|
|
# $Id: TrueType.pm,v 2.5 2009/03/20 09:54:46 areibens Exp $
|
31
|
|
|
|
|
|
|
#
|
32
|
|
|
|
|
|
|
#=======================================================================
|
33
|
|
|
|
|
|
|
package PDF::API3::Compat::API2::Resource::CIDFont::TrueType;
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
BEGIN {
|
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
1
|
|
5
|
use utf8;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
12
|
|
38
|
1
|
|
|
1
|
|
35
|
use Encode qw(:all);
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
409
|
|
39
|
|
|
|
|
|
|
|
40
|
1
|
|
|
1
|
|
7
|
use PDF::API3::Compat::API2::Util;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
203
|
|
41
|
1
|
|
|
1
|
|
6
|
use PDF::API3::Compat::API2::Basic::PDF::Utils;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
113
|
|
42
|
1
|
|
|
1
|
|
845
|
use PDF::API3::Compat::API2::Resource::CIDFont;
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
51
|
|
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
1
|
|
843
|
use PDF::API3::Compat::API2::Basic::TTF::Font;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
45
|
1
|
|
|
1
|
|
1221
|
use PDF::API3::Compat::API2::Resource::CIDFont::TrueType::FontFile;
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
50
|
|
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
1
|
|
13
|
use POSIX;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
8
|
|
48
|
|
|
|
|
|
|
|
49
|
1
|
|
|
1
|
|
3181
|
use vars qw(@ISA $VERSION);
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
125
|
|
50
|
|
|
|
|
|
|
|
51
|
1
|
|
|
1
|
|
32
|
@ISA = qw( PDF::API3::Compat::API2::Resource::CIDFont );
|
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
48
|
( $VERSION ) = sprintf '%i.%03i', split(/\./,('$Revision: 2.5 $' =~ /Revision: (\S+)\s/)[0]); # $Date: 2009/03/20 09:54:46 $
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
}
|
56
|
1
|
|
|
1
|
|
7
|
no warnings qw[ deprecated recursion uninitialized ];
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1113
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item $font = PDF::API3::Compat::API2::Resource::CIDFont::TrueType->new $pdf, $file, %options
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Returns a font object.
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Defined Options:
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
-encode ... specify fonts encoding for non-utf8 text.
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
-nosubset ... disables subsetting.
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub new {
|
71
|
0
|
|
|
0
|
1
|
|
my ($class,$pdf,$file,@opts) = @_;
|
72
|
0
|
|
|
|
|
|
my %opts=();
|
73
|
0
|
0
|
|
|
|
|
%opts=@opts if((scalar @opts)%2 == 0);
|
74
|
0
|
|
0
|
|
|
|
$opts{-encode}||='latin1';
|
75
|
0
|
|
|
|
|
|
my ($ff,$data)=PDF::API3::Compat::API2::Resource::CIDFont::TrueType::FontFile->new($pdf,$file,@opts);
|
76
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
$class = ref $class if ref $class;
|
78
|
0
|
|
|
|
|
|
my $self=$class->SUPER::new($pdf,$data->{apiname}.pdfkey().'~'.time());
|
79
|
0
|
0
|
0
|
|
|
|
$pdf->new_obj($self) if(defined($pdf) && !$self->is_obj($pdf));
|
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
$self->{' data'}=$data;
|
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my $des=$self->descrByData;
|
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
$self->{'BaseFont'} = PDFName($self->fontname);
|
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
my $de=$self->{' de'};
|
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
$de->{'FontDescriptor'} = $des;
|
90
|
0
|
0
|
|
|
|
|
$de->{'Subtype'} = PDFName($self->iscff ? 'CIDFontType0' : 'CIDFontType2');
|
91
|
|
|
|
|
|
|
## $de->{'BaseFont'} = PDFName(pdfkey().'+'.($self->fontname).'~'.time());
|
92
|
0
|
|
|
|
|
|
$de->{'BaseFont'} = PDFName($self->fontname);
|
93
|
0
|
|
|
|
|
|
$de->{'DW'} = PDFNum($self->missingwidth);
|
94
|
0
|
0
|
|
|
|
|
if($opts{-noembed} != 1)
|
95
|
|
|
|
|
|
|
{
|
96
|
0
|
0
|
|
|
|
|
$des->{$self->data->{iscff} ? 'FontFile3' : 'FontFile2'}=$ff;
|
97
|
|
|
|
|
|
|
}
|
98
|
0
|
0
|
|
|
|
|
unless($self->issymbol) {
|
99
|
0
|
|
|
|
|
|
$self->encodeByName($opts{-encode});
|
100
|
0
|
|
|
|
|
|
$self->data->{encode}=$opts{-encode};
|
101
|
0
|
|
|
|
|
|
$self->data->{decode}='ident';
|
102
|
|
|
|
|
|
|
}
|
103
|
|
|
|
|
|
|
|
104
|
0
|
0
|
|
|
|
|
if($opts{-nosubset}) {
|
105
|
0
|
|
|
|
|
|
$self->data->{nosubset}=1;
|
106
|
|
|
|
|
|
|
}
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
$self->{' ff'} = $ff;
|
110
|
0
|
|
|
|
|
|
$pdf->new_obj($ff);
|
111
|
|
|
|
|
|
|
|
112
|
0
|
0
|
|
|
|
|
$self->{-dokern}=1 if($opts{-dokern});
|
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
return($self);
|
115
|
|
|
|
|
|
|
}
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
0
|
0
|
|
sub fontfile { return( $_[0]->{' ff'} ); }
|
119
|
0
|
|
|
0
|
0
|
|
sub fontobj { return( $_[0]->data->{obj} ); }
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item $font = PDF::API3::Compat::API2::Resource::CIDFont::TrueType->new_api $api, $file, %options
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Returns a truetype-font object. This method is different from 'new' that
|
124
|
|
|
|
|
|
|
it needs an PDF::API3::Compat::API2-object rather than a Text::PDF::File-object.
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub new_api
|
129
|
|
|
|
|
|
|
{
|
130
|
0
|
|
|
0
|
1
|
|
my ($class,$api,@opts)=@_;
|
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
my $obj=$class->new($api->{pdf},@opts);
|
133
|
0
|
|
|
|
|
|
$self->{' api'}=$api;
|
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
$api->{pdf}->out_obj($api->{pages});
|
136
|
0
|
|
|
|
|
|
return($obj);
|
137
|
|
|
|
|
|
|
}
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub wxByCId
|
140
|
|
|
|
|
|
|
{
|
141
|
0
|
|
|
0
|
0
|
|
my $self=shift @_;
|
142
|
0
|
|
|
|
|
|
my $g=shift @_;
|
143
|
0
|
|
|
|
|
|
my $t = $self->fontobj->{'hmtx'}->read->{'advance'}[$g];
|
144
|
0
|
|
|
|
|
|
my $w;
|
145
|
|
|
|
|
|
|
|
146
|
0
|
0
|
|
|
|
|
if(defined $t)
|
147
|
|
|
|
|
|
|
{
|
148
|
0
|
|
|
|
|
|
$w = int($t*1000/$self->data->{upem});
|
149
|
|
|
|
|
|
|
}
|
150
|
|
|
|
|
|
|
else
|
151
|
|
|
|
|
|
|
{
|
152
|
0
|
|
|
|
|
|
$w = $self->missingwidth;
|
153
|
|
|
|
|
|
|
}
|
154
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
return($w);
|
156
|
|
|
|
|
|
|
}
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub haveKernPairs
|
159
|
|
|
|
|
|
|
{
|
160
|
0
|
|
|
0
|
0
|
|
my $self = shift @_;
|
161
|
0
|
|
|
|
|
|
return($self->fontfile->haveKernPairs(@_));
|
162
|
|
|
|
|
|
|
}
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub kernPairCid
|
165
|
|
|
|
|
|
|
{
|
166
|
0
|
|
|
0
|
0
|
|
my $self = shift @_;
|
167
|
0
|
|
|
|
|
|
return($self->fontfile->kernPairCid(@_));
|
168
|
|
|
|
|
|
|
}
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub subsetByCId
|
171
|
|
|
|
|
|
|
{
|
172
|
0
|
|
|
0
|
0
|
|
my $self = shift @_;
|
173
|
0
|
0
|
|
|
|
|
return if($self->iscff);
|
174
|
0
|
|
|
|
|
|
my $g = shift @_;
|
175
|
0
|
|
|
|
|
|
$self->fontfile->subsetByCId($g);
|
176
|
|
|
|
|
|
|
}
|
177
|
|
|
|
|
|
|
sub subvec
|
178
|
|
|
|
|
|
|
{
|
179
|
0
|
|
|
0
|
0
|
|
my $self = shift @_;
|
180
|
0
|
0
|
|
|
|
|
return(1) if($self->iscff);
|
181
|
0
|
|
|
|
|
|
my $g = shift @_;
|
182
|
0
|
|
|
|
|
|
$self->fontfile->subvec($g);
|
183
|
|
|
|
|
|
|
}
|
184
|
|
|
|
|
|
|
|
185
|
0
|
|
|
0
|
1
|
|
sub glyphNum { return ( $_[0]->fontfile->glyphNum ); }
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub outobjdeep
|
188
|
|
|
|
|
|
|
{
|
189
|
0
|
|
|
0
|
1
|
|
my ($self, $fh, $pdf, %opts) = @_;
|
190
|
|
|
|
|
|
|
|
191
|
0
|
0
|
|
|
|
|
return $self->SUPER::outobjdeep($fh, $pdf) if defined $opts{'passthru'};
|
192
|
|
|
|
|
|
|
|
193
|
0
|
|
|
|
|
|
my $notdefbefore=1;
|
194
|
|
|
|
|
|
|
|
195
|
0
|
|
|
|
|
|
my $wx=PDFArray();
|
196
|
0
|
|
|
|
|
|
$self->{' de'}->{'W'} = $wx;
|
197
|
0
|
|
|
|
|
|
my $ml;
|
198
|
|
|
|
|
|
|
|
199
|
0
|
|
|
|
|
|
foreach my $w (0..(scalar @{$self->data->{g2u}} - 1 ))
|
|
0
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
{
|
201
|
0
|
0
|
0
|
|
|
|
if($self->subvec($w) && $notdefbefore==1)
|
|
|
0
|
0
|
|
|
|
|
202
|
|
|
|
|
|
|
{
|
203
|
0
|
|
|
|
|
|
$notdefbefore=0;
|
204
|
0
|
|
|
|
|
|
$ml=PDFArray();
|
205
|
0
|
|
|
|
|
|
$wx->add_elements(PDFNum($w),$ml);
|
206
|
|
|
|
|
|
|
# $ml->add_elements(PDFNum($self->data->{wx}->[$w]));
|
207
|
0
|
|
|
|
|
|
$ml->add_elements(PDFNum($self->wxByCId($w)));
|
208
|
|
|
|
|
|
|
}
|
209
|
|
|
|
|
|
|
elsif($self->subvec($w) && $notdefbefore==0)
|
210
|
|
|
|
|
|
|
{
|
211
|
0
|
|
|
|
|
|
$notdefbefore=0;
|
212
|
|
|
|
|
|
|
# $ml->add_elements(PDFNum($self->data->{wx}->[$w]));
|
213
|
0
|
|
|
|
|
|
$ml->add_elements(PDFNum($self->wxByCId($w)));
|
214
|
|
|
|
|
|
|
}
|
215
|
|
|
|
|
|
|
else
|
216
|
|
|
|
|
|
|
{
|
217
|
0
|
|
|
|
|
|
$notdefbefore=1;
|
218
|
|
|
|
|
|
|
}
|
219
|
|
|
|
|
|
|
# optimization for cjk
|
220
|
|
|
|
|
|
|
#if($self->subvec($w) && $notdefbefore==1 && $self->data->{wx}->[$w]!=$self->missingwidth) {
|
221
|
|
|
|
|
|
|
# $notdefbefore=0;
|
222
|
|
|
|
|
|
|
# $ml=PDFArray();
|
223
|
|
|
|
|
|
|
# $wx->add_elements(PDFNum($w),$ml);
|
224
|
|
|
|
|
|
|
# $ml->add_elements(PDFNum($self->data->{wx}->[$w]));
|
225
|
|
|
|
|
|
|
#} elsif($self->subvec($w) && $notdefbefore==0 && $self->data->{wx}->[$w]!=$self->missingwidth) {
|
226
|
|
|
|
|
|
|
# $notdefbefore=0;
|
227
|
|
|
|
|
|
|
# $ml->add_elements(PDFNum($self->data->{wx}->[$w]));
|
228
|
|
|
|
|
|
|
#} else {
|
229
|
|
|
|
|
|
|
# $notdefbefore=1;
|
230
|
|
|
|
|
|
|
#}
|
231
|
|
|
|
|
|
|
}
|
232
|
|
|
|
|
|
|
|
233
|
0
|
|
|
|
|
|
$self->SUPER::outobjdeep($fh, $pdf, %opts);
|
234
|
|
|
|
|
|
|
}
|
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
1;
|
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
__END__
|