| 1 | # RCS Status : $Id: Font.pm,v 1.25 2014/12/27 20:35:14 jv Exp $ | ||||||||||||||||||||||||||||
| 2 | # Author : Johan Vromans | ||||||||||||||||||||||||||||
| 3 | # Created On : December 1998 | ||||||||||||||||||||||||||||
| 4 | # Last Modified By: Johan Vromans | ||||||||||||||||||||||||||||
| 5 | # Last Modified On: Sat Dec 27 21:35:02 2014 | ||||||||||||||||||||||||||||
| 6 | # Update Count : 468 | ||||||||||||||||||||||||||||
| 7 | # Status : Released | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | ################ Module Preamble ################ | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | package PostScript::Font; | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | BEGIN { require 5.005; } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use IO qw(File); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 1 | ▶ | use PostScript::StandardEncoding; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use PostScript::ISOLatin1Encoding; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 1 | $VERSION = "1.05"; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | # If you have the t1disasm program, have $t1disasm point to it. | ||||||||||||||||||||||||||||
| 26 | # This speeds up the glyph fetching. | ||||||||||||||||||||||||||||
| 27 | 1 | ▶ | use vars qw($t1disasm); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=12 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 31 | 1 | my $font = shift; | |||||||||||||||||||||||||||
| 32 | 1 | my (%atts) = (error => 'die', | |||||||||||||||||||||||||||
| 33 | format => 'ascii', | ||||||||||||||||||||||||||||
| 34 | verbose => 0, trace => 0, debug => 0, | ||||||||||||||||||||||||||||
| 35 | @_); | ||||||||||||||||||||||||||||
| 36 | 1 | my $self = { file => $font }; | |||||||||||||||||||||||||||
| 37 | 1 | bless $self, $class; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 1 | ▶ | return $self unless defined $font; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 1 | $self->{debug} = $atts{debug}; | |||||||||||||||||||||||||||
| 42 | 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'}
| |||||||||||||||||||||||||||||
| 43 | 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'}
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 1 | my $error = lc($atts{error}); | |||||||||||||||||||||||||||
| 46 | 0 | ▶ | $self->{die} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | die(@_) if $error eq "die"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | warn(@_) if $error eq "warn"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 1 | }; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 1 | ▶ | $atts{format} = "ascii" if lc($atts{format}) eq "pfa"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 1 | ▶ | $atts{format} = "binary" if lc($atts{format}) eq "pfb"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 1 | ▶ | $t1disasm = $self->_getexec ("t1disasm") unless defined $t1disasm; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 1 | eval { | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 1 | $self->_loadfont (); | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # Reformat if needed. | ||||||||||||||||||||||||||||
| 61 | 1 | $self->{format} = "ascii"; | |||||||||||||||||||||||||||
| 62 | 1 | ▶ | if ( lc($atts{format}) eq "asm" ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 63 | print STDERR ($self->{file}, ": Converting to ASM format\n") | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if $self->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | $self->{data} = $self->_pfa2asm; | |||||||||||||||||||||||||||
| 66 | 0 | $self->{format} = "asm"; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | elsif ( lc($atts{format}) eq "binary" ) { | ||||||||||||||||||||||||||||
| 69 | print STDERR ($self->{file}, ": Converting to Binary format\n") | ||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if $self->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | $self->{data} = $self->_pfa2pfb; | |||||||||||||||||||||||||||
| 72 | 0 | $self->{format} = "binary"; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | }; | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 1 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 0 | $self->_die($@); | |||||||||||||||||||||||||||
| 79 | 0 | return undef; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 1 | $self; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub FileName { $_[0]->{file}; } | ||||||||||||||||||||||||||
|
Subroutine
FileName: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub FontName { $_[0]->{name}; } | ||||||||||||||||||||||||||
|
Subroutine
FontName: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub FamilyName { $_[0]->{family}; } | ||||||||||||||||||||||||||
|
Subroutine
FamilyName: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub FontType { $_[0]->{type}; } | ||||||||||||||||||||||||||
|
Subroutine
FontType: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub Version { $_[0]->{version}; } | ||||||||||||||||||||||||||
|
Subroutine
Version: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub ItalicAngle { $_[0]->{italic}; } | ||||||||||||||||||||||||||
|
Subroutine
ItalicAngle: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub isFixedPitch{ $_[0]->{fixed}; } | ||||||||||||||||||||||||||
|
Subroutine
isFixedPitch: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 92 | 0 | ▶ | sub Weight { $_[0]->{weight}; } | ||||||||||||||||||||||||||
|
Subroutine
Weight: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 93 | 1 | ▶ | sub FontMatrix { $_[0]->{fontmatrix};} | ||||||||||||||||||||||||||
|
Subroutine
FontMatrix: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub FontBBox { $_[0]->{fontbbox}; } | ||||||||||||||||||||||||||
|
Subroutine
FontBBox: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sub DataFormat { $_[0]->{dataformat} } | ||||||||||||||||||||||||||
|
Subroutine
DataFormat: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 1 | ▶ | sub FontData { | ||||||||||||||||||||||||||
|
Subroutine
FontData: called CC=3 SCAR=12.3
Pod
documented
| |||||||||||||||||||||||||||||
| 98 | 1 | my ($self, $format) = @_; | |||||||||||||||||||||||||||
| 99 | 1 | ▶ | if ( defined $format ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | # Not yet supported! | ||||||||||||||||||||||||||||
| 101 | 0 | return ${$self->_cvtinternal($format)}; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | 1 | ▶ | $self->{data} = $self->_cvtinternal unless exists $self->{data}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 1 | ${$self->{data}}; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | sub FontGlyphs { | ||||||||||||||||||||||||||
|
Subroutine
FontGlyphs: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 108 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 109 | 0 | ▶ | $self->{glyphs} = $self->_getglyphnames unless exists $self->{glyphs}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 0 | $self->{glyphs}; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 0 | ▶ | sub Encoding { | ||||||||||||||||||||||||||
|
Subroutine
Encoding: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 114 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 115 | 0 | ▶ | $self->{encoding} = $self->_getencoding unless exists $self->{encoding}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 0 | $self->{encoding}; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | sub EncodingVector { | ||||||||||||||||||||||||||
|
Subroutine
EncodingVector: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 120 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 121 | 0 | my $enc = $self->{encoding}; | |||||||||||||||||||||||||||
| 122 | 0 | ▶ | return $enc if ref($enc) eq "ARRAY"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | # Return private copy for the standard encodings. | ||||||||||||||||||||||||||||
| 124 | 0 | ▶ | if ( $enc eq "StandardEncoding" ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 125 | 0 | return scalar PostScript::StandardEncoding->array; | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | elsif ( $enc eq "ISOLatin1Encoding" ) { | ||||||||||||||||||||||||||||
| 128 | 0 | return scalar PostScript::ISOLatin1Encoding->array; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | 0 | undef; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 0 | ▶ | sub StandardEncoding { | ||||||||||||||||||||||||||
|
Subroutine
StandardEncoding: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 134 | 0 | return scalar PostScript::StandardEncoding->array; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 1 | ▶ | sub ISOLatin1Encoding { | ||||||||||||||||||||||||||
|
Subroutine
ISOLatin1Encoding: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 138 | 1 | return scalar PostScript::ISOLatin1Encoding->array; | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 1 | ▶ | sub _loadfont ($) { | ||||||||||||||||||||||||||
|
Subroutine
_loadfont: called CC=30 SCAR=46.5
| |||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 144 | 1 | my $data; # font data | |||||||||||||||||||||||||||
| 145 | my $type; | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 1 | my $fn = $self->{file}; | |||||||||||||||||||||||||||
| 148 | 1 | my $fh = new IO::File; # font file | |||||||||||||||||||||||||||
| 149 | 1 | my $sz = -s $fn; # file size | |||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 1 | ▶ | $fh->open ($fn) || $self->_die("$fn: $!\n"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | 1 | ▶ | print STDERR ("$fn: Loading font file\n") if $self->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | # Read in the font data. | ||||||||||||||||||||||||||||
| 155 | 1 | binmode($fh); # (Some?) Windows need this | |||||||||||||||||||||||||||
| 156 | 1 | my $len = 0; | |||||||||||||||||||||||||||
| 157 | 1 | ▶ | while ( $fh->sysread ($data, 32768, $len) > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 2 | $len = length ($data); | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | 1 | $fh->close; | |||||||||||||||||||||||||||
| 161 | 1 | ▶ | $self->_die("$fn: Expecting at least 4 bytes, got ", | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | length($data), " bytes\n") | ||||||||||||||||||||||||||||
| 163 | unless length($data) >= 4; | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 1 | $self->{dataformat} = 'ps'; | |||||||||||||||||||||||||||
| 166 | 1 | ▶ | if ( substr($data,0,4) eq "\0\1\0\0" || substr($data, 0, 4) eq "OTTO" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
substr($data, 0, 4) eq "\0\1\0\0" or substr($data, 0, 4) eq "OTTO"
MC/DC0%0/2
substr($data, 0, 4) eq "\0\1\0\0" or substr($data, 0, 4) eq "OTTO"
substr($data, 0, 4) eq "\0\1\0\0"
substr($data, 0, 4) eq "OTTO"
Truth table33%1/3
A or B
A= substr($data, 0, 4) eq "\0\1\0\0"B= substr($data, 0, 4) eq "OTTO"
| |||||||||||||||||||||||||||||
| 167 | # For the time being, Font::TTF is optional. Be careful. | ||||||||||||||||||||||||||||
| 168 | 0 | eval { | |||||||||||||||||||||||||||
| 169 | 0 | require PostScript::Font::TTtoType42; | |||||||||||||||||||||||||||
| 170 | }; | ||||||||||||||||||||||||||||
| 171 | 0 | ▶ | if ( $@ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | 0 | $self->_die("$fn: Cannot convert True Type font\n"); | |||||||||||||||||||||||||||
| 173 | 0 | return undef; | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | my $wrapper = | ||||||||||||||||||||||||||||
| 176 | new PostScript::Font::TTtoType42:: ($fn, | ||||||||||||||||||||||||||||
| 177 | verbose => $self->{verbose}, | ||||||||||||||||||||||||||||
| 178 | trace => $self->{trace}, | ||||||||||||||||||||||||||||
| 179 | debug => $self->{debug}, | ||||||||||||||||||||||||||||
| 180 | 0 | ); | |||||||||||||||||||||||||||
| 181 | 0 | $type = "t"; | |||||||||||||||||||||||||||
| 182 | 0 | $data = $wrapper->as_string; | |||||||||||||||||||||||||||
| 183 | 0 | $self->{t42wrapper} = $wrapper; | |||||||||||||||||||||||||||
| 184 | 0 | $self->{dataformat} = "type42"; | |||||||||||||||||||||||||||
| 185 | 0 | $self->{encoding} = "StandardEncoding"; | |||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | else { | ||||||||||||||||||||||||||||
| 188 | # Make ref. | ||||||||||||||||||||||||||||
| 189 | 1 | $data = \"$data"; #"; | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 1 | ▶ | print STDERR ("Read $len bytes from $fn\n") if $self->{trace}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | 1 | ▶ | $self->_die("$fn: Expecting $sz bytes, got $len bytes\n") | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$sz > 0 and $sz != $len
MC/DC0%0/2
$sz > 0 and $sz != $len
$sz > 0
$sz != $len
Truth table33%1/3
A and B
A= $sz > 0B= $sz != $len
| |||||||||||||||||||||||||||||
| 194 | if $sz > 0 && $sz != $len; | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | # Convert .pfb encoded font data. | ||||||||||||||||||||||||||||
| 197 | 1 | ▶ | if ( $$data =~ /^\200[\001-\003]/ ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 198 | 1 | ▶ | print STDERR ("$fn: Converting to ASCII format\n") if $self->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | 1 | $data = $self->_pfb2pfa ($data); | |||||||||||||||||||||||||||
| 200 | 1 | $self->{dataformat} = 'pfa'; | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | # Otherwise, must be straight PostScript. | ||||||||||||||||||||||||||||
| 203 | elsif ( $$data !~ /^%!/ ) { | ||||||||||||||||||||||||||||
| 204 | 0 | $self->_die("$fn: Not a recognizable font file\n"); | |||||||||||||||||||||||||||
| 205 | 0 | return undef; | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | # Normalise line endings. | ||||||||||||||||||||||||||||
| 209 | 1 | $$data =~ s/\015\012?/\n/g; | |||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 1 | $self->{data} = $data; | |||||||||||||||||||||||||||
| 212 | 1 | ▶ | $self->{type} = $type if defined $type; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 1 | ▶ | if ( $$data =~ /^%!FontType(\d+)\n\/(\S+)\n/ ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 215 | 0 | ▶ | $self->{type} = $1 unless defined $self->{type}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | 0 | $self->{name} = $2; | |||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | elsif ( $$data =~ /\/FontName\s*\/(\S+)/ ) { | ||||||||||||||||||||||||||||
| 219 | 1 | $self->{name} = $1; | |||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | elsif ( $$data =~ /\/FontName\s*\(([^\051]+)\)/ ) { | ||||||||||||||||||||||||||||
| 222 | 0 | $self->{name} = $1; | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | 1 | ▶ | if ( $$data =~ /\/FamilyName\s*\/(\S+)/ ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 225 | 0 | $self->{family} = $1; | |||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | elsif ( $$data =~ /\/FamilyName\s*\(([^\051]+)\)/ ) { | ||||||||||||||||||||||||||||
| 228 | 1 | $self->{family} = $1; | |||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | 1 | ▶ | unless ( defined $self->{type} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 231 | 1 | ▶ | $self->{type} = $1 if $$data =~ /\/FontType\s+(\d+)/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | 1 | ▶ | $self->{version} = $1 if $$data =~ /\/version\s*\(([^\051]+)\)/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | 1 | ▶ | $self->{italic} = $1 if $$data =~ /\/ItalicAngle\s+([-+]?\d+)/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 235 | 1 | ▶ | $self->{fixed} = $1 eq "true" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | if $$data =~ /\/isFixedPitch\s+(true|false)/; | ||||||||||||||||||||||||||||
| 237 | 1 | ▶ | if ( $$data =~ /\/Weight\s*\/(\S+)/ ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 238 | 0 | $self->{weight} = $1; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | elsif ( $$data =~ /\/Weight\s*\(([^\051]+)\)/ ) { | ||||||||||||||||||||||||||||
| 241 | 1 | $self->{weight} = $1; | |||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | 1 | ▶ | if ( $$data =~ /\/FontMatrix\s*\[\s*(\d+(?:\.\d*)?)\s+(\d+(?:\.\d*)?)\s+(\d+(?:\.\d*)?)\s+(\d+(?:\.\d*)?)\s+(\d+(?:\.\d*)?)\s+(\d+(?:\.\d*)?)\s*\]/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | 1 | $self->{fontmatrix} = [$1,$2,$3,$4,$5,$6]; | |||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | 1 | ▶ | if ( $$data =~ /\/FontBBox\s*\{\s*(-?\d+(?:\.\d*)?)\s+(-?\d+(?:\.\d*)?)\s+(-?\d+(?:\.\d*)?)\s+(-?\d+(?:\.\d*)?)\s*\}/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 247 | 1 | $self->{fontbbox} = [$1,$2,$3,$4]; | |||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||
| 249 | 1 | $self; | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 0 | ▶ | sub _qtfn ($) { | ||||||||||||||||||||||||||
|
Subroutine
_qtfn: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 253 | 0 | my $f = shift; | |||||||||||||||||||||||||||
| 254 | 0 | $f =~ s/([\\'])/'\\$1'/g; | |||||||||||||||||||||||||||
| 255 | 0 | "'".$f."'"; | |||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 0 | ▶ | sub _cvtinternal { | ||||||||||||||||||||||||||
|
Subroutine
_cvtinternal: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 259 | 0 | my ($self, $format) = @_; | |||||||||||||||||||||||||||
| 260 | 0 | ▶ | return $self->{data} if $format eq $self->{format}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 261 | 0 | undef; | |||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | 1 | ▶ | sub _pfb2pfa ($;$) { | ||||||||||||||||||||||||||
|
Subroutine
_pfb2pfa: called CC=10 SCAR=23.5
| |||||||||||||||||||||||||||||
| 265 | 1 | my ($self, $data) = @_; # NOTE: data is a ref! | |||||||||||||||||||||||||||
| 266 | 1 | my $newdata = ""; # NOTE: will return a ref | |||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 1 | ▶ | $data = $self->{data} unless defined $data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||
| 270 | # Structure of .pfb font data: | ||||||||||||||||||||||||||||
| 271 | # | ||||||||||||||||||||||||||||
| 272 | # ( ASCII-segment | Binary-segment )+ EOF-indicator | ||||||||||||||||||||||||||||
| 273 | # | ||||||||||||||||||||||||||||
| 274 | # ASCII-segment: \200 \001 length data | ||||||||||||||||||||||||||||
| 275 | # Binary-sement: \200 \002 length data | ||||||||||||||||||||||||||||
| 276 | # EOF-indicator: \200 \003 | ||||||||||||||||||||||||||||
| 277 | # | ||||||||||||||||||||||||||||
| 278 | # length is a 4-byte little endian 'long'. | ||||||||||||||||||||||||||||
| 279 | # data are length bytes of data. | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | 1 | my $bin = ""; # accumulated unprocessed binary segments | |||||||||||||||||||||||||||
| 282 | 1 | ▶ | my $addbin = sub { # binary segment processor | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||
| 283 | print STDERR ("Processing binary segment, ", | ||||||||||||||||||||||||||||
| 284 | 1 | ▶ | length($bin), " bytes\n") if $self->{trace}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 285 | 1 | ($bin = uc (unpack ("H*", $bin))) =~ s/(.{64})/$1\n/g; | |||||||||||||||||||||||||||
| 286 | 1 | $newdata .= $bin; | |||||||||||||||||||||||||||
| 287 | 1 | ▶ | $newdata .= "\n" unless $newdata =~ /\n$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 288 | 1 | $bin = ""; | |||||||||||||||||||||||||||
| 289 | 1 | }; | |||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | 1 | ▶ | while ( length($$data) > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 292 | 4 | my ($type, $info, $seg); | |||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | 4 | ▶ | last if $$data =~ /^\200\003/; # EOF indicator | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||
| 296 | # Get font segment. | ||||||||||||||||||||||||||||
| 297 | 3 | ▶ | $self->_die($self->{file}, ": Invalid font segment format\n") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 298 | unless ($type, $info) = $$data =~ /^\200([\001-\002])(....)/s; | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | 3 | my $len = unpack ("V", $info); | |||||||||||||||||||||||||||
| 301 | # Can't use next statement since $len may be > 32766. | ||||||||||||||||||||||||||||
| 302 | # ($seg, $$data) = $$data =~ /^......(.{$len})(.*)/s; | ||||||||||||||||||||||||||||
| 303 | 3 | $seg = substr ($$data, 6, $len); | |||||||||||||||||||||||||||
| 304 | 3 | $$data = substr ($$data, $len+6); | |||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | 3 | ▶ | if ( ord($type) == 1 ) { # ASCII segment | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 307 | 2 | ▶ | $addbin->() if $bin ne ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 308 | print STDERR ($self->{file}, ": ASCII segment, $len bytes\n") | ||||||||||||||||||||||||||||
| 309 | 2 | ▶ | if $self->{trace}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 310 | 2 | $newdata .= $seg; | |||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||
| 312 | else { # ord($type) == 2 # Binary segment | ||||||||||||||||||||||||||||
| 313 | print STDERR ($self->{file}, ": Binary segment, $len bytes\n") | ||||||||||||||||||||||||||||
| 314 | 1 | ▶ | if $self->{trace}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 315 | 1 | $bin .= $seg; | |||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | 1 | ▶ | $addbin->() if $bin ne ""; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 319 | 1 | return \$newdata; | |||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | 0 | ▶ | sub _pfa2pfb ($;$) { | ||||||||||||||||||||||||||
|
Subroutine
_pfa2pfb: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 323 | 0 | my ($self, $data) = @_; # NOTE: data is a ref! | |||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | 0 | ▶ | $data = $self->{data} unless defined $data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | 0 | ▶ | return \do{"\200\001".pack("V",length($$data)).$$data."\200\003"} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 328 | unless $$data =~ m{(^.*\beexec\s*\n+) | ||||||||||||||||||||||||||||
| 329 | ([A-Fa-f0-9\n]+) | ||||||||||||||||||||||||||||
| 330 | (\s*cleartomark.*$)}sx; | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | 0 | my ($pre, $bin, $post) = ($1, $2, $3); | |||||||||||||||||||||||||||
| 333 | 0 | $bin =~ tr/A-Fa-f0-9//cd; | |||||||||||||||||||||||||||
| 334 | 0 | $bin = pack ("H*", $bin); | |||||||||||||||||||||||||||
| 335 | 0 | my $nulls; | |||||||||||||||||||||||||||
| 336 | 0 | ($bin, $nulls) = $bin =~ /(.*[^\0])(\0+)?$/s; | |||||||||||||||||||||||||||
| 337 | 0 | ▶ | $nulls = defined $nulls ? length($nulls) : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 338 | 0 | ▶ | while ( $nulls > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 339 | 0 | ▶ | $post = ("00" x ($nulls > 32 ? 32 : $nulls)) . "\n" . $post; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 340 | 0 | $nulls -= 32; | |||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | 0 | return \do{"\200\001".pack("V",length($pre)).$pre. | |||||||||||||||||||||||||||
| 344 | "\200\002".pack("V",length($bin)).$bin. | ||||||||||||||||||||||||||||
| 345 | "\200\001".pack("V",length($post)).$post. | ||||||||||||||||||||||||||||
| 346 | "\200\003" }; | ||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||
| 349 | 0 | ▶ | sub _pfa2asm ($;$) { | ||||||||||||||||||||||||||
|
Subroutine
_pfa2asm: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||
| 350 | 0 | my ($self, $data) = @_; # NOTE: data is a ref! | |||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | 0 | ▶ | $data = $self->{data} unless defined $data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | 0 | ▶ | if ( $t1disasm ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 355 | 0 | my $fn = _qtfn($self->{file}); | |||||||||||||||||||||||||||
| 356 | #### WARNING: This is Unix specific! #### | ||||||||||||||||||||||||||||
| 357 | 0 | my $cmd = "$t1disasm $fn"; | |||||||||||||||||||||||||||
| 358 | 0 | ▶ | if ( $self->{type} eq 't' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 359 | $self->_die($self->{file}, | ||||||||||||||||||||||||||||
| 360 | 0 | ": Logic error -- Cannot convert True Type font\n"); | |||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | 0 | ▶ | print STDERR ("+ $cmd |\n") if $self->{trace}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 364 | 0 | my $fh = new IO::File ("$cmd |"); | |||||||||||||||||||||||||||
| 365 | 0 | local ($/); | |||||||||||||||||||||||||||
| 366 | 0 | my $newdata = <$fh>; | |||||||||||||||||||||||||||
| 367 | 0 | ▶ | $fh->close or warn ($cmd, ": return ". sprintf("%x", $?), "\n"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 368 | 0 | $newdata =~ s/\015\012?/\n/g; | |||||||||||||||||||||||||||
| 369 | 0 | return \$newdata; | |||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | 0 | ▶ | return $data | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 373 | unless $$data =~ m{(^.*\beexec\s*\n+) | ||||||||||||||||||||||||||||
| 374 | ([A-Fa-f0-9\n]+) | ||||||||||||||||||||||||||||
| 375 | (\n\s*cleartomark.*$)}sx; | ||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | 0 | my ($pre, $bin, $post) = ($1, $2, $3); | |||||||||||||||||||||||||||
| 378 | 0 | $bin =~ tr/A-Fa-f0-9//cd; | |||||||||||||||||||||||||||
| 379 | 0 | $bin = pack ("H*", $bin); | |||||||||||||||||||||||||||
| 380 | 0 | my $nulls; | |||||||||||||||||||||||||||
| 381 | 0 | ($bin, $nulls) = $bin =~ /(.*[^\0])(\0+)?$/s; | |||||||||||||||||||||||||||
| 382 | 0 | ▶ | $nulls = defined $nulls ? length($nulls) : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 383 | 0 | ▶ | while ( $nulls > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 384 | 0 | ▶ | $post = ("00" x ($nulls > 32 ? 32 : $nulls)) . "\n" . $post; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 385 | 0 | $nulls -= 32; | |||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | 0 | my $newdata = ""; | |||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | # Conversion based on an C-program marked as follows: | ||||||||||||||||||||||||||||
| 391 | # /* Written by Carsten Wiethoff 1989 */ | ||||||||||||||||||||||||||||
| 392 | # /* You may do what you want with this code, | ||||||||||||||||||||||||||||
| 393 | # as long as this notice stays in it */ | ||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | 0 | my $input; | |||||||||||||||||||||||||||
| 396 | my $output; | ||||||||||||||||||||||||||||
| 397 | 0 | my $ignore = 4; | |||||||||||||||||||||||||||
| 398 | 0 | my $buffer = 0xd971; | |||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | 0 | ▶ | while ( length($bin) > 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 401 | 0 | ($input, $bin) = $bin =~ /^(.)(.*)$/s; | |||||||||||||||||||||||||||
| 402 | 0 | $input = ord ($input); | |||||||||||||||||||||||||||
| 403 | 0 | $output = $input ^ ($buffer >> 8); | |||||||||||||||||||||||||||
| 404 | 0 | $buffer = (($input + $buffer) * 0xce6d + 0x58bf) & 0xffff; | |||||||||||||||||||||||||||
| 405 | 0 | ▶ | next if $ignore-- > 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 406 | 0 | $newdata .= pack ("C", $output); | |||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||
| 409 | # End conversion. | ||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | # Cleanup (for display only). | ||||||||||||||||||||||||||||
| 412 | 0 | $newdata =~ s/ \-\| (.+?) (\|-?)\n/" -| <".unpack("H*",$1)."> $2\n"/ges; | |||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | # Concatenate and return. | ||||||||||||||||||||||||||||
| 415 | 0 | $newdata = $pre . $newdata . $post; | |||||||||||||||||||||||||||
| 416 | 0 | return \$newdata; | |||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||
| 419 | 0 | ▶ | sub _getglyphnames ($;$) { | ||||||||||||||||||||||||||
|
Subroutine
_getglyphnames: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||
| 420 | 0 | my ($self, $data) = @_; | |||||||||||||||||||||||||||
| 421 | 0 | my @glyphs = (); | |||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | 0 | ▶ | print STDERR ($self->{file}, ": Getting glyph info\n") if $self->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | 0 | ▶ | $data = $self->{data} unless defined $data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||
| 427 | 0 | ▶ | if ( $self->{dataformat} eq "type42" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 428 | 0 | my $g = $self->{t42wrapper}->glyphnames; | |||||||||||||||||||||||||||
| 429 | print STDERR ($self->{file}, ": Number of glyphs = ", | ||||||||||||||||||||||||||||
| 430 | scalar(@$g), "\n") | ||||||||||||||||||||||||||||
| 431 | 0 | ▶ | if $self->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 432 | 0 | return $g; | |||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||
| 435 | 0 | ▶ | if ( $self->{format} eq "binary" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 436 | 0 | $data = $self->_pfb2pfa ($data); | |||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||
| 439 | 0 | ▶ | if ( $$data =~ m|/CharStrings\s.*\n((?s)(.*))| ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 440 | 0 | $data = $2; | |||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||
| 442 | else { | ||||||||||||||||||||||||||||
| 443 | 0 | $data = $self->_pfa2asm ($data); | |||||||||||||||||||||||||||
| 444 | 0 | ▶ | if ( $$data =~ m|/CharStrings\s.*\n((?s)(.*))| ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 445 | 0 | $data = $2; | |||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||
| 447 | else { | ||||||||||||||||||||||||||||
| 448 | 0 | return undef; | |||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | # while ( $data =~ m;((^\d*\s*/([.\w]+))|(\bend\b)).*\n;mg ) { | ||||||||||||||||||||||||||||
| 453 | 0 | ▶ | while ( $data =~ m;(/([.\w]+)\b|\bend\b);mg ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 454 | 0 | ▶ | last if $1 eq "end"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 455 | 0 | push (@glyphs, $2); | |||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | print STDERR ($self->{file}, ": Number of glyphs = ", | ||||||||||||||||||||||||||||
| 459 | scalar(@glyphs), "\n") | ||||||||||||||||||||||||||||
| 460 | 0 | ▶ | if $self->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | 0 | \@glyphs; | |||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||
| 465 | 0 | ▶ | sub _getencoding ($;$) { | ||||||||||||||||||||||||||
|
Subroutine
_getencoding: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||
| 466 | 0 | my ($self, $data) = @_; | |||||||||||||||||||||||||||
| 467 | 0 | my @glyphs = (); | |||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||
| 469 | print STDERR ($self->{file}, ": Getting encoding info\n") | ||||||||||||||||||||||||||||
| 470 | 0 | ▶ | if $self->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||
| 472 | 0 | ▶ | $data = $self->{data} unless defined $data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 473 | 0 | $data = $$data; # deref | |||||||||||||||||||||||||||
| 474 | 0 | $data =~ s/\n\s*%.*$//mg; # strip comments | |||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||
| 476 | # Name -> standard encoding. | ||||||||||||||||||||||||||||
| 477 | 0 | ▶ | return $1 if $data =~ m|/Encoding\s+(\S+)\s+def|; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||
| 479 | # Array -> explicit encoding. | ||||||||||||||||||||||||||||
| 480 | 0 | ▶ | if ( $data =~ m;/Encoding[\n\s]+\[([^\]]+)\][\n\s]+def;m ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 481 | 0 | my $enc = $1; | |||||||||||||||||||||||||||
| 482 | 0 | $enc =~ s|\s*/| |g; | |||||||||||||||||||||||||||
| 483 | 0 | $enc =~ s/^\s+//; | |||||||||||||||||||||||||||
| 484 | 0 | $enc =~ s/\s+$//; | |||||||||||||||||||||||||||
| 485 | 0 | $enc =~ s/\s+/ /g; | |||||||||||||||||||||||||||
| 486 | 0 | ▶ | if ( $enc eq PostScript::StandardEncoding->string ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 487 | 0 | $enc = "StandardEncoding" | |||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||
| 489 | elsif ( $enc eq PostScript::ISOLatin1Encoding->string ) { | ||||||||||||||||||||||||||||
| 490 | 0 | $enc = "ISOLatin1Encoding" | |||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||
| 492 | else { | ||||||||||||||||||||||||||||
| 493 | 0 | $enc = [split (' ', $enc)]; | |||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||
| 495 | 0 | return $enc; | |||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | # Sparse array, probably custom encoding. | ||||||||||||||||||||||||||||
| 499 | # if ( $data =~ m;/Encoding \d+ array\n(0 1 .*for\n)?((dup \d+\s*/\S+ put(\s*%.*)?\n)+); ) { | ||||||||||||||||||||||||||||
| 500 | 0 | ▶ | if ( $data =~ m;/Encoding \d+ array\n(0 1 .*for\n)?((dup \d+\s*/\S+ put(.*)\n)+); ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 501 | 0 | my $enc = $2; | |||||||||||||||||||||||||||
| 502 | 0 | my @enc = (".notdef") x 256; | |||||||||||||||||||||||||||
| 503 | 0 | ▶ | while ( $enc =~ m;dup (\d+)\s*/(\S+) put;g ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 504 | 0 | $enc[$1] = $2; | |||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||
| 506 | 0 | ▶ | if ( "@enc" eq PostScript::StandardEncoding->string ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 507 | 0 | $enc = "StandardEncoding" | |||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||
| 509 | elsif ( "@enc" eq PostScript::ISOLatin1Encoding->string ) { | ||||||||||||||||||||||||||||
| 510 | 0 | $enc = "ISOLatin1Encoding" | |||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||
| 512 | else { | ||||||||||||||||||||||||||||
| 513 | 0 | $enc = \@enc; | |||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||
| 515 | 0 | return $enc; | |||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||
| 518 | 0 | undef; | |||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||
| 521 | 1 | ▶ | sub _getexec ($) { | ||||||||||||||||||||||||||
|
Subroutine
_getexec: called CC=6 SCAR=26.9
| |||||||||||||||||||||||||||||
| 522 | 1 | my ($self, $exec) = @_; | |||||||||||||||||||||||||||
| 523 | 1 | foreach ( File::Spec->path ) { | |||||||||||||||||||||||||||
| 524 | 10 | ▶ | if ( -x "$_/$exec" ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 525 | 0 | ▶ | print STDERR ("Using $_/$exec\n") if $self->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 526 | 0 | return "$_/$exec"; | |||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||
| 528 | elsif ( -x "$_/$exec.exe" ) { | ||||||||||||||||||||||||||||
| 529 | 0 | ▶ | print STDERR ("Using $_/$exec.exe\n") if $self->{verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 530 | 0 | return "$_/$exec.exe"; | |||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||
| 533 | '' | ||||||||||||||||||||||||||||
| 534 | 1 | } | |||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||
| 536 | 0 | ▶ | sub _die { | ||||||||||||||||||||||||||
|
Subroutine
_die: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 537 | 0 | my ($self, @msg) = @_; | |||||||||||||||||||||||||||
| 538 | 0 | $self->{die}->(@msg); | |||||||||||||||||||||||||||
| 539 | } | ||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||
| 541 | # PostScript::TTtoType42 is actually an Font::TTF::Font object. | ||||||||||||||||||||||||||||
| 542 | # Font::TTF::Font uses cyclic structures, so we need this. | ||||||||||||||||||||||||||||
| 543 | 1 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 544 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 545 | 1 | ▶ | $self->{t42wrapper}->DESTROY if $self->{t42wrapper}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||
| 548 | 1 | 1; | |||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||
| 550 | __END__ | ||||||||||||||||||||||||||||