Font/TTF/Hdmx.pm untested

filter: Statementstmt 0.0% 0 / 65 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 86 CC 4 SCAR 17.6
CC
4
Cov
0%
out
12.0
XML_element
6.0
read
2.0
CRAP 5.8
1 package Font::TTF::Hdmx;
2  
3 =head1 NAME
4  
5 Font::TTF::Hdmx - Horizontal device metrics
6  
7 =head1 DESCRIPTION
8  
9 The table consists of an hash of device metric tables indexed by the ppem for
10 that subtable. Each subtable consists of an array of advance widths in pixels
11 for each glyph at that ppem (horizontally).
12  
13 =head1 INSTANCE VARIABLES
14  
15 Individual metrics are accessed using the following referencing:
16  
17 $f->{'hdmx'}{$ppem}[$glyph_num]
18  
19 In addition there is one instance variable:
20  
21 =over 4
22  
23 =item Num
24  
25 Number of device tables.
26  
27 =back
28  
29 =head2 METHODS
30  
31 =cut
32  
33 use strict;
34 use vars qw(@ISA);
35  
36 @ISA = qw(Font::TTF::Table);
37  
38  
39 =head2 $t->read
40  
41 Reads the table into data structures
42  
43 =cut
44  
45 sub read
46 {
47 my ($self) = @_;
48 $self->SUPER::read or return $self;
49  
50 my ($fh) = $self->{' INFILE'};
51 my ($numg, $ppem, $i, $numt, $dat, $len);
52  
53 $numg = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
54  
55 $fh->read($dat, 8);
56 ($self->{'Version'}, $numt, $len) = unpack("nnN", $dat);
57 $self->{'Num'} = $numt;
58  
59 for ($i = 0; $i < $numt; $i++)
60 {
61 $fh->read($dat, $len);
62 $ppem = unpack("C", $dat);
63 $self->{$ppem} = [unpack("C$numg", substr($dat, 2))];
64 }
65 $self;
66 }
67  
68  
69 =head2 $t->out($fh)
70  
71 Outputs the device metrics for this font
72  
73 =cut
74  
75 sub out
76 {
77 my ($self, $fh) = @_;
78 my ($numg, $i, $pad, $len, $numt, @ppem, $max);
79  
80 return $self->SUPER::out($fh) unless ($self->{' read'});
81  
82 $numg = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
83 @ppem = grep(/^\d+$/, sort {$a <=> $b} keys %$self);
84 $pad = "\000" x (3 - ($numg + 1) % 4);
85 $len = $numg + 2 + length($pad);
86 $fh->print(pack("nnN", 0, $#ppem + 1, $len));
87 for $i (@ppem)
88 {
89 $max = 0;
90 foreach (@{$self->{$i}}[0..($numg - 1)])
91 { $max = $_ if $_ > $max; }
92 $fh->print(pack("C*", $i, $max, @{$self->{$i}}[0..($numg - 1)]) . $pad);
93 }
94 $self;
95 }
96  
97 =head2 $t->minsize()
98  
99 Returns the minimum size this table can be. If it is smaller than this, then the table
100 must be bad and should be deleted or whatever.
101  
102 =cut
103  
104 sub minsize
105 {
106 return 8;
107 }
108  
109  
110 =head2 $t->tables_do(&func)
111  
112 For each subtable it calls &sub($ref, $ppem)
113  
114 =cut
115  
116 sub tables_do
117 {
118 my ($self, $func) = @_;
119 my ($i);
120  
121 foreach $i (grep(/^\d+$/, %$self))
122 { &$func($self->{$i}, $i); }
123 $self;
124 }
125  
126  
127 =head2 $t->XML_element($context, $depth, $key, $value)
128  
129 Outputs device metrics a little more tidily
130  
131 =cut
132  
133 sub XML_element
134 {
135 my ($self) = shift;
136 my ($context, $depth, $key, $value) = @_;
137 my ($fh) = $context->{'fh'};
138 my ($i);
139  
140 return $self->SUPER::XML_element(@_) if (ref($value) ne 'ARRAY');
141 $fh->print("$depth<metrics ppem='$key'>\n");
142 for ($i = 0; $i <= $#{$value}; $i += 25)
143 {
144 $fh->print("$depth$context->{'indent'}". join(' ', @{$value}[$i .. $i + 24]) . "\n");
145 }
146 $fh->print("$depth</metrics>\n");
147 $self;
148 }
149  
150 1;
151  
152 =head1 BUGS
153  
154 None known
155  
156 =head1 AUTHOR
157  
158 Martin Hosken L<http://scripts.sil.org/FontUtils>.
159  
160  
161 =head1 LICENSING
162  
163 Copyright (c) 1998-2016, SIL International (http://www.sil.org)
164  
165 This module is released under the terms of the Artistic License 2.0.
166 For details, see the full text of the license in the file LICENSE.
167  
168  
169  
170 =cut
171  
172