blib/lib/PostScript/FontInfo.pm

filter: Statementstmt 84.5% 60 / 71 Branchbran 46.6% 14 / 30 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 73.3% 11 / 15 Podpod 100% 8 / 8 totaltotal 70.9% 95 / 134 CC 18 SCAR 20.7
CC
18
Cov
71%
_loadinfo
14.0
__ANON__
12.0
new
6.9
CRAP 7.9
« lib/PostScript/FontMetrics.pm ↑ Summary blib/lib/PostScript/WinANSIEncoding.pm »
1 # RCS Status : $Id: FontInfo.pm,v 1.12 2003-10-23 14:12:27+02 jv Exp $
2 # Author : Johan Vromans
3 # Created On : December 1998
4 # Last Modified By: Johan Vromans
5 # Last Modified On: Thu Oct 23 14:12:25 2003
6 # Update Count : 57
7 # Status : Released
8  
9 ################ Module Preamble ################
10  
11 package PostScript::FontInfo;
12  
13 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶BEGIN { require 5.005; }
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 ▶use IO qw(File);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 $VERSION = "1.05";
21  
22 1 ▶sub new {
Subroutine new: called CC=5 SCAR=19.3
Pod documented
23 1 my $class = shift;
24 1 my $font = shift;
25 1 my (%atts) = (error => 'die',
26 verbose => 0, trace => 0, debug => 0,
27 @_);
28 1 my $self = { file => $font };
29 1 bless $self, $class;
30  
31 1 ▶ return $self unless defined $font;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $font 0 1 1
32  
33 1 $self->{debug} = $atts{debug};
34 1 ▶ $self->{trace} = $self->{debug} || $atts{trace};
Condition33%1/3
$self->{'debug'} || $atts{'trace'}
l!l&&r!l&&!r
001
MC/DC0%0/2
$self->{'debug'} || $atts{'trace'}
$self->{'debug'} $atts{'trace'}
Truth table33%1/3
A || B
A= $self->{'debug'}B= $atts{'trace'}
ABresult
1X1
011
000
35 1 ▶ $self->{verbose} = $self->{trace} || $atts{verbose};
Condition33%1/3
$self->{'trace'} || $atts{'verbose'}
l!l&&r!l&&!r
001
MC/DC0%0/2
$self->{'trace'} || $atts{'verbose'}
$self->{'trace'} $atts{'verbose'}
Truth table33%1/3
A || B
A= $self->{'trace'}B= $atts{'verbose'}
ABresult
1X1
011
000
36  
37 1 my $error = lc($atts{error});
38 0 ▶ $self->{die} = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
39 0 ▶ die(@_) if $error eq "die";
Branch: 1 branch
BranchTrueFalseTotal
if $error eq "die" 0 0 0
40 0 ▶ warn(@_) if $error eq "warn";
Branch: 1 branch
BranchTrueFalseTotal
if $error eq "warn" 0 0 0
41 1 };
42  
43 1 eval {
44 1 $self->_loadinfo;
45 };
46  
47 1 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
48 0 $self->_die($@);
49 0 return undef;
50 }
51  
52 1 $self;
53 }
54  
55 0 ▶sub FileName { my $self = shift; $self->{file}; }
Subroutine FileName: not called CC=1 SCAR=6.9
Pod documented
56 1 ▶sub FontName { my $self = shift; $self->{name}; }
Subroutine FontName: called CC=1 SCAR=0.0
Pod documented
57 1 ▶sub FullName { my $self = shift; $self->{fullname};}
Subroutine FullName: called CC=1 SCAR=0.0
Pod documented
58 0 ▶sub InfoData { my $self = shift; $self->{data}; }
Subroutine InfoData: not called CC=1 SCAR=6.9
Pod documented
59 1 ▶sub FontFamily { my $self = shift; $self->{family}; }
Subroutine FontFamily: called CC=1 SCAR=0.0
Pod documented
60 1 ▶sub Version { my $self = shift; $self->{version}; }
Subroutine Version: called CC=1 SCAR=0.0
Pod documented
61 1 ▶sub PCFileNamePrefix { my $self = shift; $self->{pcprefix}; }
Subroutine PCFileNamePrefix: called CC=1 SCAR=0.0
Pod documented
62  
63 1 ▶sub _loadinfo ($) {
Subroutine _loadinfo: called CC=12 SCAR=26.4
64  
65 1 my ($self) = shift;
66  
67 1 my $data; # inf data
68  
69 1 eval { # so we can use die
70  
71 1 my $fn = $self->{file};
72 1 my $fh = new IO::File; # font file
73 1 my $sz = -s $fn; # file size
74  
75 1 ▶ $fh->open ($fn) || $self->_die("$fn: $!\n");
Branch: 1 branch
BranchTrueFalseTotal
$fh->open($fn) or $self->_die("${fn}: $!\n") 1 0 1
76 1 ▶ print STDERR ("$fn: Loading INF file\n") if $self->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} 0 1 1
77  
78 # Read in the inf data.
79 1 my $len = 0;
80 1 ▶ while ( $fh->sysread ($data, 32768, $len) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh->sysread($data, 32768, $len) > 0) 1 1 2
81 1 $len = length ($data);
82 }
83 1 $fh->close;
84 1 ▶ print STDERR ("Read $len bytes from $fn\n") if $self->{trace};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"trace"} 0 1 1
85 1 ▶ $self->_die("$fn: Expecting $sz bytes, got $len bytes\n") unless $sz == $len;
Branch: 1 branch
BranchTrueFalseTotal
unless $sz == $len 0 1 1
86  
87 # Normalise line endings.
88 1 $data =~ s/\015\012?/\n/g;
89  
90 1 ▶ if ( $data !~ /^FontName\s+\(\S+\)$/m ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($data =~ /^FontName\s+\(\S+\)$/m) 0 1 1
91 0 $self->_die("$fn: Not a recognizable INF file\n");
92 }
93  
94 };
95  
96 1 ▶ $self->{name} = $1 if $data =~ /^FontName\s+\((\S+)\)$/mi;
Branch: 1 branch
BranchTrueFalseTotal
if $data =~ /^FontName\s+\((\S+)\)$/im 1 0 1
97 1 ▶ $self->{fullname}= $1 if $data =~ /^FullName\s+\((.+?)\)$/mi;
Branch: 1 branch
BranchTrueFalseTotal
if $data =~ /^FullName\s+\((.+?)\)$/im 1 0 1
98 1 ▶ $self->{family} = $1 if $data =~ /^FamilyName\s+\((.+)\)$/mi;
Branch: 1 branch
BranchTrueFalseTotal
if $data =~ /^FamilyName\s+\((.+)\)$/im 1 0 1
99 1 ▶ $self->{version} = $1 if $data =~ /^Version\s+\((.+)\)$/mi;
Branch: 1 branch
BranchTrueFalseTotal
if $data =~ /^Version\s+\((.+)\)$/im 1 0 1
100 1 ▶ $self->{pcprefix}= lc($1)
Branch: 1 branch
BranchTrueFalseTotal
if $data =~ /^PCFileNamePrefix\s+\((.+)\)$/im 1 0 1
101 if $data =~ /^PCFileNamePrefix\s+\((.+)\)$/mi;
102 1 $self->{data} = $data;
103  
104 1 $self;
105 }
106  
107 0 ▶sub _die {
Subroutine _die: not called CC=1 SCAR=6.9
108 0 my ($self, @msg) = @_;
109 0 $self->{die}->(@msg);
110 }
111  
112 1 1;
113  
114 __END__
« lib/PostScript/FontMetrics.pm ↑ Summary blib/lib/PostScript/WinANSIEncoding.pm »