blob: 67d294011d91a2c972e81a7282a2dbd5c95045a6 [file] [log] [blame]
David Turnerd2b1f351999-12-16 23:11:37 +00001/***************************************************************************/
2/* */
3/* ttobjs.h */
4/* */
5/* Objects manager (specification). */
6/* */
Werner Lemberg78575dc2000-06-12 19:36:41 +00007/* Copyright 1996-2000 by */
David Turnerd2b1f351999-12-16 23:11:37 +00008/* David Turner, Robert Wilhelm, and Werner Lemberg. */
9/* */
Werner Lemberg78575dc2000-06-12 19:36:41 +000010/* This file is part of the FreeType project, and may only be used, */
11/* modified, and distributed under the terms of the FreeType project */
David Turnerd2b1f351999-12-16 23:11:37 +000012/* 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
Werner Lemberg90d99642000-12-09 00:45:38 +000019#ifndef __TTOBJS_H__
20#define __TTOBJS_H__
David Turnerd2b1f351999-12-16 23:11:37 +000021
Werner Lembergcc069be2000-12-08 16:17:16 +000022
David Turner19ed8af2000-12-08 02:42:29 +000023#include <ft2build.h>
24#include FT_INTERNAL_OBJECTS_H
25#include FT_INTERNAL_TRUETYPE_TYPES_H
26#include FT_INTERNAL_TRUETYPE_ERRORS_H
David Turnerd2b1f351999-12-16 23:11:37 +000027
Werner Lembergcc069be2000-12-08 16:17:16 +000028
David Turner19ed8af2000-12-08 02:42:29 +000029FT_BEGIN_HEADER
David Turnerd2b1f351999-12-16 23:11:37 +000030
31
32 /*************************************************************************/
33 /* */
34 /* <Type> */
35 /* TT_Driver */
36 /* */
37 /* <Description> */
38 /* A handle to a TrueType driver object. */
39 /* */
40 typedef struct TT_DriverRec_* TT_Driver;
41
42
43 /*************************************************************************/
44 /* */
45 /* <Type> */
46 /* TT_Instance */
47 /* */
48 /* <Description> */
49 /* A handle to a TrueType size object. */
50 /* */
51 typedef struct TT_SizeRec_* TT_Size;
52
53
54 /*************************************************************************/
55 /* */
56 /* <Type> */
57 /* TT_GlyphSlot */
58 /* */
59 /* <Description> */
60 /* A handle to a TrueType glyph slot object. */
61 /* */
62 /* <Note> */
63 /* This is a direct typedef of FT_GlyphSlot, as there is nothing */
64 /* specific about the TrueType glyph slot. */
65 /* */
66 typedef FT_GlyphSlot TT_GlyphSlot;
67
68
69 /*************************************************************************/
70 /* */
71 /* <Struct> */
72 /* TT_GraphicsState */
73 /* */
74 /* <Description> */
75 /* The TrueType graphics state used during bytecode interpretation. */
76 /* */
77 typedef struct TT_GraphicsState_
78 {
David Turnerf9b8dec2000-06-16 19:34:52 +000079 FT_UShort rp0;
80 FT_UShort rp1;
81 FT_UShort rp2;
David Turnerd2b1f351999-12-16 23:11:37 +000082
David Turnerf9b8dec2000-06-16 19:34:52 +000083 FT_UnitVector dualVector;
84 FT_UnitVector projVector;
85 FT_UnitVector freeVector;
David Turnerd2b1f351999-12-16 23:11:37 +000086
David Turnerf9b8dec2000-06-16 19:34:52 +000087 FT_Long loop;
88 FT_F26Dot6 minimum_distance;
89 FT_Int round_state;
David Turnerd2b1f351999-12-16 23:11:37 +000090
David Turnerf9b8dec2000-06-16 19:34:52 +000091 FT_Bool auto_flip;
92 FT_F26Dot6 control_value_cutin;
93 FT_F26Dot6 single_width_cutin;
94 FT_F26Dot6 single_width_value;
95 FT_Short delta_base;
96 FT_Short delta_shift;
David Turnerd2b1f351999-12-16 23:11:37 +000097
David Turnerf9b8dec2000-06-16 19:34:52 +000098 FT_Byte instruct_control;
99 FT_Bool scan_control;
100 FT_Int scan_type;
David Turnerd2b1f351999-12-16 23:11:37 +0000101
David Turnerf9b8dec2000-06-16 19:34:52 +0000102 FT_UShort gep0;
103 FT_UShort gep1;
104 FT_UShort gep2;
David Turnerd2b1f351999-12-16 23:11:37 +0000105
106 } TT_GraphicsState;
107
Werner Lemberg5811c7c2000-07-02 13:53:16 +0000108
Werner Lemberg321cd272000-07-27 11:20:20 +0000109#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
110
Werner Lembergdc72aff2000-11-04 08:33:38 +0000111 FT_LOCAL
112 void TT_Done_GlyphZone( TT_GlyphZone* zone );
David Turnerf9b8dec2000-06-16 19:34:52 +0000113
Werner Lembergdc72aff2000-11-04 08:33:38 +0000114 FT_LOCAL
115 FT_Error TT_New_GlyphZone( FT_Memory memory,
116 FT_UShort maxPoints,
117 FT_Short maxContours,
118 TT_GlyphZone* zone );
David Turnerf9b8dec2000-06-16 19:34:52 +0000119
Werner Lemberg321cd272000-07-27 11:20:20 +0000120#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
121
Werner Lemberg5811c7c2000-07-02 13:53:16 +0000122
David Turnerc5cdf8b2000-07-27 21:40:22 +0000123
David Turnerd2b1f351999-12-16 23:11:37 +0000124 /*************************************************************************/
125 /* */
126 /* EXECUTION SUBTABLES */
127 /* */
128 /* These sub-tables relate to instruction execution. */
129 /* */
130 /*************************************************************************/
131
132
133#define TT_MAX_CODE_RANGES 3
134
135
136 /*************************************************************************/
137 /* */
138 /* There can only be 3 active code ranges at once: */
139 /* - the Font Program */
140 /* - the CVT Program */
141 /* - a glyph's instructions set */
142 /* */
143 typedef enum TT_CodeRange_Tag_
144 {
145 tt_coderange_none = 0,
146 tt_coderange_font,
147 tt_coderange_cvt,
148 tt_coderange_glyph
149
150 } TT_CodeRange_Tag;
151
152
153 typedef struct TT_CodeRange_
154 {
David Turnerf9b8dec2000-06-16 19:34:52 +0000155 FT_Byte* base;
156 FT_ULong size;
David Turnerd2b1f351999-12-16 23:11:37 +0000157
158 } TT_CodeRange;
159
160 typedef TT_CodeRange TT_CodeRangeTable[TT_MAX_CODE_RANGES];
161
162
163 /*************************************************************************/
164 /* */
165 /* Defines a function/instruction definition record. */
166 /* */
167 typedef struct TT_DefRecord_
168 {
David Turnerf9b8dec2000-06-16 19:34:52 +0000169 FT_Int range; /* in which code range is it located? */
170 FT_Long start; /* where does it start? */
171 FT_UInt opc; /* function #, or instruction code */
172 FT_Bool active; /* is it active? */
David Turnerd2b1f351999-12-16 23:11:37 +0000173
174 } TT_DefRecord, *TT_DefArray;
175
176
David Turnerd2b1f351999-12-16 23:11:37 +0000177 /*************************************************************************/
178 /* */
179 /* Subglyph transformation record. */
180 /* */
181 typedef struct TT_Transform_
182 {
David Turnerf9b8dec2000-06-16 19:34:52 +0000183 FT_Fixed xx, xy; /* transformation matrix coefficients */
184 FT_Fixed yx, yy;
185 FT_F26Dot6 ox, oy; /* offsets */
David Turnerd2b1f351999-12-16 23:11:37 +0000186
187 } TT_Transform;
188
189
190 /*************************************************************************/
191 /* */
192 /* Subglyph loading record. Used to load composite components. */
193 /* */
194 typedef struct TT_SubglyphRec_
195 {
David Turnerf9b8dec2000-06-16 19:34:52 +0000196 FT_Long index; /* subglyph index; initialized with -1 */
197 FT_Bool is_scaled; /* is the subglyph scaled? */
198 FT_Bool is_hinted; /* should it be hinted? */
199 FT_Bool preserve_pps; /* preserve phantom points? */
David Turnerd2b1f351999-12-16 23:11:37 +0000200
David Turnerf9b8dec2000-06-16 19:34:52 +0000201 FT_Long file_offset;
David Turnerd2b1f351999-12-16 23:11:37 +0000202
David Turnerf9b8dec2000-06-16 19:34:52 +0000203 FT_BBox bbox;
204 FT_Pos left_bearing;
205 FT_Pos advance;
David Turnerd2b1f351999-12-16 23:11:37 +0000206
David Turnerf9b8dec2000-06-16 19:34:52 +0000207 TT_GlyphZone zone;
David Turnerd2b1f351999-12-16 23:11:37 +0000208
David Turnerf9b8dec2000-06-16 19:34:52 +0000209 FT_Long arg1; /* first argument */
210 FT_Long arg2; /* second argument */
David Turnerd2b1f351999-12-16 23:11:37 +0000211
David Turnerf9b8dec2000-06-16 19:34:52 +0000212 FT_UShort element_flag; /* current load element flag */
David Turnerd2b1f351999-12-16 23:11:37 +0000213
214 TT_Transform transform; /* transformation matrix */
215
David Turnerf9b8dec2000-06-16 19:34:52 +0000216 FT_Vector pp1, pp2; /* phantom points */
David Turnerd2b1f351999-12-16 23:11:37 +0000217
218 } TT_SubGlyphRec, *TT_SubGlyph_Stack;
219
220
221 /*************************************************************************/
222 /* */
223 /* A note regarding non-squared pixels: */
224 /* */
Werner Lemberg78575dc2000-06-12 19:36:41 +0000225 /* (This text will probably go into some docs at some time; for now, it */
David Turnerd2b1f351999-12-16 23:11:37 +0000226 /* is kept here to explain some definitions in the TIns_Metrics */
227 /* record). */
228 /* */
229 /* The CVT is a one-dimensional array containing values that control */
230 /* certain important characteristics in a font, like the height of all */
231 /* capitals, all lowercase letter, default spacing or stem width/height. */
232 /* */
233 /* These values are found in FUnits in the font file, and must be scaled */
234 /* to pixel coordinates before being used by the CVT and glyph programs. */
235 /* Unfortunately, when using distinct x and y resolutions (or distinct x */
236 /* and y pointsizes), there are two possible scalings. */
237 /* */
238 /* A first try was to implement a `lazy' scheme where all values were */
239 /* scaled when first used. However, while some values are always used */
240 /* in the same direction, some others are used under many different */
241 /* circumstances and orientations. */
242 /* */
243 /* I have found a simpler way to do the same, and it even seems to work */
244 /* in most of the cases: */
245 /* */
246 /* - All CVT values are scaled to the maximum ppem size. */
247 /* */
248 /* - When performing a read or write in the CVT, a ratio factor is used */
249 /* to perform adequate scaling. Example: */
250 /* */
251 /* x_ppem = 14 */
252 /* y_ppem = 10 */
253 /* */
254 /* We choose ppem = x_ppem = 14 as the CVT scaling size. All cvt */
255 /* entries are scaled to it. */
256 /* */
257 /* x_ratio = 1.0 */
258 /* y_ratio = y_ppem/ppem (< 1.0) */
259 /* */
260 /* We compute the current ratio like: */
261 /* */
262 /* - If projVector is horizontal, */
263 /* ratio = x_ratio = 1.0 */
264 /* */
265 /* - if projVector is vertical, */
266 /* ratio = y_ratio */
267 /* */
268 /* - else, */
269 /* ratio = sqrt( (proj.x * x_ratio) ^ 2 + (proj.y * y_ratio) ^ 2 ) */
270 /* */
271 /* Reading a cvt value returns */
272 /* ratio * cvt[index] */
273 /* */
274 /* Writing a cvt value in pixels: */
275 /* cvt[index] / ratio */
276 /* */
277 /* The current ppem is simply */
278 /* ratio * ppem */
279 /* */
280 /*************************************************************************/
281
282
283 /*************************************************************************/
284 /* */
285 /* Metrics used by the TrueType size and context objects. */
286 /* */
287 typedef struct TT_Size_Metrics_
288 {
289 /* for non-square pixels */
David Turnerf9b8dec2000-06-16 19:34:52 +0000290 FT_Long x_ratio;
291 FT_Long y_ratio;
David Turnerd2b1f351999-12-16 23:11:37 +0000292
David Turnerf9b8dec2000-06-16 19:34:52 +0000293 FT_UShort ppem; /* maximum ppem size */
294 FT_Long ratio; /* current ratio */
295 FT_Fixed scale;
David Turnerd2b1f351999-12-16 23:11:37 +0000296
David Turnerf9b8dec2000-06-16 19:34:52 +0000297 FT_F26Dot6 compensations[4]; /* device-specific compensations */
David Turnerd2b1f351999-12-16 23:11:37 +0000298
David Turnerf9b8dec2000-06-16 19:34:52 +0000299 FT_Bool valid;
David Turnerd2b1f351999-12-16 23:11:37 +0000300
David Turnerf9b8dec2000-06-16 19:34:52 +0000301 FT_Bool rotated; /* `is the glyph rotated?'-flag */
302 FT_Bool stretched; /* `is the glyph stretched?'-flag */
David Turnerd2b1f351999-12-16 23:11:37 +0000303
304 } TT_Size_Metrics;
305
306
Werner Lemberg5811c7c2000-07-02 13:53:16 +0000307 /*************************************************************************/
308 /* */
309 /* TrueType size class. */
310 /* */
David Turnerd2b1f351999-12-16 23:11:37 +0000311 typedef struct TT_SizeRec_
312 {
313 FT_SizeRec root;
314
315 TT_Size_Metrics ttmetrics;
316
David Turnerf96594f2000-11-06 23:07:51 +0000317#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
Werner Lemberg4b680072000-11-07 06:30:29 +0000318
319 FT_UInt strike_index; /* 0xFFFF to indicate invalid */
320 FT_Size_Metrics strike_metrics; /* current strike's metrics */
321
David Turnerf96594f2000-11-06 23:07:51 +0000322#endif
323
David Turner8f43c712000-02-02 12:16:19 +0000324#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
Werner Lemberg78575dc2000-06-12 19:36:41 +0000325
David Turnerf9b8dec2000-06-16 19:34:52 +0000326 FT_UInt num_function_defs; /* number of function definitions */
327 FT_UInt max_function_defs;
David Turnerd2b1f351999-12-16 23:11:37 +0000328 TT_DefArray function_defs; /* table of function definitions */
329
David Turnerf9b8dec2000-06-16 19:34:52 +0000330 FT_UInt num_instruction_defs; /* number of ins. definitions */
331 FT_UInt max_instruction_defs;
David Turnerd2b1f351999-12-16 23:11:37 +0000332 TT_DefArray instruction_defs; /* table of ins. definitions */
333
David Turnerf9b8dec2000-06-16 19:34:52 +0000334 FT_UInt max_func;
335 FT_UInt max_ins;
David Turnerd2b1f351999-12-16 23:11:37 +0000336
337 TT_CodeRangeTable codeRangeTable;
338
339 TT_GraphicsState GS;
340
David Turnerf9b8dec2000-06-16 19:34:52 +0000341 FT_ULong cvt_size; /* the scaled control value table */
342 FT_Long* cvt;
David Turnerd2b1f351999-12-16 23:11:37 +0000343
David Turnerf9b8dec2000-06-16 19:34:52 +0000344 FT_UShort storage_size; /* The storage area is now part of */
345 FT_Long* storage; /* the instance */
David Turnerd2b1f351999-12-16 23:11:37 +0000346
David Turnerf9b8dec2000-06-16 19:34:52 +0000347 TT_GlyphZone twilight; /* The instance's twilight zone */
David Turnerd2b1f351999-12-16 23:11:37 +0000348
349 /* debugging variables */
350
351 /* When using the debugger, we must keep the */
352 /* execution context tied to the instance */
353 /* object rather than asking it on demand. */
354
David Turnerf9b8dec2000-06-16 19:34:52 +0000355 FT_Bool debug;
David Turnerd2b1f351999-12-16 23:11:37 +0000356 TT_ExecContext context;
357
David Turner8f43c712000-02-02 12:16:19 +0000358#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */
359
David Turnerd2b1f351999-12-16 23:11:37 +0000360 } TT_SizeRec;
361
362
Werner Lemberg5811c7c2000-07-02 13:53:16 +0000363 /*************************************************************************/
364 /* */
365 /* TrueType driver class. */
366 /* */
David Turnerd2b1f351999-12-16 23:11:37 +0000367 typedef struct TT_DriverRec_
368 {
369 FT_DriverRec root;
David Turner08fdac92000-02-21 16:01:33 +0000370 TT_ExecContext context; /* execution context */
David Turnerf9b8dec2000-06-16 19:34:52 +0000371 TT_GlyphZone zone; /* glyph loader points zone */
David Turnerd2b1f351999-12-16 23:11:37 +0000372
373 void* extension_component;
374
375 } TT_DriverRec;
376
377
Werner Lemberg78575dc2000-06-12 19:36:41 +0000378 /*************************************************************************/
379 /* */
380 /* Face functions */
381 /* */
David Turner76a5f622000-11-04 01:55:49 +0000382 FT_LOCAL
David Turnerf9b8dec2000-06-16 19:34:52 +0000383 FT_Error TT_Init_Face( FT_Stream stream,
Werner Lemberg78575dc2000-06-12 19:36:41 +0000384 TT_Face face,
David Turnerf9b8dec2000-06-16 19:34:52 +0000385 FT_Int face_index,
386 FT_Int num_params,
Werner Lemberg78575dc2000-06-12 19:36:41 +0000387 FT_Parameter* params );
David Turner08fdac92000-02-21 16:01:33 +0000388
David Turner76a5f622000-11-04 01:55:49 +0000389 FT_LOCAL
Werner Lemberg78575dc2000-06-12 19:36:41 +0000390 void TT_Done_Face( TT_Face face );
David Turnerd2b1f351999-12-16 23:11:37 +0000391
392
Werner Lemberg78575dc2000-06-12 19:36:41 +0000393 /*************************************************************************/
394 /* */
395 /* Size functions */
396 /* */
David Turner76a5f622000-11-04 01:55:49 +0000397 FT_LOCAL
David Turnerf9b8dec2000-06-16 19:34:52 +0000398 FT_Error TT_Init_Size( TT_Size size );
David Turner08fdac92000-02-21 16:01:33 +0000399
David Turner76a5f622000-11-04 01:55:49 +0000400 FT_LOCAL
Werner Lemberg78575dc2000-06-12 19:36:41 +0000401 void TT_Done_Size( TT_Size size );
402
David Turner76a5f622000-11-04 01:55:49 +0000403 FT_LOCAL
David Turnerf9b8dec2000-06-16 19:34:52 +0000404 FT_Error TT_Reset_Size( TT_Size size );
David Turnerd2b1f351999-12-16 23:11:37 +0000405
406
Werner Lemberg78575dc2000-06-12 19:36:41 +0000407 /*************************************************************************/
408 /* */
Werner Lemberg78575dc2000-06-12 19:36:41 +0000409 /* Driver functions */
410 /* */
David Turner76a5f622000-11-04 01:55:49 +0000411 FT_LOCAL
David Turnerf9b8dec2000-06-16 19:34:52 +0000412 FT_Error TT_Init_Driver( TT_Driver driver );
David Turnerd2b1f351999-12-16 23:11:37 +0000413
David Turner76a5f622000-11-04 01:55:49 +0000414 FT_LOCAL
Werner Lemberg78575dc2000-06-12 19:36:41 +0000415 void TT_Done_Driver( TT_Driver driver );
David Turnerd2b1f351999-12-16 23:11:37 +0000416
Werner Lemberg5811c7c2000-07-02 13:53:16 +0000417
David Turner19ed8af2000-12-08 02:42:29 +0000418FT_END_HEADER
David Turnerd2b1f351999-12-16 23:11:37 +0000419
Werner Lemberg90d99642000-12-09 00:45:38 +0000420#endif /* __TTOBJS_H__ */
David Turnerd2b1f351999-12-16 23:11:37 +0000421
422
423/* END */