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

NAME

6       Font::TTF::Glyph - Holds a information for a single glyph
7

DESCRIPTION

9       This is a single glyph description as held in a TT font. On creation
10       only its header is read. Thus you can get the bounding box of each
11       glyph without having to read all the other information.
12

INSTANCE VARIABLES

14       In addition to the named variables in a glyph header ("xMin" etc.),
15       there are also all capital instance variables for holding working
16       information, mostly from the location table.
17
18   Variables for all glyphs:
19       The standard attributes each glyph has are:
20
21       numberOfContours
22           For simple glyphs this will be the count of contours. For compound
23           glyphs this will be -1.
24
25       xMin
26       yMin
27       xMax
28       yMax
29           These identify the bounding box of the glyph.
30
31       There are also other, derived, instance variables for each glyph which
32       are read when the whole glyph is read (via "read_dat"):
33
34       instLen
35           Number of bytes in the hinting instructions (Warning this variable
36           is deprecated, use "length($g-"{'hints'})> instead).
37
38       hints
39           The string containing the hinting code for the glyph
40
41   Variables for simple glyphs (numberOfContours >= 0):
42       endPoints
43           An array of endpoints for each contour in the glyph. There are
44           "numberOfContours" contours in a glyph. The number of points in a
45           glyph is equal to the highest endpoint of a contour.
46
47       numPoints
48           This is a generated value which contains the total number of points
49           for this simple glyph.
50
51       There are also a number of arrays indexed by point number:
52
53       flags
54           The flags associated with reading this point. The flags for a point
55           are recalculated for a point when it is "update"d. Thus the flags
56           are not very useful. The only important bit is bit 0 which
57           indicates whether the point is an 'on' curve point, or an 'off'
58           curve point.
59
60       x   The absolute x co-ordinate of the point.
61
62       y   The absolute y co-ordinate of the point
63
64   Variables for compound glyphs (numberOfContours == -1):
65       metric
66           This holds the component number (not its glyph number) of the
67           component from which the metrics for this glyph should be taken.
68
69       comps
70           This is an array of hashes for each component. Each hash has a
71           number of elements:
72
73           glyph
74               The glyph number of the glyph which comprises this component of
75               the composite.  NOTE: In some badly generated fonts, "glyph"
76               may contain a numerical value but that glyph might not actually
77               exist in the font file.  This could occur in any glyph, but is
78               particularly likely for glyphs that have no strokes, such as
79               SPACE, U+00A0 NO-BREAK SPACE, or U+200B ZERO WIDTH SPACE.
80
81           args
82               An array of two arguments which may be an x, y co-ordinate or
83               two attachment points (one on the base glyph the other on the
84               component). See flags for details.
85
86           flag
87               The flag for this component
88
89           scale
90               A 4 number array for component scaling. This allows stretching,
91               rotating, etc.  Note that scaling applies to placement co-
92               ordinates (rather than attachment points) before locating
93               rather than after.
94
95       numPoints
96           This is a generated value which contains the number of components
97           read in for this compound glyph.
98
99   Private instance variables:
100       INFILE (P)
101           The input file form which to read any information
102
103       LOC (P)
104           Location relative to the start of the glyf table in the read file
105
106       BASE (P)
107           The location of the glyf table in the read file
108
109       LEN (P)
110           This is the number of bytes required by the glyph. It should be
111           kept up to date by calling the "update" method whenever any of the
112           glyph content changes.
113
114       OUTLOC (P)
115           Location relative to the start of the glyf table. This variable is
116           only active whilst the output process is going on. It is used to
117           inform the location table where the glyph is located, since the
118           glyf table is output before the loca table due to alphabetical
119           ordering.
120
121       OUTLEN (P)
122           This indicates the length of the glyph data when it is output. This
123           more accurately reflects the internal memory form than the "LEN"
124           variable which only reflects the read file length. The "OUTLEN"
125           variable is only set after calling "out" or "out_dat".
126
127   Editing
128       If you want to edit a glyph in some way, then you should read_dat the
129       glyph, then make your changes and then update the glyph or set the
130       $g->{' isDirty'} variable.  The application must ensure that the
131       following instance variables are correct, from which update will
132       calculate the rest, including the bounding box information.
133
134           numPoints
135           numberOfContours
136           endPoints
137           x, y, flags         (only flags bit 0)
138           instLen
139           hints
140
141       For components, the numPoints, x, y, endPoints & flags are not required
142       but the following information is required for each component.
143
144           flag                (bits 2, 10, 11, 12)
145           glyph
146           args
147           scale
148           metric              (glyph instance variable)
149

METHODS

Font::TTF::Glyph->new(%parms)

152       Creates a new glyph setting various instance variables
153
154   $g->read
155       Reads the header component of the glyph (numberOfContours and bounding
156       box) and also the glyph content, but into a data field rather than
157       breaking it down into its constituent structures. Use read_dat for
158       this.
159
160   $g->read_dat
161       Reads the contents of the glyph (components and curves, etc.) from the
162       memory store "DAT" into structures within the object.
163
164   $g->out($fh)
165       Writes the glyph data to outfile
166
167   $g->out_xml($context, $depth)
168       Outputs an XML description of the glyph
169
170   $g->dirty($val)
171       This sets the dirty flag to the given value or 1 if no given value. It
172       returns the value of the flag
173
174   $g->update
175       Generates a "$self-"{'DAT'}> from the internal structures, if the data
176       has been read into structures in the first place. If you are building a
177       glyph from scratch you will need to set the instance variable '
178       isDirty'.
179
180   $g->update_bbox
181       Updates the bounding box for this glyph according to the points in the
182       glyph
183
184   $g->maxInfo
185       Returns lots of information about a glyph so that the "maxp" table can
186       update itself. Returns array containing contributions of this glyph to
187       maxPoints, maxContours, maxCompositePoints, maxCompositeContours,
188       maxSizeOfInstructions, maxComponentElements, and maxComponentDepth.
189
190   $g->empty
191       Empties the glyph of all information to the level of not having been
192       read.  Useful for saving memory in apps with many glyphs being read
193
194   $g->get_points
195       This method creates point information for a compound glyph. The
196       information is stored in the same place as if the glyph was not a
197       compound, but since numberOfContours is negative, the glyph is still
198       marked as being a compound
199
200   $g->get_refs
201       Returns an array of all the glyph ids that are used to make up this
202       glyph. That is all the compounds and their references and so on. If
203       this glyph is not a compound, then returns an empty array.
204
205       Please note the warning about bad fonts that reference nonexistent
206       glyphs under INSTANCE VARIABLES above.  This function will not attempt
207       to filter out nonexistent glyph numbers.
208

BUGS

210       •   The instance variables used here are somewhat clunky and
211           inconsistent with the other tables.
212
213       •   "update" doesn't re-calculate the bounding box or
214           "numberOfContours".
215

AUTHOR

217       Martin Hosken <http://scripts.sil.org/FontUtils>.
218

LICENSING

220       Copyright (c) 1998-2016, SIL International (http://www.sil.org)
221
222       This module is released under the terms of the Artistic License 2.0.
223       For details, see the full text of the license in the file LICENSE.
224
225
226
227perl v5.38.0                      2023-07-20               Font::TTF::Glyph(3)
Impressum