API3/Compat/API2/Resource/Font/Postscript.pm

filter: Statementstmt 12.8% 36 / 280 Branchbran 0.0% 0 / 104 Conditioncond 0.0% 0 / 38 MC/DCmcdc 0.0% 0 / 22 Subroutinesub 66.6% 12 / 18 Podpod 33.3% 2 / 6 totaltotal 10.6% 50 / 468 CC 71 SCAR 61.6
CC
71
Cov
9%
readAFM
1056.0
readPFM
240.0
readPFAPFB
210.0
CRAP 475.2
« API3/Compat/API2/Basic/TTF/Glyph.pm ↑ Summary API3/Compat/API2/Basic/TTF/OldMort.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: Postscript.pm,v 2.2 2007/06/27 20:54:16 areibens Exp $
31 #
32 #=======================================================================
33 package PDF::API3::Compat::API2::Resource::Font::Postscript;
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 1 ▶ use PDF::API3::Compat::API2::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 1 ▶ use PDF::API3::Compat::API2::Basic::PDF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 ▶ use PDF::API3::Compat::API2::Resource::Font;
Subroutine BEGIN: called CC=1 SCAR=0.0
42
43 1 ▶ use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 1 ▶ use Compress::Zlib;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 1 ▶ use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 1 ▶ use IO::File qw();
Subroutine BEGIN: called CC=1 SCAR=0.0
47 1 ▶ use vars qw(@ISA $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
48
49 1 @ISA = qw( PDF::API3::Compat::API2::Resource::Font );
50
51 1 ( $VERSION ) = sprintf '%i.%03i', split(/\./,('$Revision: 2.2 $' =~ /Revision: (\S+)\s/)[0]); # $Date: 2007/06/27 20:54:16 $
52
53 }
54 1 ▶no warnings qw[ deprecated recursion uninitialized ];
Subroutine BEGIN: called CC=1 SCAR=0.0
55
56 =item $font = PDF::API3::Compat::API2::Resource::Font::Postscript->new @parameters
57
58 Returns a adobe type1 font object (called from $pdf->psfont).
59
60 =cut
61
62 0 ▶sub new {
Subroutine new: not called CC=11 SCAR=48.8
Pod documented
63 0 my ($class, $pdf, $psfile, %opts) = @_;
64 0 my ($self,$encoding);
65 0 my (@w,$data);
66
67 0 ▶ if(defined $opts{-afmfile}) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $opts{'-afmfile'}) { } 0 0 0
elsif (defined $opts{'-pfmfile'}) { } 0 0 0
elsif (defined $opts{'-xfmfile'}) { } 0 0 0
68 0 $data = $class->readAFM($opts{-afmfile});
69 } elsif(defined $opts{-pfmfile}) {
70 0 $data = $class->readPFM($opts{-pfmfile});
71 } elsif(defined $opts{-xfmfile}) {
72 0 $data = $class->readXFM($opts{-xfmfile});
73 } else {
74 0 die "no proper font-metrics file specified for '$psfile'.";
75 }
76
77 0 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
78 0 $self = $class->SUPER::new($pdf, $data->{apiname}.pdfkey().'~'.time());
79 0 ▶ $pdf->new_obj($self) unless($self->is_obj($pdf));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_obj($pdf) 0 0 0
80 0 $self->{' data'}=$data;
81
82 0 ▶ if($opts{-pdfname}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"-pdfname"}) 0 0 0
83 0 $self->name($opts{-pdfname});
84 }
85
86 0 $self->{'Subtype'} = PDFName("Type1");
87 0 $self->{'FontDescriptor'}=$self->descrByData();
88 0 ▶ if(-f $psfile)
Branch: 1 branch
BranchTrueFalseTotal
if (-f $psfile) { } 0 0 0
89 {
90 0 $self->{'BaseFont'} = PDFName(pdfkey().'+'.($self->fontname).'~'.time());
91
92 0 my ($l1,$l2,$l3,$stream)=$self->readPFAPFB($psfile);
93
94 0 my $s = PDFDict();
95 0 $self->{'FontDescriptor'}->{'FontFile'} = $s;
96 0 $s->{'Length1'} = PDFNum($l1);
97 0 $s->{'Length2'} = PDFNum($l2);
98 0 $s->{'Length3'} = PDFNum($l3);
99 0 $s->{'Filter'} = PDFArray(PDFName("FlateDecode"));
100 0 $s->{' stream'} = $stream;
101 0 ▶ if(defined $pdf) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pdf) 0 0 0
102 0 $pdf->new_obj($s);
103 }
104 }
105 else
106 {
107 0 $self->{'BaseFont'} = PDFName($self->fontname);
108 }
109
110 0 $self->encodeByData($opts{-encode});
111
112 0 ▶ $self->{-nocomps}=1 if($opts{-nocomps});
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"-nocomps"} 0 0 0
113 0 ▶ $self->{-dokern}=1 if($opts{-dokern});
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"-dokern"} 0 0 0
114
115 0 return($self);
116 }
117
118 0 ▶sub new_api {
Subroutine new_api: not called CC=2 SCAR=17.9
Pod documented
119 0 my ($class, $api, @para) = @_;
120
121 0 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
122 0 my $self = $class->new($api->{pdf},@para);
123
124 0 $self->{' apipdf'}=$api->{pdf};
125 0 $self->{' api'}=$api;
126
127 0 return($self);
128 }
129
130 0 ▶sub readPFAPFB {
Subroutine readPFAPFB: not called CC=14 SCAR=53.5
Pod undocumented
131 0 my ($self,$file) = @_;
132 0 my ($l1,$l2,$l3,$stream,$t1stream,@lines,$line,$head,$body,$tail);
133
134 0 ▶ die "cannot find font '$file' ..." unless(-f $file);
Branch: 1 branch
BranchTrueFalseTotal
unless -f $file 0 0 0
135
136 0 $l=-s $file;
137
138 0 open(INF,$file);
139 0 binmode(INF,':raw');
140 0 read(INF,$line,2);
141 0 @lines=unpack('C*',$line);
142 0 ▶ if(($lines[0]==0x80) && ($lines[1]==1)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($lines[0] == 128 and $lines[1] == 1) { } 0 0 0
elsif ($line eq '%!') { } 0 0 0
Condition0%0/3
$lines[0] == 128 and $lines[1] == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$lines[0] == 128 and $lines[1] == 1
$lines[0] == 128 $lines[1] == 1
Truth table0%0/3
A and B
A= $lines[0] == 128B= $lines[1] == 1
ABresult
0X0
100
111
143 0 read(INF,$line,4);
144 0 $l1=unpack('V',$line);
145 0 seek(INF,$l1,1);
146 0 read(INF,$line,2);
147 0 @lines=unpack('C*',$line);
148 0 ▶ if(($lines[0]==0x80) && ($lines[1]==2)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lines[0] == 128 and $lines[1] == 2) { } 0 0 0
Condition0%0/3
$lines[0] == 128 and $lines[1] == 2
!ll&&!rl&&r
000
MC/DC0%0/2
$lines[0] == 128 and $lines[1] == 2
$lines[0] == 128 $lines[1] == 2
Truth table0%0/3
A and B
A= $lines[0] == 128B= $lines[1] == 2
ABresult
0X0
100
111
149 0 read(INF,$line,4);
150 0 $l2=unpack('V',$line);
151 } else {
152 0 die "corrupt pfb in file '$file' at marker='2'.";
153 }
154 0 seek(INF,$l2,1);
155 0 read(INF,$line,2);
156 0 @lines=unpack('C*',$line);
157 0 ▶ if(($lines[0]==0x80) && ($lines[1]==1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lines[0] == 128 and $lines[1] == 1) { } 0 0 0
Condition0%0/3
$lines[0] == 128 and $lines[1] == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$lines[0] == 128 and $lines[1] == 1
$lines[0] == 128 $lines[1] == 1
Truth table0%0/3
A and B
A= $lines[0] == 128B= $lines[1] == 1
ABresult
0X0
100
111
158 0 read(INF,$line,4);
159 0 $l3=unpack('V',$line);
160 } else {
161 0 die "corrupt pfb in file '$file' at marker='3'.";
162 }
163 0 seek(INF,0,0);
164 0 @lines=<INF>;
165 0 close(INF);
166 0 $stream=join('',@lines);
167 0 $t1stream=substr($stream,6,$l1);
168 0 $t1stream.=substr($stream,12+$l1,$l2);
169 0 $t1stream.=substr($stream,18+$l1+$l2,$l3);
170 } elsif($line eq '%!') {
171 0 seek(INF,0,0);
172 0 ▶ while($line=<INF>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline INF)) 0 0 0
173 0 ▶ if(!$l1) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $l1) { } 0 0 0
elsif (not $l2) { } 0 0 0
174 0 $head.=$line;
175 0 ▶ if($line=~/eexec$/){
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /eexec$/) 0 0 0
176 0 chomp($head);
177 0 $head.="\x0d";
178 0 $l1=length($head);
179 }
180 } elsif(!$l2) {
181 0 ▶ if($line=~/^0+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^0+$/) { } 0 0 0
182 0 $l2=length($body);
183 0 $tail=$line;
184 } else {
185 0 chomp($line);
186 0 $body.=pack('H*',$line);
187 }
188 } else {
189 0 $tail.=$line;
190 }
191 }
192 0 $l3=length($tail);
193 0 $t1stream="$head$body$tail";
194 } else {
195 0 die "unsupported font-format in file '$file' at marker='1'.";
196 }
197
198 0 return($l1,$l2,$l3,$t1stream);
199 }
200
201
202 # $datahashref = $self->readAFM( $afmfile );
203
204 sub readAFM
205 0 ▶{
Subroutine readAFM: not called CC=32 SCAR=69.6
Pod undocumented
206 0 my ($self,$file)=@_;
207 0 my $data={};
208 0 $data->{wx}={};
209 0 $data->{bbox}={};
210 0 $data->{char}=[];
211 0 $data->{firstchar}=255;
212 0 $data->{lastchar}=0;
213
214 0 ▶ if(! -e $file) {die "file='$file' not existant.";}
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $file) 0 0 0
215 0 ▶ open(AFMF, $file) or die "Can't find the AFM file for $file";
Branch: 1 branch
BranchTrueFalseTotal
open AFMF, $file or die "Can't find the AFM file for $file" 0 0 0
216 0 local($/, $_) = ("\n", undef); # ensure correct $INPUT_RECORD_SEPARATOR
217 0 ▶ while ($_=<AFMF>)
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline AFMF)) 0 0 0
218 {
219 0 ▶ if (/^StartCharMetrics/ .. /^EndCharMetrics/)
Branch: 3 branches
BranchTrueFalseTotal
if (/^StartCharMetrics/ .. /^EndCharMetrics/) { } 0 0 0
elsif (/^StartKernData/ .. /^EndKernData/) { } 0 0 0
elsif (/^StartComposites/ .. /^EndComposites/) { } 0 0 0
220 {
221 # only lines that start with "C" or "CH" are parsed
222 0 ▶ next unless $_=~/^CH?\s/;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ =~ /^CH?\s/ 0 0 0
223 0 my($ch) = $_=~/^CH?\s+(\d+)\s*;/;
224 0 ▶ $ch=$ch||0;
Condition0%0/2
$ch || 0
l!l
00
MC/DC0%0/1
$ch || 0
$ch
Truth table0%0/2
A
A= $ch
Aresult
11
00
225 0 my($name) = $_=~/\bN\s+(\.?\w+)\s*;/;
226 0 my($wx) = $_=~/\bWX\s+(\d+)\s*;/;
227 0 my($bbox) = $_=~/\bB\s+([^;]+);/;
228 0 $bbox =~ s/\s+$//;
229 # Should also parse lingature data (format: L successor lignature)
230 0 $data->{avgwidth2} += $wx ;
231 0 ▶ $data->{maxwidth} = $data->{maxwidth}<$wx ? $wx : $data->{maxwidth};
Branch: 1 branch
BranchTrueFalseTotal
$data->{'maxwidth'} < $wx ? : 0 0 0
232 0 $data->{wx}->{$name} = $wx ;
233 0 $data->{bbox}->{$name} = [split(/\s+/,$bbox)];
234 0 ▶ if($ch>0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ch > 0) 0 0 0
235 0 $data->{'char'}->[$ch]=$name ;
236 }
237 0 ▶ $data->{lastchar} = $data->{lastchar}<$ch ? $ch : $data->{lastchar};
Branch: 1 branch
BranchTrueFalseTotal
$data->{'lastchar'} < $ch ? : 0 0 0
238 0 ▶ $data->{firstchar} = $data->{firstchar}>$ch ? $ch : $data->{firstchar};
Branch: 1 branch
BranchTrueFalseTotal
$data->{'firstchar'} > $ch ? : 0 0 0
239 0 next;
240 }
241 elsif(/^StartKernData/ .. /^EndKernData/)
242 {
243 0 ▶ $data->{kern}||={};
Condition0%0/2
$data->{"kern"} ||= {}
l!l
00
MC/DC0%0/1
$data->{"kern"} ||= {}
$data->{"kern"}
Truth table0%0/2
A
A= $data->{"kern"}
Aresult
11
00
244 0 ▶ if($_=~m|^KPX\s+(\S+)\s+(\S+)\s+(\S+)\s*$|i)
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^KPX\s+(\S+)\s+(\S+)\s+(\S+)\s*$/i) 0 0 0
245 {
246 0 $data->{kern}->{"$1:$2"}=$3;
247 }
248 }
249 elsif(/^StartComposites/ .. /^EndComposites/)
250 {
251 0 ▶ $data->{comps}||={};
Condition0%0/2
$data->{"comps"} ||= {}
l!l
00
MC/DC0%0/1
$data->{"comps"} ||= {}
$data->{"comps"}
Truth table0%0/2
A
A= $data->{"comps"}
Aresult
11
00
252 0 ▶ if($_=~m|^CC\s+(\S+)\s+(\S+)\s+;|i)
Branch: 1 branch
BranchTrueFalseTotal
if ($_ =~ /^CC\s+(\S+)\s+(\S+)\s+;/i) 0 0 0
253 {
254 0 my ($name,$comp)=($1,$2);
255 0 my @cv=split(/;/,$_);
256 0 shift @cv;
257 0 my $rng=[];
258 0 foreach (1..$comp)
259 {
260 0 my @c1=split(/\s+/,shift @cv);
261 0 push @{$rng},$c1[1],$c1[2],$c1[3];
262 }
263 0 $data->{comps}->{$name}=$rng;
264 }
265 }
266 0 ▶ last if $_=~/^EndFontMetrics/;
Branch: 1 branch
BranchTrueFalseTotal
if $_ =~ /^EndFontMetrics/ 0 0 0
267 0 ▶ if (/(^\w+)\s+(.*)/)
Branch: 1 branch
BranchTrueFalseTotal
if (/(^\w+)\s+(.*)/) { } 0 0 0
268 {
269 0 my($key,$val) = ($1, $2);
270 0 $key = lc $key;
271 0 ▶ if (defined $data->{$key})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data->{$key}) { } 0 0 0
272 {
273 # $data->{$key} = [ $data->{$key} ] unless ref $data->{$key};
274 # push(@{$data->{$key}}, $val);
275 }
276 else
277 {
278 0 $val=~s/[\x00\x1f]+//g;
279 0 $data->{$key} = $val;
280 }
281 }
282 else
283 {
284 ## print STDERR "Can't parse: $_";
285 }
286 }
287 0 close(AFMF);
288 0 ▶ unless (exists $data->{wx}->{'.notdef'})
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $data->{"wx"}{".notdef"}) 0 0 0
289 {
290 0 $data->{wx}->{'.notdef'} = 0;
291 0 $data->{bbox}{'.notdef'} = [0, 0, 0, 0];
292 }
293
294 0 $data->{avgwidth2} /= scalar keys %{$data->{bbox}} ;
295 0 $data->{avgwidth2} = int($data->{avgwidth2});
296
297 0 $data->{fontname}=~s/[\x00-\x20]+//og;
298 ## $data->{fontname}=~s/[^A-Za-z0-9]+//og;
299
300 0 ▶ if(defined $data->{fullname})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data->{'fullname'}) { } 0 0 0
301 {
302 0 $data->{altname}=$data->{fullname};
303 }
304 else
305 {
306 0 $data->{altname}=$data->{familyname};
307 0 ▶ $data->{altname}.=' Italic' if($data->{italicangle}<0);
Branch: 1 branch
BranchTrueFalseTotal
if $data->{"italicangle"} < 0 0 0 0
308 0 ▶ $data->{altname}.=' Oblique' if($data->{italicangle}>0);
Branch: 1 branch
BranchTrueFalseTotal
if $data->{"italicangle"} > 0 0 0 0
309 0 $data->{altname}.=' '.$data->{weight};
310 }
311 0 $data->{apiname}=$data->{altname};
312 0 $data->{altname}=~s/[^A-Za-z0-9]+//og;
313
314 0 $data->{subname}=$data->{weight};
315 0 ▶ $data->{subname}.=' Italic' if($data->{italicangle}<0);
Branch: 1 branch
BranchTrueFalseTotal
if $data->{"italicangle"} < 0 0 0 0
316 0 ▶ $data->{subname}.=' Oblique' if($data->{italicangle}>0);
Branch: 1 branch
BranchTrueFalseTotal
if $data->{"italicangle"} > 0 0 0 0
317 0 $data->{subname}=~s/[^A-Za-z0-9]+//og;
318
319 0 ▶ $data->{missingwidth}||=$data->{avgwidth2};
Condition0%0/3
$data->{"missingwidth"} ||= $data->{"avgwidth2"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$data->{"missingwidth"} ||= $data->{"avgwidth2"}
$data->{"missingwidth"} $data->{"avgwidth2"}
Truth table0%0/3
A ||= B
A= $data->{"missingwidth"}B= $data->{"avgwidth2"}
ABresult
1X1
011
000
320
321 0 $data->{issymbol} = 0;
322 0 $data->{fontbbox} = [ split(/\s+/,$data->{fontbbox}) ];
323
324 0 $data->{apiname}=join('',map { $_=~s/[^A-Za-z0-9]+//og; $_=ucfirst(lc(substr($_,0,2))); $_; } split(/\s+/,$data->{apiname}));
325
326 0 $data->{flags} = 34;
327
328 0 ▶ $data->{uni}||=[];
Condition0%0/2
$data->{"uni"} ||= []
l!l
00
MC/DC0%0/1
$data->{"uni"} ||= []
$data->{"uni"}
Truth table0%0/2
A
A= $data->{"uni"}
Aresult
11
00
329 0 foreach my $n (0..255)
330 {
331 0 ▶ $data->{uni}->[$n]=uniByName($data->{char}->[$n] || '.notdef') || 0;
Condition0%0/4
uniByName($data->{'char'}[$n] || '.notdef') || 0
l!l
00
$data->{'char'}[$n] || '.notdef'
l!l
00
MC/DC0%0/1
uniByName($data->{'char'}[$n] || '.notdef') || 0
uniByName($data->{'char'}[$n] || '.notdef')
MC/DC0%0/1
$data->{'char'}[$n] || '.notdef'
$data->{'char'}[$n]
Truth table0%0/2
A
A= uniByName($data->{'char'}[$n] || '.notdef')
Aresult
11
00
Truth table0%0/2
A
A= $data->{'char'}[$n]
Aresult
11
00
332 }
333 0 delete $data->{bbox};
334
335 0 return($data);
336 }
337
338 0 ▶sub readPFM {
Subroutine readPFM: not called CC=15 SCAR=54.8
Pod undocumented
339 0 my ($self,$file)=@_;
340 0 ▶ if(! -e $file) {die "pfmfile='$file' not existant.";}
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $file) 0 0 0
341 0 my $fh=IO::File->new();
342 0 my $data={};
343
344 0 $data->{issymbol} = 0;
345
346 0 $data->{wx}={};
347 0 $data->{bbox}={};
348 0 $data->{kern}={};
349 0 $data->{char}=[];
350
351 0 my $buf;
352 0 ▶ open($fh,$file) || return undef;
Branch: 1 branch
BranchTrueFalseTotal
open $fh, $file or return undef 0 0 0
353 0 binmode($fh,':raw');
354 0 read($fh,$buf,117 + 30);
355
356 0 my %df;
357 # Packing structure for PFM Header
358 ( $df{Version},
359 $df{Size},
360 $df{Copyright},
361 $df{Type},
362 $df{Point},
363 $df{VertRes},
364 $df{HorizRes},
365 $df{Ascent},
366 $df{InternalLeading},
367 $df{ExternalLeading},
368 $df{Italic},
369 $df{Underline},
370 $df{StrikeOut},
371 $df{Weight},
372 #define FW_DONTCARE 0
373 #define FW_THIN 100
374 #define FW_EXTRALIGHT 200
375 #define FW_ULTRALIGHT FW_EXTRALIGHT
376 #define FW_LIGHT 300
377 #define FW_NORMAL 400
378 #define FW_REGULAR 400
379 #define FW_MEDIUM 500
380 #define FW_SEMIBOLD 600
381 #define FW_DEMIBOLD FW_SEMIBOLD
382 #define FW_BOLD 700
383 #define FW_EXTRABOLD 800
384 #define FW_ULTRABOLD FW_EXTRABOLD
385 #define FW_HEAVY 900
386 #define FW_BLACK FW_HEAVY
387 $df{CharSet},
388 #define ANSI_CHARSET 0
389 #define DEFAULT_CHARSET 1
390 #define SYMBOL_CHARSET 2
391 #define SHIFTJIS_CHARSET 128
392 #define HANGEUL_CHARSET 129
393 #define HANGUL_CHARSET 129
394 #define GB2312_CHARSET 134
395 #define CHINESEBIG5_CHARSET 136
396 #define GREEK_CHARSET 161
397 #define TURKISH_CHARSET 162
398 #define HEBREW_CHARSET 177
399 #define ARABIC_CHARSET 178
400 #define BALTIC_CHARSET 186
401 #define RUSSIAN_CHARSET 204
402 #define THAI_CHARSET 222
403 #define EASTEUROPE_CHARSET 238
404 #define OEM_CHARSET 255
405 #define JOHAB_CHARSET 130
406 #define VIETNAMESE_CHARSET 163
407 #define MAC_CHARSET 77
408 #define BALTIC_CHARSET 186
409 #define JOHAB_CHARSET 130
410 #define VIETNAMESE_CHARSET 163
411 $df{PixWidth},
412 $df{PixHeight},
413 $df{PitchAndFamily},
414 #define DEFAULT_PITCH 0
415 #define FIXED_PITCH 1
416 #define VARIABLE_PITCH 2
417 #define MONO_FONT 8
418 #define FF_DECORATIVE 80
419 #define FF_DONTCARE 0
420 #define FF_MODERN 48
421 #define FF_ROMAN 16
422 #define FF_SCRIPT 64
423 #define FF_SWISS 32
424 $df{AvgWidth},
425 $df{MaxWidth},
426 $df{FirstChar},
427 $df{LastChar},
428 $df{DefaultChar},
429 $df{BreakChar},
430 $df{WidthBytes},
431 $df{Device},
432 $df{Face},
433 $df{BitsPointer},
434 $df{BitsOffset},
435 $df{SizeFields}, # Two bytes, the size of extension section
436 $df{ExtMetricsOffset}, # Four bytes, offset value to the 'Extended Text Metrics' section
437 $df{ExtentTable}, # Four bytes Offset value to the Extent Table
438 $df{OriginTable}, # Four bytes 0
439 $df{PairKernTable}, # Four bytes 0
440 $df{TrackKernTable}, # Four bytes 0
441 $df{DriverInfo}, # Four bytes Offset value to the PostScript font name string
442 $df{Reserved}, # Four bytes 0
443 0 ) = unpack("vVa60vvvvvvvCCCvCvvCvvCCCCvVVVV vVVVVVVV",$buf); # PFM Header + Ext
444
445 0 seek($fh,$df{Device},0);
446 0 read($fh,$buf,250);
447
448 0 ($df{postScript}) = unpack("Z*",$buf);
449 0 $buf=substr($buf,length($df{postScript})+1,250);
450 0 ($df{windowsName}) = unpack("Z*",$buf);
451 0 $buf=substr($buf,length($df{windowsName})+1,250);
452 0 ($df{psName}) = unpack("Z*",$buf);
453
454 0 seek($fh,$df{ExtMetricsOffset},0);
455 0 read($fh,$buf,52);
456
457 ( $df{etmSize},
458 $df{PointSize},
459 $df{Orientation},
460 $df{MasterHeight},
461 $df{MinScale},
462 $df{MaxScale},
463 $df{MasterUnits},
464 $df{CapHeight},
465 $df{xHeight},
466 $df{LowerCaseAscent},
467 $df{LowerCaseDescent},
468 $df{Slant},
469 $df{SuperScript},
470 $df{SubScript},
471 $df{SuperScriptSize},
472 $df{SubScriptSize},
473 $df{UnderlineOffset},
474 $df{UnderlineWidth},
475 $df{DoubleUpperUnderlineOffset},
476 $df{DoubleLowerUnderlineOffset},
477 $df{DoubleUpperUnderlineWidth},
478 $df{DoubleLowerUnderlineWidth},
479 $df{StrikeOutOffset},
480 $df{StrikeOutWidth},
481 $df{KernPairs},
482 0 $df{KernTracks} ) = unpack('v*',$buf);
483
484 #use Data::Dumper;
485 # print STDERR Dumper(\%df);
486 0 $data->{fontname}=$df{psName};
487 0 $data->{fontname}=~s/[^A-Za-z0-9]+//og;
488 0 $data->{apiname}=$df{windowsName};
489 0 $data->{apiname}=join('',map { $_=~s/[^A-Za-z0-9]+//og; $_=ucfirst(lc(substr($_,0,2))); $_; } split(/\s+/,$data->{apiname}));
490
491 0 $data->{upem}=1000;
492
493 0 $data->{fontbbox}=[-100,-100,$df{MaxWidth},$df{Ascent}];
494
495 0 $data->{stemv}=0;
496 0 $data->{stemh}=0;
497
498 0 $data->{lastchar}=$df{LastChar};
499 0 $data->{firstchar}=$df{FirstChar};
500
501 0 $data->{missingwidth}=$df{AvgWidth};
502 0 $data->{maxwidth}=$df{MaxWidth};
503 0 $data->{ascender}=$df{Ascent};
504 0 $data->{descender}=-$df{LowerCaseDescent};
505
506 0 $data->{flags} = 0;
507 # FixedPitch 1
508 0 ▶ $data->{flags} |= 1 if((($df{PitchAndFamily} & 1) || ($df{PitchAndFamily} & 8)) && !($df{PitchAndFamily} & 2));
Branch: 1 branch
BranchTrueFalseTotal
if $df{"PitchAndFamily"} & 1 || $df{"PitchAndFamily"} & 8 and not $df{"PitchAndFamily"} & 2 0 0 0
Condition0%0/6
$df{"PitchAndFamily"} & 1 || $df{"PitchAndFamily"} & 8 and not $df{"PitchAndFamily"} & 2
!ll&&!rl&&r
000
$df{"PitchAndFamily"} & 1 or $df{"PitchAndFamily"} & 8
l!l&&r!l&&!r
000
MC/DC0%0/3
$df{"PitchAndFamily"} & 1 || $df{"PitchAndFamily"} & 8 and not $df{"PitchAndFamily"} & 2
$df{"PitchAndFamily"} & 1 $df{"PitchAndFamily"} & 8 not $df{"PitchAndFamily"} & 2
Truth table0%0/5
A or B and not(C)
A= $df{"PitchAndFamily"} & 1B= $df{"PitchAndFamily"} & 8C= not $df{"PitchAndFamily"} & 2
ABCresult
00X0
1X00
0100
1X11
0111
509 # Serif 2
510 0 ▶ $data->{flags} |= 2 if(($df{PitchAndFamily} & 16) && !($df{PitchAndFamily} & 32));
Branch: 1 branch
BranchTrueFalseTotal
if $df{"PitchAndFamily"} & 16 and not $df{"PitchAndFamily"} & 32 0 0 0
Condition0%0/3
$df{"PitchAndFamily"} & 16 and not $df{"PitchAndFamily"} & 32
!ll&&!rl&&r
000
MC/DC0%0/2
$df{"PitchAndFamily"} & 16 and not $df{"PitchAndFamily"} & 32
$df{"PitchAndFamily"} & 16 not $df{"PitchAndFamily"} & 32
Truth table0%0/3
A and not(B)
A= $df{"PitchAndFamily"} & 16B= not $df{"PitchAndFamily"} & 32
ABresult
0X0
100
111
511 # Symbolic 4
512 0 ▶ $data->{flags} |= 4 if($df{PitchAndFamily} & 80);
Branch: 1 branch
BranchTrueFalseTotal
if $df{"PitchAndFamily"} & 80 0 0 0
513 # Script 8
514 0 ▶ $data->{flags} |= 8 if($df{PitchAndFamily} & 64);
Branch: 1 branch
BranchTrueFalseTotal
if $df{"PitchAndFamily"} & 64 0 0 0
515 # Nonsymbolic 32
516 0 ▶ $data->{flags} |= 32 unless($df{PitchAndFamily} & 80);
Branch: 1 branch
BranchTrueFalseTotal
unless $df{"PitchAndFamily"} & 80 0 0 0
517 # Italic 64
518 0 ▶ $data->{flags} |= 64 if($df{Italic});
Branch: 1 branch
BranchTrueFalseTotal
if $df{"Italic"} 0 0 0
519
520 #bit 17 AllCap
521 #bit 18 SmallCap
522 #bit 19 ForceBold
523
524 0 $data->{capheight}=$df{CapHeight};
525 0 $data->{xheight}=$df{xHeight};
526
527 0 $data->{uni}=[ unpack('U*',decode('cp1252',pack('C*',(0..255)))) ];
528 0 ▶ $data->{char}=[ map { nameByUni($_) || '.notdef' } @{$data->{uni}} ];
Condition0%0/2
nameByUni($_) || '.notdef'
l!l
00
MC/DC0%0/1
nameByUni($_) || '.notdef'
nameByUni($_)
Truth table0%0/2
A
A= nameByUni($_)
Aresult
11
00
529
530 0 $data->{italicangle}=-12*$df{Italic};
531 0 ▶ $data->{isfixedpitch}=(($df{PitchAndFamily} & 8) || ($df{PitchAndFamily} & 1));
Condition0%0/3
$df{'PitchAndFamily'} & 8 || $df{'PitchAndFamily'} & 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$df{'PitchAndFamily'} & 8 || $df{'PitchAndFamily'} & 1
$df{'PitchAndFamily'} & 8 $df{'PitchAndFamily'} & 1
Truth table0%0/3
A || B
A= $df{'PitchAndFamily'} & 8B= $df{'PitchAndFamily'} & 1
ABresult
1X1
011
000
532 0 $data->{underlineposition}=-$df{UnderlineOffset};
533 0 $data->{underlinethickness}=$df{UnderlineWidth};
534
535 0 seek($fh,$df{ExtentTable},0);
536
537 0 foreach my $k ($df{FirstChar} .. $df{LastChar}) {
538 0 read($fh,$buf,2);
539 0 my ($wx)=unpack('v',$buf);
540 0 $data->{wx}->{$data->{char}->[$k]}=$wx;
541 # print STDERR "e: c=$k n='".$data->{char}->[$k]."' wx='$wx'\n";
542 }
543 0 $data->{pfm}=\%df;
544 0 close($fh);
545
546 0 return($data);
547 }
548
549 0 ▶sub readXFM {
Subroutine readXFM: not called CC=2 SCAR=17.9
Pod undocumented
550 0 my ($class,$xfmfile) = @_;
551 0 ▶ die "cannot find font '$xfmfile' ..." unless(-f $xfmfile);
Branch: 1 branch
BranchTrueFalseTotal
unless -f $xfmfile 0 0 0
552
553 0 my $data={};
554
555 0 return($data);
556 }
557
558
559 1 1;
560
561 __END__
« API3/Compat/API2/Basic/TTF/Glyph.pm ↑ Summary API3/Compat/API2/Basic/TTF/OldMort.pm »