1 package Font::TTF::Hdmx;
5 Font::TTF::Hdmx - Horizontal device metrics
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).
13 =head1 INSTANCE VARIABLES
15 Individual metrics are accessed using the following referencing:
17 $f->{'hdmx'}{$ppem}[$glyph_num]
19 In addition there is one instance variable:
25 Number of device tables.
36 @ISA = qw(Font::TTF::Table);
41 Reads the table into data structures
48 my ($fh) = $self->{' INFILE'};
49 my ($numg, $ppem, $i, $numt, $dat, $len);
51 $numg = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
52 $self->SUPER::read or return $self;
55 ($self->{'Version'}, $numt, $len) = unpack("nnN", $dat);
56 $self->{'Num'} = $numt;
58 for ($i = 0; $i < $numt; $i++)
60 $fh->read($dat, $len);
61 $ppem = unpack("C", $dat);
62 $self->{$ppem} = [unpack("C$numg", substr($dat, 2))];
70 Outputs the device metrics for this font
77 my ($numg, $i, $pad, $len, $numt, @ppem, $max);
79 return $self->SUPER::out($fh) unless ($self->{' read'});
81 $numg = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
82 @ppem = grep(/^\d+$/, sort {$a <=> $b} keys %$self);
83 $pad = "\000" x (3 - ($numg + 1) % 4);
84 $len = $numg + 2 + length($pad);
85 $fh->print(pack("nnN", 0, $#ppem + 1, $len));
89 foreach (@{$self->{$i}}[0..($numg - 1)])
90 { $max = $_ if $_ > $max; }
91 $fh->print(pack("C*", $i, $max, @{$self->{$i}}[0..($numg - 1)]) . $pad);
97 =head2 $t->tables_do(&func)
99 For each subtable it calls &sub($ref, $ppem)
105 my ($self, $func) = @_;
108 foreach $i (grep(/^\d+$/, %$self))
109 { &$func($self->{$i}, $i); }
114 =head2 $t->XML_element($context, $depth, $key, $value)
116 Outputs device metrics a little more tidily
123 my ($context, $depth, $key, $value) = @_;
124 my ($fh) = $context->{'fh'};
127 return $self->SUPER::XML_element(@_) if (ref($value) ne 'ARRAY');
128 $fh->print("$depth<metrics ppem='$key'>\n");
129 for ($i = 0; $i <= $#{$value}; $i += 25)
131 $fh->print("$depth$context->{'indent'}". join(' ', @{$value}[$i .. $i + 24]) . "\n");
133 $fh->print("$depth</metrics>\n");
145 Martin Hosken Martin_Hosken@sil.org. See L<Font::TTF::Font> for copyright and