Font/TTF/Glyph.pm

filter: Statementstmt 30.5% 108 / 353 Branchbran 23.2% 52 / 224 Conditioncond 4.4% 3 / 68 MC/DCmcdc 0.0% 0 / 38 Subroutinesub 55.5% 10 / 18 Podpod 78.5% 11 / 14 totaltotal 25.7% 184 / 715 CC 143 SCAR 69.9
CC
143
Cov
25%
update
2913.5
update_bbox
462.0
XML_element
90.0
CRAP 1083.7
↑ Summary Font/TTF/Cmap.pm »
1 package Font::TTF::Glyph;
2  
3 =head1 NAME
4  
5 Font::TTF::Glyph - Holds a information for a single glyph
6  
7 =head1 DESCRIPTION
8  
9 This is a single glyph description as held in a TT font. On creation only its
10 header is read. Thus you can get the bounding box of each glyph without having
11 to read all the other information.
12  
13 =head1 INSTANCE VARIABLES
14  
15 In addition to the named variables in a glyph header (C<xMin> etc.), there are
16 also all capital instance variables for holding working information, mostly
17 from the location table.
18  
19 =head2 Variables for all glyphs:
20  
21 The standard attributes each glyph has are:
22  
23 =over 4
24  
25 =item numberOfContours
26  
27 For simple glyphs this will be the count of contours. For compound glyphs this will be -1.
28  
29 =item xMin
30  
31 =item yMin
32  
33 =item xMax
34  
35 =item yMax
36  
37 These identify the bounding box of the glyph.
38  
39 =back
40  
41 There are also other, derived, instance variables for each glyph which are read
42 when the whole glyph is read (via C<read_dat>):
43  
44 =over 4
45  
46 =item instLen
47  
48 Number of bytes in the hinting instructions (Warning this variable is deprecated,
49 use C<length($g->{'hints'})> instead).
50  
51 =item hints
52  
53 The string containing the hinting code for the glyph
54  
55 =back
56  
57 =head2 Variables for simple glyphs (numberOfContours E<gt>= 0):
58  
59 =over 4
60  
61 =item endPoints
62  
63 An array of endpoints for each contour in the glyph. There are
64 C<numberOfContours> contours in a glyph. The number of points in a glyph is
65 equal to the highest endpoint of a contour.
66  
67 =item numPoints
68  
69 This is a generated value which contains the total number of points for this simple glyph.
70  
71 =back
72  
73 There are also a number of arrays indexed by point number:
74  
75 =over 4
76  
77 =item flags
78  
79 The flags associated with reading this point. The flags for a point are
80 recalculated for a point when it is C<update>d. Thus the flags are not very
81 useful. The only important bit is bit 0 which indicates whether the point is
82 an 'on' curve point, or an 'off' curve point.
83  
84 =item x
85  
86 The absolute x co-ordinate of the point.
87  
88 =item y
89  
90 The absolute y co-ordinate of the point
91  
92 =back
93  
94 =head2 Variables for compound glyphs (numberOfContours == -1):
95  
96 =over 4
97  
98 =item metric
99  
100 This holds the component number (not its glyph number) of the component from
101 which the metrics for this glyph should be taken.
102  
103 =item comps
104  
105 This is an array of hashes for each component. Each hash has a number of
106 elements:
107  
108 =over 4
109  
110 =item glyph
111  
112 The glyph number of the glyph which comprises this component of the composite.
113 NOTE: In some badly generated fonts, C<glyph> may contain a numerical value
114 but that glyph might not actually exist in the font file. This could
115 occur in any glyph, but is particularly likely for glyphs that have
116 no strokes, such as SPACE, U+00A0 NO-BREAK SPACE, or
117 U+200B ZERO WIDTH SPACE.
118  
119 =item args
120  
121 An array of two arguments which may be an x, y co-ordinate or two attachment
122 points (one on the base glyph the other on the component). See flags for details.
123  
124 =item flag
125  
126 The flag for this component
127  
128 =item scale
129  
130 A 4 number array for component scaling. This allows stretching, rotating, etc.
131 Note that scaling applies to placement co-ordinates (rather than attachment points)
132 before locating rather than after.
133  
134 =back
135  
136 =item numPoints
137  
138 This is a generated value which contains the number of components read in for this
139 compound glyph.
140  
141 =back
142  
143 =head2 Private instance variables:
144  
145 =over 4
146  
147 =item INFILE (P)
148  
149 The input file form which to read any information
150  
151 =item LOC (P)
152  
153 Location relative to the start of the glyf table in the read file
154  
155 =item BASE (P)
156  
157 The location of the glyf table in the read file
158  
159 =item LEN (P)
160  
161 This is the number of bytes required by the glyph. It should be kept up to date
162 by calling the C<update> method whenever any of the glyph content changes.
163  
164 =item OUTLOC (P)
165  
166 Location relative to the start of the glyf table. This variable is only active
167 whilst the output process is going on. It is used to inform the location table
168 where the glyph is located, since the glyf table is output before the loca
169 table due to alphabetical ordering.
170  
171 =item OUTLEN (P)
172  
173 This indicates the length of the glyph data when it is output. This more
174 accurately reflects the internal memory form than the C<LEN> variable which
175 only reflects the read file length. The C<OUTLEN> variable is only set after
176 calling C<out> or C<out_dat>.
177  
178 =back
179  
180 =head2 Editing
181  
182 If you want to edit a glyph in some way, then you should read_dat the glyph, then
183 make your changes and then update the glyph or set the $g->{' isDirty'} variable.
184 The application must ensure that the following instance variables are
185 correct, from which update will calculate the rest, including the bounding box
186 information.
187  
188 numPoints
189 numberOfContours
190 endPoints
191 x, y, flags (only flags bit 0)
192 instLen
193 hints
194  
195 For components, the numPoints, x, y, endPoints & flags are not required but
196 the following information is required for each component.
197  
198 flag (bits 2, 10, 11, 12)
199 glyph
200 args
201 scale
202 metric (glyph instance variable)
203
204  
205 =head1 METHODS
206  
207 =cut
208  
209 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
210 1 ▶use vars qw(%fields @field_info);
Subroutine BEGIN: called CC=1 SCAR=0.0
211 1 ▶use Font::TTF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
212 1 ▶use Font::TTF::Table;
Subroutine BEGIN: called CC=1 SCAR=0.0
213  
214 1 @field_info = (
215 'numberOfContours' => 's',
216 'xMin' => 's',
217 'yMin' => 's',
218 'xMax' => 's',
219 'yMax' => 's');
220  
221 sub init
222 1 ▶{
Subroutine init: called CC=4 SCAR=14.5
Pod undocumented
223 1 my ($k, $v, $c, $i);
224 1 ▶ for ($i = 0; $i < $#field_info; $i += 2)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $#Font::TTF::Glyph::field_info) 5 1 6
225 {
226 5 ($k, $v, $c) = TTF_Init_Fields($field_info[$i], $c, $field_info[$i + 1]);
227 5 ▶ next unless defined $k && $k ne "";
Branch: 1 branch
BranchTrueFalseTotal
unless defined $k and $k ne "" 0 5 5
Condition33%1/3
defined $k and $k ne ""
!ll&&!rl&&r
005
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
228 5 $fields{$k} = $v;
229 }
230 }
231  
232  
233 =head1 Font::TTF::Glyph->new(%parms)
234  
235 Creates a new glyph setting various instance variables
236  
237 =cut
238  
239 sub new
240 188 ▶{
Subroutine new: called CC=3 SCAR=11.0
Pod undocumented
241 188 my ($class, %parms) = @_;
242 188 my ($self) = {};
243 188 my ($p);
244  
245 188 bless $self, $class;
246 188 foreach $p (keys %parms)
247 1316 { $self->{" $p"} = $parms{$p}; }
248 188 ▶ init unless defined $fields{'xMin'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Font::TTF::Glyph::fields{"xMin"} 1 187 188
249 188 $self;
250 }
251  
252  
253 =head2 $g->read
254  
255 Reads the header component of the glyph (numberOfContours and bounding box) and also the
256 glyph content, but into a data field rather than breaking it down into
257 its constituent structures. Use read_dat for this.
258  
259 =cut
260  
261 sub read
262 188 ▶{
Subroutine read: called CC=3 SCAR=11.3
Pod documented
263 188 my ($self) = @_;
264 188 my ($fh) = $self->{' INFILE'};
265 188 my ($dat);
266  
267 188 ▶ return $self if (defined $self->{' read'} && $self->{' read'} > 0);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{" read"} and $self->{" read"} > 0 0 188 188
Condition33%1/3
defined $self->{" read"} and $self->{" read"} > 0
!ll&&!rl&&r
18800
MC/DC0%0/2
defined $self->{" read"} and $self->{" read"} > 0
defined $self->{" read"} $self->{" read"} > 0
Truth table33%1/3
A and B
A= defined $self->{" read"}B= $self->{" read"} > 0
ABresult
0X0
100
111
268 188 $self->{' read'} = 1;
269 188 $fh->seek($self->{' LOC'} + $self->{' BASE'}, 0);
270 188 $fh->read($dat, $self->{' LEN'});
271 188 TTF_Read_Fields($self, $self->{' DAT'} = $dat, \%fields);
272 188 $self;
273 }
274  
275  
276 =head2 $g->read_dat
277  
278 Reads the contents of the glyph (components and curves, etc.) from the memory
279 store C<DAT> into structures within the object.
280  
281 =cut
282  
283 sub read_dat
284 188 ▶{
Subroutine read_dat: called CC=30 SCAR=35.7
Pod documented
285 188 my ($self) = @_;
286 188 my ($dat, $num, $max, $i, $flag, $len, $val, $val1, $fp);
287  
288 188 ▶ return $self if (defined $self->{' read'} && $self->{' read'} > 1);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{" read"} and $self->{" read"} > 1 0 188 188
Condition33%1/3
defined $self->{" read"} and $self->{" read"} > 1
!ll&&!rl&&r
18800
MC/DC0%0/2
defined $self->{" read"} and $self->{" read"} > 1
defined $self->{" read"} $self->{" read"} > 1
Truth table33%1/3
A and B
A= defined $self->{" read"}B= $self->{" read"} > 1
ABresult
0X0
100
111
289 188 ▶ $self->read unless $self->{' read'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{" read"} 188 0 188
290 188 $dat = $self->{' DAT'};
291 188 $fp = 10;
292 188 $num = $self->{'numberOfContours'};
293 188 ▶ if ($num > 0)
Branch: 2 branches
BranchTrueFalseTotal
if ($num > 0) { } 184 4 188
elsif ($num < 0) { } 4 0 4
294 {
295 184 $self->{'endPoints'} = [unpack("n*", substr($dat, $fp, $num << 1))];
296 184 $fp += $num << 1;
297 184 $max = 0;
298 184 foreach (@{$self->{'endPoints'}})
299 260 ▶ { $max = $_ if $_ > $max; }
Branch: 1 branch
BranchTrueFalseTotal
if $_ > $max 260 0 260
300 # print STDERR join(",", unpack('C*', $self->{" DAT"}));
301 # printf STDERR ("(%d,%d in %d=%d @ %d)", scalar @{$self->{'endPoints'}}, $max, length($dat), $self->{' LEN'}, $fp);
302 184 ▶ $max++ if (@{$self->{'endPoints'}});
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"endPoints"};} 184 0 184
303 184 $self->{'numPoints'} = $max;
304 184 $self->{'instLen'} = unpack("n", substr($dat, $fp));
305 184 $self->{'hints'} = substr($dat, $fp + 2, $self->{'instLen'});
306 184 $fp += 2 + $self->{'instLen'};
307 # read the flags array
308 184 ▶ for ($i = 0; $i < $max; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $max) 5498 184 5682
309 {
310 5498 $flag = unpack("C", substr($dat, $fp++));
311 5498 $self->{'flags'}[$i] = $flag;
312 5498 ▶ if ($flag & 8)
Branch: 1 branch
BranchTrueFalseTotal
if ($flag & 8) 1474 4024 5498
313 {
314 1474 $len = unpack("C", substr($dat, $fp++));
315 1474 ▶ while ($len-- > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($len-- > 0) 2976 1474 4450
316 {
317 2976 $i++;
318 2976 $self->{'flags'}[$i] = $flag;
319 }
320 }
321 }
322 #read the x array
323 184 ▶ for ($i = 0; $i < $max; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $max) 8474 184 8658
324 {
325 8474 $flag = $self->{'flags'}[$i];
326 8474 ▶ if ($flag & 2)
Branch: 2 branches
BranchTrueFalseTotal
if ($flag & 2) { } 6630 1844 8474
elsif ($flag & 16) { } 1310 534 1844
327 {
328 6630 $val = unpack("C", substr($dat, $fp++));
329 6630 ▶ $val = -$val unless ($flag & 16);
Branch: 1 branch
BranchTrueFalseTotal
unless $flag & 16 3412 3218 6630
330 } elsif ($flag & 16)
331 1310 { $val = 0; }
332 else
333 {
334 534 $val = TTF_Unpack("s", substr($dat, $fp));
335 534 $fp += 2;
336 }
337 8474 ▶ $self->{'x'}[$i] = $i == 0 ? $val : $self->{'x'}[$i - 1] + $val;
Branch: 1 branch
BranchTrueFalseTotal
$i == 0 ? : 184 8290 8474
338 }
339 #read the y array
340 184 ▶ for ($i = 0; $i < $max; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $max) 8474 184 8658
341 {
342 8474 $flag = $self->{'flags'}[$i];
343 8474 ▶ if ($flag & 4)
Branch: 2 branches
BranchTrueFalseTotal
if ($flag & 4) { } 6774 1700 8474
elsif ($flag & 32) { } 1074 626 1700
344 {
345 6774 $val = unpack("C", substr($dat, $fp++));
346 6774 ▶ $val = -$val unless ($flag & 32);
Branch: 1 branch
BranchTrueFalseTotal
unless $flag & 32 3300 3474 6774
347 } elsif ($flag & 32)
348 1074 { $val = 0; }
349 else
350 {
351 626 $val = TTF_Unpack("s", substr($dat, $fp));
352 626 $fp += 2;
353 }
354 8474 ▶ $self->{'y'}[$i] = $i == 0 ? $val : $self->{'y'}[$i - 1] + $val;
Branch: 1 branch
BranchTrueFalseTotal
$i == 0 ? : 184 8290 8474
355 }
356 }
357
358 # compound glyph
359 elsif ($num < 0)
360 {
361 4 $flag = 1 << 5; # cheat to get the loop going
362 4 ▶ for ($i = 0; $flag & 32; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($flag & 32) 8 4 12
363 {
364 8 ($flag, $self->{'comps'}[$i]{'glyph'}) = unpack("n2", substr($dat, $fp));
365 8 $fp += 4;
366 8 $self->{'comps'}[$i]{'flag'} = $flag;
367 8 ▶ if ($flag & 1) # ARGS1_AND_2_ARE_WORDS
Branch: 1 branch
BranchTrueFalseTotal
if ($flag & 1) { } 4 4 8
368 {
369 4 $self->{'comps'}[$i]{'args'} = [TTF_Unpack("s2", substr($dat, $fp))];
370 4 $fp += 4;
371 } else
372 {
373 4 $self->{'comps'}[$i]{'args'} = [unpack("c2", substr($dat, $fp))];
374 4 $fp += 2;
375 }
376
377 8 ▶ if ($flag & 8)
Branch: 3 branches
BranchTrueFalseTotal
if ($flag & 8) { } 0 8 8
elsif ($flag & 64) { } 0 8 8
elsif ($flag & 128) { } 0 8 8
378 {
379 0 $val = TTF_Unpack("F", substr($dat, $fp));
380 0 $fp += 2;
381 0 $self->{'comps'}[$i]{'scale'} = [$val, 0, 0, $val];
382 } elsif ($flag & 64)
383 {
384 0 ($val, $val1) = TTF_Unpack("F2", substr($dat, $fp));
385 0 $fp += 4;
386 0 $self->{'comps'}[$i]{'scale'} = [$val, 0, 0, $val1];
387 } elsif ($flag & 128)
388 {
389 0 $self->{'comps'}[$i]{'scale'} = [TTF_Unpack("F4", substr($dat, $fp))];
390 0 $fp += 8;
391 }
392 8 ▶ $self->{'metric'} = $i if ($flag & 512);
Branch: 1 branch
BranchTrueFalseTotal
if $flag & 512 0 8 8
393 }
394 4 $self->{'numPoints'} = $i;
395 4 ▶ if ($flag & 256) # HAVE_INSTRUCTIONS
Branch: 1 branch
BranchTrueFalseTotal
if ($flag & 256) 0 4 4
396 {
397 0 $self->{'instLen'} = unpack("n", substr($dat, $fp));
398 0 $self->{'hints'} = substr($dat, $fp + 2, $self->{'instLen'});
399 0 $fp += 2 + $self->{'instLen'};
400 }
401 }
402 188 ▶ return undef if ($fp > length($dat));
Branch: 1 branch
BranchTrueFalseTotal
if $fp > length $dat 0 188 188
403 188 $self->{' read'} = 2;
404 188 $self;
405 }
406  
407  
408 =head2 $g->out($fh)
409  
410 Writes the glyph data to outfile
411  
412 =cut
413  
414 sub out
415 188 ▶{
Subroutine out: called CC=3 SCAR=11.2
Pod documented
416 188 my ($self, $fh) = @_;
417  
418 188 ▶ $self->read unless $self->{' read'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{" read"} 0 188 188
419 188 ▶ $self->update if $self->{' isDirty'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{" isDirty"} 0 188 188
420 188 $fh->print($self->{' DAT'});
421 188 $self->{' OUTLEN'} = length($self->{' DAT'});
422 188 $self;
423 }
424  
425  
426 =head2 $g->out_xml($context, $depth)
427  
428 Outputs an XML description of the glyph
429  
430 =cut
431  
432 sub out_xml
433 0 ▶{
Subroutine out_xml: not called CC=3 SCAR=24.8
Pod documented
434 0 my ($self, $context, $depth) = @_;
435 0 my ($addr) = ($self =~ m/\((.+)\)$/o);
436 0 my ($k, $ndepth);
437  
438 0 ▶ if ($context->{'addresses'}{$addr})
Branch: 1 branch
BranchTrueFalseTotal
if ($context->{'addresses'}{$addr}) { } 0 0 0
439 {
440 0 $context->{'fh'}->printf("%s<glyph gid='%s' id_ref='%s'/>\n", $depth, $context->{'gid'}, $context->{'addresses'}{$addr});
441 0 return $self;
442 }
443 else
444 {
445 0 $context->{'fh'}->printf("%s<glyph gid='%s'>\n", $depth, $context->{'gid'});
446 }
447
448 0 $ndepth = $depth . $context->{'indent'};
449 0 $self->read_dat;
450 0 foreach $k (sort grep {$_ !~ m/^\s/o} keys %{$self})
451 {
452 0 $self->XML_element($context, $ndepth, $k, $self->{$k});
453 }
454 0 $context->{'fh'}->print("$depth</glyph>\n");
455 0 delete $context->{'done_points'};
456 0 $self;
457 }
458
459  
460 sub XML_element
461 0 ▶{
Subroutine XML_element: not called CC=9 SCAR=45.0
Pod undocumented
462 0 my ($self, $context, $depth, $key, $val) = @_;
463 0 my ($fh) = $context->{'fh'};
464 0 my ($dind) = $depth . $context->{'indent'};
465 0 my ($i);
466
467 0 ▶ if ($self->{'numberOfContours'} >= 0 && ($key eq 'x' || $key eq 'y' || $key eq 'flags'))
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'numberOfContours'} >= 0 and $key eq 'x' || $key eq 'y' || $key eq 'flags') { } 0 0 0
elsif ($key eq 'hints') { } 0 0 0
Condition0%0/9
$self->{"numberOfContours"} >= 0 and $key eq "x" || $key eq "y" || $key eq "flags"
!ll&&!rl&&r
000
$key eq "x" or $key eq "y" or $key eq "flags"
l!l&&r!l&&!r
000
$key eq "x" or $key eq "y"
l!l&&r!l&&!r
000
MC/DC0%0/4
$self->{"numberOfContours"} >= 0 and $key eq "x" || $key eq "y" || $key eq "flags"
$self->{"numberOfContours"} >= 0 $key eq "x" $key eq "y" $key eq "flags"
Truth table0%0/5
A and B or C or D
A= $self->{"numberOfContours"} >= 0B= $key eq "x"C= $key eq "y"D= $key eq "flags"
ABCDresult
0XXX0
10000
11XX1
101X1
10011
468 {
469 0 ▶ return $self if ($context->{'done_points'});
Branch: 1 branch
BranchTrueFalseTotal
if $context->{"done_points"} 0 0 0
470 0 $context->{'done_points'} = 1;
471  
472 0 $fh->print("$depth<points>\n");
473 0 ▶ for ($i = 0; $i <= $#{$self->{'flags'}}; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#{$$self{"flags"};}) 0 0 0
474 { $fh->printf("%s<point x='%s' y='%s' flags='0x%02X'/>\n", $dind,
475 0 $self->{'x'}[$i], $self->{'y'}[$i], $self->{'flags'}[$i]); }
476 0 $fh->print("$depth</points>\n");
477 }
478 elsif ($key eq 'hints')
479 {
480 0 my ($dat);
481 0 $fh->print("$depth<hints>\n");
482 # Font::TTF::Utils::XML_hexdump($context, $depth . $context->{'indent'}, $self->{'hints'});
483 0 ▶ $dat = Font::TTF::Utils::XML_binhint($self->{'hints'}) || "";
Condition0%0/2
Font::TTF::Utils::XML_binhint($self->{'hints'}) || ''
l!l
00
MC/DC0%0/1
Font::TTF::Utils::XML_binhint($self->{'hints'}) || ''
Font::TTF::Utils::XML_binhint($self->{'hints'})
Truth table0%0/2
A
A= Font::TTF::Utils::XML_binhint($self->{'hints'})
Aresult
11
00
484 0 $dat =~ s/\n(?!$)/\n$depth$context->{'indent'}/mg;
485 0 $fh->print("$depth$context->{'indent'}$dat");
486 0 $fh->print("$depth</hints>\n");
487 }
488 else
489 0 { return Font::TTF::Table::XML_element(@_); }
490  
491 0 $self;
492 }
493  
494 =head2 $g->dirty($val)
495  
496 This sets the dirty flag to the given value or 1 if no given value. It returns the
497 value of the flag
498  
499 =cut
500  
501 sub dirty
502 0 ▶{
Subroutine dirty: not called CC=2 SCAR=17.9
Pod documented
503 0 my ($self, $val) = @_;
504 0 my ($res) = $self->{' isDirty'};
505  
506 0 ▶ $self->{' isDirty'} = defined $val ? $val : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $val ? : 0 0 0
507 0 $res;
508 }
509  
510 =head2 $g->update
511  
512 Generates a C<$self->{'DAT'}> from the internal structures, if the data has
513 been read into structures in the first place. If you are building a glyph
514 from scratch you will need to set the instance variable C<' isDirty'>.
515  
516 =cut
517  
518 sub update
519 188 ▶{
Subroutine update: called CC=55 SCAR=79.8
Pod documented
520 188 my ($self) = @_;
521 188 my ($dat, $loc, $len, $flag, $x, $y, $i, $comp, $num, @rflags, $repeat);
522  
523 188 ▶ return $self unless ($self->{' isDirty'});
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{" isDirty"} 188 0 188
524 0 $self->read_dat->update_bbox;
525 0 $self->{' DAT'} = TTF_Out_Fields($self, \%fields, 10);
526 0 $num = $self->{'numberOfContours'};
527 0 ▶ if ($num > 0)
Branch: 2 branches
BranchTrueFalseTotal
if ($num > 0) { } 0 0 0
elsif ($num < 0) { } 0 0 0
528 {
529 0 $self->{' DAT'} .= pack("n*", @{$self->{'endPoints'}});
530 0 $len = $self->{'instLen'};
531 0 $self->{' DAT'} .= pack("n", $len);
532 0 ▶ $self->{' DAT'} .= pack("a" . $len, substr($self->{'hints'}, 0, $len)) if ($len > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $len > 0 0 0 0
533 0 $repeat = 0;
534 0 ▶ for ($i = 0; $i < $self->{'numPoints'}; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->{"numPoints"}) 0 0 0
535 {
536 0 $flag = $self->{'flags'}[$i] & 1;
537 0 ▶ if ($i == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 0) { } 0 0 0
538 {
539 0 $x = $self->{'x'}[$i];
540 0 $y = $self->{'y'}[$i];
541 } else
542 {
543 0 $x = $self->{'x'}[$i] - $self->{'x'}[$i - 1];
544 0 $y = $self->{'y'}[$i] - $self->{'y'}[$i - 1];
545 }
546 0 ▶ $flag |= 16 if ($x == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $x == 0 0 0 0
547 0 ▶ $flag |= 32 if ($y == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $y == 0 0 0 0
548 0 ▶ if (($flag & 16) == 0 && $x < 256 && $x > -256)
Branch: 1 branch
BranchTrueFalseTotal
if (($flag & 16) == 0 and $x < 256 and $x > -256) 0 0 0
Condition0%0/6
($flag & 16) == 0 and $x < 256 and $x > -256
!ll&&!rl&&r
000
($flag & 16) == 0 and $x < 256
!ll&&!rl&&r
000
MC/DC0%0/3
($flag & 16) == 0 and $x < 256 and $x > -256
($flag & 16) == 0 $x < 256 $x > -256
Truth table0%0/4
A and B and C
A= ($flag & 16) == 0B= $x < 256C= $x > -256
ABCresult
0XX0
10X0
1100
1111
549 {
550 0 $flag |= 2;
551 0 ▶ $flag |= 16 if ($x >= 0);
Branch: 1 branch
BranchTrueFalseTotal
if $x >= 0 0 0 0
552 }
553 0 ▶ if (($flag & 32) == 0 && $y < 256 && $y > -256)
Branch: 1 branch
BranchTrueFalseTotal
if (($flag & 32) == 0 and $y < 256 and $y > -256) 0 0 0
Condition0%0/6
($flag & 32) == 0 and $y < 256 and $y > -256
!ll&&!rl&&r
000
($flag & 32) == 0 and $y < 256
!ll&&!rl&&r
000
MC/DC0%0/3
($flag & 32) == 0 and $y < 256 and $y > -256
($flag & 32) == 0 $y < 256 $y > -256
Truth table0%0/4
A and B and C
A= ($flag & 32) == 0B= $y < 256C= $y > -256
ABCresult
0XX0
10X0
1100
1111
554 {
555 0 $flag |= 4;
556 0 ▶ $flag |= 32 if ($y >= 0);
Branch: 1 branch
BranchTrueFalseTotal
if $y >= 0 0 0 0
557 }
558 0 ▶ if ($i > 0 && $rflags[-1] == $flag && $repeat < 255)
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0 and $rflags[-1] == $flag and $repeat < 255) { } 0 0 0
Condition0%0/6
$i > 0 and $rflags[-1] == $flag and $repeat < 255
!ll&&!rl&&r
000
$i > 0 and $rflags[-1] == $flag
!ll&&!rl&&r
000
MC/DC0%0/3
$i > 0 and $rflags[-1] == $flag and $repeat < 255
$i > 0 $rflags[-1] == $flag $repeat < 255
Truth table0%0/4
A and B and C
A= $i > 0B= $rflags[-1] == $flagC= $repeat < 255
ABCresult
0XX0
10X0
1100
1111
559 {
560 0 $repeat++;
561 } else
562 {
563 0 ▶ if ($repeat)
Branch: 1 branch
BranchTrueFalseTotal
if ($repeat) 0 0 0
564 {
565 0 $rflags[-1] |= 8;
566 0 push @rflags, $repeat;
567 }
568 0 push @rflags, $flag;
569 0 $repeat = 0;
570 }
571 0 $self->{'flags'}[$i] = $flag;
572 }
573 # Add final repeat if needed, then pack up the flag bytes:
574 0 ▶ if ($repeat)
Branch: 1 branch
BranchTrueFalseTotal
if ($repeat) 0 0 0
575 {
576 0 $rflags[-1] |= 8;
577 0 push @rflags, $repeat;
578 }
579 0 $self->{' DAT'} .= pack("C*", @rflags);
580 0 ▶ for ($i = 0; $i < $self->{'numPoints'}; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->{"numPoints"}) 0 0 0
581 {
582 0 $flag = $self->{'flags'}[$i];
583 0 ▶ $x = $self->{'x'}[$i] - (($i == 0) ? 0 : $self->{'x'}[$i - 1]);
Branch: 1 branch
BranchTrueFalseTotal
$i == 0 ? : 0 0 0
584 0 ▶ if (($flag & 18) == 0)
Branch: 3 branches
BranchTrueFalseTotal
if (($flag & 18) == 0) { } 0 0 0
elsif (($flag & 18) == 18) { } 0 0 0
elsif (($flag & 18) == 2) { } 0 0 0
585 0 { $self->{' DAT'} .= TTF_Pack("s", $x); }
586 elsif (($flag & 18) == 18)
587 0 { $self->{' DAT'} .= pack("C", $x); }
588 elsif (($flag & 18) == 2)
589 0 { $self->{' DAT'} .= pack("C", -$x); }
590 }
591 0 ▶ for ($i = 0; $i < $self->{'numPoints'}; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->{"numPoints"}) 0 0 0
592 {
593 0 $flag = $self->{'flags'}[$i];
594 0 ▶ $y = $self->{'y'}[$i] - (($i == 0) ? 0 : $self->{'y'}[$i - 1]);
Branch: 1 branch
BranchTrueFalseTotal
$i == 0 ? : 0 0 0
595 0 ▶ if (($flag & 36) == 0)
Branch: 3 branches
BranchTrueFalseTotal
if (($flag & 36) == 0) { } 0 0 0
elsif (($flag & 36) == 36) { } 0 0 0
elsif (($flag & 36) == 4) { } 0 0 0
596 0 { $self->{' DAT'} .= TTF_Pack("s", $y); }
597 elsif (($flag & 36) == 36)
598 0 { $self->{' DAT'} .= pack("C", $y); }
599 elsif (($flag & 36) == 4)
600 0 { $self->{' DAT'} .= pack("C", -$y); }
601 }
602 }
603  
604 elsif ($num < 0)
605 {
606 0 ▶ for ($i = 0; $i <= $#{$self->{'comps'}}; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#{$$self{"comps"};}) 0 0 0
607 {
608 0 $comp = $self->{'comps'}[$i];
609 0 $flag = $comp->{'flag'} & 7158; # bits 2,10,11,12
610 $flag |= 1 unless ($comp->{'args'}[0] > -129 && $comp->{'args'}[0] < 128
611 0 ▶ && $comp->{'args'}[1] > -129 && $comp->{'args'}[1] < 128);
Branch: 1 branch
BranchTrueFalseTotal
unless $comp->{"args"}[0] > -129 and $comp->{"args"}[0] < 128 and $comp->{"args"}[1] > -129 and $comp->{"args"}[1] < 128 0 0 0
Condition0%0/9
$comp->{"args"}[0] > -129 and $comp->{"args"}[0] < 128 and $comp->{"args"}[1] > -129 and $comp->{"args"}[1] < 128
!ll&&!rl&&r
000
$comp->{"args"}[0] > -129 and $comp->{"args"}[0] < 128 and $comp->{"args"}[1] > -129
!ll&&!rl&&r
000
$comp->{"args"}[0] > -129 and $comp->{"args"}[0] < 128
!ll&&!rl&&r
000
MC/DC0%0/4
$comp->{"args"}[0] > -129 and $comp->{"args"}[0] < 128 and $comp->{"args"}[1] > -129 and $comp->{"args"}[1] < 128
$comp->{"args"}[0] > -129 $comp->{"args"}[0] < 128 $comp->{"args"}[1] > -129 $comp->{"args"}[1] < 128
Truth table0%0/5
A and B and C and D
A= $comp->{"args"}[0] > -129B= $comp->{"args"}[0] < 128C= $comp->{"args"}[1] > -129D= $comp->{"args"}[1] < 128
ABCDresult
0XXX0
10XX0
110X0
11100
11111
612 0 ▶ if (defined $comp->{'scale'})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $comp->{"scale"}) 0 0 0
613 {
614 0 ▶ if ($comp->{'scale'}[1] == 0 && $comp->{'scale'}[2] == 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($comp->{'scale'}[1] == 0 and $comp->{'scale'}[2] == 0) { } 0 0 0
Condition0%0/3
$comp->{"scale"}[1] == 0 and $comp->{"scale"}[2] == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$comp->{"scale"}[1] == 0 and $comp->{"scale"}[2] == 0
$comp->{"scale"}[1] == 0 $comp->{"scale"}[2] == 0
Truth table0%0/3
A and B
A= $comp->{"scale"}[1] == 0B= $comp->{"scale"}[2] == 0
ABresult
0X0
100
111
615 {
616 0 ▶ if ($comp->{'scale'}[0] == $comp->{'scale'}[3])
Branch: 1 branch
BranchTrueFalseTotal
if ($comp->{'scale'}[0] == $comp->{'scale'}[3]) { } 0 0 0
617 { $flag |= 8 unless ($comp->{'scale'}[0] == 0
618 0 ▶ || $comp->{'scale'}[0] == 1); }
Branch: 1 branch
BranchTrueFalseTotal
unless $comp->{"scale"}[0] == 0 or $comp->{"scale"}[0] == 1 0 0 0
Condition0%0/3
$comp->{"scale"}[0] == 0 or $comp->{"scale"}[0] == 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$comp->{"scale"}[0] == 0 or $comp->{"scale"}[0] == 1
$comp->{"scale"}[0] == 0 $comp->{"scale"}[0] == 1
Truth table0%0/3
A or B
A= $comp->{"scale"}[0] == 0B= $comp->{"scale"}[0] == 1
ABresult
1X1
011
000
619 else
620 0 { $flag |= 64; }
621 } else
622 0 { $flag |= 128; }
623 }
624
625 0 ▶ $flag |= 512 if (defined $self->{'metric'} && $self->{'metric'} == $i);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"metric"} and $self->{"metric"} == $i 0 0 0
Condition0%0/3
defined $self->{"metric"} and $self->{"metric"} == $i
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"metric"} and $self->{"metric"} == $i
defined $self->{"metric"} $self->{"metric"} == $i
Truth table0%0/3
A and B
A= defined $self->{"metric"}B= $self->{"metric"} == $i
ABresult
0X0
100
111
626 0 ▶ if ($i == $#{$self->{'comps'}})
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $#{$$self{'comps'};}) { } 0 0 0
627 0 ▶ { $flag |= 256 if (defined $self->{'instLen'} && $self->{'instLen'} > 0); }
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"instLen"} and $self->{"instLen"} > 0 0 0 0
Condition0%0/3
defined $self->{"instLen"} and $self->{"instLen"} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"instLen"} and $self->{"instLen"} > 0
defined $self->{"instLen"} $self->{"instLen"} > 0
Truth table0%0/3
A and B
A= defined $self->{"instLen"}B= $self->{"instLen"} > 0
ABresult
0X0
100
111
628 else
629 0 { $flag |= 32; }
630
631 0 $self->{' DAT'} .= pack("n", $flag);
632 0 $self->{' DAT'} .= pack("n", $comp->{'glyph'});
633 0 $comp->{'flag'} = $flag;
634  
635 0 ▶ if ($flag & 1)
Branch: 1 branch
BranchTrueFalseTotal
if ($flag & 1) { } 0 0 0
636 0 { $self->{' DAT'} .= TTF_Pack("s2", @{$comp->{'args'}}); }
637 else
638 0 { $self->{' DAT'} .= pack("CC", @{$comp->{'args'}}); }
639  
640 0 ▶ if ($flag & 8)
Branch: 3 branches
BranchTrueFalseTotal
if ($flag & 8) { } 0 0 0
elsif ($flag & 64) { } 0 0 0
elsif ($flag & 128) { } 0 0 0
641 0 { $self->{' DAT'} .= TTF_Pack("F", $comp->{'scale'}[0]); }
642 elsif ($flag & 64)
643 0 { $self->{' DAT'} .= TTF_Pack("F2", $comp->{'scale'}[0], $comp->{'scale'}[3]); }
644 elsif ($flag & 128)
645 0 { $self->{' DAT'} .= TTF_Pack("F4", @{$comp->{'scale'}}); }
646 }
647 0 ▶ if (defined $self->{'instLen'} && $self->{'instLen'} > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"instLen"} and $self->{"instLen"} > 0) 0 0 0
Condition0%0/3
defined $self->{"instLen"} and $self->{"instLen"} > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"instLen"} and $self->{"instLen"} > 0
defined $self->{"instLen"} $self->{"instLen"} > 0
Truth table0%0/3
A and B
A= defined $self->{"instLen"}B= $self->{"instLen"} > 0
ABresult
0X0
100
111
648 {
649 0 $len = $self->{'instLen'};
650 0 $self->{' DAT'} .= pack("n", $len);
651 0 $self->{' DAT'} .= pack("a" . $len, substr($self->{'hints'}, 0, $len));
652 }
653 }
654 0 my ($olen) = length($self->{' DAT'});
655 0 ▶ $self->{' DAT'} .= ("\000") x (4 - ($olen & 3)) if ($olen & 3);
Branch: 1 branch
BranchTrueFalseTotal
if $olen & 3 0 0 0
656 0 $self->{' OUTLEN'} = length($self->{' DAT'});
657 0 $self->{' read'} = 2; # changed from 1 to 2 so we don't read_dat() again
658 # we leave numPoints and instLen since maxp stats use this
659 0 $self;
660 }
661  
662  
663 =head2 $g->update_bbox
664  
665 Updates the bounding box for this glyph according to the points in the glyph
666  
667 =cut
668  
669 sub update_bbox
670 0 ▶{
Subroutine update_bbox: not called CC=21 SCAR=61.4
Pod documented
671 0 my ($self) = @_;
672 0 my ($num, $maxx, $minx, $maxy, $miny, $i, $comp, $x, $y, $compg);
673  
674 0 ▶ return $self unless (defined $self->{' read'} && $self->{' read'} > 1); # only if read_dat done
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{" read"} and $self->{" read"} > 1 0 0 0
Condition0%0/3
defined $self->{" read"} and $self->{" read"} > 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{" read"} and $self->{" read"} > 1
defined $self->{" read"} $self->{" read"} > 1
Truth table0%0/3
A and B
A= defined $self->{" read"}B= $self->{" read"} > 1
ABresult
0X0
100
111
675 0 $miny = $minx = 65537; $maxx = $maxy = -65537;
676 0 $num = $self->{'numberOfContours'};
677 0 ▶ if ($num > 0)
Branch: 2 branches
BranchTrueFalseTotal
if ($num > 0) { } 0 0 0
elsif ($num < 0) { } 0 0 0
678 {
679 0 ▶ for ($i = 0; $i < $self->{'numPoints'}; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->{"numPoints"}) 0 0 0
680 {
681 0 ($x, $y) = ($self->{'x'}[$i], $self->{'y'}[$i]);
682  
683 0 ▶ $maxx = $x if ($x > $maxx);
Branch: 1 branch
BranchTrueFalseTotal
if $x > $maxx 0 0 0
684 0 ▶ $minx = $x if ($x < $minx);
Branch: 1 branch
BranchTrueFalseTotal
if $x < $minx 0 0 0
685 0 ▶ $maxy = $y if ($y > $maxy);
Branch: 1 branch
BranchTrueFalseTotal
if $y > $maxy 0 0 0
686 0 ▶ $miny = $y if ($y < $miny);
Branch: 1 branch
BranchTrueFalseTotal
if $y < $miny 0 0 0
687 }
688 }
689  
690 elsif ($num < 0)
691 {
692 0 foreach $comp (@{$self->{'comps'}})
693 {
694 0 my ($gnx, $gny, $gxx, $gxy);
695 0 my ($sxx, $sxy, $syx, $syy);
696
697 0 my $otherg = $self->{' PARENT'}{'loca'}{'glyphs'}[$comp->{'glyph'}];
698 # work around bad fonts: see documentation for 'comps' above
699 0 ▶ next unless (defined $otherg);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $otherg 0 0 0
700 0 $compg = $otherg->read->update_bbox;
701 0 ($gnx, $gny, $gxx, $gxy) = @{$compg}{'xMin', 'yMin', 'xMax', 'yMax'};
702 0 ▶ if (defined $comp->{'scale'})
Branch: 2 branches
BranchTrueFalseTotal
if (defined $comp->{'scale'}) { } 0 0 0
elsif ($comp->{'args'}[0] or $comp->{'args'}[1]) { } 0 0 0
703 {
704 0 ($sxx, $sxy, $syx, $syy) = @{$comp->{'scale'}};
705 ($gnx, $gny, $gxx, $gxy) = ($gnx*$sxx+$gny*$syx + $comp->{'args'}[0],
706 $gnx*$sxy+$gny*$syy + $comp->{'args'}[1],
707 $gxx*$sxx+$gxy*$syx + $comp->{'args'}[0],
708 0 $gxx*$sxy+$gxy*$syy + $comp->{'args'}[1]);
709 ▶ } elsif ($comp->{'args'}[0] || $comp->{'args'}[1])
Condition0%0/3
$comp->{"args"}[0] or $comp->{"args"}[1]
l!l&&r!l&&!r
000
MC/DC0%0/2
$comp->{"args"}[0] or $comp->{"args"}[1]
$comp->{"args"}[0] $comp->{"args"}[1]
Truth table0%0/3
A or B
A= $comp->{"args"}[0]B= $comp->{"args"}[1]
ABresult
1X1
011
000
710 {
711 0 $gnx += $comp->{'args'}[0];
712 0 $gny += $comp->{'args'}[1];
713 0 $gxx += $comp->{'args'}[0];
714 0 $gxy += $comp->{'args'}[1];
715 }
716 0 ▶ ($gnx, $gxx) = ($gxx, $gnx) if $gnx > $gxx;
Branch: 1 branch
BranchTrueFalseTotal
if $gnx > $gxx 0 0 0
717 0 ▶ ($gny, $gxy) = ($gxy, $gny) if $gny > $gxy;
Branch: 1 branch
BranchTrueFalseTotal
if $gny > $gxy 0 0 0
718 0 ▶ $maxx = $gxx if $gxx > $maxx;
Branch: 1 branch
BranchTrueFalseTotal
if $gxx > $maxx 0 0 0
719 0 ▶ $minx = $gnx if $gnx < $minx;
Branch: 1 branch
BranchTrueFalseTotal
if $gnx < $minx 0 0 0
720 0 ▶ $maxy = $gxy if $gxy > $maxy;
Branch: 1 branch
BranchTrueFalseTotal
if $gxy > $maxy 0 0 0
721 0 ▶ $miny = $gny if $gny < $miny;
Branch: 1 branch
BranchTrueFalseTotal
if $gny < $miny 0 0 0
722 }
723 }
724 0 $self->{'xMax'} = $maxx;
725 0 $self->{'xMin'} = $minx;
726 0 $self->{'yMax'} = $maxy;
727 0 $self->{'yMin'} = $miny;
728 0 $self;
729 }
730  
731
732 =head2 $g->maxInfo
733  
734 Returns lots of information about a glyph so that the C<maxp> table can update
735 itself. Returns array containing contributions of this glyph to maxPoints, maxContours,
736 maxCompositePoints, maxCompositeContours, maxSizeOfInstructions, maxComponentElements,
737 and maxComponentDepth.
738  
739 =cut
740  
741 sub maxInfo
742 0 ▶{
Subroutine maxInfo: not called CC=9 SCAR=45.0
Pod documented
743 0 my ($self) = @_;
744 0 my (@res, $i, @n);
745  
746 0 $self->read_dat; # make sure we've read some data
747 0 ▶ $res[4] = length($self->{'hints'}) if defined $self->{'hints'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"hints"} 0 0 0
748 0 $res[6] = 1;
749 0 ▶ if ($self->{'numberOfContours'} > 0)
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'numberOfContours'} > 0) { } 0 0 0
elsif ($self->{'numberOfContours'} < 0) { } 0 0 0
750 {
751 0 $res[0] = $self->{'numPoints'};
752 0 $res[1] = $self->{'numberOfContours'};
753 } elsif ($self->{'numberOfContours'} < 0)
754 {
755 0 ▶ for ($i = 0; $i <= $#{$self->{'comps'}}; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#{$$self{"comps"};}) 0 0 0
756 {
757 my $otherg =
758 $self->{' PARENT'}{'loca'}{'glyphs'}
759 0 [$self->{'comps'}[$i]{'glyph'}];
760
761 # work around bad fonts: see documentation for 'comps' above
762 0 ▶ next unless (defined $otherg );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $otherg 0 0 0
763
764 0 @n = $otherg->maxInfo;
765  
766 0 ▶ $res[2] += $n[2] == 0 ? $n[0] : $n[2];
Branch: 1 branch
BranchTrueFalseTotal
$n[2] == 0 ? : 0 0 0
767 0 ▶ $res[3] += $n[3] == 0 ? $n[1] : $n[3];
Branch: 1 branch
BranchTrueFalseTotal
$n[3] == 0 ? : 0 0 0
768 0 $res[5]++;
769 0 ▶ $res[6] = $n[6] + 1 if ($n[6] >= $res[6]);
Branch: 1 branch
BranchTrueFalseTotal
if $n[6] >= $res[6] 0 0 0
770 }
771 }
772 0 @res;
773 }
774  
775 =head2 $g->empty
776  
777 Empties the glyph of all information to the level of not having been read.
778 Useful for saving memory in apps with many glyphs being read
779  
780 =cut
781  
782 sub empty
783 0 ▶{
Subroutine empty: not called CC=2 SCAR=17.9
Pod documented
784 0 my ($self) = @_;
785 0 my (%keep) = map {(" $_" => 1)} ('LOC', 'OUTLOC', 'PARENT', 'INFILE', 'BASE',
786 'OUTLEN', 'LEN');
787 0 ▶ map {delete $self->{$_} unless $keep{$_}} keys %$self;
Branch: 1 branch
BranchTrueFalseTotal
unless $keep{$_} 0 0 0
788
789 0 $self;
790 }
791  
792  
793 =head2 $g->get_points
794  
795 This method creates point information for a compound glyph. The information is
796 stored in the same place as if the glyph was not a compound, but since
797 numberOfContours is negative, the glyph is still marked as being a compound
798  
799 =cut
800  
801 sub get_points
802 0 ▶{
Subroutine get_points: not called CC=8 SCAR=42.8
Pod documented
803 0 my ($self) = @_;
804 0 my ($comp, $compg, $nump, $e, $i);
805  
806 0 $self->read_dat;
807 0 ▶ return undef unless ($self->{'numberOfContours'} < 0);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"numberOfContours"} < 0 0 0 0
808  
809 0 foreach $comp (@{$self->{'comps'}})
810 {
811 0 $compg = $self->{' PARENT'}{'loca'}{'glyphs'}[$comp->{'glyph'}];
812 # work around bad fonts: see documentation for 'comps' above
813 0 ▶ next unless (defined $compg );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $compg 0 0 0
814 0 $compg->get_points;
815  
816 0 ▶ for ($i = 0; $i < $compg->{'numPoints'}; $i++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $compg->{"numPoints"}) 0 0 0
817 {
818 0 my ($x, $y) = ($compg->{'x'}[$i], $compg->{'y'}[$i]);
819 0 ▶ if (defined $comp->{'scale'})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $comp->{"scale"}) 0 0 0
820 {
821 ($x, $y) = ($x * $comp->{'scale'}[0] + $y * $comp->{'scale'}[2],
822 0 $x * $comp->{'scale'}[1] + $y * $comp->{'scale'}[3]);
823 }
824 0 ▶ if (defined $comp->{'args'})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $comp->{"args"}) 0 0 0
825 0 { ($x, $y) = ($x + $comp->{'args'}[0], $y + $comp->{'args'}[1]); }
826 0 push (@{$self->{'x'}}, $x);
827 0 push (@{$self->{'y'}}, $y);
828 0 push (@{$self->{'flags'}}, $compg->{'flags'}[$i]);
829 }
830 0 foreach $e (@{$compg->{'endPoints'}})
831 0 { push (@{$self->{'endPoints'}}, $e + $nump); }
832 0 $nump += $compg->{'numPoints'};
833 }
834 0 $self->{'numPoints'} = $nump;
835 0 $self;
836 }
837  
838  
839 =head2 $g->get_refs
840  
841 Returns an array of all the glyph ids that are used to make up this glyph. That
842 is all the compounds and their references and so on. If this glyph is not a
843 compound, then returns an empty array.
844  
845 Please note the warning about bad fonts that reference nonexistent glyphs
846 under INSTANCE VARIABLES above. This function will not attempt to
847 filter out nonexistent glyph numbers.
848  
849 =cut
850  
851 sub get_refs
852 0 ▶{
Subroutine get_refs: not called CC=4 SCAR=30.0
Pod documented
853 0 my ($self) = @_;
854 0 my (@res, $g);
855  
856 0 $self->read_dat;
857 0 ▶ return unless ($self->{'numberOfContours'} < 0);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"numberOfContours"} < 0 0 0 0
858 0 foreach $g (@{$self->{'comps'}})
859 {
860 0 push (@res, $g->{'glyph'});
861 0 my $otherg = $self->{' PARENT'}{'loca'}{'glyphs'}[$g->{'glyph'}];
862 # work around bad fonts: see documentation for 'comps' above
863 0 ▶ next unless (defined $otherg);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $otherg 0 0 0
864 0 my @list = $otherg->get_refs;
865 0 push(@res, @list);
866 }
867 0 return @res;
868 }
869  
870 1 1;
871  
872 =head1 BUGS
873  
874 =over 4
875  
876 =item *
877  
878 The instance variables used here are somewhat clunky and inconsistent with
879 the other tables.
880  
881 =item *
882  
883 C<update> doesn't re-calculate the bounding box or C<numberOfContours>.
884  
885 =back
886  
887 =head1 AUTHOR
888  
889 Martin Hosken L<http://scripts.sil.org/FontUtils>.
890  
891  
892 =head1 LICENSING
893  
894 Copyright (c) 1998-2016, SIL International (http://www.sil.org)
895  
896 This module is released under the terms of the Artistic License 2.0.
897 For details, see the full text of the license in the file LICENSE.
898  
899  
900  
901 =cut
902  
↑ Summary Font/TTF/Cmap.pm »