1Font::TTF::Glyph(3) User Contributed Perl Documentation Font::TTF::Glyph(3)
2
3
4
6 Font::TTF::Glyph - Holds a information for a single glyph
7
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
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 The standard attributes each glyph has are:
19
20 numberOfContours
21 xMin
22 yMin
23 xMax
24 yMax
25
26 There are also other, derived, instance variables for each glyph which
27 are read when the whole glyph is read (via "read_dat"):
28
29 instLen
30 Number of bytes in the hinting instructions (Warning this variable
31 is deprecated, use "length($g-"{'hints'})> instead).
32
33 hints
34 The string containing the hinting code for the glyph
35
36 In addition there are other attribute like instance variables for
37 simple glyphs:
38
39 For each contour there is:
40
41 endPoints
42 An array of endpoints for each contour in the glyph. There are
43 "numberOfContours" contours in a glyph. The number of points in
44 a glyph is equal to the highest endpoint of a contour.
45
46 There are also a number of arrays indexed by point number
47
48 flags
49 The flags associated with reading this point. The flags for a
50 point are recalculated for a point when it is "update"d. Thus
51 the flags are not very useful. The only important bit is bit 0
52 which indicates whether the point is an 'on' curve point, or an
53 'off' curve point.
54
55 x The absolute x co-ordinate of the point.
56
57 y The absolute y co-ordinate of the point
58
59 For composite glyphs there are other variables
60
61 metric
62 This holds the component number (not its glyph number) of the
63 component from which the metrics for this glyph should be taken.
64
65 comps
66 This is an array of hashes for each component. Each hash has a
67 number of elements:
68
69 glyph
70 The glyph number of the glyph which comprises this component of
71 the composite. NOTE: In some badly generated fonts, "glyph"
72 may contain a numerical value but that glyph might not actually
73 exist in the font file. This could occur in any glyph, but is
74 particularly likely for glyphs that have no strokes, such as
75 SPACE, U+00A0 NO-BREAK SPACE, or U+200B ZERO WIDTH SPACE.
76
77 args
78 An array of two arguments which may be an x, y co-ordinate or
79 two attachment points (one on the base glyph the other on the
80 component). See flags for details.
81
82 flag
83 The flag for this component
84
85 scale
86 A 4 number array for component scaling. This allows stretching,
87 rotating, etc. Note that scaling applies to placement co-
88 ordinates (rather than attachment points) before locating
89 rather than after.
90
91 numPoints
92 This is a generated value which contains the number of components
93 read in for this compound glyph.
94
95 The private instance variables are:
96
97 INFILE (P)
98 The input file form which to read any information
99
100 LOC (P)
101 Location relative to the start of the glyf table in the read file
102
103 BASE (P)
104 The location of the glyf table in the read file
105
106 LEN (P)
107 This is the number of bytes required by the glyph. It should be
108 kept up to date by calling the "update" method whenever any of the
109 glyph content changes.
110
111 OUTLOC (P)
112 Location relative to the start of the glyf table. This variable is
113 only active whilst the output process is going on. It is used to
114 inform the location table where the glyph is located, since the
115 glyf table is output before the loca table due to alphabetical
116 ordering.
117
118 OUTLEN (P)
119 This indicates the length of the glyph data when it is output. This
120 more accurately reflects the internal memory form than the "LEN"
121 variable which only reflects the read file length. The "OUTLEN"
122 variable is only set after calling "out" or "out_dat".
123
124 Editing
125 If you want to edit a glyph in some way, then you should read_dat the
126 glyph, then make your changes and then update the glyph or set the
127 $g->{' isDirty'} variable. The application must ensure that the
128 following instance variables are correct, from which update will
129 calculate the rest, including the bounding box information.
130
131 numPoints
132 numberOfContours
133 endPoints
134 x, y, flags (only flags bit 0)
135 instLen
136 hints
137
138 For components, the numPoints, x, y, endPoints & flags are not required
139 but the following information is required for each component.
140
141 flag (bits 2, 10, 11, 12)
142 glyph
143 args
144 scale
145 metric (glyph instance variable)
146
149 Creates a new glyph setting various instance variables
150
151 $g->read
152 Reads the header component of the glyph (numberOfContours and bounding
153 box) and also the glyph content, but into a data field rather than
154 breaking it down into its constituent structures. Use read_dat for
155 this.
156
157 $g->read_dat
158 Reads the contents of the glyph (components and curves, etc.) from the
159 memory store "DAT" into structures within the object.
160
161 $g->out($fh)
162 Writes the glyph data to outfile
163
164 $g->out_xml($context, $depth)
165 Outputs an XML description of the glyph
166
167 $g->dirty($val)
168 This sets the dirty flag to the given value or 1 if no given value. It
169 returns the value of the flag
170
171 $g->update
172 Generates a "$self-"{'DAT'}> from the internal structures, if the data
173 has been read into structures in the first place. If you are building a
174 glyph from scratch you will need to set the instance variable '
175 isDirty'.
176
177 $g->update_bbox
178 Updates the bounding box for this glyph according to the points in the
179 glyph
180
181 $g->maxInfo
182 Returns lots of information about a glyph so that the "maxp" table can
183 update itself. Returns array containing contributions of this glyph to
184 maxPoints, maxContours, maxCompositePoints, maxCompositeContours,
185 maxSizeOfInstructions, maxComponentElements, and maxComponentDepth.
186
187 $g->empty
188 Empties the glyph of all information to the level of not having been
189 read. Useful for saving memory in apps with many glyphs being read
190
191 $g->get_points
192 This method creates point information for a compound glyph. The
193 information is stored in the same place as if the glyph was not a
194 compound, but since numberOfContours is negative, the glyph is still
195 marked as being a compound
196
197 $g->get_refs
198 Returns an array of all the glyph ids that are used to make up this
199 glyph. That is all the compounds and their references and so on. If
200 this glyph is not a compound, then returns an empty array.
201
202 Please note the warning about bad fonts that reference nonexistant
203 glyphs under INSTANCE VARIABLES above. This function will not attempt
204 to filter out nonexistant glyph numbers.
205
207 · The instance variables used here are somewhat clunky and
208 inconsistent with the other tables.
209
210 · "update" doesn't re-calculate the bounding box or
211 "numberOfContours".
212
214 Martin Hosken Martin_Hosken@sil.org. See Font::TTF::Font for copyright
215 and licensing.
216
217
218
219perl v5.16.3 2012-08-08 Font::TTF::Glyph(3)