/usr/share/perl5/Font/TTF/OldCmap.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 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | package Font::TTF::OldCmap;
=head1 NAME
Font::TTF::OldCmap - Character map table
This module is deprecated
=head1 DESCRIPTION
Looks after the character map. The primary structure used for handling a cmap
is the L<Font::TTF::Segarr> which handles the segmented arrays of format 4 tables,
and in a simpler form for format 0 tables.
Due to the complexity of working with segmented arrays, most of the handling of
such arrays is via methods rather than via instance variables.
One important feature of a format 4 table is that it always contains a segment
with a final address of 0xFFFF. If you are creating a table from scratch this is
important (although L<Font::TTF::Segarr> can work quite happily without it).
=head1 INSTANCE VARIABLES
The instance variables listed here are not preceded by a space due to their
emulating structural information in the font.
=over 4
=item Num
Number of subtables in this table
=item Tables
An array of subtables ([0..Num-1])
=back
Each subtables also has its own instance variables which are, again, not
preceded by a space.
=over 4
=item Platform
The platform number for this subtable
=item Encoding
The encoding number for this subtable
=item Format
Gives the stored format of this subtable
=item Ver
Gives the version (or language) information for this subtable
=item val
This points to a L<Font::TTF::Segarr> which contains the content of the particular
subtable.
=back
=head1 METHODS
=cut
use strict;
use vars qw(@ISA);
require Font::TTF::Table;
require Font::TTF::Segarr;
@ISA = qw(Font::TTF::Table);
=head2 $t->read
Reads the cmap into memory. Format 4 subtables read the whole subtable and
fill in the segmented array accordingly.
Format 2 subtables are not read at all.
=cut
sub read
{
my ($self) = @_;
$self->SUPER::read or return $self;
my ($dat, $i, $j, $k, $id, @ids, $s);
my ($start, $end, $range, $delta, $form, $len, $num, $ver);
my ($fh) = $self->{' INFILE'};
$fh->read($dat, 4);
$self->{'Num'} = unpack("x2n", $dat);
$self->{'Tables'} = [];
for ($i = 0; $i < $self->{'Num'}; $i++)
{
$s = {};
$fh->read($dat, 8);
($s->{'Platform'}, $s->{'Encoding'}, $s->{'LOC'}) = (unpack("nnN", $dat));
$s->{'LOC'} += $self->{' OFFSET'};
push(@{$self->{'Tables'}}, $s);
}
for ($i = 0; $i < $self->{'Num'}; $i++)
{
$s = $self->{'Tables'}[$i];
$fh->seek($s->{'LOC'}, 0);
$fh->read($dat, 6);
($form, $len, $ver) = (unpack("n3", $dat));
$s->{'Format'} = $form;
$s->{'Ver'} = $ver;
if ($form == 0)
{
$s->{'val'} = Font::TTF::Segarr->new;
$fh->read($dat, 256);
$s->{'val'}->fastadd_segment(0, 2, unpack("C*", $dat));
$s->{'Start'} = 0;
$s->{'Num'} = 256;
} elsif ($form == 6)
{
my ($start, $ecount);
$fh->read($dat, 4);
($start, $ecount) = unpack("n2", $dat);
$fh->read($dat, $ecount << 1);
$s->{'val'} = Font::TTF::Segarr->new;
$s->{'val'}->fastadd_segment($start, 2, unpack("n*", $dat));
$s->{'Start'} = $start;
$s->{'Num'} = $ecount;
} elsif ($form == 2)
{
# no idea what to do here yet
} elsif ($form == 4)
{
$fh->read($dat, 8);
$num = unpack("n", $dat);
$num >>= 1;
$fh->read($dat, $len - 14);
$s->{'val'} = Font::TTF::Segarr->new;
for ($j = 0; $j < $num; $j++)
{
$end = unpack("n", substr($dat, $j << 1, 2));
$start = unpack("n", substr($dat, ($j << 1) + ($num << 1) + 2, 2));
$delta = unpack("n", substr($dat, ($j << 1) + ($num << 2) + 2, 2));
$delta -= 65536 if $delta > 32767;
$range = unpack("n", substr($dat, ($j << 1) + $num * 6 + 2, 2));
@ids = ();
for ($k = $start; $k <= $end; $k++)
{
if ($range == 0)
{ $id = $k + $delta; }
else
{ $id = unpack("n", substr($dat, ($j << 1) + $num * 6 +
2 + ($k - $start) * 2 + $range, 2)) + $delta; }
$id -= 65536 if $id > 65536;
push (@ids, $id);
}
$s->{'val'}->fastadd_segment($start, 0, @ids);
}
$s->{'val'}->tidy;
$s->{'Num'} = 0x10000; # always ends here
$s->{'Start'} = $s->{'val'}[0]{'START'};
}
}
$self;
}
=head2 $t->ms_lookup($uni)
Given a Unicode value in the MS table (Platform 3, Encoding 1) locates that
table and looks up the appropriate glyph number from it.
=cut
sub ms_lookup
{
my ($self, $uni) = @_;
$self->find_ms || return undef unless (defined $self->{' mstable'});
return $self->{' mstable'}{'val'}->at($uni);
}
=head2 $t->find_ms
Finds the Microsoft Unicode table and sets the C<mstable> instance variable
to it if found. Returns the table it finds.
=cut
sub find_ms
{
my ($self) = @_;
my ($i, $s, $alt);
return $self->{' mstable'} if defined $self->{' mstable'};
$self->read;
for ($i = 0; $i < $self->{'Num'}; $i++)
{
$s = $self->{'Tables'}[$i];
if ($s->{'Platform'} == 3)
{
$self->{' mstable'} = $s;
last if ($s->{'Encoding'} == 1);
} elsif ($s->{'Platform'} == 0 || ($s->{'Platform'} == 2 && $s->{'Encoding'} == 1))
{ $self->{' mstable'} = $s; }
}
$self->{' mstable'};
}
=head2 $t->out($fh)
Writes out a cmap table to a filehandle. If it has not been read, then
just copies from input file to output
=cut
sub out
{
my ($self, $fh) = @_;
my ($loc, $s, $i, $base_loc, $j);
return $self->SUPER::out($fh) unless $self->{' read'};
$base_loc = $fh->tell();
$fh->print(pack("n2", 0, $self->{'Num'}));
for ($i = 0; $i < $self->{'Num'}; $i++)
{ $fh->print(pack("nnN", $self->{'Tables'}[$i]{'Platform'}, $self->{'Tables'}[$i]{'Encoding'}, 0)); }
for ($i = 0; $i < $self->{'Num'}; $i++)
{
$s = $self->{'Tables'}[$i];
$s->{'val'}->tidy;
$s->{' outloc'} = $fh->tell();
$fh->print(pack("n3", $s->{'Format'}, 0, $s->{'Ver'})); # come back for length
if ($s->{'Format'} == 0)
{
$fh->print(pack("C256", $s->{'val'}->at(0, 256)));
} elsif ($s->{'Format'} == 6)
{
$fh->print(pack("n2", $s->{'Start'}, $s->{'Num'}));
$fh->print(pack("n*", $s->{'val'}->at($s->{'Start'}, $s->{'Num'})));
} elsif ($s->{'Format'} == 2)
{
} elsif ($s->{'Format'} == 4)
{
my ($num, $sRange, $eSel);
my (@deltas, $delta, @range, $flat, $k, $segs, $count);
$num = $#{$s->{'val'}} + 1;
$segs = $s->{'val'};
for ($sRange = 1, $eSel = 0; $sRange <= $num; $eSel++)
{ $sRange <<= 1;}
$eSel--;
$fh->print(pack("n4", $num * 2, $sRange, $eSel, ($num * 2) - $sRange));
$fh->print(pack("n*", map {$_->{'START'} + $_->{'LEN'} - 1} @$segs));
$fh->print(pack("n", 0));
$fh->print(pack("n*", map {$_->{'START'}} @$segs));
for ($j = 0; $j < $num; $j++)
{
$delta = $segs->[$j]{'VAL'}[0]; $flat = 1;
for ($k = 1; $k < $segs->[$j]{'LEN'}; $k++)
{
if ($segs->[$j]{'VAL'}[$k] == 0)
{ $flat = 0; }
if ($delta + $k != $segs->[$j]{'VAL'}[$k])
{
$delta = 0;
last;
}
}
push (@range, $flat);
push (@deltas, ($delta ? $delta - $segs->[$j]{'START'} : 0));
}
$fh->print(pack("n*", @deltas));
$count = 0;
for ($j = 0; $j < $num; $j++)
{
$delta = $deltas[$j];
if ($delta != 0 && $range[$j] == 1)
{ $range[$j] = 0; }
else
{
$range[$j] = ($count + $num - $j) << 1;
$count += $segs->[$j]{'LEN'};
}
}
$fh->print(pack("n*", @range));
for ($j = 0; $j < $num; $j++)
{
next if ($range[$j] == 0);
for ($k = 0; $k < $segs->[$j]{'LEN'}; $k++)
{ $fh->print(pack("n", $segs->[$j]{'VAL'}[$k])); }
}
}
$loc = $fh->tell();
$fh->seek($s->{' outloc'} + 2, 0);
$fh->print(pack("n", $loc - $s->{' outloc'}));
$fh->seek($base_loc + 8 + ($i << 3), 0);
$fh->print(pack("N", $s->{' outloc'} - $base_loc));
$fh->seek($loc, 0);
}
$self;
}
=head2 @map = $t->reverse([$num])
Returns a reverse map of the table of given number or the Microsoft
cmap. I.e. given a glyph gives the Unicode value for it.
=cut
sub reverse
{
my ($self, $tnum) = @_;
my ($table) = defined $tnum ? $self->{'Tables'}[$tnum] : $self->find_ms;
my (@res, $i, $s, $first);
foreach $s (@{$table->{'val'}})
{
$first = $s->{'START'};
map {$res[$_] = $first unless $res[$_]; $first++;} @{$s->{'VAL'}};
}
@res;
}
1;
=head1 BUGS
=over 4
=item *
No support for format 2 tables (MBCS)
=back
=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
|