1Font::TTF::Font(3) User Contributed Perl Documentation Font::TTF::Font(3)
2
3
4
6 Font::TTF::Font - Memory representation of a font
7
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
11 differences 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
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
30 table within the font. Note that it does not read each table into
31 memory, 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
37 "table" 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 Feat Font::TTF::GrFeat
44 GDEF Font::TTF::GDEF
45 GPOS Font::TTF::GPOS
46 GSUB Font::TTF::GSUB
47 LTSH Font::TTF::LTSH
48 OS/2 Font::TTF::OS_2
49 PCLT Font::TTF::PCLT
50 bsln Font::TTF::Bsln
51 cmap Font::TTF::Cmap - see also Font::TTF::OldCmap
52 cvt Font::TTF::Cvt_
53 fdsc Font::TTF::Fdsc
54 feat Font::TTF::Feat
55 fmtx Font::TTF::Fmtx
56 fpgm Font::TTF::Fpgm
57 glyf Font::TTF::Glyf - see also Font::TTF::Glyph
58 hdmx Font::TTF::Hdmx
59 head Font::TTF::Head
60 hhea Font::TTF::Hhea
61 hmtx Font::TTF::Hmtx
62 kern Font::TTF::Kern - see alternative Font::TTF::AATKern
63 loca Font::TTF::Loca
64 maxp Font::TTF::Maxp
65 mort Font::TTF::Mort - see also Font::TTF::OldMort
66 name Font::TTF::Name
67 post Font::TTF::Post
68 prep Font::TTF::Prep
69 prop Font::TTF::Prop
70 vhea Font::TTF::Vhea
71 vmtx Font::TTF::Vmtx
72
73 Links are:
74
75 Font::TTF::Table Font::TTF::EBDT Font::TTF::EBLC Font::TTF::GrFeat
76 Font::TTF::GDEF Font::TTF::GPOS Font::TTF::GSUB Font::TTF::LTSH
77 Font::TTF::OS_2 Font::TTF::PCLT Font::TTF::Bsln Font::TTF::Cmap
78 Font::TTF::Cvt_ Font::TTF::Fdsc Font::TTF::Feat Font::TTF::Fmtx
79 Font::TTF::Fpgm Font::TTF::Glyf Font::TTF::Hdmx Font::TTF::Head
80 Font::TTF::Hhea Font::TTF::Hmtx Font::TTF::Kern Font::TTF::Loca
81 Font::TTF::Maxp Font::TTF::Mort Font::TTF::Name Font::TTF::Post
82 Font::TTF::Prep Font::TTF::Prop Font::TTF::Vhea Font::TTF::Vmtx
83 Font::TTF::OldCmap Font::TTF::Glyph Font::TTF::AATKern
84 Font::TTF::OldMort
85
87 Instance variables begin with a space (and have lengths greater than
88 the 4 characters which make up table names).
89
90 nocsum
91 This is used during output to disable the creation of the file
92 checksum in the head table. For example, during DSIG table
93 creation, this flag will be set to ensure that the file checksum is
94 left at zero.
95
96 noharmony
97 If set, do not harmonize the script and lang trees of GPOS and GSUB
98 tables. See Font::TTF::Ttopen for more info.
99
100 fname (R)
101 Contains the filename of the font which this object was read from.
102
103 INFILE (P)
104 The file handle which reflects the source file for this font.
105
106 OFFSET (P)
107 Contains the offset from the beginning of the read file of this
108 particular font directory, thus providing support for TrueType
109 Collections.
110
112 Font::TTF::Font->AddTable($tablename, $class)
113 Adds the given class to be used when representing the given table name.
114 It also 'requires' the class for you.
115
116 Font::TTF::Font->Init
117 For those people who like making fonts without reading them. This
118 subroutine will require all the table code for the various table types
119 for you. Not needed if using Font::TTF::Font::read before using a
120 table.
121
122 Font::TTF::Font->new(%props)
123 Creates a new font object and initialises with the given properties.
124 This is primarily for use when a TTF is embedded somewhere. Notice that
125 the properties are automatically preceded by a space when inserted into
126 the object. This is in order that fields do not clash with tables.
127
128 Font::TTF::Font->open($fname)
129 Reads the header and directory for the given font file and creates
130 appropriate objects for each table in the font.
131
132 $f->read
133 Reads a Truetype font directory starting from the current location in
134 the file. This has been separated from the "open" function to allow
135 support for embedded TTFs for example in TTCs. Also reads the "head"
136 and "maxp" tables immediately.
137
138 $f->out($fname [, @tablelist])
139 Writes a TTF file consisting of the tables in tablelist. The list is
140 checked to ensure that only tables that exist are output. (This means
141 that you can't have non table information stored in the font object
142 with key length of exactly 4)
143
144 In many cases the user simply wants to output all the tables in
145 alphabetical order. This can be done by not including a @tablelist, in
146 which case the subroutine will output all the defined tables in the
147 font in alphabetical order.
148
149 Returns $f on success and undef on failure, including warnings.
150
151 All output files must include the "head" table.
152
153 $f->out_xml($filename [, @tables])
154 Outputs the font in XML format
155
156 $f->XML_start($context, $tag, %attrs)
157 Handles start messages from the XML parser. Of particular interest to
158 us are <font> and <table>.
159
160 $f->update
161 Sends update to all the tables in the font and then resets all the
162 isDirty flags on each table. The data structure in now consistent as a
163 font (we hope).
164
165 $f->dirty
166 Dirties all the tables in the font
167
168 $f->tables_do(&func [, tables])
169 Calls &func for each table in the font. Calls the table in alphabetical
170 sort order as per the order in the directory:
171
172 &func($table, $name);
173
174 May optionally take a list of table names in which case func is called
175 for each of them in the given order.
176
177 $f->release
178 Releases ALL of the memory used by the TTF font and all of its
179 component objects. After calling this method, do NOT expect to have
180 anything left in the "Font::TTF::Font" object.
181
182 NOTE, that it is important that you call this method on any
183 "Font::TTF::Font" object when you wish to destruct it and free up its
184 memory. Internally, we track things in a structure that can result in
185 circular references, and without calling '"release()"' these will not
186 properly get cleaned up by Perl. Once you've called this method,
187 though, don't expect to be able to do anything else with the
188 "Font::TTF::Font" object; it'll have no internal state whatsoever.
189
190 Developer note: As part of the brute-force cleanup done here, this
191 method will throw a warning message whenever unexpected key values are
192 found within the "Font::TTF::Font" object. This is done to help ensure
193 that any unexpected and unfreed values are brought to your attention so
194 that you can bug us to keep the module updated properly; otherwise the
195 potential for memory leaks due to dangling circular references will
196 exist.
197
199 Bugs abound aplenty I am sure. There is a lot of code here and plenty
200 of scope. The parts of the code which haven't been implemented yet
201 are:
202
203 Post
204 Version 4 format types are not supported yet.
205
206 Cmap
207 Format type 2 (MBCS) has not been implemented yet and therefore may
208 cause somewhat spurious results for this table type.
209
210 Kern
211 Only type 0 & type 2 tables are supported (type 1 & type 3 yet to
212 come).
213
214 TTC The current Font::TTF::Font::out method does not support the
215 writing of TrueType Collections.
216
217 In addition there are weaknesses or features of this module library
218
219 · There is very little (or no) error reporting. This means that if
220 you have garbled data or garbled data structures, then you are
221 liable to generate duff fonts.
222
223 · The exposing of the internal data structures everywhere means that
224 doing radical re-structuring is almost impossible. But it stop the
225 code from becoming ridiculously large.
226
227 Apart from these, I try to keep the code in a state of "no known bugs",
228 which given the amount of testing this code has had, is not a guarantee
229 of high quality, yet.
230
231 For more details see the appropriate class files.
232
234 Martin Hosken Martin_Hosken@sil.org
235
236 Copyright Martin Hosken 1998.
237
238 No warranty or expression of effectiveness, least of all regarding
239 anyone's safety, is implied in this software or documentation.
240
241 Licensing
242 The Perl TTF module is licensed under the Perl Artistic License.
243
244
245
246perl v5.12.0 2008-06-11 Font::TTF::Font(3)