| 1 | package Font::TTF::EBLC; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | Font::TTF::EBLC - Embeeded Bitmap Location Table | ||
| 6 | |||
| 7 | =head1 DESCRIPTION | ||
| 8 | |||
| 9 | Contains the sizes and glyph ranges of bitmaps, and the offsets to | ||
| 10 | glyph bitmap data in indexSubTables for EBDT. | ||
| 11 | |||
| 12 | Possibly contains glyph metrics information. | ||
| 13 | |||
| 14 | =head1 INSTANCE VARIABLES | ||
| 15 | |||
| 16 | The information specified 'B<(R)>ead only' is read only, those | ||
| 17 | are calculated from EBDT, when it is 'update'-ed. | ||
| 18 | |||
| 19 | =over 4 | ||
| 20 | |||
| 21 | =item bitmapSizeTable | ||
| 22 | |||
| 23 | An array of tables of following information | ||
| 24 | |||
| 25 | =over 8 | ||
| 26 | |||
| 27 | =item indexSubTableArrayOffset (R) | ||
| 28 | |||
| 29 | =item indexTablesSize (R) | ||
| 30 | |||
| 31 | =item numberOfIndexSubTables (R) | ||
| 32 | |||
| 33 | =item colorRef | ||
| 34 | |||
| 35 | =item hori | ||
| 36 | |||
| 37 | =item vert | ||
| 38 | |||
| 39 | =item startGlyphIndex (R) | ||
| 40 | |||
| 41 | =item endGlyphIndex (R) | ||
| 42 | |||
| 43 | =item ppemX | ||
| 44 | |||
| 45 | =item ppemY | ||
| 46 | |||
| 47 | =item bitDepth | ||
| 48 | |||
| 49 | =item flags | ||
| 50 | |||
| 51 | =back | ||
| 52 | |||
| 53 | =item indexSubTableArray (R) | ||
| 54 | |||
| 55 | An array which contains range information. | ||
| 56 | |||
| 57 | =item indexSubTable (R) | ||
| 58 | |||
| 59 | An array which contains offsets of EBDT table. | ||
| 60 | |||
| 61 | =back | ||
| 62 | |||
| 63 | =head1 METHODS | ||
| 64 | |||
| 65 | =cut | ||
| 66 | |||
| 67 | use strict; | ||
| 68 | use vars qw(@ISA); | ||
| 69 | require Font::TTF::Table; | ||
| 70 | |||
| 71 | @ISA = qw(Font::TTF::Table); | ||
| 72 | |||
| 73 | |||
| 74 | =head2 $t->read | ||
| 75 | |||
| 76 | Reads the location information of embedded bitmap from the TTF file into memory | ||
| 77 | |||
| 78 | =cut | ||
| 79 | |||
| 80 | sub read | ||
| 81 | { | ||
| 82 | my ($self) = @_; | ||
| 83 | |||
| 84 | $self->SUPER::read or return $self; | ||
| 85 | |||
| 86 | my ($fh) = $self->{' INFILE'}; | ||
| 87 | my ($i, $dat); | ||
| 88 | my ($indexSubTableArrayOffset, | ||
| 89 | $indexTablesSize, | ||
| 90 | $numberOfIndexSubTables, | ||
| 91 | $colorRef); | ||
| 92 | my ($startGlyphIndex, | ||
| 93 | $endGlyphIndex, | ||
| 94 | $ppemX, $ppemY, | ||
| 95 | $bitDepth, $flags); | ||
| 96 | my (@hori, @vert); | ||
| 97 | my ($bst, $ista, $ist); | ||
| 98 | my ($j); | ||
| 99 | |||
| 100 | |||
| 101 | # eblcHeader | ||
| 102 | $fh->read($dat, 4); | ||
| 103 | $self->{'version'} = unpack("N",$dat); | ||
| 104 | |||
| 105 | $fh->read($dat, 4); | ||
| 106 | $self->{'Num'} = unpack("N",$dat); | ||
| 107 | |||
| 108 | # bitmapSizeTable | ||
| 109 | for ($i = 0; $i < $self->{'Num'}; $i++) { | ||
| 110 | $fh->read($dat, 16); | ||
| 111 | ($indexSubTableArrayOffset, $indexTablesSize, | ||
| 112 | $numberOfIndexSubTables, $colorRef) = unpack("NNNN", $dat); | ||
| 113 | $fh->read($dat, 12); @hori = unpack("cccccccccccc", $dat); | ||
| 114 | $fh->read($dat, 12); @vert = unpack("cccccccccccc", $dat); | ||
| 115 | |||
| 116 | $fh->read($dat, 8); | ||
| 117 | ($startGlyphIndex, $endGlyphIndex, | ||
| 118 | $ppemX, $ppemY, $bitDepth, $flags) = unpack("nnCCCC", $dat); | ||
| 119 | |||
| 120 | $self->{'bitmapSizeTable'}[$i] = { | ||
| 121 | 'indexSubTableArrayOffset' => $indexSubTableArrayOffset, | ||
| 122 | 'indexTablesSize' => $indexTablesSize, | ||
| 123 | 'numberOfIndexSubTables' => $numberOfIndexSubTables, | ||
| 124 | 'colorRef' => $colorRef, | ||
| 125 | 'hori' => [@hori], | ||
| 126 | 'vert' => [@vert], | ||
| 127 | 'startGlyphIndex' => $startGlyphIndex, | ||
| 128 | 'endGlyphIndex' => $endGlyphIndex, | ||
| 129 | 'ppemX' => $ppemX, | ||
| 130 | 'ppemY' => $ppemY, | ||
| 131 | 'bitDepth' => $bitDepth, | ||
| 132 | 'flags' => $flags | ||
| 133 | }; | ||
| 134 | } | ||
| 135 | |||
| 136 | for ($i = 0; $i < $self->{'Num'}; $i++) { | ||
| 137 | my ($count, $x); | ||
| 138 | |||
| 139 | $bst = $self->{'bitmapSizeTable'}[$i]; | ||
| 140 | |||
| 141 | for ($j = 0; $j < $bst->{'numberOfIndexSubTables'}; $j++) { | ||
| 142 | $ista = {}; | ||
| 143 | |||
| 144 | # indexSubTableArray | ||
| 145 | $self->{'indexSubTableArray'}[$i][$j] = $ista; | ||
| 146 | $fh->read($dat, 8); | ||
| 147 | ($ista->{'firstGlyphIndex'}, | ||
| 148 | $ista->{'lastGlyphIndex'}, | ||
| 149 | $ista->{'additionalOffsetToIndexSubtable'}) | ||
| 150 | = unpack("nnN", $dat); | ||
| 151 | } | ||
| 152 | |||
| 153 | # indexSubTable | ||
| 154 | # indexSubHeader | ||
| 155 | $fh->read($dat, 8); | ||
| 156 | ($bst->{'indexFormat'}, | ||
| 157 | $bst->{'imageFormat'}, | ||
| 158 | $bst->{'imageDataOffset'}) = unpack("nnN", $dat); | ||
| 159 | |||
| 160 | die "Only indexFormat == 1 is supported" unless ($bst->{'indexFormat'} == 1); | ||
| 161 | |||
| 162 | for ($j = 0; $j < $bst->{'numberOfIndexSubTables'}; $j++) { | ||
| 163 | $ista = $self->{'indexSubTableArray'}[$i][$j]; | ||
| 164 | $count = $ista->{'lastGlyphIndex'} - $ista->{'firstGlyphIndex'} + 1 + 1; | ||
| 165 | $fh->seek($self->{' OFFSET'} + $bst->{'indexSubTableArrayOffset'} | ||
| 166 | + $ista->{'additionalOffsetToIndexSubtable'} + 8, 0); | ||
| 167 | |||
| 168 | # $count += 2 if $j < $bst->{'numberOfIndexSubTables'} - 1; | ||
| 169 | |||
| 170 | $fh->read($dat, 4*$count); | ||
| 171 | |||
| 172 | $self->{'indexSubTable'}[$i][$j] = [unpack("N*", $dat)]; | ||
| 173 | } | ||
| 174 | } | ||
| 175 | |||
| 176 | $self; | ||
| 177 | } | ||
| 178 | |||
| 179 | =head2 $t->out($fh) | ||
| 180 | |||
| 181 | Outputs the location information of embedded bitmap for this font. | ||
| 182 | |||
| 183 | =cut | ||
| 184 | |||
| 185 | sub out | ||
| 186 | { | ||
| 187 | my ($self, $fh) = @_; | ||
| 188 | my ($i); | ||
| 189 | |||
| 190 | return $self->SUPER::out($fh) unless $self->{' read'}; | ||
| 191 | |||
| 192 | my ($bst_array) = $self->{'bitmapSizeTable'}; | ||
| 193 | |||
| 194 | $fh->print(pack("N", 0x00020000)); | ||
| 195 | $fh->print(pack("N", $self->{'Num'})); | ||
| 196 | |||
| 197 | for ($i = 0; $i < $self->{'Num'}; $i++) { | ||
| 198 | my ($bst) = $bst_array->[$i]; | ||
| 199 | |||
| 200 | $fh->print(pack("NNNN", | ||
| 201 | $bst->{'indexSubTableArrayOffset'}, | ||
| 202 | $bst->{'indexTablesSize'}, | ||
| 203 | $bst->{'numberOfIndexSubTables'}, | ||
| 204 | $bst->{'colorRef'})); | ||
| 205 | $fh->print(pack("cccccccccccc", @{$bst->{'hori'}})); | ||
| 206 | $fh->print(pack("cccccccccccc", @{$bst->{'vert'}})); | ||
| 207 | $fh->print(pack("nnCCCC", $bst->{'startGlyphIndex'}, | ||
| 208 | $bst->{'endGlyphIndex'}, $bst->{'ppemX'}, | ||
| 209 | $bst->{'ppemY'}, $bst->{'bitDepth'}, $bst->{'flags'})); | ||
| 210 | } | ||
| 211 | |||
| 212 | for ($i = 0; $i < $self->{'Num'}; $i++) { | ||
| 213 | my ($bst) = $bst_array->[$i]; | ||
| 214 | my ($j); | ||
| 215 | |||
| 216 | for ($j = 0; $j < $bst->{'numberOfIndexSubTables'}; $j++) { | ||
| 217 | my ($ista) = $self->{'indexSubTableArray'}[$i][$j]; | ||
| 218 | |||
| 219 | $fh->print("nnN", | ||
| 220 | $ista->{'firstGlyphIndex'}, | ||
| 221 | $ista->{'lastGlyphIndex'}, | ||
| 222 | $ista->{'additionalOffsetToIndexSubtable'}); | ||
| 223 | } | ||
| 224 | |||
| 225 | $fh->print(pack("nnN", $bst->{'indexFormat'}, $bst->{'imageFormat'}, | ||
| 226 | $bst->{'imageDataOffset'})); | ||
| 227 | |||
| 228 | die "Only indexFormat == 1 is supported" unless ($bst->{'indexFormat'} == 1); | ||
| 229 | |||
| 230 | for ($j = 0; $j < $bst->{'numberOfIndexSubTables'}; $j++) { | ||
| 231 | $fh->print(pack("N*", $self->{'indexSubTable'}[$i][$j])); | ||
| 232 | } | ||
| 233 | } | ||
| 234 | } | ||
| 235 | |||
| 236 | 1; | ||
| 237 | |||
| 238 | =head1 BUGS | ||
| 239 | |||
| 240 | Only indexFormat ==1 is implemented. XML output is not supported (yet). | ||
| 241 | |||
| 242 | =head1 AUTHOR | ||
| 243 | |||
| 244 | NIIBE Yutaka L<mailto:gniibe@fsij.org>. | ||
| 245 | This was written at the CodeFest Akihabara 2006 hosted by FSIJ. | ||
| 246 | |||
| 247 | Patch sent with licensing requirements?? | ||
| 248 | |||
| 249 | =head1 LICENSING | ||
| 250 | |||
| 251 | Copyright (c) 1998-2016, SIL International (http://www.sil.org) | ||
| 252 | |||
| 253 | This module is released under the terms of the Artistic License 2.0. | ||
| 254 | For details, see the full text of the license in the file LICENSE. | ||
| 255 | |||
| 256 | |||
| 257 | |||
| 258 | =cut | ||
| 259 |