| 1 | # RCS Status : $Id: FontMetrics.pm,v 1.25 2005-06-10 22:56:21+02 jv Exp $ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # Author : Johan Vromans | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # Created On : December 1998 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # Last Modified By: Johan Vromans | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # Last Modified On: Fri Jun 10 19:00:43 2005 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # Update Count : 479 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # Status : Released | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | ################ Module Preamble ################ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | package PostScript::FontMetrics; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | BEGIN { require 5.005; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use IO qw(File); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | $VERSION = "1.06"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use constant FONTSCALE => 1000; # normal value for font design | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=19.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | my $font = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | my (%atts) = (error => 'die', | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | verbose => 0, trace => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | @_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | my $self = { file => $font }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | return $self unless defined $font; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | $self->{debug} = $atts{debug}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | ▶ | $self->{trace} = $self->{debug} || $atts{trace}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{'debug'} || $atts{'trace'}
MC/DC0%0/2
$self->{'debug'} || $atts{'trace'}
$self->{'debug'}
$atts{'trace'}
Truth table33%1/3
A || B
A= $self->{'debug'}B= $atts{'trace'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | $self->{verbose} = $self->{trace} || $atts{verbose}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{'trace'} || $atts{'verbose'}
MC/DC0%0/2
$self->{'trace'} || $atts{'verbose'}
$self->{'trace'}
$atts{'verbose'}
Truth table33%1/3
A || B
A= $self->{'trace'}B= $atts{'verbose'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | my $error = lc($atts{error}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | $self->{die} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | die(@_) if $error eq "die"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | warn(@_) if $error eq "warn"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | eval { $self->_loadafm }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | $self->_die($@); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub FileName { my $self = shift; $self->{file}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FileName: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub MetricsData { my $self = shift; $self->{data}; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
MetricsData: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 219 | ▶ | sub CharWidthData { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
CharWidthData: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 219 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 219 | ▶ | $self->_getwidthdata() unless defined $self->{Wx}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 219 | $self->{Wx}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 219 | ▶ | sub EncodingVector { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
EncodingVector: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 219 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 219 | ▶ | $self->_getwidthdata() unless defined $self->{encodingvector}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 219 | $self->{encodingvector}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub CharBBoxData { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
CharBBoxData: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | $self->_getbboxdata() unless defined $self->{BBox}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $self->{BBox}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 216 | ▶ | sub KernData { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
KernData: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 216 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 216 | ▶ | $self->_getkerndata() unless defined $self->{Kern}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 216 | $self->{Kern}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | ▶ | sub _loadafm ($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_loadafm: called CC=21 SCAR=34.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | my ($self) = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | my $data; # afm data | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | my $fn = $self->{file}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | my $fh = new IO::File; # font file | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | my $sz = -s $fn; # file size | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | ▶ | $fh->open ($fn) || $self->_die("$fn: $!\n"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | ▶ | print STDERR ("$fn: Loading AFM file\n") if $self->{verbose}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # Read in the afm data. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | my $len = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | binmode($fh); # (Some?) Windows need this | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | ▶ | unless ( ($len = $fh->sysread ($data, 4, 0)) == 4 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $self->_die("$fn: Expecting $sz bytes, got $len bytes\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | $self->{origdataformat} = 'afm'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | ▶ | if ( $data eq "\0\1\0\0" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $fh->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # For the time being, Font::TTF is optional. Be careful. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | require PostScript::Font::TTtoType42; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | $self->_die("$fn: Cannot convert True Type font\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | my $wrapper = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | new PostScript::Font::TTtoType42:: ($fn, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | verbose => $self->{verbose}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | trace => $self->{trace}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | debug => $self->{debug}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $data = ${$wrapper->afm_as_string}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | $self->{t42wrapper} = $wrapper; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $self->{origdataformat} = 'ttf'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 1 | ▶ | while ( $fh->sysread ($data, 32768, $len) > 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | $len = length ($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | $fh->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | ▶ | print STDERR ("Read $len bytes from $fn\n") if $self->{trace}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | ▶ | $self->_die("$fn: Expecting $sz bytes, got $len bytes\n") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$sz == -1 or $sz == $len
MC/DC0%0/2
$sz == -1 or $sz == $len
$sz == -1
$sz == $len
Truth table33%1/3
A or B
A= $sz == -1B= $sz == $len
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | unless $sz == -1 || $sz == $len; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # Normalise line endings. Get rid of trailing space as well. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | $data =~ s/\s*\015\012?/\n/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | ▶ | if ( $data !~ /StartFontMetrics/ || $data !~ /EndFontMetrics/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$data =~ /StartFontMetrics/ and $data =~ /EndFontMetrics/
MC/DC0%0/2
$data =~ /StartFontMetrics/ and $data =~ /EndFontMetrics/
$data =~ /StartFontMetrics/
$data =~ /EndFontMetrics/
Truth table33%1/3
A and B
A= $data =~ /StartFontMetrics/B= $data =~ /EndFontMetrics/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $self->_die("$fn: Not a recognizable AFM file\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | $self->{data} = $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # Initially, we only load the "global" info from the AFM data. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # Other parts are parsed when required. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | local ($_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | foreach ( split (/\n/, $self->{data}) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 598 | ▶ | next if /^StartKernData/ .. /^EndKernData/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 318 | ▶ | next if /^StartComposites/ .. /^EndComposites/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 260 | ▶ | next if /^StartCharMetrics/ .. /^EndCharMetrics/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 30 | ▶ | last if /^EndFontMetrics/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 29 | ▶ | if ( /^FontBBox\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)\s*$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | $self->{fontbbox} = [$1,$2,$3,$4]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | elsif ( /(^\w+)\s+(.*)/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 28 | my ($key, $val) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 28 | $key = lc ($key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 28 | ▶ | if ( defined $self->{$key}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 11 | ▶ | $self->{$key} = [ $self->{$key} ] unless ref $self->{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 11 | push (@{$self->{$key}}, $val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 17 | $self->{$key} = $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | ▶ | sub _getwidthdata { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_getwidthdata: called CC=14 SCAR=28.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # This is adapted from Gisle Aas' Font-AFM 1.17 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 1 | local ($_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | my %wx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 1 | my $dontencode = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 1 | ▶ | unless ( defined $self->{encodingvector} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 1 | $dontencode = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | ▶ | if ( defined $self->{encodingscheme} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | ▶ | if ( $self->{encodingscheme} eq "AdobeStandardEncoding" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 1 | require PostScript::StandardEncoding; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | $self->{encodingvector} = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 1 | [ @{PostScript::StandardEncoding->array} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 1 | $dontencode = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | elsif ( $self->{encodingscheme} eq "ISOLatin1Encoding" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | require PostScript::ISOLatin1Encoding; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | $self->{encodingvector} = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | [ @{PostScript::ISOLatin1Encoding->array} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | $dontencode = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | $self->{encodingvector} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | $self->{encodingvector} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 1 | my $enc = $self->{encodingvector}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | my $nglyphs = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 1 | my $nenc = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 1 | foreach ( split (/\n/, $self->{data}) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 598 | ▶ | if ( /^StartCharMetrics/ .. /^EndCharMetrics/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | # Only lines that start with "C" or "CH" are parsed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # C nn, C -1 or C <HH> (two hexits). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 230 | ▶ | next unless /^CH?\s+(-?\d+|<[0-9a-f]+>)\s*;/i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 228 | my $ix = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 228 | ▶ | $ix = hex($1) if $1 =~ /^<(.+)>$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 228 | my ($name) = /\bN\s+(\.?\w+(?:-\w+)?)\s*;/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 228 | my ($wx) = /\bWX\s+(\d+)\s*;/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 228 | $wx{$name} = $wx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 228 | $nglyphs++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 228 | ▶ | $enc->[$ix] = $name, $nenc++ unless $dontencode || $ix < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$dontencode or $ix < 0
MC/DC0%0/2
$dontencode or $ix < 0
$dontencode
$ix < 0
Truth table33%1/3
A or B
A= $dontencodeB= $ix < 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 228 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 368 | ▶ | last if /^EndFontMetrics/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 1 | ▶ | unless ( exists $wx{'.notdef'} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 1 | $wx{'.notdef'} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | print STDERR ($self->FileName, ": Number of glyphs = $nglyphs, ", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 1 | ▶ | "encoded = $nenc\n") if $self->{verbose}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 1 | $self->{Wx} = \%wx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 1 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | ▶ | sub _getbboxdata { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_getbboxdata: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | # This is adapted from Gisle Aas' Font-AFM 1.17 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | local ($_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | my %bbox; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | foreach ( split (/\n/, $self->{data}) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | if ( /^StartCharMetrics/ .. /^EndCharMetrics/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # Only lines that start with "C" or "CH" are parsed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | next unless /^CH?\s/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | my ($name) = /\bN\s+(\.?\w+)\s*;/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | my (@bbox) = /\bB\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)\s+(-?\d+)\s*;/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | $bbox{$name} = \@bbox; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | last if /^EndFontMetrics/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | unless ( exists $bbox{'.notdef'} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | $bbox{'.notdef'} = [0, 0, 0, 0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | $self->{BBox} = \%bbox; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 1 | ▶ | sub _getkerndata { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_getkerndata: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 1 | local ($_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 1 | my $k = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 1 | my %kern; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 1 | foreach ( split (/\n/, $self->{data}) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 598 | ▶ | if ( /^StartKern(Data|Pairs)/ .. /^EndKern(Data|Pairs)/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 274 | ▶ | next unless /^KPX\s+(\S+)\s+(\S+)\s+(-?\d+)/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 271 | $kern{$1,$2} = $3; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 271 | $k++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 595 | ▶ | last if /^EndFontMetrics/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 1 | ▶ | ${kern}{'.notdef','.notdef'} = 0 unless %kern; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | print STDERR ($self->FileName, ": Number of kern pairs = $k\n") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 1 | ▶ | if $self->{verbose}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 1 | $self->{Kern} = \%kern; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 1 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 1 | ▶ | sub setEncoding { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setEncoding: called CC=7 SCAR=32.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 1 | my ($self, $enc) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 1 | ▶ | if ( ref($enc) && UNIVERSAL::isa($enc,'ARRAY') && scalar(@$enc) == 256 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition33%2/6
ref $enc and UNIVERSAL::isa($enc, "ARRAY") and scalar @$enc == 256
ref $enc and UNIVERSAL::isa($enc, "ARRAY")
MC/DC0%0/3
ref $enc and UNIVERSAL::isa($enc, "ARRAY") and scalar @$enc == 256
ref $enc
UNIVERSAL::isa($enc, "ARRAY")
scalar @$enc == 256
Truth table25%1/4
A and B and C
A= ref $encB= UNIVERSAL::isa($enc, "ARRAY")C= scalar @$enc == 256
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | # Array ref is okay. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | elsif ( $enc eq "StandardEncoding" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | require PostScript::StandardEncoding; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | $enc = [ @{PostScript::StandardEncoding->array} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | elsif ( $enc eq "ISOLatin1Encoding" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | require PostScript::ISOLatin1Encoding; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | $enc = [ @{PostScript::ISOLatin1Encoding->array} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | elsif ( $enc eq "ISOLatin9Encoding" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | require PostScript::ISOLatin9Encoding; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | $enc = [ @{PostScript::ISOLatin9Encoding->array} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | croak ("Invalid encoding vector"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 1 | $self->{encodingvector} = $enc; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 1 | delete $self->{_charcache}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 1 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 3 | ▶ | sub stringwidth { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stringwidth: called CC=6 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 3 | my ($self, $string, $pt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 3 | my $wx = $self->CharWidthData; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 3 | my $ev = $self->EncodingVector; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 3 | ▶ | if ( scalar(@{$self->{encodingvector}}) <= 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | $self->_die($self->FileName . ": Missing Encoding\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 3 | my $wd = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 3 | foreach ( unpack ("C*", $string) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 3 | ▶ | $wd += $wx->{$ev->[$_]||'.undef'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ev->[$_] || '.undef'
MC/DC0%0/1
$ev->[$_] || '.undef'
$ev->[$_]
Truth table50%1/2
A
A= $ev->[$_]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 3 | ▶ | if ( defined $pt ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | ▶ | carp ("Using a PointSize argument to stringwidth is deprecated") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | if $^W; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | $wd *= $pt / FONTSCALE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 3 | $wd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 195 | ▶ | sub kstringwidth { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
kstringwidth: called CC=8 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 195 | my ($self, $string, $pt) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 195 | my $wx = $self->CharWidthData; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 195 | my $ev = $self->EncodingVector; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 195 | ▶ | if ( scalar(@{$self->{encodingvector}}) <= 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | croak ($self->FileName . ": Missing Encoding\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 195 | my $kr = $self->KernData; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 195 | my $wd = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 195 | my $prev; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 195 | foreach ( unpack ("C*", $string) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 1046 | ▶ | my $this = $ev->[$_] || '.notdef'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ev->[$_] || '.notdef'
MC/DC0%0/1
$ev->[$_] || '.notdef'
$ev->[$_]
Truth table50%1/2
A
A= $ev->[$_]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 1046 | $wd += $wx->{$this}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 1046 | ▶ | if ( defined $prev ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 851 | my $kw = $kr->{$prev,$this}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 851 | ▶ | $wd += $kw if defined $kw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 1046 | $prev = $this; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 195 | ▶ | if ( defined $pt ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | carp ("Using a PointSize argument to kstringwidth is deprecated") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | if $^W; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | $wd *= $pt / FONTSCALE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 195 | $wd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 22 | ▶ | sub kstring { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
kstring: called CC=20 SCAR=30.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 22 | my ($self, $string, $ext) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 22 | ▶ | return (wantarray ? () : []) unless length ($string); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 22 | my $wx = $self->CharWidthData; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 22 | my $ev = $self->EncodingVector; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 22 | ▶ | if ( scalar(@{$self->{encodingvector}}) <= 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | croak ($self->FileName . ": Missing Encoding\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 22 | my $kr = $self->KernData; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 22 | ▶ | my $wd = (defined $ext ? $wx->{'space'}+$ext : 0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 22 | my @res = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 22 | my $prev = '.undef'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 22 | foreach ( split ('', $string) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | # Check for flex space. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 1327 | ▶ | if ( defined $ext && $_ eq " " ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $ext and $_ eq " "
MC/DC100%2/2
defined $ext and $_ eq " "
defined $ext
$_ eq " "
Truth table100%3/3
A and B
A= defined $extB= $_ eq " "
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | # If we have something, accumulate. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 184 | ▶ | if ( @res ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | # Add to displacement. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 184 | ▶ | if ( $prev eq 'space' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | $res[$#res] += $wd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | # Turn last item into string, and push the displacement. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 184 | $res[$#res] =~ s/([()\\]|[^\040-\176])/sprintf("\\%03o",ord($1))/eg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 184 | $res[$#res] = "(".$res[$#res].")"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 184 | push (@res, $wd); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | # First item, push. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | push (@res, $wd); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 184 | $prev = 'space'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 184 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | # Get the glyph name and kern value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 1143 | ▶ | my $this = $ev->[ord($_)] || '.undef'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$ev[ord $_] || '.undef'
MC/DC0%0/1
$$ev[ord $_] || '.undef'
$$ev[ord $_]
Truth table50%1/2
A
A= $$ev[ord $_]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 1143 | ▶ | my $kw = $kr->{$prev,$this} || 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$kr{join $;, $prev, $this} || 0
MC/DC100%1/1
$$kr{join $;, $prev, $this} || 0
$$kr{join $;, $prev, $this}
Truth table100%2/2
A
A= $$kr{join $;, $prev, $this}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 1143 | { local ($^W) = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | print STDERR ("$prev $this $kw :$res[-3]:$res[-2]:$res[-1]:\n") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 1143 | ▶ | if $self->{debug}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | # Nothing to kern? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 1143 | ▶ | if ( defined $ext && $prev eq 'space' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
defined $ext and $prev eq "space"
MC/DC100%2/2
defined $ext and $prev eq "space"
defined $ext
$prev eq "space"
Truth table100%3/3
A and B
A= defined $extB= $prev eq "space"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | # Accumulate displacement. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 184 | $res[$#res] += $kw; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 184 | push (@res, $_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | elsif ( $kw == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 943 | ▶ | if ( $prev eq '.undef' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | # New item. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 22 | push (@res, $_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | # Accumulate text. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 921 | $res[$#res] .= $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | # Turn previous into string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 16 | $res[$#res] =~ s/([()\\]|[^\040-\176])/sprintf("\\%03o",ord($1))/eg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 16 | $res[$#res] = "(".$res[$#res].")"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | # Add kerning value and the new item. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 16 | push (@res, $kw, $_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 1143 | $prev = $this; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | # Turn the last item into string, if needed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 22 | ▶ | if ( !(defined $ext && $prev eq 'space') ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $ext and $prev eq "space"
MC/DC0%0/2
defined $ext and $prev eq "space"
defined $ext
$prev eq "space"
Truth table66%2/3
A and B
A= defined $extB= $prev eq "space"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 22 | $res[$#res] =~ s/([()\\]|[^\040-\176])/sprintf("\\%03o",ord($1))/eg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 22 | $res[$#res] = "(".$res[$#res].")"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | # Return. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 22 | ▶ | wantarray ? @res : \@res; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | sub char { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
char: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | my ($self, $glyph) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | # Return from cache if possible. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | my $char = $self->{_charcache}->{$glyph}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | ▶ | return $char if defined $char; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | # Look it up. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | $char = -1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | foreach ( @{$self->EncodingVector} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | $char++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | next unless $_ eq $glyph; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | return $self->{_charcache}->{$glyph} = pack("C",$char); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 2 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | # This is adapted from Gisle Aas' Font-AFM 1.17 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 2 | ▶ | no strict 'vars'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 2 | ▶ | if ( $AUTOLOAD =~ /::DESTROY$/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | # Prevent the eval from clobbering outer eval error status. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 1 | local ($@); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | # Define a dummy destoyer, and jump tp it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 1 | ▶ | eval "sub $AUTOLOAD {}"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 1 | goto &$AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 1 | my $name = $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 1 | $name =~ s/^.*:://; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 1 | return $_[0]->{lc $name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | ▶ | sub _die { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_die: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | my ($self, @msg) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | $self->{die}->(@msg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||