blib/lib/Font/TFM.pm

filter: Statementstmt 65.1% 187 / 287 Branchbran 48.1% 80 / 166 Conditioncond 54.1% 13 / 24 MC/DCmcdc 40.0% 6 / 15 Subroutinesub 60.8% 14 / 23 Podpod 35.2% 6 / 17 totaltotal 57.5% 306 / 532 CC 95 SCAR 35.3
CC
95
Cov
59%
find_tfm_file_in_ls
132.0
new
51.9
word_dimensions
42.0
CRAP 34.2
↑ Summary
1  
2 =head1 NAME
3  
4 Font::TFM -- read information from TeX font metric files
5  
6 =cut
7  
8  
9 package Font::TFM;
10 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use vars qw( $VERSION $DEBUG $TEXFONTSDIR $TEXFONTSUSELS
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 $LSFILENAME $MULTIPLY $errstr );
13  
14 # ################
15 # Global variables
16 #
17 1 $VERSION = '1.01';
18 1 $errstr = '';
19 1 $DEBUG = 0;
20 53 ▶sub DEBUG () { $DEBUG; }
Subroutine DEBUG: called CC=1 SCAR=0.0
Pod undocumented
21 1 ▶sub Error {
Subroutine Error: called CC=2 SCAR=7.2
Pod undocumented
22 1 $errstr = join '', @_;
23 1 ▶ print STDERR @_, "\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Font::TFM::DEBUG 0 1 1
24 }
25  
26 1 $TEXFONTSDIR = '.';
27 1 $TEXFONTSUSELS = 1;
28 1 $LSFILENAME = "ls-R";
29 1 $MULTIPLY = 65536;
30  
31 # #####################
32 # Load new font at size
33 #
34 0 ▶sub new_at {
Subroutine new_at: not called CC=1 SCAR=6.9
Pod undocumented
35 0 my ($class, $fontname, $size) = @_;
36 0 new($class, 'name' => $fontname, 'at' => $size);
37 }
38  
39 # ########################
40 # Load new font with scale
41 #
42 6 ▶sub new {
Subroutine new: called CC=29 SCAR=39.5
Pod undocumented
43 6 my $class = shift;
44 6 my %opts = ();
45 6 ▶ if (@_ > 2 or (@_ == 2 and $_[1] !~ /^(\d*\.)?\d+$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 2 or @_ == 2 and not $_[1] =~ /^(\d*\.)?\d+$/) { } 2 4 6
Condition50%3/6
@_ > 2 or @_ == 2 and not $_[1] =~ /^(\d*\.)?\d+$/
l!l&&r!l&&!r
204
@_ == 2 and not $_[1] =~ /^(\d*\.)?\d+$/
!ll&&!rl&&r
400
MC/DC33%1/3
@_ > 2 or @_ == 2 and not $_[1] =~ /^(\d*\.)?\d+$/
@_ > 2 @_ == 2 not $_[1] =~ /^(\d*\.)?\d+$/
Truth table50%2/4
A or B and not(C)
A= @_ > 2B= @_ == 2C= not $_[1] =~ /^(\d*\.)?\d+$/
ABCresult
1XX1
0111
00X0
0100
46 2 ▶ if (@_ % 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ % 2) 0 2 2
47 0 $opts{name} = shift;
48 }
49 2 %opts = @_;
50 } else {
51 4 @opts{'name', 'scale'} = @_;
52 }
53
54 # make the object
55 6 my $self = bless {}, $class;
56  
57 6 my ($file_handle);
58 6 eval {
59 6 $file_handle = $self->open_tfm(%opts);
60 };
61 6 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 5 6
62 1 Error($@); return;
63 }
64  
65 # read header
66 5 my $buffer = '';
67 5 ▶ if (read($file_handle, $buffer, 24) != 24) {
Branch: 1 branch
BranchTrueFalseTotal
if (read($file_handle, $buffer, 24) != 24) 0 5 5
68 0 Error("Error reading TFM header: $!"); return;
69 }
70  
71 # get 12 fields of the header
72 5 @{$self}{ qw(length headerlength smallest largest numwidth
73 numheight numdepth numic numligkern numkern numext numparam) }
74 = unpack "n12", $buffer;
75 5 $self->{numofchars} = $self->{largest} - $self->{smallest} + 1;
76 5 $self->{'length'} = $self->{'length'} * 4 - 24;
77 5 $self->{headerlength} *= 4;
78  
79 # read rest of the file
80 5 ▶ if (read($file_handle, $buffer, $self->{'length'})
Branch: 1 branch
BranchTrueFalseTotal
if (read($file_handle, $buffer, $self->{"length"}) != $self->{"length"}) 0 5 5
81 != $self->{'length'}) {
82 0 Error("Error reading body: $!"); return;
83 }
84 5 close $file_handle;
85  
86 5 my $headerrestlength = $self->{headerlength} - 18 * 4;
87  
88 5 my ($face, $headerrest, @charinfo, @width, @height, @depth,
89 @italic, @ligkern, @kern, @exten);
90  
91 # split the file into various arrays
92 5 (@{$self}{ qw(checksum designsize codingschemestringlength
93 codingscheme familystringlength family sevenbitsafe ) },
94 undef, undef, $face,
95 $headerrest,
96 @charinfo[0 .. $self->{numofchars} - 1],
97 @width[0 .. $self->{numwidth} - 1],
98 @height[0 .. $self->{numheight} - 1],
99 @depth[0 .. $self->{numdepth} - 1],
100 @italic[0 .. $self->{numic} - 1],
101 @ligkern[0 .. $self->{numligkern} - 1],
102 @kern[0 .. $self->{numkern} - 1],
103 @exten[0 .. $self->{numext} - 1],
104 5 @{$self->{param}}[1 .. $self->{numparam}],
105 )
106 = unpack "NNCA39CA19C4a$headerrestlength" .
107 "a4" x $self->{numofchars} .
108 "N$self->{numwidth}N$self->{numheight}N$self->{numdepth}N$self->{numic}" .
109 "a4" x $self->{numligkern} .
110 "N$self->{numkern}" .
111 "a4" x $self->{numext} .
112 5 "N$self->{numparam}", $buffer;
113 # the unpack above does all the work, isn't it neat?
114
115 5 $self->{designsize} = getfixword($self->{designsize});
116  
117 5 my $fontsize = $self->{designsize};
118 5 ▶ if (defined $opts{at}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $opts{'at'}) { } 2 3 5
elsif (defined $opts{'scale'}) { } 0 3 3
119 2 $fontsize = $opts{at};
120 } elsif (defined $opts{scale}) {
121 0 $fontsize *= $opts{scale};
122 }
123 5 $self->{fontsize} = $fontsize;
124 my $multiplysize = $fontsize *
125 5 ▶ ( defined $opts{'multiply'} ? $opts{'multiply'} : $MULTIPLY );
Branch: 1 branch
BranchTrueFalseTotal
defined $opts{'multiply'} ? : 0 5 5
126  
127 5 ▶ if ($self->{sevenbitsafe}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"sevenbitsafe"}) 0 5 5
128 0 $self->{sevenbitsafe} = 1;
129 }
130  
131 5 $self->{face} = ""; # computation of face seems useless
132 5 ▶ if ($face < 18) {
Branch: 1 branch
BranchTrueFalseTotal
if ($face < 18) 0 5 5
133 0 my ($weight, $slope, $expansion) = ("M", "R", "R");
134 0 ▶ if ($face - 12 >= 0) { $expansion = "E"; $face -= 12; }
Branch: 2 branches
BranchTrueFalseTotal
if ($face - 12 >= 0) { } 0 0 0
elsif ($face - 6 >= 0) { } 0 0 0
135 0 elsif ($face - 6 >= 0) { $expansion = "C"; $face -= 6; }
136 0 ▶ if ($face - 4 >= 0) { $weight = "L"; $face -= 4; }
Branch: 2 branches
BranchTrueFalseTotal
if ($face - 4 >= 0) { } 0 0 0
elsif ($face - 2 >= 0) { } 0 0 0
137 0 elsif ($face - 2 >= 0) { $weight = "B"; $face -= 2; }
138 0 ▶ if ($face > 0) { $slope = "I"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($face > 0) 0 0 0
139 0 $self->{face} = "$weight$slope$expansion";
140 }
141  
142 5 @{$self->{headerrest}}[0 .. $headerrestlength] = split //, $headerrest;
143  
144 5 @width = map { getfixword($_) * $multiplysize } @width;
145 5 @height = map { getfixword($_) * $multiplysize } @height;
146 5 @depth = map { getfixword($_) * $multiplysize } @depth;
147 5 @italic = map { getfixword($_) * $multiplysize } @italic;
148 5 @kern = map { getfixword($_) * $multiplysize } @kern;
149 5 $self->{param}[1] = getfixword($self->{param}[1]);
150 5 @{$self->{param}}[2 .. $self->{numparam}] =
151 51 map { getfixword($_) * $multiplysize }
152 5 @{$self->{param}}[2 .. $self->{numparam}];
153 # compute the actual dimensions
154  
155 5 ▶ if (@ligkern) { # check for boundary char
Branch: 1 branch
BranchTrueFalseTotal
if (@ligkern) 4 1 5
156 4 my ($skip, $next, $opbyte, $remainder);
157 4 ($skip, $next) = unpack "Ca1", $ligkern[0];
158 4 ▶ if ($skip == 255) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skip == 255) 0 4 4
159 0 $self->{"boundary"} = $next;
160 }
161 4 ($skip, $next, $opbyte, $remainder) = unpack
162 "Ca1CC", $ligkern[$#ligkern];
163 4 ▶ if ($skip == 255) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skip == 255) 0 4 4
164 0 process_lig_kern($self, "boundary", \@ligkern,
165 256 * $opbyte + $remainder, \@kern);
166 }
167 }
168  
169 5 for (0 .. $self->{numofchars} - 1) {
170 640 my $char = pack "C", $_ + $self->{smallest};
171 640 my ($wid, $heidep, $italtag, $remainder)
172 = unpack "C4", $charinfo[$_];
173 640 ▶ next if ($wid == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $wid == 0 0 640 640
174 # set up dimensions of the character
175 ($self->{width}{$char}, $self->{height}{$char},
176 640 $self->{depth}{$char}, $self->{italic}{$char})
177 = ($width[$wid], $height[$heidep >> 4],
178 $depth[$heidep & 0x0f], $italic[$italtag >> 2]);
179
180 640 my $tag = $italtag & 0x03; # other info
181 640 ▶ if ($tag == 1) { # lig/kern program
Branch: 3 branches
BranchTrueFalseTotal
if ($tag == 1) { } 140 500 640
elsif ($tag == 2) { } 74 426 500
elsif ($tag == 3) { } 28 398 426
182 140 process_lig_kern($self, $char, \@ligkern, $remainder, \@kern);
183 }
184 elsif ($tag == 2) { # larger character
185 74 $self->{larger}{$char} = pack "C", $remainder;
186 }
187 elsif ($tag == 3) { # extensible character
188 28 my ($top, $mid, $bot, $rep) = unpack "C4", $exten[$remainder];
189 28 ▶ $self->{extentop}{$char} = pack "C", $top if $top;
Branch: 1 branch
BranchTrueFalseTotal
if $top 17 11 28
190 28 ▶ $self->{extenmid}{$char} = pack "C", $mid if $mid;
Branch: 1 branch
BranchTrueFalseTotal
if $mid 2 26 28
191 28 ▶ $self->{extenbot}{$char} = pack "C", $bot if $bot;
Branch: 1 branch
BranchTrueFalseTotal
if $bot 17 11 28
192 28 $self->{extenrep}{$char} = $rep;
193 }
194 }
195 5 $self;
196 }
197  
198 # ###################################
199 # Open the file and return filehandle
200 #
201 6 ▶sub open_tfm {
Subroutine open_tfm: called CC=6 SCAR=18.2
Pod undocumented
202 6 my ($self, %opts) = @_;
203 6 my $filename;
204 6 ▶ if (defined $opts{file}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $opts{'file'}) { } 1 5 6
elsif (defined $opts{'name'}) { } 5 0 5
205 $filename = $opts{file}
206 1 } elsif (defined $opts{name}) {
207 5 ▶ $filename = find_tfm_file(%opts) or
Branch: 1 branch
BranchTrueFalseTotal
$filename = find_tfm_file(%opts) or die qq[No tfm file found for font $opts{"name"}] 4 1 5
208 die "No tfm file found for font $opts{name}";
209 } else {
210 0 die "Either font name or file name has to be specified";
211 }
212  
213 # try to open the file
214 5 ▶ print STDERR "Loading $filename\n" if DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if &DEBUG() 0 5 5
215 5 ▶ open TFMFILE, $filename or
Branch: 1 branch
BranchTrueFalseTotal
open TFMFILE, $filename or die "Error opening ${filename}: $!" 5 0 5
216 die "Error opening $filename: $!";
217 5 binmode TFMFILE;
218  
219 5 $self->{name} = $filename;
220 5 $self->{name} =~ s/\.tfm$//i;
221 5 $self->{name} =~ s!^.*/!!;
222  
223 5 return(\*TFMFILE);
224 }
225  
226 # ###################################################
227 # Process the ligature/kerning program for a character
228 #
229 140 ▶sub process_lig_kern {
Subroutine process_lig_kern: called CC=10 SCAR=23.3
Pod undocumented
230 140 my ($self, $char, $ligkernref, $prognum, $kernref) = @_;
231 140 my $firstinstr = 1;
232 140 while (1) {
233 608 my ($skipbyte, $nextchar, $opbyte, $remainder)
234 = unpack "Ca1CC", $ligkernref->[$prognum];
235 608 ▶ if ($firstinstr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($firstinstr) 140 468 608
236 140 ▶ if ($skipbyte > 128) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skipbyte > 128) 0 140 140
237 0 $prognum = 256 * $opbyte + $remainder;
238 0 ($skipbyte, $nextchar, $opbyte, $remainder)
239 = unpack "Ca1CC", $ligkernref->[$prognum];
240 }
241 }
242 608 ▶ if ($opbyte >= 128
Branch: 1 branch
BranchTrueFalseTotal
if ($opbyte >= 128 and not exists $self->{"kern"}{$char . $nextchar}) 569 39 608
Condition100%3/3
$opbyte >= 128 and not exists $self->{"kern"}{$char . $nextchar}
!ll&&!rl&&r
336569
MC/DC100%2/2
$opbyte >= 128 and not exists $self->{"kern"}{$char . $nextchar}
$opbyte >= 128 not exists $self->{"kern"}{$char . $nextchar}
Truth table100%3/3
A and not(B)
A= $opbyte >= 128B= not exists $self->{"kern"}{$char . $nextchar}
ABresult
0X0
100
111
243 and not exists $self->{kern}{$char . $nextchar}) {
244 569 $self->{kern}{$char . $nextchar}
245 = $kernref->[ 256 * ($opbyte - 128)
246 + $remainder];
247 }
248 608 ▶ if ($opbyte < 128
Branch: 1 branch
BranchTrueFalseTotal
if ($opbyte < 128 and not exists $self->{"lig"}{$char . $nextchar}) 33 575 608
Condition66%2/3
$opbyte < 128 and not exists $self->{"lig"}{$char . $nextchar}
!ll&&!rl&&r
575033
MC/DC50%1/2
$opbyte < 128 and not exists $self->{"lig"}{$char . $nextchar}
$opbyte < 128 not exists $self->{"lig"}{$char . $nextchar}
Truth table66%2/3
A and not(B)
A= $opbyte < 128B= not exists $self->{"lig"}{$char . $nextchar}
ABresult
0X0
100
111
249 and not exists $self->{lig}{$char . $nextchar}) {
250 33 my ($a, $b, $c) = ($opbyte >> 2, ($opbyte >> 1) & 0x01, $opbyte & 0x01);
251 33 my $out = "";
252 33 ▶ $out .= $char if $b;
Branch: 1 branch
BranchTrueFalseTotal
if $b 0 33 33
253 33 $out .= pack "C", $remainder;
254 33 ▶ $out .= $nextchar if $c;
Branch: 1 branch
BranchTrueFalseTotal
if $c 0 33 33
255 33 $self->{lig}{$char . $nextchar} = $out;
256 33 $self->{ligpassover}{$char . $nextchar} = $a;
257 }
258 608 ▶ last if ($skipbyte >= 128);
Branch: 1 branch
BranchTrueFalseTotal
if $skipbyte >= 128 140 468 608
259 468 $prognum += $skipbyte + 1;
260 468 $firstinstr = 0;
261 }
262 }
263  
264 # #################
265 # Find the TFM file
266 #
267 5 ▶sub find_tfm_file {
Subroutine find_tfm_file: called CC=7 SCAR=20.0
Pod undocumented
268 5 my %opts = @_;
269 5 my $fontname = $opts{name};
270 5 ▶ $fontname .= ".tfm" unless $fontname =~ /\.tfm$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $fontname =~ /\.tfm$/i 5 0 5
271 5 ▶ print STDERR "Font::TFM::find_tfm_file: \$fontname = $fontname\n" if DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if &DEBUG() 0 5 5
272 5 my $directory;
273 5 ▶ for $directory (split /:/,
Branch: 1 branch
BranchTrueFalseTotal
defined $opts{'path'} ? : 0 5 5
274 (defined $opts{path} ? $opts{path} : $TEXFONTSDIR)) {
275 5 ▶ print STDERR "Font::TFM::find_tfm_file: \$directory = $directory\n" if DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if &DEBUG() 0 5 5
276 5 my $file = find_tfm_file_in_directory(%opts,
277 name => $fontname, dir => $directory);
278 5 ▶ return $file if defined $file;
Branch: 1 branch
BranchTrueFalseTotal
if defined $file 4 1 5
279 }
280 1 return;
281 }
282 25 ▶sub find_tfm_file_in_directory {
Subroutine find_tfm_file_in_directory: called CC=13 SCAR=30.9
Pod undocumented
283 25 my %opts = @_;
284 25 my ($fontname, $directory) = ($opts{name}, $opts{dir});
285 25 ▶ $directory .= '/' unless $directory eq '';
Branch: 1 branch
BranchTrueFalseTotal
unless $directory eq "" 25 0 25
286 25 my $tfmfile = "$directory$fontname";
287 25 my $lsfile = "$directory$LSFILENAME";
288 25 ▶ print STDERR "Font::TFM::find_tfm_file_in_directory: \$directory = $directory\n" if DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if &DEBUG() 0 25 25
289 25 ▶ if (-f $tfmfile) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $tfmfile) 4 21 25
290 4 return $tfmfile;
291 }
292 21 my $usels = $TEXFONTSUSELS;
293 21 ▶ if (defined $opts{usels}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"usels"}) 0 21 21
294 0 $usels = 1;
295 0 ▶ $usels = 0 if $opts{usels} eq '0' or $opts{usels} eq 'no';
Branch: 1 branch
BranchTrueFalseTotal
if $opts{"usels"} eq 0 or $opts{"usels"} eq "no" 0 0 0
Condition0%0/3
$opts{"usels"} eq 0 or $opts{"usels"} eq "no"
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"usels"} eq 0 or $opts{"usels"} eq "no"
$opts{"usels"} eq 0 $opts{"usels"} eq "no"
Truth table0%0/3
A or B
A= $opts{"usels"} eq 0B= $opts{"usels"} eq "no"
ABresult
1X1
011
000
296 }
297 21 ▶ if (-f $lsfile and $usels) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $lsfile and $usels) { } 0 21 21
Condition33%1/3
-f $lsfile and $usels
!ll&&!rl&&r
2100
MC/DC0%0/2
-f $lsfile and $usels
-f $lsfile $usels
Truth table33%1/3
A and B
A= -f $lsfileB= $usels
ABresult
0X0
100
111
298 0 my $file = find_tfm_file_in_ls($fontname, $lsfile);
299 0 ▶ return $file if defined $file;
Branch: 1 branch
BranchTrueFalseTotal
if defined $file 0 0 0
300 }
301 else {
302 21 my $subdir;
303 1 ▶ for $subdir (<$directory/*>) {
Subroutine BEGIN: called CC=1 SCAR=0.0
304 42 ▶ next unless -d $subdir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $subdir 22 20 42
305 20 my $file = find_tfm_file_in_directory(%opts,
306 dir => $subdir);
307 20 ▶ return $file if defined $file;
Branch: 1 branch
BranchTrueFalseTotal
if defined $file 0 20 20
308 }
309 }
310 21 return;
311 }
312 0 ▶sub find_tfm_file_in_ls {
Subroutine find_tfm_file_in_ls: not called CC=11 SCAR=48.8
Pod undocumented
313 0 my ($fontname, $lsfile) = @_;
314 0 my $lsdir = $lsfile;
315 0 $lsdir =~ s!/$LSFILENAME$!!;
316 0 ▶ print STDERR "Font::TFM::find_tfm_file_in_ls: \$lsfile = $lsfile\n" if DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if &DEBUG() 0 0 0
317 0 ▶ print STDERR "Font::TFM::find_tfm_file_in_ls: \$lsdir = $lsdir\n" if DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if &DEBUG() 0 0 0
318 0 ▶ if (not open LSFILE, $lsfile) {
Branch: 1 branch
BranchTrueFalseTotal
unless (open LSFILE, $lsfile) 0 0 0
319 0 Error("Error opening $lsfile: $!"); return;
320 }
321 0 local ($/) = "\n";
322 0 ▶ while (<LSFILE>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline LSFILE)) 0 0 0
323 0 chomp;
324 0 ▶ if (/:$/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/:$/) { } 0 0 0
elsif ($_ eq $fontname) { } 0 0 0
325 0 $lsdir = $_;
326 0 $lsdir =~ s!:$!!;
327 0 ▶ print STDERR "Font::TFM::find_tfm_file_in_ls: \$lsdir = $lsdir\n" if (DEBUG > 10);
Branch: 1 branch
BranchTrueFalseTotal
if &DEBUG() > 10 0 0 0
328 }
329 elsif ($_ eq $fontname) {
330 0 my $file = "$lsdir/$fontname";
331 0 ▶ if (-f $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $file) 0 0 0
332 0 close LSFILE;
333 0 ▶ print STDERR "file $fontname found in $lsfile\n" if DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if &DEBUG() 0 0 0
334 0 return $file;
335 }
336 }
337 }
338 0 ▶ print STDERR "file $fontname not found in $lsfile\n" if DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if &DEBUG() 0 0 0
339 0 return;
340 }
341 447 ▶sub getfixword {
Subroutine getfixword: called CC=2 SCAR=6.9
Pod undocumented
342 447 my $val = $_[0];
343 447 my $p = pack "L", $val;
344 447 ▶ if ($val & 0x80000000) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val & 2147483648) 26 421 447
345 26 $val = unpack "l", $p;
346 }
347 447 return ($val / (1 << 20));
348 }
349 2 ▶sub kern {
Subroutine kern: called CC=3 SCAR=12.0
Pod documented
350 2 my ($self, $double, $second) = @_;
351 2 ▶ $double .= $second if (defined $second);
Branch: 1 branch
BranchTrueFalseTotal
if defined $second 0 2 2
352 2 ▶ if (defined $self->{kern}{$double}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"kern"}{$double}) 2 0 2
353 2 return $self->{kern}{$double};
354 }
355 0 return 0;
356 }
357 0 ▶sub lig {
Subroutine lig: not called CC=3 SCAR=24.8
Pod documented
358 0 my ($self, $double, $second) = @_;
359 0 ▶ $double .= $second if (defined $second);
Branch: 1 branch
BranchTrueFalseTotal
if defined $second 0 0 0
360 0 ▶ if (defined $self->{lig}{$double}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"lig"}{$double}) 0 0 0
361 0 return $self->{lig}{$double};
362 }
363 0 return undef;
364 }
365 0 ▶sub ligpassover {
Subroutine ligpassover: not called CC=1 SCAR=6.9
Pod documented
366 0 my ($self, $double) = @_;
367 0 $self->{ligpassover}{$double};
368 }
369 0 ▶sub param {
Subroutine param: not called CC=1 SCAR=6.9
Pod documented
370 0 my ($self, $param) = @_;
371 0 $self->{param}[$param];
372 }
373 0 ▶sub word_dimensions {
Subroutine word_dimensions: not called CC=6 SCAR=37.4
Pod documented
374 0 my ($self, $text) = @_;
375 0 my @expanded = $self->expand($text);
376 0 my ($width, $height, $depth) = (0, 0, 0);
377 0 ▶ while (@expanded) {
Branch: 1 branch
BranchTrueFalseTotal
if (@expanded) 0 0 0
378 0 my $word = shift @expanded;
379 0 ▶ while ($word =~ /./sg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word =~ /./gs) 0 0 0
380 0 my $char = $&;
381 0 $width += $self->width($char);
382 0 my $newval = $self->height($char);
383 0 ▶ $height = $newval if ($newval > $height);
Branch: 1 branch
BranchTrueFalseTotal
if $newval > $height 0 0 0
384 0 $newval = $self->depth($char);
385 0 ▶ $depth = $newval if ($newval > $depth);
Branch: 1 branch
BranchTrueFalseTotal
if $newval > $depth 0 0 0
386 }
387 0 ▶ last if (not @expanded);
Branch: 1 branch
BranchTrueFalseTotal
unless @expanded 0 0 0
388 0 $width += shift @expanded;
389 }
390 0 ($width, $height, $depth);
391 }
392 0 ▶sub expand {
Subroutine expand: not called CC=5 SCAR=34.0
Pod documented
393 0 my ($self, $text) = @_;
394 0 my $pos = 0;
395
396 # ligature substitutions
397 0 ▶ while ($pos < (length $text) - 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos < length($text) - 1) 0 0 0
398 0 my $found;
399 0 my $substr = substr $text, $pos, 2;
400 0 $found = $self->lig(substr $text, $pos, 2);
401 0 ▶ if (defined $found) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $found) { } 0 0 0
402 0 substr($text, $pos, 2) = $found;
403 0 $pos += $self->ligpassover($substr);
404 }
405 else
406 0 { $pos++ }
407 }
408  
409 # kerning processing
410 0 my @out = ();
411 0 my $currentstring = substr $text, 0, 1;
412 0 ▶ while ($text =~ /(.)(?=(.))/gs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /(.)(?=(.))/gs) 0 0 0
413 0 ▶ if ($self->kern($1 . $2)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->kern($1 . $2)) 0 0 0
414 0 push @out, $currentstring;
415 0 $currentstring = '';
416 0 push @out, $self->kern($1 . $2);
417 }
418 0 $currentstring .= $2
419 }
420 0 push @out, $currentstring;
421 0 @out;
422 }
423  
424  
425 1 my %PARAM_NAMES = ( slant => 1, space => 2, spacestretch => 3,
426 spaceshrink => 4, xheight => 5, emwidth => 6, quad => 6,
427 extraspace => 7,
428 );
429 1 my @GENERAL_NAMES = qw( fontsize designsize name checksum codingscheme );
430 1 my @CHAR_NAMES = qw( width height depth italic );
431 1 my %WORD_NAMES = ( word_width => 0, word_height => 1, word_depth => 2 );
432 1 my %MATH_SY_NAMES = ( num1 => 8, num2 => 9, num3 => 10,
433 denom1 => 11, denom2 => 12,
434 sup1 => 13, sup2 => 14, sup3 => 15,
435 sub1 => 16, sub2 => 17,
436 supdrop => 18,
437 subdrop => 19,
438 delim1 => 20, delim2 => 21,
439 axisheight => 22,
440 );
441 1 my %MATH_EX_NAMES = (
442 defaultrulethickness => 8,
443 bigopspacing1 => 9,
444 bigopspacing2 => 10,
445 bigopspacing3 => 11,
446 bigopspacing4 => 12,
447 bigopspacing5 => 13,
448 );
449  
450 1 ▶use vars qw( $AUTOLOAD );
Subroutine BEGIN: called CC=1 SCAR=0.0
451 13 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=10 SCAR=23.2
452 13 my $self = shift;
453 13 my $function = $AUTOLOAD;
454 13 local ($_);
455 13 $function =~ s/^.*:://;
456 13 $function =~ s/_//g;
457 13 ▶ print STDERR "Autoloading $function\n" if DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if &DEBUG() 0 13 13
458 return ($self->word_dimensions(shift))[$WORD_NAMES{$function}]
459 13 ▶ if defined $WORD_NAMES{$function};
Branch: 1 branch
BranchTrueFalseTotal
if defined $WORD_NAMES{$function} 0 13 13
460 return $self->{'param'}[$PARAM_NAMES{$function}]
461 13 ▶ if (defined $PARAM_NAMES{$function});
Branch: 1 branch
BranchTrueFalseTotal
if defined $PARAM_NAMES{$function} 2 11 13
462 return $self->{$function}{$_[0]}
463 11 ▶ if grep { $_ eq $function } @CHAR_NAMES;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $function;} @CHAR_NAMES 3 8 11
464 return $self->{$function}
465 8 ▶ if grep { $_ eq $function } @GENERAL_NAMES;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $function;} @GENERAL_NAMES 2 6 8
466 6 ▶ if ($self->{codingscheme} eq 'TeX math symbols'
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"codingscheme"} eq "TeX math symbols" and defined $MATH_SY_NAMES{$function}) 2 4 6
Condition66%2/3
$self->{"codingscheme"} eq "TeX math symbols" and defined $MATH_SY_NAMES{$function}
!ll&&!rl&&r
402
MC/DC50%1/2
$self->{"codingscheme"} eq "TeX math symbols" and defined $MATH_SY_NAMES{$function}
$self->{"codingscheme"} eq "TeX math symbols" defined $MATH_SY_NAMES{$function}
Truth table66%2/3
A and B
A= $self->{"codingscheme"} eq "TeX math symbols"B= defined $MATH_SY_NAMES{$function}
ABresult
0X0
100
111
467 and defined $MATH_SY_NAMES{$function}) {
468 2 return $self->{'param'}[$MATH_SY_NAMES{$function}]
469 }
470 4 ▶ if ($self->{codingscheme} eq 'TeX math extension'
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"codingscheme"} eq "TeX math extension" and defined $MATH_EX_NAMES{$function}) 2 2 4
Condition66%2/3
$self->{"codingscheme"} eq "TeX math extension" and defined $MATH_EX_NAMES{$function}
!ll&&!rl&&r
202
MC/DC50%1/2
$self->{"codingscheme"} eq "TeX math extension" and defined $MATH_EX_NAMES{$function}
$self->{"codingscheme"} eq "TeX math extension" defined $MATH_EX_NAMES{$function}
Truth table66%2/3
A and B
A= $self->{"codingscheme"} eq "TeX math extension"B= defined $MATH_EX_NAMES{$function}
ABresult
0X0
100
111
471 and defined $MATH_EX_NAMES{$function}) {
472 2 return $self->{'param'}[$MATH_EX_NAMES{$function}]
473 }
474 2 die "Method $function not defined for $self";
475 }
476  
477 0 ▶sub Version { $VERSION; }
Subroutine Version: not called CC=1 SCAR=6.9
Pod undocumented
478 0 ▶sub DESTROY {}
Subroutine DESTROY: not called CC=1 SCAR=0.0
479 1 1;
480  
481 __END__
↑ Summary