| 1 | # RCS Status : $Id: Resources.pm,v 1.12 2004/12/18 16:40:52 jv Exp $# Author : Johan Vromans | ||||||||||||||||||||||||||||
| 2 | # Created On : Januari 1999 | ||||||||||||||||||||||||||||
| 3 | # Last Modified By: Johan Vromans | ||||||||||||||||||||||||||||
| 4 | # Last Modified On: Thu Oct 23 14:11:52 2003 | ||||||||||||||||||||||||||||
| 5 | # Update Count : 187 | ||||||||||||||||||||||||||||
| 6 | # Status : Released | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | ################ Module Preamble ################ | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | package PostScript::Resources; | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | BEGIN { require 5.005; } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use IO qw(File); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use File::Basename; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 1 | $VERSION = "1.03"; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | my $ResourcePath = "."; # default standard resource path | |||||||||||||||||||||||||||
| 24 | 1 | my $defupr = "PSref.upr"; # principal resource file | |||||||||||||||||||||||||||
| 25 | 1 | my $fn; # file currently being loaded | |||||||||||||||||||||||||||
| 26 | my $fh; # handle of file currently being loaded | ||||||||||||||||||||||||||||
| 27 | 1 | my $section; # section currently being loaded | |||||||||||||||||||||||||||
| 28 | 1 | my $exclusive; # last loaded file was exclusive | |||||||||||||||||||||||||||
| 29 | 1 | my $rscidx; # current resource index | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 1 | my $trace; | |||||||||||||||||||||||||||
| 32 | 1 | my $debug; | |||||||||||||||||||||||||||
| 33 | 1 | my $verbose; | |||||||||||||||||||||||||||
| 34 | 1 | my $error; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=24 SCAR=47.2
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 38 | 1 | ▶ | my (%atts) = (path => $ENV{"PSRESOURCEPATH"} || "::", | ||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{'PSRESOURCEPATH'} || '::'
MC/DC0%0/1
$ENV{'PSRESOURCEPATH'} || '::'
$ENV{'PSRESOURCEPATH'}
Truth table50%1/2
A
A= $ENV{'PSRESOURCEPATH'}
| |||||||||||||||||||||||||||||
| 39 | stdpath => $ResourcePath, | ||||||||||||||||||||||||||||
| 40 | error => 'die', # 'die', 'warn' or 'ignore' | ||||||||||||||||||||||||||||
| 41 | verbose => 0, | ||||||||||||||||||||||||||||
| 42 | trace => 0, | ||||||||||||||||||||||||||||
| 43 | debug => 0, | ||||||||||||||||||||||||||||
| 44 | @_); | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 1 | $debug = lc($atts{debug}); | |||||||||||||||||||||||||||
| 47 | 1 | ▶ | $trace = $debug || lc($atts{trace}); | ||||||||||||||||||||||||||
|
Condition33%1/3
$debug || lc $atts{'trace'}
MC/DC0%0/2
$debug || lc $atts{'trace'}
$debug
lc $atts{'trace'}
Truth table33%1/3
A || B
A= $debugB= lc $atts{'trace'}
| |||||||||||||||||||||||||||||
| 48 | 1 | ▶ | $verbose = $trace || lc($atts{verbose}); | ||||||||||||||||||||||||||
|
Condition33%1/3
$trace || lc $atts{'verbose'}
MC/DC0%0/2
$trace || lc $atts{'verbose'}
$trace
lc $atts{'verbose'}
Truth table33%1/3
A || B
A= $traceB= lc $atts{'verbose'}
| |||||||||||||||||||||||||||||
| 49 | 1 | $error = lc($atts{error}); | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 1 | my $self = {}; | |||||||||||||||||||||||||||
| 52 | 1 | bless $self, $class; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # Get the resource paths. | ||||||||||||||||||||||||||||
| 55 | 1 | my $path = $atts{path}; | |||||||||||||||||||||||||||
| 56 | 1 | $path =~ s|::|:$atts{stdpath}:|g; | |||||||||||||||||||||||||||
| 57 | 1 | $path =~ s|^:||; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | # According to the specs, the file names are either literal, | ||||||||||||||||||||||||||||
| 60 | # absolute or relative. In the latter case, the current prefix | ||||||||||||||||||||||||||||
| 61 | # (which defaults to the directory of the .upr file) must be | ||||||||||||||||||||||||||||
| 62 | # appended. | ||||||||||||||||||||||||||||
| 63 | # To avoid lots of unnecessary file name parsing, each prefix | ||||||||||||||||||||||||||||
| 64 | # will be stored in a prefix array, and the index in this array | ||||||||||||||||||||||||||||
| 65 | # will be prepended to each file name entry. | ||||||||||||||||||||||||||||
| 66 | # The costly filename manipulation will only be done when a | ||||||||||||||||||||||||||||
| 67 | # filename needs to be returned (sub _buildfilename). | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | # Create the prefix array and reset the index. | ||||||||||||||||||||||||||||
| 70 | 1 | $self->{prefix} = []; | |||||||||||||||||||||||||||
| 71 | 1 | $rscidx = 0; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # Process the entries in the list. | ||||||||||||||||||||||||||||
| 74 | 1 | foreach my $rsc ( split (":", $path) ) { | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 1 | ▶ | print STDERR ("rsc#$rscidx: $rsc <file>\n") if $debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 1 | ▶ | if ( -d $rsc ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 1 | ▶ | print STDERR ("rsc#$rscidx: $rsc <dir>\n") if $debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | # Directory. | ||||||||||||||||||||||||||||
| 82 | 1 | $exclusive = 0; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | # First check for a PSres.upr, and load it if possible. | ||||||||||||||||||||||||||||
| 85 | 1 | $fn = File::Spec->catfile ($rsc, "PSres.upr"); | |||||||||||||||||||||||||||
| 86 | 1 | ▶ | if ( -f $fn ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | print STDERR ("rsc#$rscidx: load $fn\n") if $debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | $rscidx++; | |||||||||||||||||||||||||||
| 89 | 0 | eval { _loadFile ($self) }; | |||||||||||||||||||||||||||
| 90 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | die ($@) if $error eq "die"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | warn ($@) if $error eq "warn"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 0 | next; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | # Unless PSres.upr was an exclusive resource, load all | ||||||||||||||||||||||||||||
| 98 | # files with .upr extension. | ||||||||||||||||||||||||||||
| 99 | 1 | ▶ | unless ( $exclusive ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 1 | my $dh = do { local *DH }; | |||||||||||||||||||||||||||
| 101 | 1 | opendir ($dh, $rsc); | |||||||||||||||||||||||||||
| 102 | 1 | my @files = grep (/\.upr$/, readdir ($dh)); | |||||||||||||||||||||||||||
| 103 | 1 | closedir ($dh); | |||||||||||||||||||||||||||
| 104 | 1 | foreach my $file ( @files ) { | |||||||||||||||||||||||||||
| 105 | # Skip the PSres.upr. It is already loaded. | ||||||||||||||||||||||||||||
| 106 | 2 | ▶ | next if $file eq "PSres.upr"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 2 | $fn = File::Spec->catfile ($rsc, $file); | |||||||||||||||||||||||||||
| 109 | 2 | ▶ | print STDERR ("rsc#$rscidx: load $fn\n") if $debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 2 | $rscidx++; | |||||||||||||||||||||||||||
| 111 | 2 | eval { _loadFile ($self) }; | |||||||||||||||||||||||||||
| 112 | 2 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 0 | ▶ | die ($@) if $error eq "die"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | warn ($@) if $error eq "warn"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 0 | next; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | else { | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | # File. This is _not_ defined in the specs. | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 0 | $fn = $rsc; | |||||||||||||||||||||||||||
| 125 | 0 | ▶ | print STDERR ("rsc#$rscidx: load $fn\n") if $debug; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 0 | $rscidx++; | |||||||||||||||||||||||||||
| 127 | 0 | eval { _loadFile ($self) }; | |||||||||||||||||||||||||||
| 128 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 0 | ▶ | die ($@) if $error eq "die"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 0 | ▶ | warn ($@) if $error eq "warn"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 0 | next; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 1 | $self; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 1 | ▶ | sub FontAFM ($$) { | ||||||||||||||||||||||||||
|
Subroutine
FontAFM: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||
| 140 | 1 | my ($self, $font) = @_; | |||||||||||||||||||||||||||
| 141 | return _buildfilename ($self, $font) | ||||||||||||||||||||||||||||
| 142 | 1 | ▶ | if defined ($font = $self->{FontAFM}->{$font}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 0 | undef; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 1 | ▶ | sub FontOutline ($$) { | ||||||||||||||||||||||||||
|
Subroutine
FontOutline: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||
| 147 | 1 | my ($self, $font) = @_; | |||||||||||||||||||||||||||
| 148 | return _buildfilename ($self, $font) | ||||||||||||||||||||||||||||
| 149 | 1 | ▶ | if defined ($font = $self->{FontOutline}->{$font}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 150 | 0 | undef; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 2 | ▶ | sub _buildfilename ($$) { | ||||||||||||||||||||||||||
|
Subroutine
_buildfilename: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||
| 154 | 2 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 155 | 2 | my $i; | |||||||||||||||||||||||||||
| 156 | 2 | ($i, $name) = unpack ("IA*", $name); | |||||||||||||||||||||||||||
| 157 | 2 | ▶ | return $1 if $name =~ /^=(.*)$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 2 | ▶ | return $name if File::Spec->file_name_is_absolute ($name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 2 | File::Spec->canonpath (File::Spec->catfile ($self->{prefix}->[$i], $name)); | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 2 | ▶ | sub _loadFile ($) { | ||||||||||||||||||||||||||
|
Subroutine
_loadFile: called CC=12 SCAR=27.0
| |||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 2 | my $data; # data | |||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 2 | eval { # so we can use die | |||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 2 | $fh = new IO::File; # font file | |||||||||||||||||||||||||||
| 171 | 2 | my $sz = -s $fn; # file size | |||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 2 | ▶ | $fh->open ($fn) || die ("$fn: $!\n"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | 2 | ▶ | print STDERR ($fn, ": Loading Resources\n") if $verbose; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | # Read in the data. | ||||||||||||||||||||||||||||
| 177 | 2 | my $line = <$fh>; | |||||||||||||||||||||||||||
| 178 | 2 | ▶ | die ($fn."[$.]: Unrecognized file format\n") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | unless $line =~ /^PS-Resources-(Exclusive-)?([\d.]+)/; | ||||||||||||||||||||||||||||
| 180 | 2 | $exclusive = defined $1; | |||||||||||||||||||||||||||
| 181 | 2 | my $version = $2; | |||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | # The resources file is organised in sections, each starting | ||||||||||||||||||||||||||||
| 184 | # with the section name and terminated by a line with just | ||||||||||||||||||||||||||||
| 185 | # a period. | ||||||||||||||||||||||||||||
| 186 | # Following the first PS-Resources line, the sections are | ||||||||||||||||||||||||||||
| 187 | # enumerated, e.g.: | ||||||||||||||||||||||||||||
| 188 | # | ||||||||||||||||||||||||||||
| 189 | # PS-Resources-1.0 | ||||||||||||||||||||||||||||
| 190 | # FontAFM | ||||||||||||||||||||||||||||
| 191 | # FontOutlines | ||||||||||||||||||||||||||||
| 192 | # FontFamily | ||||||||||||||||||||||||||||
| 193 | # FontPrebuilt | ||||||||||||||||||||||||||||
| 194 | # FontBDF | ||||||||||||||||||||||||||||
| 195 | # FontBDFSizes | ||||||||||||||||||||||||||||
| 196 | # . | ||||||||||||||||||||||||||||
| 197 | # | ||||||||||||||||||||||||||||
| 198 | # Optionally, the name of the resource directory follows. It | ||||||||||||||||||||||||||||
| 199 | # is preceded with a slash, e.g.: | ||||||||||||||||||||||||||||
| 200 | # | ||||||||||||||||||||||||||||
| 201 | # //usr/share/psresources | ||||||||||||||||||||||||||||
| 202 | # | ||||||||||||||||||||||||||||
| 203 | # This is then followed by each of the sections, e.g.: | ||||||||||||||||||||||||||||
| 204 | # | ||||||||||||||||||||||||||||
| 205 | # FontAFM | ||||||||||||||||||||||||||||
| 206 | # ... afm info ... | ||||||||||||||||||||||||||||
| 207 | # . | ||||||||||||||||||||||||||||
| 208 | # FontOutlines | ||||||||||||||||||||||||||||
| 209 | # ... outlines info ... | ||||||||||||||||||||||||||||
| 210 | # . | ||||||||||||||||||||||||||||
| 211 | # FontFamily | ||||||||||||||||||||||||||||
| 212 | # ... family info ... | ||||||||||||||||||||||||||||
| 213 | # . | ||||||||||||||||||||||||||||
| 214 | # | ||||||||||||||||||||||||||||
| 215 | # Backslash escapes are NOT handled, except for continuation. | ||||||||||||||||||||||||||||
| 216 | # | ||||||||||||||||||||||||||||
| 217 | # We have a _loadXXX subroutine for each section, where XXX is | ||||||||||||||||||||||||||||
| 218 | # the section name. Flexible and extensible. | ||||||||||||||||||||||||||||
| 219 | # | ||||||||||||||||||||||||||||
| 220 | # The current approach is to ignore the first section. | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 2 | $self->_skipSection ($fh); | |||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | # Then, load the sections from the file, skipping unknown ones. | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 2 | my $checkdir = 1; | |||||||||||||||||||||||||||
| 227 | 2 | ▶ | while ( defined ($section = _readLine ($self, $fh)) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 228 | 4 | chomp ($section); | |||||||||||||||||||||||||||
| 229 | 4 | ▶ | if ( $checkdir && $section =~ /^\/(.*)/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$checkdir and $section =~ m[^/(.*)]
MC/DC0%0/2
$checkdir and $section =~ m[^/(.*)]
$checkdir
$section =~ m[^/(.*)]
Truth table66%2/3
A and B
A= $checkdirB= $section =~ m[^/(.*)]
| |||||||||||||||||||||||||||||
| 230 | 0 | $self->{prefix}->[$rscidx] = $1; | |||||||||||||||||||||||||||
| 231 | 0 | $checkdir = 0; | |||||||||||||||||||||||||||
| 232 | 0 | next; | |||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | 4 | $checkdir = 0; | |||||||||||||||||||||||||||
| 235 | 4 | ▶ | my $loader = defined &{"_load$section"} ? "_load$section" : | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | "_skipSection"; | ||||||||||||||||||||||||||||
| 237 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 238 | 4 | ▶ | die ($fn."[$.]: Premature end of $section section\n") | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$fh->eof or not &$loader($self)
MC/DC0%0/2
$fh->eof or not &$loader($self)
$fh->eof
not &$loader($self)
Truth table33%1/3
A or not(B)
A= $fh->eofB= not &$loader($self)
| |||||||||||||||||||||||||||||
| 239 | if $fh->eof || !$loader->($self); | ||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | }; | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | # Set the dfeault value for the directory prefix, if necessary. | ||||||||||||||||||||||||||||
| 245 | 2 | ▶ | $self->{prefix}->[$rscidx] ||= dirname ($fn); | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"prefix"}[$rscidx] ||= dirname($fn)
MC/DC0%0/2
$self->{"prefix"}[$rscidx] ||= dirname($fn)
$self->{"prefix"}[$rscidx]
dirname($fn)
Truth table33%1/3
A ||= B
A= $self->{"prefix"}[$rscidx]B= dirname($fn)
| |||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 2 | $fh->close; | |||||||||||||||||||||||||||
| 248 | 2 | ▶ | die ($@) if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 249 | 2 | $self; | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 22 | ▶ | sub _readLine () { | ||||||||||||||||||||||||||
|
Subroutine
_readLine: called CC=5 SCAR=17.8
| |||||||||||||||||||||||||||||
| 253 | # Read a line, handling continuation lines. | ||||||||||||||||||||||||||||
| 254 | 22 | my $line; | |||||||||||||||||||||||||||
| 255 | 22 | while ( 1 ) { | |||||||||||||||||||||||||||
| 256 | 22 | ▶ | return undef if $fh->eof; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 257 | 20 | $line .= <$fh>; | |||||||||||||||||||||||||||
| 258 | 20 | ▶ | if ( $line =~ /^(.*)\\$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 259 | 0 | $line = $1; | |||||||||||||||||||||||||||
| 260 | 0 | redo; | |||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||
| 262 | 20 | ▶ | $line = $1 if $line =~ /^(.*)%/; # remove comments | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 263 | 20 | $line =~ s/\s+$//; # remove trailing blanks | |||||||||||||||||||||||||||
| 264 | 20 | ▶ | next unless $line =~ /\S/; # skip empty lines | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 265 | 20 | return $line; | |||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | 0 | continue { $line = "" } | |||||||||||||||||||||||||||
| 268 | 0 | undef; | |||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | 2 | ▶ | sub _loadFontAFM ($) { | ||||||||||||||||||||||||||
|
Subroutine
_loadFontAFM: called CC=8 SCAR=22.7
| |||||||||||||||||||||||||||||
| 272 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 273 | 2 | ▶ | print STDERR ($fn, "[$.]: Loading section $section\n") if $trace; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | 2 | my $afm; | |||||||||||||||||||||||||||
| 276 | $afm = $self->{FontAFM} = {} | ||||||||||||||||||||||||||||
| 277 | 2 | ▶ | unless defined ($afm = $self->{FontAFM}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | 2 | my $line; | |||||||||||||||||||||||||||
| 280 | 2 | my $rscidx = pack ("I", $rscidx); | |||||||||||||||||||||||||||
| 281 | 2 | ▶ | while ( defined ($line = _readLine ()) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 282 | 6 | ▶ | return 1 if $line =~ /^\.$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | # PostScriptName=the/file.afm | ||||||||||||||||||||||||||||
| 285 | 4 | ▶ | if ( $line =~ /^([^=]+)=(.*)$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 286 | 4 | ▶ | $afm->{$1} = $rscidx.$2 unless $afm->{$1}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 287 | 4 | next; | |||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||
| 289 | 0 | ▶ | warn ($fn, "[$.]: Invalid FontAFM entry\n") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 290 | unless $error eq "ignore"; | ||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||
| 292 | 0 | return 1; | |||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 0 | ▶ | sub x_loadFontFamily ($) { | ||||||||||||||||||||||||||
|
Subroutine
x_loadFontFamily: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 296 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 297 | 0 | ▶ | print STDERR ($fn, "[$.]: Loading section $section\n") if $trace; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 0 | my $fam; | |||||||||||||||||||||||||||
| 300 | $fam = $self->{FontFamily} = {} | ||||||||||||||||||||||||||||
| 301 | 0 | ▶ | unless defined ($fam = $self->{FontFamily}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | 0 | my $line; | |||||||||||||||||||||||||||
| 304 | 0 | ▶ | while ( defined ($line = _readLine ()) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 305 | 0 | ▶ | return 1 if $line =~ /^\.$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | # Familiyname=Type1,PostScriptName1,Type2,PostScriptName2,... | ||||||||||||||||||||||||||||
| 308 | 0 | ▶ | if ( $line =~ /^([^=]+)==?(.*)$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 309 | 0 | $fam->{$1} = { split (',', $2) }; | |||||||||||||||||||||||||||
| 310 | 0 | next; | |||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||
| 312 | 0 | ▶ | warn ($fn, "[$.]: Invalid FontFamily entry\n") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 313 | unless $error eq "ignore"; | ||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||
| 315 | 0 | return 1; | |||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | 2 | ▶ | sub _loadFontOutline ($) { | ||||||||||||||||||||||||||
|
Subroutine
_loadFontOutline: called CC=8 SCAR=22.7
| |||||||||||||||||||||||||||||
| 319 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 320 | 2 | ▶ | print STDERR ($fn, "[$.]: Loading section $section\n") if $trace; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | 2 | my $pfa; | |||||||||||||||||||||||||||
| 323 | $pfa = $self->{FontOutline} = {} | ||||||||||||||||||||||||||||
| 324 | 2 | ▶ | unless defined ($pfa = $self->{FontOutline}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | 2 | my $line; | |||||||||||||||||||||||||||
| 327 | 2 | my $rscidx = pack ("I", $rscidx); | |||||||||||||||||||||||||||
| 328 | 2 | ▶ | while ( defined ($line = _readLine ()) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 329 | 4 | ▶ | return 1 if $line =~ /^\.$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | # PostScriptName=the/file.pfa | ||||||||||||||||||||||||||||
| 332 | 2 | ▶ | if ( $line =~ /^([^=]+)=(.*)$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 333 | 2 | ▶ | $pfa->{$1} = $rscidx.$2 unless $pfa->{$1}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 334 | 2 | next; | |||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||
| 336 | 0 | ▶ | warn ($fn, "[$.]: Invalid FontOutline entry\n") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 337 | unless $error eq "ignore"; | ||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||
| 339 | 0 | return 1; | |||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | 2 | ▶ | sub _skipSection ($) { | ||||||||||||||||||||||||||
|
Subroutine
_skipSection: called CC=5 SCAR=17.0
| |||||||||||||||||||||||||||||
| 343 | 2 | my ($self) = (@_); | |||||||||||||||||||||||||||
| 344 | 2 | ▶ | $section ||= "list"; | ||||||||||||||||||||||||||
|
Condition50%1/2
$section ||= "list"
MC/DC0%0/1
$section ||= "list"
$section
Truth table50%1/2
A
A= $section
| |||||||||||||||||||||||||||||
| 345 | 2 | ▶ | print STDERR ($fn, "[$.]: Skipping section $section\n") if $trace; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||
| 347 | 2 | my $line; | |||||||||||||||||||||||||||
| 348 | 2 | ▶ | while ( defined ($line = _readLine ()) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 349 | 6 | ▶ | return 1 if $line =~ /^\.$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||
| 351 | 0 | return 1; | |||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | 1 | 1; | |||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | __END__ | ||||||||||||||||||||||||||||