PDF::API2::Basic::TTF::Font - Memory representation of a font |
PDF::API2::Basic::TTF::Font - Memory representation of a font
Here is the regression test (you provide your own font). Run it once and then again on the output of the first run. There should be no differences between the outputs of the two runs.
$f = PDF::API2::Basic::TTF::Font->open($ARGV[0]);
# force a read of all the tables $f->tables_do(sub { $_[0]->read; });
# force read of all glyphs (use read_dat to use lots of memory!) # $f->{'loca'}->glyphs_do(sub { $_[0]->read; }); $f->{'loca'}->glyphs_do(sub { $_[0]->read_dat; }); # NB. no need to $g->update since $f->{'glyf'}->out will do it for us
$f->out($ARGV[1]); $f->release; # clear up memory forcefully!
A Truetype font consists of a header containing a directory of tables which constitute the rest of the file. This class holds that header and directory and also creates objects of the appropriate type for each table within the font. Note that it does not read each table into memory, but creates a short reference which can be read using the form:
$f->{$tablename}->read;
Classes are included that support many of the different TrueType tables. For
those for which no special code exists, the table type table
is used, which
defaults to the PDF::API2::Basic::TTF::Table manpage. The current tables which are supported are:
table PDF::API2::Basic::TTF::Table - for unknown tables GDEF PDF::API2::Basic::TTF::GDEF GPOS PDF::API2::Basic::TTF::GPOS GSUB PDF::API2::Basic::TTF::GSUB LTSH PDF::API2::Basic::TTF::LTSH OS/2 PDF::API2::Basic::TTF::OS_2 PCLT PDF::API2::Basic::TTF::PCLT bsln PDF::API2::Basic::TTF::Bsln cmap PDF::API2::Basic::TTF::Cmap - see also PDF::API2::Basic::TTF::OldCmap cvt PDF::API2::Basic::TTF::Cvt_ fdsc PDF::API2::Basic::TTF::Fdsc feat PDF::API2::Basic::TTF::Feat fmtx PDF::API2::Basic::TTF::Fmtx fpgm PDF::API2::Basic::TTF::Fpgm glyf PDF::API2::Basic::TTF::Glyf - see also PDF::API2::Basic::TTF::Glyph hdmx PDF::API2::Basic::TTF::Hdmx head PDF::API2::Basic::TTF::Head hhea PDF::API2::Basic::TTF::Hhea hmtx PDF::API2::Basic::TTF::Hmtx kern PDF::API2::Basic::TTF::Kern - see alternative PDF::API2::Basic::TTF::AATKern loca PDF::API2::Basic::TTF::Loca maxp PDF::API2::Basic::TTF::Maxp mort PDF::API2::Basic::TTF::Mort - see also PDF::API2::Basic::TTF::OldMort name PDF::API2::Basic::TTF::Name post PDF::API2::Basic::TTF::Post prep PDF::API2::Basic::TTF::Prep prop PDF::API2::Basic::TTF::Prop vhea PDF::API2::Basic::TTF::Vhea vmtx PDF::API2::Basic::TTF::Vmtx
Links are:
the PDF::API2::Basic::TTF::Table manpage the PDF::API2::Basic::TTF::GDEF manpage the PDF::API2::Basic::TTF::GPOS manpage the PDF::API2::Basic::TTF::GSUB manpage the PDF::API2::Basic::TTF::LTSH manpage the PDF::API2::Basic::TTF::OS_2 manpage the PDF::API2::Basic::TTF::PCLT manpage the PDF::API2::Basic::TTF::Bsln manpage the PDF::API2::Basic::TTF::Cmap manpage the PDF::API2::Basic::TTF::Cvt_ manpage the PDF::API2::Basic::TTF::Fdsc manpage the PDF::API2::Basic::TTF::Feat manpage the PDF::API2::Basic::TTF::Fmtx manpage the PDF::API2::Basic::TTF::Fpgm manpage the PDF::API2::Basic::TTF::Glyf manpage the PDF::API2::Basic::TTF::Hdmx manpage the PDF::API2::Basic::TTF::Head manpage the PDF::API2::Basic::TTF::Hhea manpage the PDF::API2::Basic::TTF::Hmtx manpage the PDF::API2::Basic::TTF::Kern manpage the PDF::API2::Basic::TTF::Loca manpage the PDF::API2::Basic::TTF::Maxp manpage the PDF::API2::Basic::TTF::Mort manpage the PDF::API2::Basic::TTF::Name manpage the PDF::API2::Basic::TTF::Post manpage the PDF::API2::Basic::TTF::Prep manpage the PDF::API2::Basic::TTF::Prop manpage the PDF::API2::Basic::TTF::Vhea manpage the PDF::API2::Basic::TTF::Vmtx manpage the PDF::API2::Basic::TTF::OldCmap manpage the PDF::API2::Basic::TTF::Glyph manpage the PDF::API2::Basic::TTF::AATKern manpage the PDF::API2::Basic::TTF::OldMort manpage
=head1 INSTANCE VARIABLES
Instance variables begin with a space (and have lengths greater than the 4 characters which make up table names).
new(%props)
Creates a new font object and initialises with the given properties. This is primarily for use when a TTF is embedded somewhere. Notice that the properties are automatically preceded by a space when inserted into the object. This is in order that fields do not clash with tables.
Reads a Truetype font directory starting from the current location in the file.
This has been separated from the open
function to allow support for embedded
TTFs for example in TTCs. Also reads the head
and maxp
tables immediately.
Sends update to all the tables in the font and then resets all the isDirty flags on each table. The data structure in now consistent as a font (we hope).
Dirties all the tables in the font
tables_do(&func)
Calls &func for each table in the font. Calls the table in alphabetical sort order as per the order in the directory:
&func($table, $name);
Bugs abound aplenty I am sure. There is a lot of code here and plenty of scope. The parts of the code which haven't been implemented yet are:
In addition there are weaknesses or features of this module library
Apart from these, I try to keep the code in a state of ``no known bugs'', which given the amount of testing this code has had, is not a guarantee of high quality, yet.
For more details see the appropriate class files.
Martin Hosken Martin_Hosken@sil.org
Copyright Martin Hosken 1998.
No warranty or expression of effectiveness, least of all regarding anyone's safety, is implied in this software or documentation.
The Perl TTF module is licensed under the Perl Artistic License.
PDF::API2::Basic::TTF::Font - Memory representation of a font |