Font/TTF/Post.pm

filter: Statementstmt 48.1% 53 / 110 Branchbran 29.1% 21 / 72 Conditioncond 16.6% 2 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 75.0% 6 / 8 Podpod 80.0% 4 / 5 totaltotal 40.0% 86 / 215 CC 41 SCAR 43.9
CC
41
Cov
39%
read
122.3
out
90.0
XML_element
30.0
CRAP 80.6
« Font/TTF/XMLparse.pm ↑ Summary Font/TTF/Hhea.pm »
1 package Font::TTF::Post;
2  
3 =head1 NAME
4  
5 Font::TTF::Post - Holds the Postscript names for each glyph
6  
7 =head1 DESCRIPTION
8  
9 Holds the postscript names for glyphs. Note that they are not held as an
10 array, but as indexes into two lists. The first list is the standard Postscript
11 name list defined by the TrueType standard. The second comes from the font
12 directly.
13  
14 Looking up a glyph from a Postscript name or a name from a glyph number is
15 achieved through methods rather than variable lookup.
16  
17 This class handles PostScript table types of 1, 2, 2.5 & 3, but not version 4.
18 Support for version 2.5 is as per Apple spec rather than MS.
19  
20 The way to look up Postscript names or glyphs is:
21  
22 $pname = $f->{'post'}{'VAL'}[$gnum];
23 $gnum = $f->{'post'}{'STRINGS'}{$pname};
24  
25 =head1 INSTANCE VARIABLES
26  
27 Due to different systems having different limitations, there are various class
28 variables available to control what post table types can be written.
29  
30 =over 4
31  
32 =item $Font::TTF::Post::no25
33  
34 If set tells Font::TTF::Post::out to use table type 2 instead of 2.5 in case apps
35 cannot handle version 2.5.
36  
37 =item VAL
38  
39 Contains an array indexed by glyph number of Postscript names. This is used when
40 writing out a font.
41  
42 =item STRINGS
43  
44 An associative array of Postscript names mapping to the highest glyph with that
45 name. These may not be in sync with VAL.
46  
47 =back
48  
49 In addition there are the standard introductory variables defined in the
50 standard:
51  
52 FormatType
53 italicAngle
54 underlinePosition
55 underlineThickness
56 isFixedPitch
57 minMemType42
58 maxMemType42
59 minMemType1
60 maxMemType1
61  
62 =head1 METHODS
63  
64 =cut
65  
66 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
67 1 ▶use vars qw(@ISA @base_set %base_set %fields $VERSION $no25 @field_info @base_set);
Subroutine BEGIN: called CC=1 SCAR=0.0
68 1 require Font::TTF::Table;
69 1 ▶use Font::TTF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
70  
71 1 $no25 = 1; # officially deprecated format 2.5 tables in MS spec 1.3
72  
73 1 @ISA = qw(Font::TTF::Table);
74 1 @field_info = (
75 'FormatType' => 'f',
76 'italicAngle' => 'f',
77 'underlinePosition' => 's',
78 'underlineThickness' => 's',
79 'isFixedPitch' => 'L',
80 'minMemType42' => 'L',
81 'maxMemType42' => 'L',
82 'minMemType1' => 'L',
83 'maxMemType1' => 'L');
84 1 @base_set = qw(.notdef .null nonmarkingreturn space exclam quotedbl numbersign dollar percent ampersand quotesingle
85 parenleft parenright asterisk plus comma hyphen period slash zero one two three four five six
86 seven eight nine colon semicolon less equal greater question at A B C D E F G H I J K L M N O P Q
87 R S T U V W X Y Z bracketleft backslash bracketright asciicircum underscore grave a b c d e f g h
88 i j k l m n o p q r s t u v w x y z braceleft bar braceright asciitilde Adieresis Aring Ccedilla
89 Eacute Ntilde Odieresis Udieresis aacute agrave acircumflex adieresis atilde aring ccedilla eacute
90 egrave ecircumflex edieresis iacute igrave icircumflex idieresis ntilde oacute ograve ocircumflex
91 odieresis otilde uacute ugrave ucircumflex udieresis dagger degree cent sterling section bullet
92 paragraph germandbls registered copyright trademark acute dieresis notequal AE Oslash infinity
93 plusminus lessequal greaterequal yen mu partialdiff summation product pi integral ordfeminine
94 ordmasculine Omega ae oslash questiondown exclamdown logicalnot radical florin approxequal
95 Delta guillemotleft guillemotright ellipsis nonbreakingspace Agrave Atilde Otilde OE oe endash emdash
96 quotedblleft quotedblright quoteleft quoteright divide lozenge ydieresis Ydieresis fraction currency
97 guilsinglleft guilsinglright fi fl daggerdbl periodcentered quotesinglbase quotedblbase perthousand
98 Acircumflex Ecircumflex Aacute Edieresis Egrave Iacute Icircumflex Idieresis Igrave Oacute Ocircumflex
99 apple Ograve Uacute Ucircumflex Ugrave dotlessi circumflex tilde macron breve dotaccent
100 ring cedilla hungarumlaut ogonek caron Lslash lslash Scaron scaron Zcaron zcaron brokenbar Eth eth
101 Yacute yacute Thorn thorn minus multiply onesuperior twosuperior threesuperior onehalf onequarter
102 threequarters franc Gbreve gbreve Idotaccent Scedilla scedilla Cacute cacute Ccaron ccaron dcroat);
103  
104 1 $VERSION = 0.01; # MJPH 5-AUG-1998 Re-organise data structures
105  
106 sub init
107 1 ▶{
Subroutine init: called CC=4 SCAR=14.2
Pod undocumented
108 1 my ($k, $v, $c, $i);
109 1 ▶ for ($i = 0; $i < $#field_info; $i += 2)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $#Font::TTF::Post::field_info) 9 1 10
110 {
111 9 ($k, $v, $c) = TTF_Init_Fields($field_info[$i], $c, $field_info[$i + 1]);
112 9 ▶ next unless defined $k && $k ne "";
Branch: 1 branch
BranchTrueFalseTotal
unless defined $k and $k ne "" 0 9 9
Condition33%1/3
defined $k and $k ne ""
!ll&&!rl&&r
009
MC/DC0%0/2
defined $k and $k ne ""
defined $k $k ne ""
Truth table33%1/3
A and B
A= defined $kB= $k ne ""
ABresult
0X0
100
111
113 9 $fields{$k} = $v;
114 }
115 1 $i = 0;
116 1 %base_set = map {$_ => $i++} @base_set;
117 }
118  
119  
120 =head2 $t->read
121  
122 Reads the Postscript table into memory from disk
123  
124 =cut
125  
126 sub read
127 2 ▶{
Subroutine read: called CC=17 SCAR=48.1
Pod documented
128 2 my ($self) = @_;
129 2 ▶ $self->SUPER::read or return $self;
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::read or return $self 2 0 2
130  
131 2 my ($dat, $dat1, $i, $off, $c, $maxoff, $form, $angle, $numGlyphs);
132 2 my ($fh) = $self->{' INFILE'};
133  
134 2 $numGlyphs = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
135 2 ▶ init unless ($fields{'FormatType'});
Branch: 1 branch
BranchTrueFalseTotal
unless $Font::TTF::Post::fields{"FormatType"} 1 1 2
136 2 $fh->read($dat, 32);
137 2 TTF_Read_Fields($self, $dat, \%fields);
138  
139 2 ▶ if (int($self->{'FormatType'} + .5) == 1)
Branch: 3 branches
BranchTrueFalseTotal
if (int $self->{'FormatType'} + 0.5 == 1) { } 2 0 2
elsif (int $self->{'FormatType'} * 2 + 0.1 == 5) { } 0 0 0
elsif (int $self->{'FormatType'} + 0.5 == 2) { } 0 0 0
140 {
141 2 ▶ for ($i = 0; $i < 258; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 258) 516 2 518
142 {
143 516 $self->{'VAL'}[$i] = $base_set[$i];
144 516 ▶ $self->{'STRINGS'}{$base_set[$i]} = $i unless (defined $self->{'STRINGS'}{$base_set[$i]});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"STRINGS"}{$Font::TTF::Post::base_set[$i]} 516 0 516
145 }
146 } elsif (int($self->{'FormatType'} * 2 + .1) == 5)
147 {
148 0 $fh->read($dat, 2);
149 0 $numGlyphs = unpack("n", $dat);
150 0 $fh->read($dat, $numGlyphs);
151 0 ▶ for ($i = 0; $i < $numGlyphs; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $numGlyphs) 0 0 0
152 {
153 0 $off = unpack("c", substr($dat, $i, 1));
154 0 $self->{'VAL'}[$i] = $base_set[$i + $off];
155 0 ▶ $self->{'STRINGS'}{$base_set[$i + $off]} = $i unless (defined $self->{'STRINGS'}{$base_set[$i + $off]});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"STRINGS"}{$Font::TTF::Post::base_set[$i + $off]} 0 0 0
156 }
157 } elsif (int($self->{'FormatType'} + .5) == 2)
158 {
159 0 my (@strings);
160
161 0 $fh->read($dat, ($numGlyphs + 1) << 1);
162 0 ▶ for ($i = 0; $i < $numGlyphs; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $numGlyphs) 0 0 0
163 {
164 0 $off = unpack("n", substr($dat, ($i + 1) << 1, 2));
165 0 ▶ $maxoff = $off if (!defined $maxoff || $off > $maxoff);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $maxoff or $off > $maxoff 0 0 0
Condition0%0/3
not defined $maxoff or $off > $maxoff
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $maxoff or $off > $maxoff
not defined $maxoff $off > $maxoff
Truth table0%0/3
not(A) or B
A= not defined $maxoffB= $off > $maxoff
ABresult
1X1
011
000
166 }
167 0 ▶ for ($i = 0; $i < $maxoff - 257; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $maxoff - 257) 0 0 0
168 {
169 0 $fh->read($dat1, 1);
170 0 $off = unpack("C", $dat1);
171 0 $fh->read($dat1, $off);
172 0 $strings[$i] = $dat1;
173 }
174 0 ▶ for ($i = 0; $i < $numGlyphs; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $numGlyphs) 0 0 0
175 {
176 0 $off = unpack("n", substr($dat, ($i + 1) << 1, 2));
177 0 ▶ if ($off > 257)
Branch: 1 branch
BranchTrueFalseTotal
if ($off > 257) { } 0 0 0
178 {
179 0 $self->{'VAL'}[$i] = $strings[$off - 258];
180 0 $self->{'STRINGS'}{$strings[$off - 258]} = $i;
181 }
182 else
183 {
184 0 $self->{'VAL'}[$i] = $base_set[$off];
185 0 ▶ $self->{'STRINGS'}{$base_set[$off]} = $i unless (defined $self->{'STRINGS'}{$base_set[$off]});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"STRINGS"}{$Font::TTF::Post::base_set[$off]} 0 0 0
186 }
187 }
188 }
189 2 $self;
190 }
191  
192  
193 =head2 $t->out($fh)
194  
195 Writes out a new Postscript name table from memory or copies from disk
196  
197 =cut
198  
199 sub out
200 2 ▶{
Subroutine out: called CC=18 SCAR=45.0
Pod documented
201 2 my ($self, $fh) = @_;
202 2 my ($i, $num);
203  
204 2 ▶ return $self->SUPER::out($fh) unless $self->{' read'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{" read"} 0 2 2
205  
206 2 $num = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
207  
208 2 ▶ init unless ($fields{'FormatType'});
Branch: 1 branch
BranchTrueFalseTotal
unless $Font::TTF::Post::fields{"FormatType"} 0 2 2
209  
210 2 ▶ for ($i = $#{$self->{'VAL'}}; !defined $self->{'VAL'}[$i] && $i > 0; $i--)
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{"VAL"}[$i] and $i > 0) 0 2 2
Condition33%1/3
not defined $self->{"VAL"}[$i] and $i > 0
!ll&&!rl&&r
200
MC/DC0%0/2
not defined $self->{"VAL"}[$i] and $i > 0
not defined $self->{"VAL"}[$i] $i > 0
Truth table33%1/3
not(A) and B
A= not defined $self->{"VAL"}[$i]B= $i > 0
ABresult
0X0
100
111
211 0 { pop(@{$self->{'VAL'}}); }
212 2 ▶ if ($#{$self->{'VAL'}} < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($#{$$self{'VAL'};} < 0) { } 0 2 2
213 0 { $self->{'FormatType'} = 3; }
214 else
215 {
216 2 $self->{'FormatType'} = 1;
217 2 ▶ for ($i = 0; $i < $num; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $num) 196 2 198
218 {
219 196 ▶ if (!defined $base_set{$self->{'VAL'}[$i]})
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $Font::TTF::Post::base_set{$self->{'VAL'}[$i]}) { } 0 196 196
elsif ($Font::TTF::Post::base_set{$self->{'VAL'}[$i]} != $i) { } 0 196 196
220 {
221 0 $self->{'FormatType'} = 2;
222 0 last;
223 }
224 elsif ($base_set{$self->{'VAL'}[$i]} != $i)
225 0 ▶ { $self->{'FormatType'} = ($no25 ? 2 : 2.5); }
Branch: 1 branch
BranchTrueFalseTotal
$Font::TTF::Post::no25 ? : 0 0 0
226 }
227 }
228  
229 2 $fh->print(TTF_Out_Fields($self, \%fields, 32));
230  
231 2 ▶ return $self if (int($self->{'FormatType'} + .4) == 3);
Branch: 1 branch
BranchTrueFalseTotal
if int $self->{"FormatType"} + "0.4" == 3 0 2 2
232  
233 2 ▶ if (int($self->{'FormatType'} + .5) == 2)
Branch: 2 branches
BranchTrueFalseTotal
if (int $self->{'FormatType'} + 0.5 == 2) { } 0 2 2
elsif (int $self->{'FormatType'} * 2 + 0.5 == 5) { } 0 2 2
234 {
235 0 my (@ind);
236 0 my ($count) = 0;
237
238 0 $fh->print(pack("n", $num));
239 0 ▶ for ($i = 0; $i < $num; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $num) 0 0 0
240 {
241 0 ▶ if (defined $base_set{$self->{'VAL'}[$i]})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Font::TTF::Post::base_set{$self->{'VAL'}[$i]}) { } 0 0 0
242 0 { $fh->print(pack("n", $base_set{$self->{'VAL'}[$i]})); }
243 else
244 {
245 0 $fh->print(pack("n", $count + 258));
246 0 $ind[$count++] = $i;
247 }
248 }
249 0 ▶ for ($i = 0; $i < $count; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $count) 0 0 0
250 {
251 0 $fh->print(pack("C", length($self->{'VAL'}[$ind[$i]])));
252 0 $fh->print($self->{'VAL'}[$ind[$i]]);
253 }
254 } elsif (int($self->{'FormatType'} * 2 + .5) == 5)
255 {
256 0 $fh->print(pack("n", $num));
257 0 ▶ for ($i = 0; $i < $num; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $num) 0 0 0
258 { $fh->print(pack("c", defined $base_set{$self->{'VAL'}[$i]} ?
259 0 ▶ $base_set{$self->{'VAL'}[$i]} - $i : -$i)); }
Branch: 1 branch
BranchTrueFalseTotal
defined $Font::TTF::Post::base_set{$self->{'VAL'}[$i]} ? : 0 0 0
260 }
261
262 2 $self;
263 }
264  
265  
266 =head2 $t->XML_element($context, $depth, $key, $val)
267  
268 Outputs the names as one block of XML
269  
270 =cut
271  
272 sub XML_element
273 0 ▶{
Subroutine XML_element: not called CC=5 SCAR=34.0
Pod documented
274 0 my ($self) = shift;
275 0 my ($context, $depth, $key, $val) = @_;
276 0 my ($fh) = $context->{'fh'};
277 0 my ($i);
278  
279 0 ▶ return $self->SUPER::XML_element(@_) unless ($key eq 'STRINGS' || $key eq 'VAL');
Branch: 1 branch
BranchTrueFalseTotal
unless $key eq "STRINGS" or $key eq "VAL" 0 0 0
Condition0%0/3
$key eq "STRINGS" or $key eq "VAL"
l!l&&r!l&&!r
000
MC/DC0%0/2
$key eq "STRINGS" or $key eq "VAL"
$key eq "STRINGS" $key eq "VAL"
Truth table0%0/3
A or B
A= $key eq "STRINGS"B= $key eq "VAL"
ABresult
1X1
011
000
280 0 ▶ return unless ($key eq 'VAL');
Branch: 1 branch
BranchTrueFalseTotal
unless $key eq "VAL" 0 0 0
281  
282 0 $fh->print("$depth<names>\n");
283 0 ▶ for ($i = 0; $i <= $#{$self->{'VAL'}}; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#{$$self{"VAL"};}) 0 0 0
284 0 { $fh->print("$depth$context->{'indent'}<name post='$self->{'VAL'}[$i]' gid='$i'/>\n"); }
285 0 $fh->print("$depth</names>\n");
286 0 $self;
287 }
288  
289 =head2 $t->minsize()
290  
291 Returns the minimum size this table can be. If it is smaller than this, then the table
292 must be bad and should be deleted or whatever.
293  
294 =cut
295  
296 sub minsize
297 0 ▶{
Subroutine minsize: not called CC=1 SCAR=6.9
Pod documented
298 0 return 32;
299 }
300  
301 1 1;
302  
303 =head1 BUGS
304  
305 =over 4
306  
307 =item *
308  
309 No support for type 4 tables
310  
311 =back
312  
313 =head1 AUTHOR
314  
315 Martin Hosken L<http://scripts.sil.org/FontUtils>.
316  
317  
318 =head1 LICENSING
319  
320 Copyright (c) 1998-2016, SIL International (http://www.sil.org)
321  
322 This module is released under the terms of the Artistic License 2.0.
323 For details, see the full text of the license in the file LICENSE.
324  
325  
326  
327 =cut
328  
329  
« Font/TTF/XMLparse.pm ↑ Summary Font/TTF/Hhea.pm »