PDF/SFont.pm

filter: Statementstmt 46.1% 24 / 52 Branchbran 12.5% 2 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 60.0% 6 / 10 Podpod 80.0% 4 / 5 totaltotal 40.9% 36 / 88 CC 12 SCAR 27.5
CC
12
Cov
37%
width
30.0
trim
30.0
getBase
6.0
CRAP 15.6
« PDF/Pages.pm ↑ Summary PDF/Array.pm »
1 package Text::PDF::SFont;
2  
3 # use strict;
4 1 ▶use vars qw(@ISA %widths @encodings);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 @ISA = qw(Text::PDF::Dict);
6  
7 1 ▶use Text::PDF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Compress::Zlib;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 # no warnings qw(uninitialized);
10  
11 =head1 NAME
12  
13 Text::PDF::SFont - PDF Standard inbuilt font resource object. Inherits from
14 L<Text::PDF::Dict>
15  
16 =head1 METHODS
17  
18 =head2 Text::PDF::SFont->new($parent, $name, $pdfname)
19  
20 Creates a new font object with given parent and name. The name must be from
21 one of the core 14 base fonts included with PDF. These are:
22  
23 Courier, Courier-Bold, Courier-Oblique, Courier-BoldOblique
24 Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic
25 Helvetica, Helvetica-Bold, Helvetica-Oblique, Helvetica-BoldOblique
26 Symbol, ZapfDingbats
27  
28 The $pdfname is the name that this particular font object will be referenced
29 by throughout the PDF file. If you want to play silly games with naming, then
30 you can write the code to do it!
31  
32 All fonts in this system are full PDF objects.
33  
34 =head1 BUGS
35  
36 Currently no width support for Symbol or ZapfDingbats, I haven't
37 got my head around the AFMs yet.
38  
39 MacExpertEncoding not supported yet (I don't have the width info for any
40 of the fonts)
41  
42 =cut
43  
44 BEGIN
45 {
46 1 ▶ @encodings = ('WinAnsiEncoding', 'MacRomanEncoding');
Subroutine BEGIN: called CC=1 SCAR=0.0
47 1 %enc_map = (
48 'WinAnsiEncoding' => [0 .. 126, 128, 160, 128, 145,134, 140,
49 131, 129, 130, 26, 139, 151, 136, 150, 128, 153, 128, 128, 143,
50 144, 141, 142, 128, 133, 132, 31, 146, 157, 137, 156, 128, 158,
51 152, 32, 161 .. 255],
52 'MacRomanEncoding' => [0 .. 127, 196, 197, 199, 201, 209, 214,
53 220, 225, 224, 226, 228, 227, 229, 231, 233, 232, 234, 235, 237,
54 236, 238, 239, 241, 243, 242, 244, 246, 245, 250, 249, 251, 252,
55 129, 176, 162, 163, 128, 182, 223, 174, 169, 146, 180, 168, 0,
56 198, 216, 0, 177, 0, 0, 165, 181, 0, 0, 0, 0, 0, 186, 169, 0,
57 230, 248, 192, 161, 172, 0, 134, 0, 0, 171, 187, 131, 32, 192,
58 195, 213, 150, 156, 133, 132, 141 .. 144, 247, 0, 255, 152, 135,
59 164, 136, 137, 147, 148, 130, 183, 145, 140, 139, 194, 202, 200,
60 205, 206, 207, 204, 211, 212, 0, 210, 218, 219, 217, 154, 26,
61 31, 175, 24, 27, 30, 184, 28, 29, 25],
62 'PDFDocEncoding' => [0 .. 255],
63 'AdobeStandardEncoding' => [
64 0 .. 38, 144, 40 .. 95, 143, 97 .. 126, 0, 0, 0, 0, 0, 0, 0,
65 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
66 0, 0, 0, 0, 0, 0, 0, 161, 162, 163, 135, 165, 134, 167, 164,
67 39, 141, 171, 136, 137, 147, 148, 0, 133, 129, 130, 183, 0,
68 182, 128, 145, 140, 142, 187, 131, 139, 0, 191, 0, 96, 180,
69 26, 31,175, 24, 27, 168, 0, 30, 231, 0, 28, , 25, 29, 132,
70 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 198, 0, 170,
71 0, 0, 0, 0, 149, 216, 150, 186, 0, 0, 0, 0, 0, 230, 0, 0, 0,
72 154, 0, 0, 155, 248, 156, 223, 0, 0, 0, 0],
73 );
74 }
75  
76 sub new
77 {
78 1 ▶ my ($class, $parent, $name, $pdfname, $encoding) = @_;
Subroutine new: called CC=3 SCAR=11.1
Pod documented
79 1 my ($self) = $class->SUPER::new;
80  
81 1 ▶ return undef unless exists $width_data{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $width_data{$name} 0 1 1
82 1 $self->{'Type'} = PDFName("Font");
83 1 $self->{'Subtype'} = PDFName("Type1");
84 1 $self->{'BaseFont'} = PDFName($name);
85 1 $self->{'Name'} = PDFName($pdfname);
86 1 ▶ $self->{'Encoding'} = PDFName($encodings[$encoding-1]) if ($encoding);
Branch: 1 branch
BranchTrueFalseTotal
if $encoding 0 1 1
87 1 $parent->new_obj($self);
88 1 $self;
89 }
90  
91 =head2 $f->width($text)
92  
93 Returns the width of the text in em.
94  
95 =cut
96  
97 sub getBase
98 {
99 0 ▶ my ($self) = @_;
Subroutine getBase: not called CC=2 SCAR=17.9
Pod undocumented
100  
101 0 ▶ unless (defined $widths{$self->{'BaseFont'}->val})
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $widths{$self->{"BaseFont"}->val}) 0 0 0
102 0 { @{$widths{$self->{'BaseFont'}->val}} = unpack("n*",
103 0 uncompress(unpack("u", $width_data{$self->{'BaseFont'}->val}))); }
104 0 $self;
105 }
106  
107 sub width
108 {
109 0 ▶ my ($self, $text) = @_;
Subroutine width: not called CC=5 SCAR=34.0
Pod documented
110 0 my ($width);
111 0 my ($str) = $self->{'BaseFont'}->val;
112 0 my ($enc);
113 0 ▶ $enc = $self->{'Encoding'}->val if defined $self->{'Encoding'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"Encoding"} 0 0 0
114
115 0 $self->getBase;
116 0 foreach (unpack("C*", $text))
117 0 ▶ { $width += $widths{$str}[(defined $enc and $enc ne "") ? $enc_map{$enc}[$_] : $_]; }
Branch: 1 branch
BranchTrueFalseTotal
defined $enc && $enc ne '' ? : 0 0 0
Condition0%0/3
defined $enc and $enc ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $enc and $enc ne ""
defined $enc $enc ne ""
Truth table0%0/3
A and B
A= defined $encB= $enc ne ""
ABresult
0X0
100
111
118 0 $width / 1000;
119 }
120  
121 =head2 $f->trim($text, $len)
122  
123 Trims the given text to the given length (in em) returning the trimmed
124 text
125  
126 =cut
127  
128 sub trim
129 {
130 0 ▶ my ($self, $text, $len) = @_;
Subroutine trim: not called CC=5 SCAR=34.0
Pod documented
131 0 my ($width, $i);
132 0 my ($str) = $self->{'BaseFont'}->val;
133 0 my ($enc);
134 0 ▶ $enc = $self->{'Encoding'}->val if defined $self->{'Encoding'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"Encoding"} 0 0 0
135
136 0 $self->getBase;
137 0 $len *= 1000;
138
139 0 foreach (unpack("C*", $text))
140 {
141 0 ▶ $width += $widths{$str}[$enc ne "" ? $enc_map{$enc}[$_] : $_];
Branch: 1 branch
BranchTrueFalseTotal
$enc ne '' ? : 0 0 0
142 0 ▶ last if ($width > $len);
Branch: 1 branch
BranchTrueFalseTotal
if $width > $len 0 0 0
143 0 $i++;
144 }
145 0 return substr($text, 0, $i);
146 }
147  
148 =head2 $f->out_text($text)
149  
150 Acknowledges the text to be output for subsetting purposes, etc.
151  
152 =cut
153  
154 sub out_text
155 {
156 0 ▶ my ($self, $text) = @_;
Subroutine out_text: not called CC=1 SCAR=6.9
Pod documented
157  
158 0 return PDFStr($text)->as_pdf;
159 }
160  
161 BEGIN
162 {
163 1 ▶%width_data = (
Subroutine BEGIN: called CC=1 SCAR=0.0
164 'Courier' => <<'EOT',
165 8>)QC8"`-,$4,)TB9?_"%Q]`(*0`U#D_/
166 EOT
167  
168 'Courier-Bold' => <<'EOT',
169 8>)QC8"`-,$4,)TB9?_"%Q]`(*0`U#D_/
170 EOT
171  
172 'Courier-BoldOblique' => <<'EOT',
173 8>)QC8"`-,$4,)TB9?_"%Q]`(*0`U#D_/
174 EOT
175  
176 'Courier-Oblique' => <<'EOT',
177 8>)QC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$I]16-JF>;<H72;M2W=C=U
254 MNU-"PPDJ1A1R<?<%)_W7<Y2Z8,L:GXJ$?=ABKPG/?DR\"]]RVO17^!JXR&S'
255 MZ($7S5;U<[3Z[_NPMZYUD'[@VN;:=&H["V+N65..\-IR\:A.OVJK[>+(/Z'H
256 3]4S^3R/20`@HD+%V_NJ_?N9DIP``
257 EOT
258  
259 'ZapfDingbats' => <<'EOT',
260 M>)RMD#M+`T$4A>>>TZ3TD4V,51K!3CO!!R$B@LTV%M:2*BFUL1!+"19:F2)9
261 MB"AIM)`$B6D$14%,D11:^@,DJ(46NT8$#_X"0>?CFP<S<^?.=>YOS1+L\$H^
262 MH$N/"2;1X"5/,,85[K$FZ^S@G3[Z^,`,:OA$A!!O]HIQI)#%&8<8%PFF.,I)
263 M3BG.DOJLYAE6\(1[O&AW!.>,T6D,<8T;'.."TYS0:4_K4[105Z1AW#')09G7
264 M>WT1(N2FB'/`FF['/*M:T8H($"C_;3$GXN)+E*WL>JYGOOF_JP`>D4::NZCH
265 M7Q%C6$83:S\_^D^VN,C(VGAF($NL\D#,,\]9!F*?ASRR+M>Y('+,J1XM%IQC
266 405DU2*[*#=[*C&Y5V6;I&TT<5J(`
267 EOT
268 );
269 }
270  
271 1 1;
272  
« PDF/Pages.pm ↑ Summary PDF/Array.pm »