1 package Font::TTF::Glyf;
5 Font::TTF::Glyf - The Glyf data table
9 This is a stub table. The real data is held in the loca table. If you want to get a glyf
10 look it up in the loca table as C<$f->{'loca'}{'glyphs'}[$num]>. It won't be here!
12 The difference between reading this table as opposed to the loca table is that
13 reading this table will cause updated glyphs to be written out rather than just
14 copying the glyph information from the input file. This causes font writing to be
15 slower. So read the glyf as opposed to the loca table if you want to change glyf
16 data. Read the loca table only if you are just wanting to read the glyf information.
18 This class is used when writing the glyphs though.
27 @ISA = qw(Font::TTF::Table);
31 Reads the C<loca> table instead!
39 $self->{' PARENT'}{'loca'}->read;
47 Writes out all the glyphs in the parent's location table, calculating a new
48 output location for each one.
55 my ($i, $loca, $offset, $numGlyphs);
57 return $self->SUPER::out($fh) unless $self->{' read'};
59 $loca = $self->{' PARENT'}{'loca'}{'glyphs'};
60 $numGlyphs = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
63 for ($i = 0; $i < $numGlyphs; $i++)
65 next unless defined $loca->[$i];
67 $loca->[$i]{' OUTLOC'} = $offset;
68 $loca->[$i]->out($fh);
69 $offset += $loca->[$i]{' OUTLEN'};
71 $self->{' PARENT'}{'head'}{'indexToLocFormat'} = ($offset >= 0x20000);
76 =head2 $t->out_xml($context, $depth)
78 Outputs all the glyphs in the glyph table just where they are supposed to be output!
84 my ($self, $context, $depth) = @_;
85 my ($fh) = $context->{'fh'};
86 my ($loca, $i, $numGlyphs);
88 $loca = $self->{' PARENT'}{'loca'}{'glyphs'};
89 $numGlyphs = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
91 for ($i = 0; $i < $numGlyphs; $i++)
93 $context->{'gid'} = $i;
94 $loca->[$i]->out_xml($context, $depth) if (defined $loca->[$i]);
101 =head2 $t->XML_start($context, $tag, %attrs)
103 Pass control to glyphs as they occur
110 my ($context, $tag, %attrs) = @_;
114 $context->{'tree'}[-1] = Font::TTF::Glyph->new(read => 2, PARENT => $self->{' PARENT'});
115 $context->{'receiver'} = $context->{'tree'}[-1];
120 =head2 $t->XML_end($context, $tag, %attrs)
122 Collect up glyphs and put them into the loca table
129 my ($context, $tag, %attrs) = @_;
133 unless (defined $context->{'glyphs'})
135 if (defined $self->{' PARENT'}{'loca'})
136 { $context->{'glyphs'} = $self->{' PARENT'}{'loca'}{'glyphs'}; }
138 { $context->{'glyphs'} = []; }
140 $context->{'glyphs'}[$attrs{'gid'}] = $context->{'tree'}[-1];
143 { return $self->SUPER::XML_end(@_); }
154 Martin Hosken Martin_Hosken@sil.org. See L<Font::TTF::Font> for copyright and