API3/Compat/API2/Resource/CIDFont/TrueType.pm

filter: Statementstmt 31.1% 33 / 106 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 50.0% 11 / 22 Podpod 36.3% 4 / 11 totaltotal 25.6% 48 / 187 CC 21 SCAR 40.1
CC
21
Cov
22%
new
156.0
outobjdeep
56.0
wxByCId
6.0
CRAP 55.3
« API3/Compat/API2/Basic/PDF/Filter.pm ↑ Summary API3/Compat/API2/Resource/ColorSpace/Indexed/WebColor.pm »
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 <areibens@cpan.org>.
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 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
36
37 1 ▶ use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 ▶ use Encode qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
39
40 1 ▶ use PDF::API3::Compat::API2::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 ▶ use PDF::API3::Compat::API2::Basic::PDF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 1 ▶ use PDF::API3::Compat::API2::Resource::CIDFont;
Subroutine BEGIN: called CC=1 SCAR=0.0
43
44 1 ▶ use PDF::API3::Compat::API2::Basic::TTF::Font;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 1 ▶ use PDF::API3::Compat::API2::Resource::CIDFont::TrueType::FontFile;
Subroutine BEGIN: called CC=1 SCAR=0.0
46
47 1 ▶ use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
48
49 1 ▶ use vars qw(@ISA $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
50
51 1 @ISA = qw( PDF::API3::Compat::API2::Resource::CIDFont );
52
53 1 ( $VERSION ) = sprintf '%i.%03i', split(/\./,('$Revision: 2.5 $' =~ /Revision: (\S+)\s/)[0]); # $Date: 2009/03/20 09:54:46 $
54
55 }
56 1 ▶no warnings qw[ deprecated recursion uninitialized ];
Subroutine BEGIN: called CC=1 SCAR=0.0
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 0 ▶sub new {
Subroutine new: not called CC=12 SCAR=50.5
Pod documented
71 0 my ($class,$pdf,$file,@opts) = @_;
72 0 my %opts=();
73 0 ▶ %opts=@opts if((scalar @opts)%2 == 0);
Branch: 1 branch
BranchTrueFalseTotal
if scalar(@opts) % 2 == 0 0 0 0
74 0 ▶ $opts{-encode}||='latin1';
Condition0%0/2
$opts{"-encode"} ||= "latin1"
l!l
00
MC/DC0%0/1
$opts{"-encode"} ||= "latin1"
$opts{"-encode"}
Truth table0%0/2
A
A= $opts{"-encode"}
Aresult
11
00
75 0 my ($ff,$data)=PDF::API3::Compat::API2::Resource::CIDFont::TrueType::FontFile->new($pdf,$file,@opts);
76
77 0 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
78 0 my $self=$class->SUPER::new($pdf,$data->{apiname}.pdfkey().'~'.time());
79 0 ▶ $pdf->new_obj($self) if(defined($pdf) && !$self->is_obj($pdf));
Branch: 1 branch
BranchTrueFalseTotal
if defined $pdf and not $self->is_obj($pdf) 0 0 0
Condition0%0/3
defined $pdf and not $self->is_obj($pdf)
!ll&&!rl&&r
000
MC/DC0%0/2
defined $pdf and not $self->is_obj($pdf)
defined $pdf not $self->is_obj($pdf)
Truth table0%0/3
A and not(B)
A= defined $pdfB= not $self->is_obj($pdf)
ABresult
0X0
100
111
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 ▶ $de->{'Subtype'} = PDFName($self->iscff ? 'CIDFontType0' : 'CIDFontType2');
Branch: 1 branch
BranchTrueFalseTotal
$self->iscff ? : 0 0 0
91 ## $de->{'BaseFont'} = PDFName(pdfkey().'+'.($self->fontname).'~'.time());
92 0 $de->{'BaseFont'} = PDFName($self->fontname);
93 0 $de->{'DW'} = PDFNum($self->missingwidth);
94 0 ▶ if($opts{-noembed} != 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"-noembed"} != 1) 0 0 0
95 {
96 0 ▶ $des->{$self->data->{iscff} ? 'FontFile3' : 'FontFile2'}=$ff;
Branch: 1 branch
BranchTrueFalseTotal
$self->data->{'iscff'} ? : 0 0 0
97 }
98 0 ▶ unless($self->issymbol) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->issymbol) 0 0 0
99 0 $self->encodeByName($opts{-encode});
100 0 $self->data->{encode}=$opts{-encode};
101 0 $self->data->{decode}='ident';
102 }
103
104 0 ▶ if($opts{-nosubset}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"-nosubset"}) 0 0 0
105 0 $self->data->{nosubset}=1;
106 }
107
108
109 0 $self->{' ff'} = $ff;
110 0 $pdf->new_obj($ff);
111
112 0 ▶ $self->{-dokern}=1 if($opts{-dokern});
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"-dokern"} 0 0 0
113
114 0 return($self);
115 }
116
117
118 0 ▶sub fontfile { return( $_[0]->{' ff'} ); }
Subroutine fontfile: not called CC=1 SCAR=6.9
Pod undocumented
119 0 ▶sub fontobj { return( $_[0]->data->{obj} ); }
Subroutine fontobj: not called CC=1 SCAR=6.9
Pod undocumented
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 0 ▶{
Subroutine new_api: not called CC=1 SCAR=6.9
Pod documented
130 0 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 0 ▶{
Subroutine wxByCId: not called CC=2 SCAR=17.9
Pod undocumented
141 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 ▶ if(defined $t)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $t) { } 0 0 0
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 0 ▶{
Subroutine haveKernPairs: not called CC=1 SCAR=6.9
Pod undocumented
160 0 my $self = shift @_;
161 0 return($self->fontfile->haveKernPairs(@_));
162 }
163
164 sub kernPairCid
165 0 ▶{
Subroutine kernPairCid: not called CC=1 SCAR=6.9
Pod undocumented
166 0 my $self = shift @_;
167 0 return($self->fontfile->kernPairCid(@_));
168 }
169
170 sub subsetByCId
171 0 ▶{
Subroutine subsetByCId: not called CC=2 SCAR=17.9
Pod undocumented
172 0 my $self = shift @_;
173 0 ▶ return if($self->iscff);
Branch: 1 branch
BranchTrueFalseTotal
if $self->iscff 0 0 0
174 0 my $g = shift @_;
175 0 $self->fontfile->subsetByCId($g);
176 }
177 sub subvec
178 0 ▶{
Subroutine subvec: not called CC=2 SCAR=17.9
Pod undocumented
179 0 my $self = shift @_;
180 0 ▶ return(1) if($self->iscff);
Branch: 1 branch
BranchTrueFalseTotal
if $self->iscff 0 0 0
181 0 my $g = shift @_;
182 0 $self->fontfile->subvec($g);
183 }
184
185 0 ▶sub glyphNum { return ( $_[0]->fontfile->glyphNum ); }
Subroutine glyphNum: not called CC=1 SCAR=6.9
Pod documented
186
187 sub outobjdeep
188 0 ▶{
Subroutine outobjdeep: not called CC=7 SCAR=40.3
Pod documented
189 0 my ($self, $fh, $pdf, %opts) = @_;
190
191 0 ▶ return $self->SUPER::outobjdeep($fh, $pdf) if defined $opts{'passthru'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts{"passthru"} 0 0 0
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 ))
200 {
201 0 ▶ if($self->subvec($w) && $notdefbefore==1)
Branch: 2 branches
BranchTrueFalseTotal
if ($self->subvec($w) and $notdefbefore == 1) { } 0 0 0
elsif ($self->subvec($w) and $notdefbefore == 0) { } 0 0 0
Condition0%0/3
$self->subvec($w) and $notdefbefore == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$self->subvec($w) and $notdefbefore == 1
$self->subvec($w) $notdefbefore == 1
Truth table0%0/3
A and B
A= $self->subvec($w)B= $notdefbefore == 1
ABresult
0X0
100
111
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)
Condition0%0/3
$self->subvec($w) and $notdefbefore == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$self->subvec($w) and $notdefbefore == 0
$self->subvec($w) $notdefbefore == 0
Truth table0%0/3
A and B
A= $self->subvec($w)B= $notdefbefore == 0
ABresult
0X0
100
111
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 1;
238
239 __END__
« API3/Compat/API2/Basic/PDF/Filter.pm ↑ Summary API3/Compat/API2/Resource/ColorSpace/Indexed/WebColor.pm »