API3/Compat/API2/Basic/TTF/Hdmx.pm untested

filter: Statementstmt 0.0% 0 / 64 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 83 CC 4 SCAR 18.3
CC
4
Cov
0%
out
12.0
XML_element
6.0
read
2.0
CRAP 6.2
1 #=======================================================================
2 # ____ ____ _____ _ ____ ___ ____
3 # | _ \| _ \| ___| _ _ / \ | _ \_ _| |___ \
4 # | |_) | | | | |_ (_) (_) / _ \ | |_) | | __) |
5 # | __/| |_| | _| _ _ / ___ \| __/| | / __/
6 # |_| |____/|_| (_) (_) /_/ \_\_| |___| |_____|
7 #
8 # A Perl Module Chain to faciliate the Creation and Modification
9 # of High-Quality "Portable Document Format (PDF)" Files.
10 #
11 #=======================================================================
12 #
13 # THIS IS A REUSED PERL MODULE, FOR PROPER LICENCING TERMS SEE BELOW:
14 #
15 #
16 # Copyright Martin Hosken <Martin_Hosken@sil.org>
17 #
18 # No warranty or expression of effectiveness, least of all regarding
19 # anyone's safety, is implied in this software or documentation.
20 #
21 # This specific module is licensed under the Perl Artistic License.
22 #
23 #
24 # $Id: Hdmx.pm,v 2.0 2005/11/16 02:16:00 areibens Exp $
25 #
26 #=======================================================================
27 package PDF::API3::Compat::API2::Basic::TTF::Hdmx;
28
29 =head1 NAME
30
31 PDF::API3::Compat::API2::Basic::TTF::Hdmx - Horizontal device metrics
32
33 =head1 DESCRIPTION
34
35 The table consists of an hash of device metric tables indexed by the ppem for
36 that subtable. Each subtable consists of an array of advance widths in pixels
37 for each glyph at that ppem (horizontally).
38
39 =head1 INSTANCE VARIABLES
40
41 Individual metrics are accessed using the following referencing:
42
43 $f->{'hdmx'}{$ppem}[$glyph_num]
44
45 In addition there is one instance variable:
46
47 =over 4
48
49 =item Num
50
51 Number of device tables.
52
53 =back
54
55 =head2 METHODS
56
57 =cut
58
59 use strict;
60 use vars qw(@ISA);
61
62 @ISA = qw(PDF::API3::Compat::API2::Basic::TTF::Table);
63
64
65 =head2 $t->read
66
67 Reads the table into data structures
68
69 =cut
70
71 sub read
72 {
73 my ($self) = @_;
74 my ($fh) = $self->{' INFILE'};
75 my ($numg, $ppem, $i, $numt, $dat, $len);
76
77 $numg = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
78 $self->SUPER::read or return $self;
79
80 $fh->read($dat, 8);
81 ($self->{'Version'}, $numt, $len) = unpack("nnN", $dat);
82 $self->{'Num'} = $numt;
83
84 for ($i = 0; $i < $numt; $i++)
85 {
86 $fh->read($dat, $len);
87 $ppem = unpack("C", $dat);
88 $self->{$ppem} = [unpack("C$numg", substr($dat, 2))];
89 }
90 $self;
91 }
92
93
94 =head2 $t->out($fh)
95
96 Outputs the device metrics for this font
97
98 =cut
99
100 sub out
101 {
102 my ($self, $fh) = @_;
103 my ($numg, $i, $pad, $len, $numt, @ppem, $max);
104
105 return $self->SUPER::out($fh) unless ($self->{' read'});
106
107 $numg = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
108 @ppem = grep(/^\d+$/, sort {$a <=> $b} keys %$self);
109 $pad = "\000" x (3 - ($numg + 1) % 4);
110 $len = $numg + 2 + length($pad);
111 $fh->print(pack("nnN", 0, $#ppem + 1, $len));
112 for $i (@ppem)
113 {
114 $max = 0;
115 foreach (@{$self->{$i}}[0..($numg - 1)])
116 { $max = $_ if $_ > $max; }
117 $fh->print(pack("C*", $i, $max, @{$self->{$i}}[0..($numg - 1)]) . $pad);
118 }
119 $self;
120 }
121
122
123 =head2 $t->tables_do(&func)
124
125 For each subtable it calls &sub($ref, $ppem)
126
127 =cut
128
129 sub tables_do
130 {
131 my ($self, $func) = @_;
132 my ($i);
133
134 foreach $i (grep(/^\d+$/, %$self))
135 { &$func($self->{$i}, $i); }
136 $self;
137 }
138
139
140 =head2 $t->XML_element($context, $depth, $key, $value)
141
142 Outputs device metrics a little more tidily
143
144 =cut
145
146 sub XML_element
147 {
148 my ($self) = shift;
149 my ($context, $depth, $key, $value) = @_;
150 my ($fh) = $context->{'fh'};
151 my ($i);
152
153 return $self->SUPER::XML_element(@_) if (ref($value) ne 'ARRAY');
154 $fh->print("$depth<metrics ppem='$key'>\n");
155 for ($i = 0; $i <= $#{$value}; $i += 25)
156 {
157 $fh->print("$depth$context->{'indent'}". join(' ', @{$value}[$i .. $i + 24]) . "\n");
158 }
159 $fh->print("$depth</metrics>\n");
160 $self;
161 }
162
163 1;
164
165 =head1 BUGS
166
167 None known
168
169 =head1 AUTHOR
170
171 Martin Hosken Martin_Hosken@sil.org. See L<PDF::API3::Compat::API2::Basic::TTF::Font> for copyright and
172 licensing.
173
174 =cut
175