ttobjs.h 20.7 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-2000 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
19
20
21
22
/*  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.                                        */
/*                                                                         */
/***************************************************************************/


#ifndef TTOBJS_H
#define TTOBJS_H


23
24
#include <freetype/internal/ftobjs.h>
#include <freetype/internal/tttypes.h>
Werner Lemberg's avatar
   
Werner Lemberg committed
25
#include <freetype/internal/tterrors.h>
David Turner's avatar
David Turner committed
26
27
28
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
78
79


#ifdef __cplusplus
  extern "C" {
#endif


  /*************************************************************************/
  /*                                                                       */
  /* <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_
  {
80
81
82
    FT_UShort      rp0;
    FT_UShort      rp1;
    FT_UShort      rp2;
David Turner's avatar
David Turner committed
83

84
85
86
    FT_UnitVector  dualVector;
    FT_UnitVector  projVector;
    FT_UnitVector  freeVector;
David Turner's avatar
David Turner committed
87

88
89
90
    FT_Long        loop;
    FT_F26Dot6     minimum_distance;
    FT_Int         round_state;
David Turner's avatar
David Turner committed
91

92
93
94
95
96
97
    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
98

99
100
101
    FT_Byte        instruct_control;
    FT_Bool        scan_control;
    FT_Int         scan_type;
David Turner's avatar
David Turner committed
102

103
104
105
    FT_UShort      gep0;
    FT_UShort      gep1;
    FT_UShort      gep2;
David Turner's avatar
David Turner committed
106
107
108

  } TT_GraphicsState;

109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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
 /************************************************************************
  *
  *  <Struct>
  *     TT_GlyphZone
  *
  *  <Description>
  *     A glyph zone is used to load, scale and hint glyph outline
  *     coordinates.
  *
  *  <Fields>
  *     memory       :: handle to memory manager
  *     max_points   :: max size in points of zone
  *     max_contours :: max size in contours of zone
  *     n_points     :: current number of points in zone
  *     n_contours   :: current number of contours in zone
  *     org          :: original glyph coordinates (font units/scaled)
  *     cur          :: current glyph coordinates  (scaled/hinted)
  *     tags         :: point control tags
  *     contours     :: contour end points
  *
  ***********************************************************************/

  typedef struct  TT_GlyphZone_
  {
    FT_Memory   memory;
    FT_UShort   max_points;
    FT_UShort   max_contours;
    FT_UShort   n_points;   /* number of points in zone    */
    FT_Short    n_contours; /* number of contours          */

    FT_Vector*  org;        /* original point coordinates  */
    FT_Vector*  cur;        /* current point coordinates   */

    FT_Byte*    tags;       /* current touch flags         */
    FT_UShort*  contours;   /* contour end points          */

  } TT_GlyphZone;

  LOCAL_DEF void  TT_Done_GlyphZone( TT_GlyphZone*  zone );

  LOCAL_DEF FT_Error TT_New_GlyphZone( FT_Memory      memory,
                                       FT_UShort      maxPoints,
                                       FT_Short       maxContours,
                                       TT_GlyphZone*  zone );

  LOCAL_DEF FT_Error TT_Update_GlyphZone( TT_GlyphZone*  zone,
                                          FT_UShort      newPoints,
                                          FT_Short       newContours );
David Turner's avatar
David Turner committed
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188

  /*************************************************************************/
  /*                                                                       */
  /*  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_
  {
189
190
    FT_Byte*  base;
    FT_ULong  size;
David Turner's avatar
David Turner committed
191
192
193
194
195
196
197
198
199
200
201
202

  } TT_CodeRange;

  typedef TT_CodeRange  TT_CodeRangeTable[TT_MAX_CODE_RANGES];


  /*************************************************************************/
  /*                                                                       */
  /* Defines a function/instruction definition record.                     */
  /*                                                                       */
  typedef struct  TT_DefRecord_
  {
203
204
205
206
    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
207
208
209
210
211
212
213
214
215
216
217

  } TT_DefRecord, *TT_DefArray;



  /*************************************************************************/
  /*                                                                       */
  /* Subglyph transformation record.                                       */
  /*                                                                       */
  typedef struct  TT_Transform_
  {
218
219
220
    FT_Fixed    xx, xy;     /* transformation matrix coefficients */
    FT_Fixed    yx, yy;
    FT_F26Dot6  ox, oy;     /* offsets        */
David Turner's avatar
David Turner committed
221
222
223
224
225
226
227
228
229
230

  } TT_Transform;


  /*************************************************************************/
  /*                                                                       */
  /* Subglyph loading record.  Used to load composite components.          */
  /*                                                                       */
  typedef struct  TT_SubglyphRec_
  {
231
232
233
234
    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
235

236
    FT_Long       file_offset;
David Turner's avatar
David Turner committed
237

238
239
240
    FT_BBox       bbox;
    FT_Pos        left_bearing;
    FT_Pos        advance;
David Turner's avatar
David Turner committed
241

242
    TT_GlyphZone  zone;
David Turner's avatar
David Turner committed
243

244
245
    FT_Long       arg1;         /* first argument                      */
    FT_Long       arg2;         /* second argument                     */
David Turner's avatar
David Turner committed
246

247
    FT_UShort     element_flag; /* current load element flag           */
David Turner's avatar
David Turner committed
248
249
250

    TT_Transform  transform;    /* transformation matrix               */

251
    FT_Vector     pp1, pp2;     /* phantom points                      */
David Turner's avatar
David Turner committed
252
253
254
255
256
257
258
259

  } TT_SubGlyphRec, *TT_SubGlyph_Stack;


  /*************************************************************************/
  /*                                                                       */
  /* A note regarding non-squared pixels:                                  */
  /*                                                                       */
Werner Lemberg's avatar
   
Werner Lemberg committed
260
  /* (This text will probably go into some docs at some time; for now, it  */
David Turner's avatar
David Turner committed
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
  /*  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 */
325
326
    FT_Long     x_ratio;
    FT_Long     y_ratio;
David Turner's avatar
David Turner committed
327

328
329
330
    FT_UShort   ppem;               /* maximum ppem size              */
    FT_Long     ratio;              /* current ratio                  */
    FT_Fixed    scale;
David Turner's avatar
David Turner committed
331

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

334
    FT_Bool     valid;
David Turner's avatar
David Turner committed
335

336
337
    FT_Bool     rotated;            /* `is the glyph rotated?'-flag   */
    FT_Bool     stretched;          /* `is the glyph stretched?'-flag */
David Turner's avatar
David Turner committed
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361

  } TT_Size_Metrics;


  /*************************************************************************/
  /*                                                                       */
  /* FreeType execution context type.                                      */
  /*                                                                       */
  /* This is a forward declaration; the full specification is in the file  */
  /* `ttinterp.h'.                                                         */
  /*                                                                       */
  typedef struct TT_ExecContextRec_*  TT_ExecContext;


  /***********************************************************************/
  /*                                                                     */
  /* TrueType size class.                                                */
  /*                                                                     */
  typedef struct  TT_SizeRec_
  {
    FT_SizeRec         root;

    TT_Size_Metrics    ttmetrics;

362
#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER
Werner Lemberg's avatar
   
Werner Lemberg committed
363

364
365
    FT_UInt            num_function_defs; /* number of function definitions */
    FT_UInt            max_function_defs;
David Turner's avatar
David Turner committed
366
367
    TT_DefArray        function_defs;     /* table of function definitions  */

368
369
    FT_UInt            num_instruction_defs;  /* number of ins. definitions */
    FT_UInt            max_instruction_defs;
David Turner's avatar
David Turner committed
370
371
    TT_DefArray        instruction_defs;      /* table of ins. definitions  */

372
373
    FT_UInt            max_func;
    FT_UInt            max_ins;
David Turner's avatar
David Turner committed
374
375
376
377
378

    TT_CodeRangeTable  codeRangeTable;

    TT_GraphicsState   GS;

379
380
    FT_ULong           cvt_size;      /* the scaled control value table */
    FT_Long*           cvt;
David Turner's avatar
David Turner committed
381

382
383
    FT_UShort          storage_size; /* The storage area is now part of */
    FT_Long*           storage;      /* the instance                    */
David Turner's avatar
David Turner committed
384

385
    TT_GlyphZone       twilight;     /* The instance's twilight zone    */
David Turner's avatar
David Turner committed
386
387
388
389
390
391
392

    /* debugging variables */

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

393
    FT_Bool            debug;
David Turner's avatar
David Turner committed
394
395
    TT_ExecContext     context;

396
397
#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */

David Turner's avatar
David Turner committed
398
399
400
401
402
403
404
405
406
407
  } TT_SizeRec;


  /***********************************************************************/
  /*                                                                     */
  /* TrueType driver class.                                              */
  /*                                                                     */
  typedef struct  TT_DriverRec_
  {
    FT_DriverRec    root;
408
    TT_ExecContext  context;  /* execution context        */
409
    TT_GlyphZone    zone;     /* glyph loader points zone */
David Turner's avatar
David Turner committed
410
411
412
413
414
415

    void*           extension_component;

  } TT_DriverRec;


Werner Lemberg's avatar
   
Werner Lemberg committed
416
417
418
419
420
  /*************************************************************************/
  /*                                                                       */
  /* Face functions                                                        */
  /*                                                                       */
  LOCAL_DEF
421
  FT_Error  TT_Init_Face( FT_Stream      stream,
Werner Lemberg's avatar
   
Werner Lemberg committed
422
                          TT_Face        face,
423
424
                          FT_Int         face_index,
                          FT_Int         num_params,
Werner Lemberg's avatar
   
Werner Lemberg committed
425
                          FT_Parameter*  params );
David Turner's avatar
David Turner committed
426

Werner Lemberg's avatar
   
Werner Lemberg committed
427
428
  LOCAL_DEF
  void  TT_Done_Face( TT_Face  face );
David Turner's avatar
David Turner committed
429
430


Werner Lemberg's avatar
   
Werner Lemberg committed
431
432
433
434
435
  /*************************************************************************/
  /*                                                                       */
  /* Size functions                                                        */
  /*                                                                       */
  LOCAL_DEF
436
  FT_Error  TT_Init_Size( TT_Size  size );
David Turner's avatar
David Turner committed
437

Werner Lemberg's avatar
   
Werner Lemberg committed
438
439
  LOCAL_DEF
  void  TT_Done_Size( TT_Size  size );
David Turner's avatar
David Turner committed
440

Werner Lemberg's avatar
   
Werner Lemberg committed
441
  LOCAL_DEF
442
  FT_Error  TT_Reset_Size( TT_Size  size );
David Turner's avatar
David Turner committed
443
444


Werner Lemberg's avatar
   
Werner Lemberg committed
445
446
447
448
449
  /*************************************************************************/
  /*                                                                       */
  /* GlyphSlot functions                                                   */
  /*                                                                       */
  LOCAL_DEF
450
  FT_Error  TT_Init_GlyphSlot( TT_GlyphSlot  slot );
David Turner's avatar
David Turner committed
451

Werner Lemberg's avatar
   
Werner Lemberg committed
452
453
  LOCAL_DEF
  void  TT_Done_GlyphSlot( TT_GlyphSlot  slot );
David Turner's avatar
David Turner committed
454
455


Werner Lemberg's avatar
   
Werner Lemberg committed
456
457
458
459
460
  /*************************************************************************/
  /*                                                                       */
  /* Driver functions                                                      */
  /*                                                                       */
  LOCAL_DEF
461
  FT_Error  TT_Init_Driver( TT_Driver  driver );
David Turner's avatar
David Turner committed
462

Werner Lemberg's avatar
   
Werner Lemberg committed
463
464
  LOCAL_DEF
  void  TT_Done_Driver( TT_Driver  driver );
David Turner's avatar
David Turner committed
465
466
467
468
469
470
471
472
473

#ifdef __cplusplus
  }
#endif

#endif /* TTOBJS_H */


/* END */