1 package Font::TTF::Delta;
5 Font::TTF::Delta - Opentype Device tables
9 Each device table corresponds to a set of deltas for a particular point over
10 a range of ppem values.
14 The first ppem value in the range
18 The last ppem value in the range
22 This is an array of deltas corresponding to each ppem in the range between
23 first and last inclusive.
27 This is the fmt used (log2 of number bits per value) when the device table was
28 read. It is recalculated on output.
39 Creates a new device table
54 Reads a device table from the given IO object at the current location
61 my ($dat, $fmt, $num, $i, $j, $mask);
64 ($self->{'first'}, $self->{'last'}, $fmt) = TTF_Unpack("S3", $dat);
65 $self->{'fmt'} = $fmt;
68 $num = ((($self->{'last'} - $self->{'first'} + 1) * $fmt) + 15) >> 8;
69 $fh->read($dat, $num);
71 $mask = (0xffff << (16 - $fmt)) & 0xffff;
73 for ($i = $self->{'first'}; $i <= $self->{'last'}; $i++)
77 $num = TTF_Unpack("S", substr($dat, 0, 2));
78 substr($dat, 0, 2) = '';
80 push (@{$self->{'val'}}, ($num & $mask) >> (16 - $fmt));
89 =head2 out($fh, $style)
91 Outputs a device table to the given IO object at the current location, or just
92 returns the data to be output if $style != 0
98 my ($self, $fh, $style) = @_;
99 my ($dat, $fmt, $num, $mask, $j, $f, $out);
101 foreach $f (@{$self->{'val'}})
103 my ($tfmt) = $f > 0 ? $f + 1 : -$f;
104 $fmt = $tfmt if $tfmt > $fmt;
114 $out = TTF_Pack("S3", $self->{'first'}, $self->{'last'}, $fmt);
117 $mask = 0xffff >> (16 - $fmt);
119 foreach $f (@{$self->{'val'}})
121 $dat |= ($f & $mask) << (16 - $fmt - $j);
126 $out .= TTF_Pack("S", $dat);
130 $out .= pack('n', $dat) if ($j > 0);
131 $fh->print($out) unless $style;
135 =head2 $d->signature()
137 Returns a content based identifying string for this delta for
145 return join (",", $self->{'first'}, $self->{'last'}, @{$self->{'val'}});
149 =head2 $d->out_xml($context)
151 Outputs a delta in XML
157 my ($self, $context, $depth) = @_;
158 my ($fh) = $context->{'fh'};
160 $fh->printf("%s<delta first='%s' last='%s'>\n", $depth, $self->{'first'}, $self->{'last'});
161 $fh->print("$depth$context->{'indent'}" . join (' ', @{$self->{'val'}}) . "\n") if defined ($self->{'val'});
162 $fh->print("$depth</delta>\n");
167 Martin Hosken Martin_Hosken@sil.org. See L<Font::TTF::Font> for copyright and