/usr/share/perl5/Font/TTF/Loca.pm is in libfont-ttf-perl 1.06-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | package Font::TTF::Loca;
=head1 NAME
Font::TTF::Loca - the Locations table, which is intimately tied to the glyf table
=head1 DESCRIPTION
The location table holds the directory of locations of each glyph within the
glyf table. Due to this relationship and the unimportance of the actual locations
when it comes to holding glyphs in memory, reading the location table results
in the creation of glyph objects for each glyph and stores them here.
So if you are looking for glyphs, do not look in the C<glyf> table, look here
instead.
Things get complicated if you try to change the glyph list within the one table.
The recommendation is to create another clean location object to replace this
table in the font, ensuring that the old table is read first and to transfer
or copy glyphs across from the read table to the new table.
=head1 INSTANCE VARIABLES
The instance variables do not start with a space
=over 4
=item glyphs
An array of glyph objects for each glyph.
=item glyphtype
A string containing the class name to create for each new glyph. If empty,
defaults to L<Font::TTF::Glyph>.
=back
=head1 METHODS
=cut
use strict;
use vars qw(@ISA);
@ISA = qw(Font::TTF::Table);
require Font::TTF::Glyph;
=head2 $t->new
Creates a new location table making sure it has a glyphs array
=cut
sub new
{
my ($class) = shift;
my ($res) = $class->SUPER::new(@_);
$res->{'glyphs'} = [];
$res;
}
=head2 $t->read
Reads the location table creating glyph objects (L<Font::TTF::Glyph>) for each glyph
allowing their later reading.
=cut
sub read
{
my ($self) = @_;
# Do this before $self->SUPER::read because this can alter the file pointer:
my ($glyfLoc) = $self->{' PARENT'}{'glyf'}->_read->{' OFFSET'}; # May seek on $fh!
$self->SUPER::read or return $self;
my ($fh) = $self->{' INFILE'};
my ($locFmt) = $self->{' PARENT'}{'head'}{'indexToLocFormat'};
my ($numGlyphs) = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
my ($dat, $last, $i, $loc);
$fh->read($dat, $locFmt ? 4 : 2);
$last = unpack($locFmt ? "N" : "n", $dat);
for ($i = 0; $i < $numGlyphs; $i++)
{
$fh->read($dat, $locFmt ? 4 : 2);
$loc = unpack($locFmt ? "N" : "n", $dat);
$self->{'glyphs'}[$i] = ($self->{'glyphtype'} || "Font::TTF::Glyph")->new(
LOC => $last << ($locFmt ? 0 : 1),
OUTLOC => $last << ($locFmt ? 0 : 1),
PARENT => $self->{' PARENT'},
INFILE => $self->{' PARENT'}{'glyf'}{' INFILE'},
BASE => $glyfLoc,
OUTLEN => ($loc - $last) << ($locFmt ? 0 : 1),
LEN => ($loc - $last) << ($locFmt ? 0 : 1)) if ($loc != $last);
$last = $loc;
}
$self;
}
=head2 $t->out($fh)
Writes the location table out to $fh. Notice that not having read the location
table implies that the glyf table has not been read either, so the numbers in
the location table are still valid. Let's hope that C<maxp/numGlyphs> and
C<head/indexToLocFmt> haven't changed otherwise we are in big trouble.
The function uses the OUTLOC location in the glyph calculated when the glyf
table was attempted to be output.
=cut
sub out
{
my ($self, $fh) = @_;
my ($locFmt) = $self->{' PARENT'}{'head'}{'indexToLocFormat'};
my ($numGlyphs) = $self->{' PARENT'}{'maxp'}{'numGlyphs'};
my ($count, $i, $offset, $g);
return $self->SUPER::out($fh) unless ($self->{' read'});
$count = 0;
for ($i = 0; $i < $numGlyphs; $i++)
{
$g = ($self->{'glyphs'}[$i]) || "";
unless ($g)
{
$count++;
next;
} else
{
if ($locFmt)
{ $fh->print(pack("N", $g->{' OUTLOC'}) x ($count + 1)); }
else
{ $fh->print(pack("n", $g->{' OUTLOC'} >> 1) x ($count + 1)); }
$count = 0;
$offset = $g->{' OUTLOC'} + $g->{' OUTLEN'};
}
}
$fh->print(pack($locFmt ? "N" : "n", ($locFmt ? $offset: $offset >> 1)) x ($count + 1));
}
=head2 $t->out_xml($context, $depth)
No need to output a loca table, this is dynamically generated
=cut
sub out_xml
{ return $_[0]; }
=head2 $t->glyphs_do(&func)
Calls func for each glyph in this location table in numerical order:
&func($glyph, $glyph_num)
=cut
sub glyphs_do
{
my ($self, $func) = @_;
my ($i);
for ($i = 0; $i <= $#{$self->{'glyphs'}}; $i++)
{ &$func($self->{'glyphs'}[$i], $i) if defined $self->{'glyphs'}[$i]; }
$self;
}
1;
=head1 BUGS
None known
=head1 AUTHOR
Martin Hosken L<http://scripts.sil.org/FontUtils>.
=head1 LICENSING
Copyright (c) 1998-2016, SIL International (http://www.sil.org)
This module is released under the terms of the Artistic License 2.0.
For details, see the full text of the license in the file LICENSE.
=cut
|