| 1 | # RCS Status : $Id: PrinterFontMetrics.pm,v 1.7 2003-10-23 14:12:04+02 jv Exp $ | ||||||||||||||||||||||||||||
| 2 | # Author : Andrew Ford | ||||||||||||||||||||||||||||
| 3 | # Created On : March 2001 | ||||||||||||||||||||||||||||
| 4 | # Last Modified By: Johan Vromans | ||||||||||||||||||||||||||||
| 5 | # Last Modified On: Thu Oct 23 14:12:02 2003 | ||||||||||||||||||||||||||||
| 6 | # Update Count : 45 | ||||||||||||||||||||||||||||
| 7 | # Status : Development | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | ################ Module Preamble ################ | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | package PostScript::PrinterFontMetrics; | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | BEGIN { require 5.005; } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use IO qw(File); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use vars qw($VERSION @ISA $AUTOLOAD); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 1 | $VERSION = "0.08"; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use PostScript::FontMetrics; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use PostScript::StandardEncoding; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 1 | @ISA = qw(PostScript::FontMetrics); | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | # Definitions of the PFM file layout | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 1 | ▶ | use constant PFM_HEADER_LENGTH => 117; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | 1 | ▶ | use constant PFM_HEADER_TEMPLATE => 'vVa60vvvvvvvCCCvCvvCvvCCCCvVVVV'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | my @pfm_header_fields | ||||||||||||||||||||||||||||
| 35 | 1 | = ( | |||||||||||||||||||||||||||
| 36 | 'dfVersion', | ||||||||||||||||||||||||||||
| 37 | 'dfSize', | ||||||||||||||||||||||||||||
| 38 | 'dfCopyright', | ||||||||||||||||||||||||||||
| 39 | 'dfType', | ||||||||||||||||||||||||||||
| 40 | 'dfPoint', | ||||||||||||||||||||||||||||
| 41 | 'dfVertRes', | ||||||||||||||||||||||||||||
| 42 | 'dfHorisRes', | ||||||||||||||||||||||||||||
| 43 | 'dfAscent', # ATM FontBBox (fourth element) | ||||||||||||||||||||||||||||
| 44 | 'dfInternalLeading', | ||||||||||||||||||||||||||||
| 45 | 'dfExternalLeading', | ||||||||||||||||||||||||||||
| 46 | 'dfItalic', | ||||||||||||||||||||||||||||
| 47 | 'dfUnderline', | ||||||||||||||||||||||||||||
| 48 | 'dfStrikeOut', | ||||||||||||||||||||||||||||
| 49 | 'dfWeight', | ||||||||||||||||||||||||||||
| 50 | 'dfCharSet', | ||||||||||||||||||||||||||||
| 51 | 'dfPixWidth', | ||||||||||||||||||||||||||||
| 52 | 'dfPixHeight', | ||||||||||||||||||||||||||||
| 53 | 'dfPitchAndFamily', | ||||||||||||||||||||||||||||
| 54 | 'dfAvgWidth', | ||||||||||||||||||||||||||||
| 55 | 'dfMaxWidth', | ||||||||||||||||||||||||||||
| 56 | 'dfFirstChar', | ||||||||||||||||||||||||||||
| 57 | 'dfLastChar', | ||||||||||||||||||||||||||||
| 58 | 'dfBreakChar', | ||||||||||||||||||||||||||||
| 59 | 'dfWidthBytes', | ||||||||||||||||||||||||||||
| 60 | 'dfDevice', | ||||||||||||||||||||||||||||
| 61 | 'dfFace', | ||||||||||||||||||||||||||||
| 62 | 'dfBitsPointer', | ||||||||||||||||||||||||||||
| 63 | 'dfBitsOffset', | ||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | # The PFM Extension table just contains offsets of other structures | ||||||||||||||||||||||||||||
| 67 | # and so its members are not entered into the data hash | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 1 | ▶ | use constant PFM_EXTENSION_OFFSET => PFM_HEADER_LENGTH; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 70 | 1 | ▶ | use constant PFM_EXTENSION_LENGTH => 30; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 71 | 1 | ▶ | use constant PFM_EXTENSION_TEMPLATE => 'vVVVVVVV'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 72 | my @pfm_extension_fields | ||||||||||||||||||||||||||||
| 73 | 1 | = ( | |||||||||||||||||||||||||||
| 74 | 'dfSizeFields', # size of this section | ||||||||||||||||||||||||||||
| 75 | 'dfExtMetricsOffset', # offset of the Extended Text Metrics section | ||||||||||||||||||||||||||||
| 76 | 'dfExtentTable', # offset of the Extent table | ||||||||||||||||||||||||||||
| 77 | 'dfOriginTable', | ||||||||||||||||||||||||||||
| 78 | 'dfPairKernTable', # offset of the kern pair table | ||||||||||||||||||||||||||||
| 79 | 'dfTrackKernTable', | ||||||||||||||||||||||||||||
| 80 | 'dfDriverInfo', | ||||||||||||||||||||||||||||
| 81 | 'dfReserved' | ||||||||||||||||||||||||||||
| 82 | ); | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 1 | ▶ | use constant PFM_EXT_METRICS_OFFSET => PFM_EXTENSION_OFFSET + PFM_EXTENSION_LENGTH; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 85 | 1 | ▶ | use constant PFM_EXT_METRICS_LENGTH => 52; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 86 | 1 | ▶ | use constant PFM_EXT_METRICS_TEMPLATE => 'v' x 26; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 87 | my @pfm_ext_metrics_fields | ||||||||||||||||||||||||||||
| 88 | 1 | = ( | |||||||||||||||||||||||||||
| 89 | 'etmSize', | ||||||||||||||||||||||||||||
| 90 | 'etmPointSize', | ||||||||||||||||||||||||||||
| 91 | 'etmOrientation', | ||||||||||||||||||||||||||||
| 92 | 'etmMasterHeight', | ||||||||||||||||||||||||||||
| 93 | 'etmMinScale', | ||||||||||||||||||||||||||||
| 94 | 'etmMaxScale', | ||||||||||||||||||||||||||||
| 95 | 'etmMasterUnits', | ||||||||||||||||||||||||||||
| 96 | 'etmCapHeight', # AFM CapHeight | ||||||||||||||||||||||||||||
| 97 | 'etmXHeight', # AFM XHeight | ||||||||||||||||||||||||||||
| 98 | 'etmLowerCaseAscent', # AFM Ascender | ||||||||||||||||||||||||||||
| 99 | 'etmLowerCaseDescent', # AFM -Descender | ||||||||||||||||||||||||||||
| 100 | 'etmSlant', | ||||||||||||||||||||||||||||
| 101 | 'etmSuperScript', | ||||||||||||||||||||||||||||
| 102 | 'etmSubScript', | ||||||||||||||||||||||||||||
| 103 | 'etmSuperScriptSize', | ||||||||||||||||||||||||||||
| 104 | 'etmSubScriptSize', | ||||||||||||||||||||||||||||
| 105 | 'etmUnderlineOffset', # AFM -UnderlinePostition | ||||||||||||||||||||||||||||
| 106 | 'etmUnderlineWidth', # AFM UnderlineThickness | ||||||||||||||||||||||||||||
| 107 | 'etmDoubleUpperUnderlineOffset', | ||||||||||||||||||||||||||||
| 108 | 'etmDoubleLowerUnderlineOffset', | ||||||||||||||||||||||||||||
| 109 | 'etmDoubleUpperUnderlineWidth', | ||||||||||||||||||||||||||||
| 110 | 'etmDoubleLowerUnderlineWidth', | ||||||||||||||||||||||||||||
| 111 | 'etmStrikeOutOffset', | ||||||||||||||||||||||||||||
| 112 | 'etmStrikeOutWidth', | ||||||||||||||||||||||||||||
| 113 | 'etmKernPairs', # number of kern pairs | ||||||||||||||||||||||||||||
| 114 | 'etmKernTracks', | ||||||||||||||||||||||||||||
| 115 | ); | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 1 | ▶ | use constant PFM_PSINFO_OFFSET => PFM_EXT_METRICS_OFFSET + PFM_EXT_METRICS_LENGTH; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 118 | my @pfm_postscript_info_fields | ||||||||||||||||||||||||||||
| 119 | 1 | = ( | |||||||||||||||||||||||||||
| 120 | 'DeviceType', | ||||||||||||||||||||||||||||
| 121 | 'WindowsName', | ||||||||||||||||||||||||||||
| 122 | 'PostScriptName', # AFM FontName | ||||||||||||||||||||||||||||
| 123 | ); | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 172 | my %pfm_field_map = ( map { $_ => \&_pfm_header } @pfm_header_fields, | |||||||||||||||||||||||||||
| 126 | 72 | map { $_ => \&_pfm_extension } @pfm_extension_fields, | |||||||||||||||||||||||||||
| 127 | 32 | map { $_ => \&_pfm_ext_metrics } @pfm_ext_metrics_fields, | |||||||||||||||||||||||||||
| 128 | 1 | map { $_ => \&_pfm_device_section } @pfm_postscript_info_fields ); | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=19.3
Pod
documented
| |||||||||||||||||||||||||||||
| 131 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 132 | 1 | my $font = shift; | |||||||||||||||||||||||||||
| 133 | 1 | my %atts = ( error => 'die', | |||||||||||||||||||||||||||
| 134 | verbose => 0, trace => 0, debug => 0, | ||||||||||||||||||||||||||||
| 135 | @_ ); | ||||||||||||||||||||||||||||
| 136 | 1 | my $self = { file => $font }; | |||||||||||||||||||||||||||
| 137 | 1 | bless $self, $class; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 1 | ▶ | return $self unless defined $font; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 1 | $self->{debug} = $atts{debug}; | |||||||||||||||||||||||||||
| 142 | 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'}
| |||||||||||||||||||||||||||||
| 143 | 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'}
| |||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 1 | my $error = lc($atts{error}); | |||||||||||||||||||||||||||
| 146 | 0 | ▶ | $self->{die} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 147 | 0 | ▶ | die(@_) if $error eq "die"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | 0 | ▶ | warn(@_) if $error eq "warn"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 1 | }; | |||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 1 | eval { $self->_loadpfm }; | |||||||||||||||||||||||||||
| 152 | 1 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | 0 | $self->_die($@); | |||||||||||||||||||||||||||
| 154 | 0 | return undef; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 1 | $self; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | sub FileName { return $_[0]->{file}; } | ||||||||||||||||||||||||||
|
Subroutine
FileName: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 161 | 0 | ▶ | sub FontName { return $_[0]->_pfm_device_section->{PostScriptName}; } | ||||||||||||||||||||||||||
|
Subroutine
FontName: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 162 | 0 | ▶ | sub CapHeight { return $_[0]->_pfm_extended_text_metrics->{etmCapHeight}; } | ||||||||||||||||||||||||||
|
Subroutine
CapHeight: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 163 | 0 | ▶ | sub XHeight { return $_[0]->_pfm_extended_text_metrics->{etmXHeight}; } | ||||||||||||||||||||||||||
|
Subroutine
XHeight: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 164 | 0 | ▶ | sub Ascender { return $_[0]->_pfm_extended_text_metrics->{etmLowerCaseAscent}; } | ||||||||||||||||||||||||||
|
Subroutine
Ascender: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 165 | 0 | ▶ | sub Descender { return -$_[0]->_pfm_extended_text_metrics->{etmLowerCaseDescent}; } | ||||||||||||||||||||||||||
|
Subroutine
Descender: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 166 | 0 | ▶ | sub MetricsData { return $_[0]->{_rawdata}; } | ||||||||||||||||||||||||||
|
Subroutine
MetricsData: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 0 | ▶ | sub HeaderFields { return @pfm_header_fields; } | ||||||||||||||||||||||||||
|
Subroutine
HeaderFields: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 169 | 0 | ▶ | sub ExtensionFields { return @pfm_extension_fields; } | ||||||||||||||||||||||||||
|
Subroutine
ExtensionFields: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 170 | 0 | ▶ | sub ExtMetricsFields { return @pfm_ext_metrics_fields; } | ||||||||||||||||||||||||||
|
Subroutine
ExtMetricsFields: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 171 | 0 | ▶ | sub DeviceInfoFields { return @pfm_postscript_info_fields; } | ||||||||||||||||||||||||||
|
Subroutine
DeviceInfoFields: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 1 | ▶ | sub CharWidthData { | ||||||||||||||||||||||||||
|
Subroutine
CharWidthData: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||
| 174 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 175 | 1 | my $char = $self->_pfm_header->{dfFirstChar}; | |||||||||||||||||||||||||||
| 176 | my $encoding = | ||||||||||||||||||||||||||||
| 177 | 1 | ▶ | $self->{encodingvector} ||= PostScript::StandardEncoding->array; | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"encodingvector"} ||= "PostScript::StandardEncoding"->array
MC/DC0%0/2
$self->{"encodingvector"} ||= "PostScript::StandardEncoding"->array
$self->{"encodingvector"}
"PostScript::StandardEncoding"->array
Truth table33%1/3
A ||= B
A= $self->{"encodingvector"}B= "PostScript::StandardEncoding"->array
| |||||||||||||||||||||||||||||
| 178 | 1 | my $widthdata = {}; | |||||||||||||||||||||||||||
| 179 | 1 | foreach my $width (@{$self->_pfm_extent_table}) { | |||||||||||||||||||||||||||
| 180 | 224 | my $char = $encoding->[$char++]; | |||||||||||||||||||||||||||
| 181 | 224 | ▶ | $widthdata->{$char} = $width if $char and $char ne '.notdef'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$char and $char ne ".notdef"
MC/DC50%1/2
$char and $char ne ".notdef"
$char
$char ne ".notdef"
Truth table66%2/3
A and B
A= $charB= $char ne ".notdef"
| |||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | 1 | $widthdata; | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 1 | ▶ | sub EncodingVector { | ||||||||||||||||||||||||||
|
Subroutine
EncodingVector: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||
| 187 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 188 | 1 | ▶ | $self->{encodingvector} ||= PostScript::StandardEncoding->array; | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"encodingvector"} ||= "PostScript::StandardEncoding"->array
MC/DC0%0/2
$self->{"encodingvector"} ||= "PostScript::StandardEncoding"->array
$self->{"encodingvector"}
"PostScript::StandardEncoding"->array
Truth table33%1/3
A ||= B
A= $self->{"encodingvector"}B= "PostScript::StandardEncoding"->array
| |||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 1 | ▶ | sub KernData { | ||||||||||||||||||||||||||
|
Subroutine
KernData: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 192 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 193 | 1 | my $raw_kerndata = $self->_pfm_kerndata; | |||||||||||||||||||||||||||
| 194 | 1 | my %enc_kerndata; | |||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | my $encoding = | ||||||||||||||||||||||||||||
| 197 | 1 | ▶ | $self->{encodingvector} ||= PostScript::StandardEncoding->array; | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"encodingvector"} ||= "PostScript::StandardEncoding"->array
MC/DC0%0/2
$self->{"encodingvector"} ||= "PostScript::StandardEncoding"->array
$self->{"encodingvector"}
"PostScript::StandardEncoding"->array
Truth table33%1/3
A ||= B
A= $self->{"encodingvector"}B= "PostScript::StandardEncoding"->array
| |||||||||||||||||||||||||||||
| 198 | 1 | ▶ | while (my($pair, $kern) = each(%$raw_kerndata)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | 998 | my($c1,$c2) = unpack("aa", $pair); | |||||||||||||||||||||||||||
| 200 | 998 | $enc_kerndata{$encoding->[ord $c1], $encoding->[ord $c2]} = $kern; | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | 1 | return \%enc_kerndata; | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | # _loadpfm just reads the PFM file into memory (as the _rawdata element) | ||||||||||||||||||||||||||||
| 206 | # The individual file sections are only unpacked as and when they are needed. | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 1 | ▶ | sub _loadpfm ($) { | ||||||||||||||||||||||||||
|
Subroutine
_loadpfm: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||
| 209 | 1 | my($self) = @_; | |||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 1 | my $fn = $self->{file}; | |||||||||||||||||||||||||||
| 212 | 1 | local *FH; # font file | |||||||||||||||||||||||||||
| 213 | 1 | my $sz = $self->{filesize} = -s $fn; # file size | |||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 1 | ▶ | open(FH, $fn) || $self->_die("$fn: $!\n"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | 1 | ▶ | print STDERR ("$fn: Loading PFM file\n") if $self->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | 1 | binmode(FH); # requires a file handle, yuck | |||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | # Read in the pfm data. | ||||||||||||||||||||||||||||
| 220 | 1 | my $len = 0; | |||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 1 | ▶ | unless ( ($len = sysread (FH, $self->{_rawdata}, $sz, 0)) == $sz ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | 0 | $self->_die("$fn: Expecting $sz bytes, got $len bytes\n"); | |||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | # Return the PFM file Header section (unpacking if necessary) | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 2 | ▶ | sub _pfm_header { | ||||||||||||||||||||||||||
|
Subroutine
_pfm_header: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 230 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 231 | 2 | ▶ | my $header = $self->{_pfm_header} ||= {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"_pfm_header"} ||= {}
MC/DC100%1/1
$self->{"_pfm_header"} ||= {}
$self->{"_pfm_header"}
Truth table100%2/2
A
A= $self->{"_pfm_header"}
| |||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 2 | ▶ | if (! keys %$header) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | @$header{@pfm_header_fields} | ||||||||||||||||||||||||||||
| 235 | = unpack(PFM_HEADER_TEMPLATE, | ||||||||||||||||||||||||||||
| 236 | 1 | substr($self->{_rawdata}, 0, PFM_HEADER_LENGTH)); | |||||||||||||||||||||||||||
| 237 | 1 | $header->{dfCopyright} =~ s/\0.*//; | |||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | die "$self->{file}: file size is $self->{filesize} but dfSize = $header->{dfsize}" | ||||||||||||||||||||||||||||
| 240 | 1 | ▶ | unless $header->{dfSize} == $self->{filesize}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | 2 | $header; | |||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | # Unpack the PFM Extension | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 2 | ▶ | sub _pfm_extension { | ||||||||||||||||||||||||||
|
Subroutine
_pfm_extension: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 248 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 249 | 2 | ▶ | my $extension = $self->{_pfm_extension} ||= {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"_pfm_extension"} ||= {}
MC/DC100%1/1
$self->{"_pfm_extension"} ||= {}
$self->{"_pfm_extension"}
Truth table100%2/2
A
A= $self->{"_pfm_extension"}
| |||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 2 | ▶ | if (! keys %$extension) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 252 | @$extension{@pfm_extension_fields} | ||||||||||||||||||||||||||||
| 253 | = unpack(PFM_EXTENSION_TEMPLATE, | ||||||||||||||||||||||||||||
| 254 | 1 | substr($self->{_rawdata}, PFM_EXTENSION_OFFSET, PFM_EXTENSION_LENGTH)); | |||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | 2 | $extension; | |||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | # Unpack PFM extended text metrics | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 0 | ▶ | sub _pfm_extended_text_metrics { | ||||||||||||||||||||||||||
|
Subroutine
_pfm_extended_text_metrics: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 262 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 263 | 0 | my $ext_metrics = $self->{_ext_metrics} = {}; | |||||||||||||||||||||||||||
| 264 | 0 | ▶ | if (! keys %$ext_metrics) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 265 | 0 | my $extension = $self->_pfm_extension; | |||||||||||||||||||||||||||
| 266 | my $ext_metrics_offset = $extension->{dfExtMetricsOffset} | ||||||||||||||||||||||||||||
| 267 | 0 | ▶ | || PFM_EXT_METRICS_OFFSET; | ||||||||||||||||||||||||||
|
Condition0%0/2
$extension->{'dfExtMetricsOffset'} || 147
MC/DC0%0/1
$extension->{'dfExtMetricsOffset'} || 147
$extension->{'dfExtMetricsOffset'}
Truth table0%0/2
A
A= $extension->{'dfExtMetricsOffset'}
| |||||||||||||||||||||||||||||
| 268 | die "$self->{file}: dfDriverInfo points outside file" | ||||||||||||||||||||||||||||
| 269 | 0 | ▶ | if $ext_metrics_offset > $self->{filesize}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | @$ext_metrics{@pfm_ext_metrics_fields} | ||||||||||||||||||||||||||||
| 272 | = unpack(PFM_EXT_METRICS_TEMPLATE, | ||||||||||||||||||||||||||||
| 273 | 0 | substr($self->{_rawdata}, $ext_metrics_offset, PFM_EXT_METRICS_LENGTH)); | |||||||||||||||||||||||||||
| 274 | delete($extension->{dfExtMetricsOffset}) | ||||||||||||||||||||||||||||
| 275 | 0 | ▶ | unless $self->{_keep_raw_data}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 276 | # delete($self->{_rawdata}) unless keys $self->{_pfm_extension} | ||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||
| 278 | $ext_metrics | ||||||||||||||||||||||||||||
| 279 | 0 | } | |||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | # Unpack the PFM Device Section | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | 0 | ▶ | sub _pfm_device_section { | ||||||||||||||||||||||||||
|
Subroutine
_pfm_device_section: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 284 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 285 | 0 | my $psinfo = $self->{_pfm_device} = {}; | |||||||||||||||||||||||||||
| 286 | 0 | ▶ | if (! keys %$psinfo) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 287 | 0 | my $header = $self->_pfm_header; | |||||||||||||||||||||||||||
| 288 | 0 | ▶ | my $psinfo_offset = $header->{dfDevice} || PFM_PSINFO_OFFSET; | ||||||||||||||||||||||||||
|
Condition0%0/2
$header->{'dfDevice'} || 199
MC/DC0%0/1
$header->{'dfDevice'} || 199
$header->{'dfDevice'}
Truth table0%0/2
A
A= $header->{'dfDevice'}
| |||||||||||||||||||||||||||||
| 289 | die "$self->{file}: dfDevice points outside file ($psinfo_offset > $self->{filesize})" | ||||||||||||||||||||||||||||
| 290 | 0 | ▶ | if $psinfo_offset > $self->{filesize}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 291 | @$psinfo{@pfm_postscript_info_fields} | ||||||||||||||||||||||||||||
| 292 | 0 | = split(/\0/, substr($self->{_rawdata}, $psinfo_offset), 4); | |||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||
| 294 | 0 | $psinfo; | |||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | # Extent table (2 bytes x (1 + dfLastChar - dfFirstChar)) | ||||||||||||||||||||||||||||
| 298 | # location is defined by dfExtentTable field in extension table | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | 1 | ▶ | sub _pfm_extent_table { | ||||||||||||||||||||||||||
|
Subroutine
_pfm_extent_table: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||
| 301 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 302 | 1 | ▶ | my $extent_table = $self->{_pfm_extent_table} ||= []; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"_pfm_extent_table"} ||= []
MC/DC0%0/1
$self->{"_pfm_extent_table"} ||= []
$self->{"_pfm_extent_table"}
Truth table50%1/2
A
A= $self->{"_pfm_extent_table"}
| |||||||||||||||||||||||||||||
| 303 | 1 | ▶ | if (! @$extent_table) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 304 | 1 | my $header = $self->_pfm_header; | |||||||||||||||||||||||||||
| 305 | 1 | my $extension = $self->_pfm_extension; | |||||||||||||||||||||||||||
| 306 | 1 | my $extent_offset = $extension->{dfExtentTable}; | |||||||||||||||||||||||||||
| 307 | 1 | my $extent_entries = 1 + $header->{dfLastChar} - $header->{dfFirstChar}; | |||||||||||||||||||||||||||
| 308 | @$extent_table = unpack('v' x $extent_entries, | ||||||||||||||||||||||||||||
| 309 | 1 | substr($self->{_rawdata}, $extent_offset)); | |||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||
| 311 | 1 | $extent_table; | |||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | # Return the raw kern data (unpacking if necessary) | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | 1 | ▶ | sub _pfm_kerndata { | ||||||||||||||||||||||||||
|
Subroutine
_pfm_kerndata: called CC=6 SCAR=18.1
| |||||||||||||||||||||||||||||
| 317 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 318 | 1 | ▶ | my $kerndata = $self->{_pfm_kerndata} ||= {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"_pfm_kerndata"} ||= {}
MC/DC0%0/1
$self->{"_pfm_kerndata"} ||= {}
$self->{"_pfm_kerndata"}
Truth table50%1/2
A
A= $self->{"_pfm_kerndata"}
| |||||||||||||||||||||||||||||
| 319 | 1 | ▶ | if (! keys %$kerndata) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 320 | 1 | my $extension = $self->_pfm_extension; | |||||||||||||||||||||||||||
| 321 | 1 | my $kerntable_offset = $extension->{dfPairKernTable}; | |||||||||||||||||||||||||||
| 322 | 1 | ▶ | if ($kerntable_offset) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 323 | my($kerntable_len) = unpack('v', substr($self->{_rawdata}, | ||||||||||||||||||||||||||||
| 324 | 1 | $kerntable_offset, 2)); | |||||||||||||||||||||||||||
| 325 | 1 | foreach (unpack('a4' x $kerntable_len, | |||||||||||||||||||||||||||
| 326 | substr($self->{_rawdata}, | ||||||||||||||||||||||||||||
| 327 | $kerntable_offset + 2, | ||||||||||||||||||||||||||||
| 328 | 4 * $kerntable_len))) { | ||||||||||||||||||||||||||||
| 329 | 998 | my($pair, $kern) = unpack('a2v', $_); | |||||||||||||||||||||||||||
| 330 | 998 | ▶ | $kern -= 65536 if $kern > 32768; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 331 | 998 | $kerndata->{$pair} = int $kern; | |||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||
| 335 | 1 | $kerndata; | |||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | 1 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=3 SCAR=19.8
| |||||||||||||||||||||||||||||
| 339 | 1 | ▶ | return if $AUTOLOAD =~ /::DESTROY$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 340 | die "Undefined subroutine $AUTOLOAD" | ||||||||||||||||||||||||||||
| 341 | 0 | ▶ | unless exists $pfm_field_map{$AUTOLOAD}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 342 | 0 | my $struct = &{$pfm_field_map{$AUTOLOAD}}; | |||||||||||||||||||||||||||
| 343 | 0 | $struct->{$AUTOLOAD}; | |||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | 0 | ▶ | sub _die { | ||||||||||||||||||||||||||
|
Subroutine
_die: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 347 | 0 | my ($self, @msg) = @_; | |||||||||||||||||||||||||||
| 348 | 0 | $self->{die}->(@msg); | |||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | 1 | 1; | |||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | __END__ | ||||||||||||||||||||||||||||