]> git.saurik.com Git - wxWidgets.git/blob - src/freetype/truetype/ttobjs.h
wxDC::SetFont can now handle invalid font and doesn't assert anymore (other ports...
[wxWidgets.git] / src / freetype / truetype / ttobjs.h
1 /***************************************************************************/
2 /* */
3 /* ttobjs.h */
4 /* */
5 /* Objects manager (specification). */
6 /* */
7 /* Copyright 1996-2000 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
9 /* */
10 /* This file is part of the FreeType project, and may only be used, */
11 /* modified, and distributed under the terms of the FreeType project */
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
13 /* this file you indicate that you have read the license and */
14 /* understand and accept it fully. */
15 /* */
16 /***************************************************************************/
17
18
19 #ifndef TTOBJS_H
20 #define TTOBJS_H
21
22
23 #include <freetype/internal/ftobjs.h>
24 #include <freetype/internal/tttypes.h>
25 #include <freetype/internal/tterrors.h>
26
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32
33 /*************************************************************************/
34 /* */
35 /* <Type> */
36 /* TT_Driver */
37 /* */
38 /* <Description> */
39 /* A handle to a TrueType driver object. */
40 /* */
41 typedef struct TT_DriverRec_* TT_Driver;
42
43
44 /*************************************************************************/
45 /* */
46 /* <Type> */
47 /* TT_Instance */
48 /* */
49 /* <Description> */
50 /* A handle to a TrueType size object. */
51 /* */
52 typedef struct TT_SizeRec_* TT_Size;
53
54
55 /*************************************************************************/
56 /* */
57 /* <Type> */
58 /* TT_GlyphSlot */
59 /* */
60 /* <Description> */
61 /* A handle to a TrueType glyph slot object. */
62 /* */
63 /* <Note> */
64 /* This is a direct typedef of FT_GlyphSlot, as there is nothing */
65 /* specific about the TrueType glyph slot. */
66 /* */
67 typedef FT_GlyphSlot TT_GlyphSlot;
68
69
70 /*************************************************************************/
71 /* */
72 /* <Struct> */
73 /* TT_GraphicsState */
74 /* */
75 /* <Description> */
76 /* The TrueType graphics state used during bytecode interpretation. */
77 /* */
78 typedef struct TT_GraphicsState_
79 {
80 FT_UShort rp0;
81 FT_UShort rp1;
82 FT_UShort rp2;
83
84 FT_UnitVector dualVector;
85 FT_UnitVector projVector;
86 FT_UnitVector freeVector;
87
88 FT_Long loop;
89 FT_F26Dot6 minimum_distance;
90 FT_Int round_state;
91
92 FT_Bool auto_flip;
93 FT_F26Dot6 control_value_cutin;
94 FT_F26Dot6 single_width_cutin;
95 FT_F26Dot6 single_width_value;
96 FT_Short delta_base;
97 FT_Short delta_shift;
98
99 FT_Byte instruct_control;
100 FT_Bool scan_control;
101 FT_Int scan_type;
102
103 FT_UShort gep0;
104 FT_UShort gep1;
105 FT_UShort gep2;
106
107 } TT_GraphicsState;
108
109
110 LOCAL_DEF void TT_Done_GlyphZone( TT_GlyphZone* zone );
111
112 LOCAL_DEF FT_Error TT_New_GlyphZone( FT_Memory memory,
113 FT_UShort maxPoints,
114 FT_Short maxContours,
115 TT_GlyphZone* zone );
116
117
118 /*************************************************************************/
119 /* */
120 /* EXECUTION SUBTABLES */
121 /* */
122 /* These sub-tables relate to instruction execution. */
123 /* */
124 /*************************************************************************/
125
126
127 #define TT_MAX_CODE_RANGES 3
128
129
130 /*************************************************************************/
131 /* */
132 /* There can only be 3 active code ranges at once: */
133 /* - the Font Program */
134 /* - the CVT Program */
135 /* - a glyph's instructions set */
136 /* */
137 typedef enum TT_CodeRange_Tag_
138 {
139 tt_coderange_none = 0,
140 tt_coderange_font,
141 tt_coderange_cvt,
142 tt_coderange_glyph
143
144 } TT_CodeRange_Tag;
145
146
147 typedef struct TT_CodeRange_
148 {
149 FT_Byte* base;
150 FT_ULong size;
151
152 } TT_CodeRange;
153
154 typedef TT_CodeRange TT_CodeRangeTable[TT_MAX_CODE_RANGES];
155
156
157 /*************************************************************************/
158 /* */
159 /* Defines a function/instruction definition record. */
160 /* */
161 typedef struct TT_DefRecord_
162 {
163 FT_Int range; /* in which code range is it located? */
164 FT_Long start; /* where does it start? */
165 FT_UInt opc; /* function #, or instruction code */
166 FT_Bool active; /* is it active? */
167
168 } TT_DefRecord, *TT_DefArray;
169
170
171 /*************************************************************************/
172 /* */
173 /* Subglyph transformation record. */
174 /* */
175 typedef struct TT_Transform_
176 {
177 FT_Fixed xx, xy; /* transformation matrix coefficients */
178 FT_Fixed yx, yy;
179 FT_F26Dot6 ox, oy; /* offsets */
180
181 } TT_Transform;
182
183
184 /*************************************************************************/
185 /* */
186 /* Subglyph loading record. Used to load composite components. */
187 /* */
188 typedef struct TT_SubglyphRec_
189 {
190 FT_Long index; /* subglyph index; initialized with -1 */
191 FT_Bool is_scaled; /* is the subglyph scaled? */
192 FT_Bool is_hinted; /* should it be hinted? */
193 FT_Bool preserve_pps; /* preserve phantom points? */
194
195 FT_Long file_offset;
196
197 FT_BBox bbox;
198 FT_Pos left_bearing;
199 FT_Pos advance;
200
201 TT_GlyphZone zone;
202
203 FT_Long arg1; /* first argument */
204 FT_Long arg2; /* second argument */
205
206 FT_UShort element_flag; /* current load element flag */
207
208 TT_Transform transform; /* transformation matrix */
209
210 FT_Vector pp1, pp2; /* phantom points */
211
212 } TT_SubGlyphRec, *TT_SubGlyph_Stack;
213
214
215 /*************************************************************************/
216 /* */
217 /* A note regarding non-squared pixels: */
218 /* */
219 /* (This text will probably go into some docs at some time; for now, it */
220 /* is kept here to explain some definitions in the TIns_Metrics */
221 /* record). */
222 /* */
223 /* The CVT is a one-dimensional array containing values that control */
224 /* certain important characteristics in a font, like the height of all */
225 /* capitals, all lowercase letter, default spacing or stem width/height. */
226 /* */
227 /* These values are found in FUnits in the font file, and must be scaled */
228 /* to pixel coordinates before being used by the CVT and glyph programs. */
229 /* Unfortunately, when using distinct x and y resolutions (or distinct x */
230 /* and y pointsizes), there are two possible scalings. */
231 /* */
232 /* A first try was to implement a `lazy' scheme where all values were */
233 /* scaled when first used. However, while some values are always used */
234 /* in the same direction, some others are used under many different */
235 /* circumstances and orientations. */
236 /* */
237 /* I have found a simpler way to do the same, and it even seems to work */
238 /* in most of the cases: */
239 /* */
240 /* - All CVT values are scaled to the maximum ppem size. */
241 /* */
242 /* - When performing a read or write in the CVT, a ratio factor is used */
243 /* to perform adequate scaling. Example: */
244 /* */
245 /* x_ppem = 14 */
246 /* y_ppem = 10 */
247 /* */
248 /* We choose ppem = x_ppem = 14 as the CVT scaling size. All cvt */
249 /* entries are scaled to it. */
250 /* */
251 /* x_ratio = 1.0 */
252 /* y_ratio = y_ppem/ppem (< 1.0) */
253 /* */
254 /* We compute the current ratio like: */
255 /* */
256 /* - If projVector is horizontal, */
257 /* ratio = x_ratio = 1.0 */
258 /* */
259 /* - if projVector is vertical, */
260 /* ratio = y_ratio */
261 /* */
262 /* - else, */
263 /* ratio = sqrt( (proj.x * x_ratio) ^ 2 + (proj.y * y_ratio) ^ 2 ) */
264 /* */
265 /* Reading a cvt value returns */
266 /* ratio * cvt[index] */
267 /* */
268 /* Writing a cvt value in pixels: */
269 /* cvt[index] / ratio */
270 /* */
271 /* The current ppem is simply */
272 /* ratio * ppem */
273 /* */
274 /*************************************************************************/
275
276
277 /*************************************************************************/
278 /* */
279 /* Metrics used by the TrueType size and context objects. */
280 /* */
281 typedef struct TT_Size_Metrics_
282 {
283 /* for non-square pixels */
284 FT_Long x_ratio;
285 FT_Long y_ratio;
286
287 FT_UShort ppem; /* maximum ppem size */
288 FT_Long ratio; /* current ratio */
289 FT_Fixed scale;
290
291 FT_F26Dot6 compensations[4]; /* device-specific compensations */
292
293 FT_Bool valid;
294
295 FT_Bool rotated; /* `is the glyph rotated?'-flag */
296 FT_Bool stretched; /* `is the glyph stretched?'-flag */
297
298 } TT_Size_Metrics;
299
300
301 /*************************************************************************/
302 /* */
303 /* TrueType size class. */
304 /* */
305 typedef struct TT_SizeRec_
306 {
307 FT_SizeRec root;
308
309 TT_Size_Metrics ttmetrics;
310
311 #ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
312
313 FT_UInt num_function_defs; /* number of function definitions */
314 FT_UInt max_function_defs;
315 TT_DefArray function_defs; /* table of function definitions */
316
317 FT_UInt num_instruction_defs; /* number of ins. definitions */
318 FT_UInt max_instruction_defs;
319 TT_DefArray instruction_defs; /* table of ins. definitions */
320
321 FT_UInt max_func;
322 FT_UInt max_ins;
323
324 TT_CodeRangeTable codeRangeTable;
325
326 TT_GraphicsState GS;
327
328 FT_ULong cvt_size; /* the scaled control value table */
329 FT_Long* cvt;
330
331 FT_UShort storage_size; /* The storage area is now part of */
332 FT_Long* storage; /* the instance */
333
334 TT_GlyphZone twilight; /* The instance's twilight zone */
335
336 /* debugging variables */
337
338 /* When using the debugger, we must keep the */
339 /* execution context tied to the instance */
340 /* object rather than asking it on demand. */
341
342 FT_Bool debug;
343 TT_ExecContext context;
344
345 #endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
346
347 } TT_SizeRec;
348
349
350 /*************************************************************************/
351 /* */
352 /* TrueType driver class. */
353 /* */
354 typedef struct TT_DriverRec_
355 {
356 FT_DriverRec root;
357 TT_ExecContext context; /* execution context */
358 TT_GlyphZone zone; /* glyph loader points zone */
359
360 void* extension_component;
361
362 } TT_DriverRec;
363
364
365 /*************************************************************************/
366 /* */
367 /* Face functions */
368 /* */
369 LOCAL_DEF
370 FT_Error TT_Init_Face( FT_Stream stream,
371 TT_Face face,
372 FT_Int face_index,
373 FT_Int num_params,
374 FT_Parameter* params );
375
376 LOCAL_DEF
377 void TT_Done_Face( TT_Face face );
378
379
380 /*************************************************************************/
381 /* */
382 /* Size functions */
383 /* */
384 LOCAL_DEF
385 FT_Error TT_Init_Size( TT_Size size );
386
387 LOCAL_DEF
388 void TT_Done_Size( TT_Size size );
389
390 LOCAL_DEF
391 FT_Error TT_Reset_Size( TT_Size size );
392
393
394 /*************************************************************************/
395 /* */
396 /* Driver functions */
397 /* */
398 LOCAL_DEF
399 FT_Error TT_Init_Driver( TT_Driver driver );
400
401 LOCAL_DEF
402 void TT_Done_Driver( TT_Driver driver );
403
404
405 #ifdef __cplusplus
406 }
407 #endif
408
409 #endif /* TTOBJS_H */
410
411
412 /* END */