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