| 1 | package Font::TTF::Gloc; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | Font::TTF::Gloc - Offsets into Glat table for the start of the attributes for each glyph | ||
| 6 | |||
| 7 | =head1 DESCRIPTION | ||
| 8 | |||
| 9 | The Gloc table is a bit like the Loca table only for Graphite glyph attributes. The table | ||
| 10 | has the following elements: | ||
| 11 | |||
| 12 | =over 4 | ||
| 13 | |||
| 14 | =item Version | ||
| 15 | |||
| 16 | Table format version | ||
| 17 | |||
| 18 | =item numAttrib | ||
| 19 | |||
| 20 | Maximum number of attributes associated with a glyph. | ||
| 21 | |||
| 22 | =item locations | ||
| 23 | |||
| 24 | An array of offsets into the Glat table for the start of each glyph | ||
| 25 | |||
| 26 | =item names | ||
| 27 | |||
| 28 | If defined, an array of name table name ids indexed by attribute number. | ||
| 29 | |||
| 30 | =cut | ||
| 31 | |||
| 32 | use Font::TTF::Table; | ||
| 33 | use Font::TTF::Utils; | ||
| 34 | use strict; | ||
| 35 | use vars qw(@ISA); | ||
| 36 | @ISA = qw(Font::TTF::Table); | ||
| 37 | |||
| 38 | sub read | ||
| 39 | { | ||
| 40 | my ($self) = @_; | ||
| 41 | $self->SUPER::read or return $self; | ||
| 42 | |||
| 43 | my ($fh) = $self->{' INFILE'}; | ||
| 44 | my ($numGlyphs); | ||
| 45 | my ($dat, $flags); | ||
| 46 | |||
| 47 | $fh->read($dat, 4); | ||
| 48 | ($self->{'Version'}) = TTF_Unpack("v", $dat); | ||
| 49 | $fh->read($dat, 4); | ||
| 50 | ($flags, $self->{'numAttrib'}) = TTF_Unpack("SS", $dat); | ||
| 51 | $numGlyphs = ($self->{' LENGTH'} - 8 - ($flags & 2 ? $self->{'numAttrib'} * 2 : 0)) / (($flags & 1) ? 4 : 2) - 1; | ||
| 52 | $self->{'numGlyphs'} = $numGlyphs; | ||
| 53 | if ($flags & 1) | ||
| 54 | { | ||
| 55 | $fh->read($dat, 4 * ($numGlyphs + 1)); | ||
| 56 | $self->{'locations'} = [unpack("N*", $dat)]; | ||
| 57 | } | ||
| 58 | else | ||
| 59 | { | ||
| 60 | $fh->read($dat, 2 * ($numGlyphs + 1)); | ||
| 61 | $self->{'locations'} = [unpack("n*", $dat)]; | ||
| 62 | } | ||
| 63 | if ($flags & 2) | ||
| 64 | { | ||
| 65 | $fh->read($dat, 2 * $self->{'numAttrib'}); | ||
| 66 | $self->{'names'} = [unpack("n*", $dat)]; | ||
| 67 | } | ||
| 68 | return $self; | ||
| 69 | } | ||
| 70 | |||
| 71 | sub out | ||
| 72 | { | ||
| 73 | my ($self, $fh) = @_; | ||
| 74 | my ($numGlyphs) = 0; | ||
| 75 | my ($flags, $num); | ||
| 76 | |||
| 77 | return $self->SUPER::out($fh) unless ($self->{' read'}); | ||
| 78 | $numGlyphs = scalar @{$self->{' PARENT'}{'Glat'}{'attribs'}}; | ||
| 79 | $num = $self->{'numAttrib'}; | ||
| 80 | $flags = 1 if ($self->{'locations'}[-1] > 0xFFFF); | ||
| 81 | $flags |= 2 if ($self->{'names'}); | ||
| 82 | $fh->print(TTF_Pack("vSS", $self->{'Version'}, $flags, $num)); | ||
| 83 | $fh->write(pack(($flags & 1 ? "N" : "n") . ($numGlyphs + 1), @{$self->{'locations'}})); | ||
| 84 | if ($flags & 2) | ||
| 85 | { $fh->write(pack("n$num", @{$self->{'names'}})); } | ||
| 86 | } | ||
| 87 | |||
| 88 | =back | ||
| 89 | |||
| 90 | =head2 $t->minsize() | ||
| 91 | |||
| 92 | Returns the minimum size this table can be. If it is smaller than this, then the table | ||
| 93 | must be bad and should be deleted or whatever. | ||
| 94 | |||
| 95 | =cut | ||
| 96 | |||
| 97 | sub minsize | ||
| 98 | { | ||
| 99 | return 8; | ||
| 100 | } | ||
| 101 | |||
| 102 | 1; | ||
| 103 | |||
| 104 | =head1 AUTHOR | ||
| 105 | |||
| 106 | Martin Hosken L<http://scripts.sil.org/FontUtils>. | ||
| 107 | |||
| 108 | |||
| 109 | =head1 LICENSING | ||
| 110 | |||
| 111 | Copyright (c) 1998-2016, SIL International (http://www.sil.org) | ||
| 112 | |||
| 113 | This module is released under the terms of the Artistic License 2.0. | ||
| 114 | For details, see the full text of the license in the file LICENSE. | ||
| 115 | |||
| 116 | |||
| 117 | |||
| 118 | =cut |