line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PDF::Builder::Resource::CIDFont::TrueType; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1080
|
use base 'PDF::Builder::Resource::CIDFont'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
111
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
21
|
|
6
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
48
|
|
7
|
|
|
|
|
|
|
#no warnings qw[ deprecated recursion uninitialized ]; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '3.023'; # VERSION |
10
|
|
|
|
|
|
|
our $LAST_UPDATE = '3.021'; # manually update whenever code is changed |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
6
|
use PDF::Builder::Basic::PDF::Utils; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
113
|
|
13
|
1
|
|
|
1
|
|
597
|
use PDF::Builder::Resource::CIDFont::TrueType::FontFile; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
50
|
|
14
|
1
|
|
|
1
|
|
10
|
use PDF::Builder::Util; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1068
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 NAME |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
PDF::Builder::Resource::CIDFont::TrueType - TrueType font support |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 METHODS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=over |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=item $font = PDF::Builder::Resource::CIDFont::TrueType->new($pdf, $file, %options) |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=item $font = PDF::Builder::Resource::CIDFont::TrueType->new($pdf, $file) |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Returns a font object. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Defined Options: |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
-encode ... specify fonts encoding for non-UTF-8 text. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
-nosubset ... disables subsetting. Any value causes the full font to be |
35
|
|
|
|
|
|
|
embedded, rather than only the glyphs needed. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=cut |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub new { |
40
|
0
|
|
|
0
|
1
|
|
my ($class, $pdf, $file, @opts) = @_; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my %opts = (); |
43
|
0
|
0
|
|
|
|
|
%opts = @opts if (scalar @opts)%2 == 0; |
44
|
0
|
|
0
|
|
|
|
$opts{'-encode'} ||= 'latin1'; |
45
|
0
|
|
|
|
|
|
my ($ff, $data) = PDF::Builder::Resource::CIDFont::TrueType::FontFile->new($pdf, $file, @opts); |
46
|
|
|
|
|
|
|
|
47
|
0
|
0
|
|
|
|
|
$class = ref $class if ref $class; |
48
|
|
|
|
|
|
|
# my $self = $class->SUPER::new($pdf, $data->{'apiname'}.pdfkey().'~'.time()); |
49
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new($pdf, $data->{'apiname'}.pdfkey()); |
50
|
0
|
0
|
0
|
|
|
|
$pdf->new_obj($self) if defined($pdf) && !$self->is_obj($pdf); |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
$self->{' data'} = $data; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my $des = $self->descrByData(); |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$self->{'BaseFont'} = PDFName($self->fontname()); |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $de = $self->{' de'}; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
$de->{'FontDescriptor'} = $des; |
61
|
0
|
0
|
|
|
|
|
$de->{'Subtype'} = PDFName($self->iscff()? 'CIDFontType0': 'CIDFontType2'); |
62
|
|
|
|
|
|
|
## $de->{'BaseFont'} = PDFName(pdfkey().'+'.($self->fontname()).'~'.time()); |
63
|
0
|
|
|
|
|
|
$de->{'BaseFont'} = PDFName($self->fontname()); |
64
|
0
|
|
|
|
|
|
$de->{'DW'} = PDFNum($self->missingwidth()); |
65
|
0
|
0
|
0
|
|
|
|
if (($opts{'-noembed'}||0) != 1) { |
66
|
0
|
0
|
|
|
|
|
$des->{$self->data()->{'iscff'}? 'FontFile3': 'FontFile2'} = $ff; |
67
|
|
|
|
|
|
|
} |
68
|
0
|
0
|
|
|
|
|
unless ($self->issymbol()) { |
69
|
0
|
|
|
|
|
|
$self->encodeByName($opts{'-encode'}); |
70
|
0
|
|
|
|
|
|
$self->data->{'encode'} = $opts{'-encode'}; |
71
|
0
|
|
|
|
|
|
$self->data->{'decode'} = 'ident'; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
if ($opts{'-nosubset'}) { |
75
|
0
|
|
|
|
|
|
$self->data()->{'nosubset'} = 1; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
$self->{' ff'} = $ff; |
79
|
0
|
|
|
|
|
|
$pdf->new_obj($ff); |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
$self->{'-dokern'} = 1 if $opts{'-dokern'}; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return $self; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub fontfile { |
87
|
0
|
|
|
0
|
0
|
|
return $_[0]->{' ff'}; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub fontobj { |
91
|
0
|
|
|
0
|
0
|
|
return $_[0]->data()->{'obj'}; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub wxByCId { |
95
|
0
|
|
|
0
|
0
|
|
my ($self, $g) = @_; |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
|
|
|
my $t = $self->fontobj()->{'hmtx'}->read()->{'advance'}[$g]; |
98
|
0
|
|
|
|
|
|
my $w; |
99
|
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
|
if (defined $t) { |
101
|
0
|
|
|
|
|
|
$w = int($t *1000/$self->data()->{'upem'}); |
102
|
|
|
|
|
|
|
} else { |
103
|
0
|
|
|
|
|
|
$w = $self->missingwidth(); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
return $w; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub haveKernPairs { |
110
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
return $self->fontfile()->haveKernPairs(@_); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub kernPairCid { |
116
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
return $self->fontfile()->kernPairCid(@_); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub subsetByCId { |
122
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
123
|
|
|
|
|
|
|
|
124
|
0
|
0
|
|
|
|
|
return if $self->iscff(); |
125
|
0
|
|
|
|
|
|
my $g = shift; |
126
|
0
|
|
|
|
|
|
return $self->fontfile()->subsetByCId($g); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub subvec { |
130
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
131
|
|
|
|
|
|
|
|
132
|
0
|
0
|
|
|
|
|
return 1 if $self->iscff(); |
133
|
0
|
|
|
|
|
|
my $g = shift; |
134
|
0
|
|
|
|
|
|
return $self->fontfile()->subvec($g); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub glyphNum { |
138
|
0
|
|
|
0
|
1
|
|
return $_[0]->fontfile()->glyphNum(); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub outobjdeep { |
142
|
0
|
|
|
0
|
1
|
|
my ($self, $fh, $pdf) = @_; |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
my $notdefbefore = 1; |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
my $wx = PDFArray(); |
147
|
0
|
|
|
|
|
|
$self->{' de'}->{'W'} = $wx; |
148
|
0
|
|
|
|
|
|
my $ml; |
149
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
|
foreach my $w (0 .. (scalar @{$self->data()->{'g2u'}} - 1 )) { |
|
0
|
|
|
|
|
|
|
151
|
0
|
0
|
0
|
|
|
|
if ($self->subvec($w) && $notdefbefore == 1) { |
|
|
0
|
0
|
|
|
|
|
152
|
0
|
|
|
|
|
|
$notdefbefore = 0; |
153
|
0
|
|
|
|
|
|
$ml = PDFArray(); |
154
|
0
|
|
|
|
|
|
$wx->add_elements(PDFNum($w), $ml); |
155
|
|
|
|
|
|
|
# $ml->add_elements(PDFNum($self->data()->{'wx'}->[$w])); |
156
|
0
|
|
|
|
|
|
$ml->add_elements(PDFNum($self->wxByCId($w))); |
157
|
|
|
|
|
|
|
} elsif ($self->subvec($w) && $notdefbefore == 0) { |
158
|
0
|
|
|
|
|
|
$notdefbefore = 0; |
159
|
|
|
|
|
|
|
# $ml->add_elements(PDFNum($self->data()->{'wx'}->[$w])); |
160
|
0
|
|
|
|
|
|
$ml->add_elements(PDFNum($self->wxByCId($w))); |
161
|
|
|
|
|
|
|
} else { |
162
|
0
|
|
|
|
|
|
$notdefbefore = 1; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
# optimization for CJK |
165
|
|
|
|
|
|
|
#if ($self->subvec($w) && $notdefbefore == 1 && $self->data()->{'wx'}->[$w] != $self->missingwidth()) { |
166
|
|
|
|
|
|
|
# $notdefbefore = 0; |
167
|
|
|
|
|
|
|
# $ml = PDFArray(); |
168
|
|
|
|
|
|
|
# $wx->add_elements(PDFNum($w), $ml); |
169
|
|
|
|
|
|
|
# $ml->add_elements(PDFNum($self->data()->{'wx'}->[$w])); |
170
|
|
|
|
|
|
|
#} elsif ($self->subvec($w) && $notdefbefore == 0 && $self->data()->{'wx'}->[$w] != $self->missingwidth()) { |
171
|
|
|
|
|
|
|
# $notdefbefore = 0; |
172
|
|
|
|
|
|
|
# $ml->add_elements(PDFNum($self->data()->{'wx'}->[$w])); |
173
|
|
|
|
|
|
|
#} else { |
174
|
|
|
|
|
|
|
# $notdefbefore = 1; |
175
|
|
|
|
|
|
|
#} |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
0
|
|
|
|
|
|
return $self->SUPER::outobjdeep($fh, $pdf); |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=back |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=cut |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
1; |