1Font::TTF::Font(3)    User Contributed Perl Documentation   Font::TTF::Font(3)
2
3
4

NAME

6       Font::TTF::Font - Memory representation of a font
7

SYNOPSIS

9       Here is the regression test (you provide your own font). Run it once
10       and then again on the output of the first run. There should be no dif‐
11       ferences between the outputs of the two runs.
12
13           $f = Font::TTF::Font->open($ARGV[0]);
14
15           # force a read of all the tables
16           $f->tables_do(sub { $_[0]->read; });
17
18           # force read of all glyphs (use read_dat to use lots of memory!)
19           # $f->{'loca'}->glyphs_do(sub { $_[0]->read; });
20           $f->{'loca'}->glyphs_do(sub { $_[0]->read_dat; });
21           # NB. no need to $g->update since $f->{'glyf'}->out will do it for us
22
23           $f->out($ARGV[1]);
24           $f->release;            # clear up memory forcefully!
25

DESCRIPTION

27       A Truetype font consists of a header containing a directory of tables
28       which constitute the rest of the file. This class holds that header and
29       directory and also creates objects of the appropriate type for each ta‐
30       ble within the font.  Note that it does not read each table into mem‐
31       ory, but creates a short reference which can be read using the form:
32
33           $f->{$tablename}->read;
34
35       Classes are included that support many of the different TrueType
36       tables. For those for which no special code exists, the table type "ta‐
37       ble" is used, which defaults to Font::TTF::Table. The current tables
38       which are supported are:
39
40           table       Font::TTF::Table      - for unknown tables
41           EBDT        Font::TTF::EBDT
42           EBLC        Font::TTF::EBLC
43           GDEF        Font::TTF::GDEF
44           GPOS        Font::TTF::GPOS
45           GSUB        Font::TTF::GSUB
46           LTSH        Font::TTF::LTSH
47           OS/2        Font::TTF::OS_2
48           PCLT        Font::TTF::PCLT
49           bsln        Font::TTF::Bsln
50           cmap        Font::TTF::Cmap       - see also Font::TTF::OldCmap
51           cvt         Font::TTF::Cvt_
52           fdsc        Font::TTF::Fdsc
53           feat        Font::TTF::Feat
54           fmtx        Font::TTF::Fmtx
55           fpgm        Font::TTF::Fpgm
56           glyf        Font::TTF::Glyf       - see also Font::TTF::Glyph
57           hdmx        Font::TTF::Hdmx
58           head        Font::TTF::Head
59           hhea        Font::TTF::Hhea
60           hmtx        Font::TTF::Hmtx
61           kern        Font::TTF::Kern       - see alternative Font::TTF::AATKern
62           loca        Font::TTF::Loca
63           maxp        Font::TTF::Maxp
64           mort        Font::TTF::Mort       - see also Font::TTF::OldMort
65           name        Font::TTF::Name
66           post        Font::TTF::Post
67           prep        Font::TTF::Prep
68           prop        Font::TTF::Prop
69           vhea        Font::TTF::Vhea
70           vmtx        Font::TTF::Vmtx
71
72       Links are:
73
74       Font::TTF::Table Font::TTF::EBDT Font::TTF::EBLC Font::TTF::GDEF
75       Font::TTF::GPOS Font::TTF::GSUB Font::TTF::LTSH Font::TTF::OS_2
76       Font::TTF::PCLT Font::TTF::Bsln Font::TTF::Cmap Font::TTF::Cvt_
77       Font::TTF::Fdsc Font::TTF::Feat Font::TTF::Fmtx Font::TTF::Fpgm
78       Font::TTF::Glyf Font::TTF::Hdmx Font::TTF::Head Font::TTF::Hhea
79       Font::TTF::Hmtx Font::TTF::Kern Font::TTF::Loca Font::TTF::Maxp
80       Font::TTF::Mort Font::TTF::Name Font::TTF::Post Font::TTF::Prep
81       Font::TTF::Prop Font::TTF::Vhea Font::TTF::Vmtx Font::TTF::OldCmap
82       Font::TTF::Glyph Font::TTF::AATKern Font::TTF::OldMort
83

INSTANCE VARIABLES

85       Instance variables begin with a space (and have lengths greater than
86       the 4 characters which make up table names).
87
88       nocsum
89           This is used during output to disable the creation of the file
90           checksum in the head table. For example, during DSIG table cre‐
91           ation, this flag will be set to ensure that the file checksum is
92           left at zero.
93
94       fname (R)
95           Contains the filename of the font which this object was read from.
96
97       INFILE (P)
98           The file handle which reflects the source file for this font.
99
100       OFFSET (P)
101           Contains the offset from the beginning of the read file of this
102           particular font directory, thus providing support for TrueType Col‐
103           lections.
104

METHODS

106       Font::TTF::Font->AddTable($tablename, $class)
107
108       Adds the given class to be used when representing the given table name.
109       It also 'requires' the class for you.
110
111       Font::TTF::Font->Init
112
113       For those people who like making fonts without reading them. This sub‐
114       routine will require all the table code for the various table types for
115       you. Not needed if using Font::TTF::Font::read before using a table.
116
117       Font::TTF::Font->new(%props)
118
119       Creates a new font object and initialises with the given properties.
120       This is primarily for use when a TTF is embedded somewhere. Notice that
121       the properties are automatically preceded by a space when inserted into
122       the object. This is in order that fields do not clash with tables.
123
124       Font::TTF::Font->open($fname)
125
126       Reads the header and directory for the given font file and creates
127       appropriate objects for each table in the font.
128
129       $f->read
130
131       Reads a Truetype font directory starting from the current location in
132       the file.  This has been separated from the "open" function to allow
133       support for embedded TTFs for example in TTCs. Also reads the "head"
134       and "maxp" tables immediately.
135
136       $f->out($fname [, @tablelist])
137
138       Writes a TTF file consisting of the tables in tablelist. The list is
139       checked to ensure that only tables that exist are output. (This means
140       that you can't have non table information stored in the font object
141       with key length of exactly 4)
142
143       In many cases the user simply wants to output all the tables in alpha‐
144       betical order.  This can be done by not including a @tablelist, in
145       which case the subroutine will output all the defined tables in the
146       font in alphabetical order.
147
148       Returns $f on success and undef on failure, including warnings.
149
150       All output files must include the "head" table.
151
152       $f->out_xml($filename [, @tables])
153
154       Outputs the font in XML format
155
156       $f->XML_start($context, $tag, %attrs)
157
158       Handles start messages from the XML parser. Of particular interest to
159       us are <font> and <table>.
160
161       $f->update
162
163       Sends update to all the tables in the font and then resets all the
164       isDirty flags on each table. The data structure in now consistent as a
165       font (we hope).
166
167       $f->dirty
168
169       Dirties all the tables in the font
170
171       $f->tables_do(&func [, tables])
172
173       Calls &func for each table in the font. Calls the table in alphabetical
174       sort order as per the order in the directory:
175
176           &func($table, $name);
177
178       May optionally take a list of table names in which case func is called
179       for each of them in the given order.  =cut
180
181       sub tables_do {
182           my ($self, $func, @tables) = @_;
183           my ($t);
184
185           foreach $t (@tables ? @tables : sort grep {length($_) == 4} keys %$self)
186           { &$func($self->{$t}, $t); }
187           $self;
188       }
189
190       $f->release
191
192       Releases ALL of the memory used by the TTF font and all of its compo‐
193       nent objects.  After calling this method, do NOT expect to have any‐
194       thing left in the "Font::TTF::Font" object.
195
196       NOTE, that it is important that you call this method on any
197       "Font::TTF::Font" object when you wish to destruct it and free up its
198       memory.  Internally, we track things in a structure that can result in
199       circular references, and without calling '"release()"' these will not
200       properly get cleaned up by Perl.  Once you've called this method,
201       though, don't expect to be able to do anything else with the
202       "Font::TTF::Font" object; it'll have no internal state whatsoever.
203
204       Developer note: As part of the brute-force cleanup done here, this
205       method will throw a warning message whenever unexpected key values are
206       found within the "Font::TTF::Font" object.  This is done to help ensure
207       that any unexpected and unfreed values are brought to your attention so
208       that you can bug us to keep the module updated properly; otherwise the
209       potential for memory leaks due to dangling circular references will
210       exist.
211

BUGS

213       Bugs abound aplenty I am sure. There is a lot of code here and plenty
214       of scope.  The parts of the code which haven't been implemented yet
215       are:
216
217       Post
218           Version 4 format types are not supported yet.
219
220       Cmap
221           Format type 2 (MBCS) has not been implemented yet and therefore may
222           cause somewhat spurious results for this table type.
223
224       Kern
225           Only type 0 & type 2 tables are supported (type 1 & type 3 yet to
226           come).
227
228       TTC The current Font::TTF::Font::out method does not support the writ‐
229           ing of TrueType Collections.
230
231       In addition there are weaknesses or features of this module library
232
233       ·   There is very little (or no) error reporting. This means that if
234           you have garbled data or garbled data structures, then you are
235           liable to generate duff fonts.
236
237       ·   The exposing of the internal data structures everywhere means that
238           doing radical re-structuring is almost impossible. But it stop the
239           code from becoming ridiculously large.
240
241       Apart from these, I try to keep the code in a state of "no known bugs",
242       which given the amount of testing this code has had, is not a guarantee
243       of high quality, yet.
244
245       For more details see the appropriate class files.
246

AUTHOR

248       Martin Hosken Martin_Hosken@sil.org
249
250       Copyright Martin Hosken 1998.
251
252       No warranty or expression of effectiveness, least of all regarding any‐
253       one's safety, is implied in this software or documentation.
254
255       Licensing
256
257       The Perl TTF module is licensed under the Perl Artistic License.
258
259
260
261perl v5.8.8                       2005-06-14                Font::TTF::Font(3)
Impressum