ttobjs.h 18.5 KB
Newer Older
David Turner's avatar
David Turner committed
1
2
3
4
5
6
/***************************************************************************/
/*                                                                         */
/*  ttobjs.h                                                               */
/*                                                                         */
/*    Objects manager (specification).                                     */
/*                                                                         */
Werner Lemberg's avatar
Werner Lemberg committed
7
/*  Copyright 1996-2001, 2002, 2003 by                                     */
David Turner's avatar
David Turner committed
8
9
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
/*                                                                         */
Werner Lemberg's avatar
   
Werner Lemberg committed
10
11
/*  This file is part of the FreeType project, and may only be used,       */
/*  modified, and distributed under the terms of the FreeType project      */
David Turner's avatar
David Turner committed
12
13
14
15
16
17
18
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
/*  this file you indicate that you have read the license and              */
/*  understand and accept it fully.                                        */
/*                                                                         */
/***************************************************************************/


19
20
#ifndef __TTOBJS_H__
#define __TTOBJS_H__
David Turner's avatar
David Turner committed
21

Werner Lemberg's avatar
   
Werner Lemberg committed
22

23
24
25
#include <ft2build.h>
#include FT_INTERNAL_OBJECTS_H
#include FT_INTERNAL_TRUETYPE_TYPES_H
David Turner's avatar
David Turner committed
26

Werner Lemberg's avatar
   
Werner Lemberg committed
27

28
FT_BEGIN_HEADER
David Turner's avatar
David Turner committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77


  /*************************************************************************/
  /*                                                                       */
  /* <Type>                                                                */
  /*    TT_Driver                                                          */
  /*                                                                       */
  /* <Description>                                                         */
  /*    A handle to a TrueType driver object.                              */
  /*                                                                       */
  typedef struct TT_DriverRec_*  TT_Driver;


  /*************************************************************************/
  /*                                                                       */
  /* <Type>                                                                */
  /*    TT_Instance                                                        */
  /*                                                                       */
  /* <Description>                                                         */
  /*    A handle to a TrueType size object.                                */
  /*                                                                       */
  typedef struct TT_SizeRec_*  TT_Size;


  /*************************************************************************/
  /*                                                                       */
  /* <Type>                                                                */
  /*    TT_GlyphSlot                                                       */
  /*                                                                       */
  /* <Description>                                                         */
  /*    A handle to a TrueType glyph slot object.                          */
  /*                                                                       */
  /* <Note>                                                                */
  /*    This is a direct typedef of FT_GlyphSlot, as there is nothing      */
  /*    specific about the TrueType glyph slot.                            */
  /*                                                                       */
  typedef FT_GlyphSlot  TT_GlyphSlot;


  /*************************************************************************/
  /*                                                                       */
  /* <Struct>                                                              */
  /*    TT_GraphicsState                                                   */
  /*                                                                       */
  /* <Description>                                                         */
  /*    The TrueType graphics state used during bytecode interpretation.   */
  /*                                                                       */
  typedef struct  TT_GraphicsState_
  {
78
79
80
    FT_UShort      rp0;
    FT_UShort      rp1;
    FT_UShort      rp2;
David Turner's avatar
David Turner committed
81

82
83
84
    FT_UnitVector  dualVector;
    FT_UnitVector  projVector;
    FT_UnitVector  freeVector;
David Turner's avatar
David Turner committed
85

86
#ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING
87
88
89
    FT_Bool        both_x_axis;
#endif

90
91
92
    FT_Long        loop;
    FT_F26Dot6     minimum_distance;
    FT_Int         round_state;
David Turner's avatar
David Turner committed
93

94
95
96
97
98
99
    FT_Bool        auto_flip;
    FT_F26Dot6     control_value_cutin;
    FT_F26Dot6     single_width_cutin;
    FT_F26Dot6     single_width_value;
    FT_Short       delta_base;
    FT_Short       delta_shift;
David Turner's avatar
David Turner committed
100

101
102
103
    FT_Byte        instruct_control;
    FT_Bool        scan_control;
    FT_Int         scan_type;
David Turner's avatar
David Turner committed
104

105
106
107
    FT_UShort      gep0;
    FT_UShort      gep1;
    FT_UShort      gep2;
David Turner's avatar
David Turner committed
108
109
110

  } TT_GraphicsState;

Werner Lemberg's avatar
   
Werner Lemberg committed
111

Werner Lemberg's avatar
   
Werner Lemberg committed
112
113
#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER

114
  FT_LOCAL( void )
115
  tt_glyphzone_done( TT_GlyphZone  zone );
Werner Lemberg's avatar
   
Werner Lemberg committed
116

117
  FT_LOCAL( FT_Error )
118
  tt_glyphzone_new( FT_Memory     memory,
Werner Lemberg's avatar
   
Werner Lemberg committed
119
120
121
                    FT_UShort     maxPoints,
                    FT_Short      maxContours,
                    TT_GlyphZone  zone );
122

Werner Lemberg's avatar
   
Werner Lemberg committed
123
124
#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */

Werner Lemberg's avatar
   
Werner Lemberg committed
125

126

David Turner's avatar
David Turner committed
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
  /*************************************************************************/
  /*                                                                       */
  /*  EXECUTION SUBTABLES                                                  */
  /*                                                                       */
  /*  These sub-tables relate to instruction execution.                    */
  /*                                                                       */
  /*************************************************************************/


#define TT_MAX_CODE_RANGES  3


  /*************************************************************************/
  /*                                                                       */
  /* There can only be 3 active code ranges at once:                       */
  /*   - the Font Program                                                  */
  /*   - the CVT Program                                                   */
  /*   - a glyph's instructions set                                        */
  /*                                                                       */
  typedef enum  TT_CodeRange_Tag_
  {
    tt_coderange_none = 0,
    tt_coderange_font,
    tt_coderange_cvt,
    tt_coderange_glyph

  } TT_CodeRange_Tag;


  typedef struct  TT_CodeRange_
  {
158
159
    FT_Byte*  base;
    FT_ULong  size;
David Turner's avatar
David Turner committed
160
161
162
163
164
165
166
167
168
169
170
171

  } TT_CodeRange;

  typedef TT_CodeRange  TT_CodeRangeTable[TT_MAX_CODE_RANGES];


  /*************************************************************************/
  /*                                                                       */
  /* Defines a function/instruction definition record.                     */
  /*                                                                       */
  typedef struct  TT_DefRecord_
  {
172
173
174
175
    FT_Int   range;      /* in which code range is it located? */
    FT_Long  start;      /* where does it start?               */
    FT_UInt  opc;        /* function #, or instruction code    */
    FT_Bool  active;     /* is it active?                      */
David Turner's avatar
David Turner committed
176
177
178
179
180
181
182
183
184
185

  } TT_DefRecord, *TT_DefArray;


  /*************************************************************************/
  /*                                                                       */
  /* Subglyph transformation record.                                       */
  /*                                                                       */
  typedef struct  TT_Transform_
  {
186
187
188
    FT_Fixed    xx, xy;     /* transformation matrix coefficients */
    FT_Fixed    yx, yy;
    FT_F26Dot6  ox, oy;     /* offsets        */
David Turner's avatar
David Turner committed
189
190
191
192
193
194
195
196
197
198

  } TT_Transform;


  /*************************************************************************/
  /*                                                                       */
  /* Subglyph loading record.  Used to load composite components.          */
  /*                                                                       */
  typedef struct  TT_SubglyphRec_
  {
Werner Lemberg's avatar
   
Werner Lemberg committed
199
200
201
202
    FT_Long          index;        /* subglyph index; initialized with -1 */
    FT_Bool          is_scaled;    /* is the subglyph scaled?             */
    FT_Bool          is_hinted;    /* should it be hinted?                */
    FT_Bool          preserve_pps; /* preserve phantom points?            */
David Turner's avatar
David Turner committed
203

Werner Lemberg's avatar
   
Werner Lemberg committed
204
    FT_Long          file_offset;
David Turner's avatar
David Turner committed
205

Werner Lemberg's avatar
   
Werner Lemberg committed
206
207
208
    FT_BBox          bbox;
    FT_Pos           left_bearing;
    FT_Pos           advance;
David Turner's avatar
David Turner committed
209

210
    TT_GlyphZoneRec  zone;
David Turner's avatar
David Turner committed
211

Werner Lemberg's avatar
   
Werner Lemberg committed
212
213
    FT_Long          arg1;         /* first argument                      */
    FT_Long          arg2;         /* second argument                     */
David Turner's avatar
David Turner committed
214

Werner Lemberg's avatar
   
Werner Lemberg committed
215
    FT_UShort        element_flag; /* current load element flag           */
David Turner's avatar
David Turner committed
216

Werner Lemberg's avatar
   
Werner Lemberg committed
217
    TT_Transform     transform;    /* transformation matrix               */
David Turner's avatar
David Turner committed
218

Werner Lemberg's avatar
   
Werner Lemberg committed
219
    FT_Vector        pp1, pp2;     /* phantom points                      */
David Turner's avatar
David Turner committed
220
221
222
223
224
225
226
227

  } TT_SubGlyphRec, *TT_SubGlyph_Stack;


  /*************************************************************************/
  /*                                                                       */
  /* A note regarding non-squared pixels:                                  */
  /*                                                                       */
Werner Lemberg's avatar
   
Werner Lemberg committed
228
  /* (This text will probably go into some docs at some time; for now, it  */
David Turner's avatar
David Turner committed
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
  /*  is kept here to explain some definitions in the TIns_Metrics         */
  /*  record).                                                             */
  /*                                                                       */
  /* The CVT is a one-dimensional array containing values that control     */
  /* certain important characteristics in a font, like the height of all   */
  /* capitals, all lowercase letter, default spacing or stem width/height. */
  /*                                                                       */
  /* These values are found in FUnits in the font file, and must be scaled */
  /* to pixel coordinates before being used by the CVT and glyph programs. */
  /* Unfortunately, when using distinct x and y resolutions (or distinct x */
  /* and y pointsizes), there are two possible scalings.                   */
  /*                                                                       */
  /* A first try was to implement a `lazy' scheme where all values were    */
  /* scaled when first used.  However, while some values are always used   */
  /* in the same direction, some others are used under many different      */
  /* circumstances and orientations.                                       */
  /*                                                                       */
  /* I have found a simpler way to do the same, and it even seems to work  */
  /* in most of the cases:                                                 */
  /*                                                                       */
  /* - All CVT values are scaled to the maximum ppem size.                 */
  /*                                                                       */
  /* - When performing a read or write in the CVT, a ratio factor is used  */
  /*   to perform adequate scaling.  Example:                              */
  /*                                                                       */
  /*     x_ppem = 14                                                       */
  /*     y_ppem = 10                                                       */
  /*                                                                       */
  /*   We choose ppem = x_ppem = 14 as the CVT scaling size.  All cvt      */
  /*   entries are scaled to it.                                           */
  /*                                                                       */
  /*     x_ratio = 1.0                                                     */
  /*     y_ratio = y_ppem/ppem (< 1.0)                                     */
  /*                                                                       */
  /*   We compute the current ratio like:                                  */
  /*                                                                       */
  /*   - If projVector is horizontal,                                      */
  /*       ratio = x_ratio = 1.0                                           */
  /*                                                                       */
  /*   - if projVector is vertical,                                        */
  /*       ratio = y_ratio                                                 */
  /*                                                                       */
  /*   - else,                                                             */
  /*       ratio = sqrt( (proj.x * x_ratio) ^ 2 + (proj.y * y_ratio) ^ 2 ) */
  /*                                                                       */
  /*   Reading a cvt value returns                                         */
  /*     ratio * cvt[index]                                                */
  /*                                                                       */
  /*   Writing a cvt value in pixels:                                      */
  /*     cvt[index] / ratio                                                */
  /*                                                                       */
  /*   The current ppem is simply                                          */
  /*     ratio * ppem                                                      */
  /*                                                                       */
  /*************************************************************************/


  /*************************************************************************/
  /*                                                                       */
  /* Metrics used by the TrueType size and context objects.                */
  /*                                                                       */
  typedef struct  TT_Size_Metrics_
  {
    /* for non-square pixels */
293
294
    FT_Long     x_ratio;
    FT_Long     y_ratio;
David Turner's avatar
David Turner committed
295

296
297
298
    FT_UShort   ppem;               /* maximum ppem size              */
    FT_Long     ratio;              /* current ratio                  */
    FT_Fixed    scale;
David Turner's avatar
David Turner committed
299

300
    FT_F26Dot6  compensations[4];   /* device-specific compensations  */
David Turner's avatar
David Turner committed
301

302
    FT_Bool     valid;
David Turner's avatar
David Turner committed
303

304
305
    FT_Bool     rotated;            /* `is the glyph rotated?'-flag   */
    FT_Bool     stretched;          /* `is the glyph stretched?'-flag */
David Turner's avatar
David Turner committed
306
307
308
309

  } TT_Size_Metrics;


Werner Lemberg's avatar
   
Werner Lemberg committed
310
311
312
313
  /*************************************************************************/
  /*                                                                       */
  /* TrueType size class.                                                  */
  /*                                                                       */
David Turner's avatar
David Turner committed
314
315
316
317
  typedef struct  TT_SizeRec_
  {
    FT_SizeRec         root;

Werner Lemberg's avatar
Werner Lemberg committed
318
    FT_Size_Metrics    metrics; /* slightly different from the root metrics */
David Turner's avatar
David Turner committed
319
320
    TT_Size_Metrics    ttmetrics;

321
#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS
Werner Lemberg's avatar
   
Werner Lemberg committed
322
323
324
325

    FT_UInt            strike_index;    /* 0xFFFF to indicate invalid */
    FT_Size_Metrics    strike_metrics;  /* current strike's metrics   */

326
327
#endif

328
#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
Werner Lemberg's avatar
   
Werner Lemberg committed
329

330
331
    FT_UInt            num_function_defs; /* number of function definitions */
    FT_UInt            max_function_defs;
David Turner's avatar
David Turner committed
332
333
    TT_DefArray        function_defs;     /* table of function definitions  */

334
335
    FT_UInt            num_instruction_defs;  /* number of ins. definitions */
    FT_UInt            max_instruction_defs;
David Turner's avatar
David Turner committed
336
337
    TT_DefArray        instruction_defs;      /* table of ins. definitions  */

338
339
    FT_UInt            max_func;
    FT_UInt            max_ins;
David Turner's avatar
David Turner committed
340
341
342
343
344

    TT_CodeRangeTable  codeRangeTable;

    TT_GraphicsState   GS;

345
346
    FT_ULong           cvt_size;      /* the scaled control value table */
    FT_Long*           cvt;
David Turner's avatar
David Turner committed
347

348
349
    FT_UShort          storage_size; /* The storage area is now part of */
    FT_Long*           storage;      /* the instance                    */
David Turner's avatar
David Turner committed
350

Werner Lemberg's avatar
   
Werner Lemberg committed
351
    TT_GlyphZoneRec    twilight;     /* The instance's twilight zone    */
David Turner's avatar
David Turner committed
352
353
354
355
356
357
358

    /* debugging variables */

    /* When using the debugger, we must keep the */
    /* execution context tied to the instance    */
    /* object rather than asking it on demand.   */

359
    FT_Bool            debug;
David Turner's avatar
David Turner committed
360
361
    TT_ExecContext     context;

362
363
#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */

David Turner's avatar
David Turner committed
364
365
366
  } TT_SizeRec;


Werner Lemberg's avatar
   
Werner Lemberg committed
367
368
369
370
  /*************************************************************************/
  /*                                                                       */
  /* TrueType driver class.                                                */
  /*                                                                       */
David Turner's avatar
David Turner committed
371
372
  typedef struct  TT_DriverRec_
  {
Werner Lemberg's avatar
   
Werner Lemberg committed
373
374
375
    FT_DriverRec     root;
    TT_ExecContext   context;  /* execution context        */
    TT_GlyphZoneRec  zone;     /* glyph loader points zone */
David Turner's avatar
David Turner committed
376

Werner Lemberg's avatar
   
Werner Lemberg committed
377
    void*            extension_component;
David Turner's avatar
David Turner committed
378
379
380
381

  } TT_DriverRec;


Werner Lemberg's avatar
   
Werner Lemberg committed
382
383
384
385
  /*************************************************************************/
  /*                                                                       */
  /* Face functions                                                        */
  /*                                                                       */
386
  FT_LOCAL( FT_Error )
387
  tt_face_init( FT_Stream      stream,
Werner Lemberg's avatar
   
Werner Lemberg committed
388
389
390
391
                TT_Face        face,
                FT_Int         face_index,
                FT_Int         num_params,
                FT_Parameter*  params );
David Turner's avatar
David Turner committed
392

393
  FT_LOCAL( void )
394
  tt_face_done( TT_Face  face );
David Turner's avatar
David Turner committed
395
396


Werner Lemberg's avatar
   
Werner Lemberg committed
397
398
399
400
  /*************************************************************************/
  /*                                                                       */
  /* Size functions                                                        */
  /*                                                                       */
401
  FT_LOCAL( FT_Error )
402
  tt_size_init( TT_Size  size );
David Turner's avatar
David Turner committed
403

404
  FT_LOCAL( void )
405
  tt_size_done( TT_Size  size );
David Turner's avatar
David Turner committed
406

407
  FT_LOCAL( FT_Error )
408
  tt_size_reset( TT_Size  size );
David Turner's avatar
David Turner committed
409
410


Werner Lemberg's avatar
   
Werner Lemberg committed
411
412
413
414
  /*************************************************************************/
  /*                                                                       */
  /* Driver functions                                                      */
  /*                                                                       */
415
  FT_LOCAL( FT_Error )
416
  tt_driver_init( TT_Driver  driver );
David Turner's avatar
David Turner committed
417

418
  FT_LOCAL( void )
419
  tt_driver_done( TT_Driver  driver );
David Turner's avatar
David Turner committed
420

Werner Lemberg's avatar
   
Werner Lemberg committed
421

422
FT_END_HEADER
David Turner's avatar
David Turner committed
423

424
#endif /* __TTOBJS_H__ */
David Turner's avatar
David Turner committed
425
426
427


/* END */