1 package Font::TTF::EBDT;
5 Font::TTF::EBDT - Embeeded Bitmap Data Table
9 Contains the metrics and bitmap image data.
11 =head1 INSTANCE VARIABLES
13 Only has 'bitmap' instance variable. It is an array of assosiative
14 array keyed by glyph-id. The element is an object which consists
15 of metric information and image data.
44 require Font::TTF::Table;
46 @ISA = qw(Font::TTF::Table);
51 Reads the embedded bitmap data from the TTF file into memory.
52 This routine should be called _after_ {'EBLC'}->read.
59 my ($fh) = $self->{' INFILE'};
61 my ($eblc) = $self->{' PARENT'}->{'EBLC'};
65 $self->SUPER::read || return $self;
68 $fh->read($dat, 4); # version
70 $bst_array = $eblc->{'bitmapSizeTable'};
72 for ($i = 0; $i < $eblc->{'Num'}; $i++)
74 my ($bst) = $bst_array->[$i];
75 my ($format) = $bst->{'imageFormat'};
76 my ($offset) = $bst->{'imageDataOffset'};
78 my ($ist_array) = $eblc->{'indexSubTableArray'}[$i];
81 die "Only EBDT format 7 is implemented." unless ($format == 7);
83 $self->{'bitmap'}[$i] = $bitmap;
85 for ($j = 0; $j < $bst->{'numberOfIndexSubTables'}; $j++) {
86 my ($ista) = $ist_array->[$j];
87 my ($offsetArray) = $eblc->{'indexSubTable'}[$i][$j];
90 # if ($fh->tell != $self->{' OFFSET'} + $offset) {
91 # $fh->seek($self->{' OFFSET'} + $offset, 0);
95 $o0 = $offsetArray->[$p++];
96 for ($c = $ista->{'firstGlyphIndex'}; $c <= $ista->{'lastGlyphIndex'}; $c++)
99 my ($o1) = $offsetArray->[$p++];
100 my ($len) = $o1 - $o0 - 8;
102 # if ($fh->tell != $self->{' OFFSET'} + $offset + $o0) {
103 # $fh->seek($self->{' OFFSET'} + $offset + $o0, 0);
109 $b->{'horiBearingX'},
110 $b->{'horiBearingY'},
112 $b->{'vertBearingX'},
113 $b->{'vertBearingY'},
115 = unpack("cccccccc", $dat);
117 $fh->read($dat, $len);
118 $b->{'imageData'} = $dat;
119 $b->{'format'} = 7; # bitmap and bigMetrics
135 Update EBLC information using EBDT data.
150 if ($last + 1 != $e) { # not contiguous
151 $r[++$#r] = [$first, $last];
158 $r[++$#r] = [$first, $last];
165 my ($eblc) = $self->{' PARENT'}->{'EBLC'};
166 my ($bst_array) = [];
169 my ($bitmap_array) = $self->{'bitmap'};
170 my ($istao) = 8 + 48 * $eblc->{'Num'};
172 $eblc->{'bitmapSizeTable'} = $bst_array;
174 for ($i = 0; $i < $eblc->{'Num'}; $i++) {
176 my ($ist_array) = [];
178 my ($bitmap) = $bitmap_array->[$i];
179 my (@regions) = get_regions(sort {$a <=> $b} keys (%$bitmap));
180 my ($aotis) = 8 * (1+$#regions);
182 $bst->{'indexFormat'} = 1;
183 $bst->{'imageFormat'} = 7;
184 $bst->{'imageDataOffset'} = $offset;
185 $bst->{'numberOfIndexSubTables'} = 1+$#regions;
186 $bst->{'indexSubTableArrayOffset'} = $istao;
187 $bst->{'colorRef'} = 0;
189 $bst->{'startGlyphIndex'} = $regions[0][0];
190 $bst->{'endGlyphIndex'} = $regions[-1][1];
191 $bst->{'bitDepth'} = 1;
192 $bst->{'flags'} = 1; # Horizontal
193 $bst_array->[$i] = $bst;
195 $eblc->{'indexSubTableArray'}[$i] = $ist_array;
196 for ($j = 0; $j <= $#regions; $j++) {
198 my ($offsetArray) = [];
200 $ist_array->[$j] = $ista;
202 $ista->{'firstGlyphIndex'} = $regions[$j][0];
203 $ista->{'lastGlyphIndex'} = $regions[$j][1];
204 $ista->{'additionalOffsetToIndexSubtable'} = $aotis;
205 $eblc->{'indexSubTable'}[$i][$j] = $offsetArray;
208 for ($c = $regions[$j][0]; $c <= $regions[$j][1]; $c++) {
209 my ($b) = $bitmap->{$c};
211 $offsetArray->[$p++] = $o0;
212 $o0 += 8 + length($b->{'imageData'});
215 $offsetArray->[$p++] = $o0;
217 $aotis += ($regions[$j][1] - $regions[$j][0] + 1 + 1)*4;
220 # Do we need the element of 0x10007 and absolute offset here,
221 # at the end of offsetArray?
222 # if ($j + 1 <= $#regions) {
223 # $offsetArray->[$p++] = 0x10007;
224 # $offsetArray->[$p++] = $offset;
229 $istao += $aotis + 8;
230 $bst->{'indexTablesSize'} = $aotis + 8;
236 Outputs the bitmap data of embedded bitmap for this font.
242 my ($self, $fh) = @_;
243 my ($eblc) = $self->{' PARENT'}->{'EBLC'};
245 my ($bitmap_array) = $self->{'bitmap'};
247 $fh->print(pack("N", 0x00020000));
249 for ($i = 0; $i < $eblc->{'Num'}; $i++) {
251 my ($bitmap) = $bitmap_array->[$i];
252 my (@regions) = get_regions(sort {$a <=> $b} keys (%$bitmap));
254 for ($j = 0; $j <= $#regions; $j++) {
257 for ($c = $regions[$j][0]; $c <= $regions[$j][1]; $c++) {
258 my ($b) = $bitmap->{$c};
260 $fh->print(pack("cccccccc",
261 $b->{'height'}, $b->{'width'},
262 $b->{'horiBearingX'}, $b->{'horiBearingY'},
263 $b->{'horiAdvance'}, $b->{'vertBearingX'},
264 $b->{'vertBearingY'}, $b->{'vertAdvance'}));
265 $fh->print($b->{'imageData'});
275 Only Format 7 is implemented. XML output is not supported (yet).
279 NIIBE Yutaka L<gniibe@fsij.org>. See L<Font::TTF::Font> for copyright and
282 This was written at the CodeFest Akihabara 2006 hosted by FSIJ.