1/***************************************************************************/
2/*                                                                         */
3/*  ttobjs.h                                                               */
4/*                                                                         */
5/*    Objects manager (specification).                                     */
6/*                                                                         */
7/*  Copyright 1996-2015 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 <ft2build.h>
24#include FT_INTERNAL_OBJECTS_H
25#include FT_INTERNAL_TRUETYPE_TYPES_H
26
27
28FT_BEGIN_HEADER
29
30
31  /*************************************************************************/
32  /*                                                                       */
33  /* <Type>                                                                */
34  /*    TT_Driver                                                          */
35  /*                                                                       */
36  /* <Description>                                                         */
37  /*    A handle to a TrueType driver object.                              */
38  /*                                                                       */
39  typedef struct TT_DriverRec_*  TT_Driver;
40
41
42  /*************************************************************************/
43  /*                                                                       */
44  /* <Type>                                                                */
45  /*    TT_GlyphSlot                                                       */
46  /*                                                                       */
47  /* <Description>                                                         */
48  /*    A handle to a TrueType glyph slot object.                          */
49  /*                                                                       */
50  /* <Note>                                                                */
51  /*    This is a direct typedef of FT_GlyphSlot, as there is nothing      */
52  /*    specific about the TrueType glyph slot.                            */
53  /*                                                                       */
54  typedef FT_GlyphSlot  TT_GlyphSlot;
55
56
57  /*************************************************************************/
58  /*                                                                       */
59  /* <Struct>                                                              */
60  /*    TT_GraphicsState                                                   */
61  /*                                                                       */
62  /* <Description>                                                         */
63  /*    The TrueType graphics state used during bytecode interpretation.   */
64  /*                                                                       */
65  typedef struct  TT_GraphicsState_
66  {
67    FT_UShort      rp0;
68    FT_UShort      rp1;
69    FT_UShort      rp2;
70
71    FT_UnitVector  dualVector;
72    FT_UnitVector  projVector;
73    FT_UnitVector  freeVector;
74
75#ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING
76    FT_Bool        both_x_axis;
77#endif
78
79    FT_Long        loop;
80    FT_F26Dot6     minimum_distance;
81    FT_Int         round_state;
82
83    FT_Bool        auto_flip;
84    FT_F26Dot6     control_value_cutin;
85    FT_F26Dot6     single_width_cutin;
86    FT_F26Dot6     single_width_value;
87    FT_UShort      delta_base;
88    FT_UShort      delta_shift;
89
90    FT_Byte        instruct_control;
91    /* According to Greg Hitchcock from Microsoft, the `scan_control'     */
92    /* variable as documented in the TrueType specification is a 32-bit   */
93    /* integer; the high-word part holds the SCANTYPE value, the low-word */
94    /* part the SCANCTRL value.  We separate it into two fields.          */
95    FT_Bool        scan_control;
96    FT_Int         scan_type;
97
98    FT_UShort      gep0;
99    FT_UShort      gep1;
100    FT_UShort      gep2;
101
102  } TT_GraphicsState;
103
104
105#ifdef TT_USE_BYTECODE_INTERPRETER
106
107  FT_LOCAL( void )
108  tt_glyphzone_done( TT_GlyphZone  zone );
109
110  FT_LOCAL( FT_Error )
111  tt_glyphzone_new( FT_Memory     memory,
112                    FT_UShort     maxPoints,
113                    FT_Short      maxContours,
114                    TT_GlyphZone  zone );
115
116#endif /* TT_USE_BYTECODE_INTERPRETER */
117
118
119
120  /*************************************************************************/
121  /*                                                                       */
122  /*  EXECUTION SUBTABLES                                                  */
123  /*                                                                       */
124  /*  These sub-tables relate to instruction execution.                    */
125  /*                                                                       */
126  /*************************************************************************/
127
128
129#define TT_MAX_CODE_RANGES  3
130
131
132  /*************************************************************************/
133  /*                                                                       */
134  /* There can only be 3 active code ranges at once:                       */
135  /*   - the Font Program                                                  */
136  /*   - the CVT Program                                                   */
137  /*   - a glyph's instructions set                                        */
138  /*                                                                       */
139  typedef enum  TT_CodeRange_Tag_
140  {
141    tt_coderange_none = 0,
142    tt_coderange_font,
143    tt_coderange_cvt,
144    tt_coderange_glyph
145
146  } TT_CodeRange_Tag;
147
148
149  typedef struct  TT_CodeRange_
150  {
151    FT_Byte*  base;
152    FT_Long   size;
153
154  } TT_CodeRange;
155
156  typedef TT_CodeRange  TT_CodeRangeTable[TT_MAX_CODE_RANGES];
157
158
159  /*************************************************************************/
160  /*                                                                       */
161  /* Defines a function/instruction definition record.                     */
162  /*                                                                       */
163  typedef struct  TT_DefRecord_
164  {
165    FT_Int    range;          /* in which code range is it located?     */
166    FT_Long   start;          /* where does it start?                   */
167    FT_Long   end;            /* where does it end?                     */
168    FT_UInt   opc;            /* function #, or instruction code        */
169    FT_Bool   active;         /* is it active?                          */
170    FT_Bool   inline_delta;   /* is function that defines inline delta? */
171    FT_ULong  sph_fdef_flags; /* flags to identify special functions    */
172
173  } TT_DefRecord, *TT_DefArray;
174
175
176  /*************************************************************************/
177  /*                                                                       */
178  /* Subglyph transformation record.                                       */
179  /*                                                                       */
180  typedef struct  TT_Transform_
181  {
182    FT_Fixed    xx, xy;     /* transformation matrix coefficients */
183    FT_Fixed    yx, yy;
184    FT_F26Dot6  ox, oy;     /* offsets                            */
185
186  } TT_Transform;
187
188
189  /*************************************************************************/
190  /*                                                                       */
191  /* A note regarding non-squared pixels:                                  */
192  /*                                                                       */
193  /* (This text will probably go into some docs at some time; for now, it  */
194  /* is kept here to explain some definitions in the TT_Size_Metrics       */
195  /* record).                                                              */
196  /*                                                                       */
197  /* The CVT is a one-dimensional array containing values that control     */
198  /* certain important characteristics in a font, like the height of all   */
199  /* capitals, all lowercase letter, default spacing or stem width/height. */
200  /*                                                                       */
201  /* These values are found in FUnits in the font file, and must be scaled */
202  /* to pixel coordinates before being used by the CVT and glyph programs. */
203  /* Unfortunately, when using distinct x and y resolutions (or distinct x */
204  /* and y pointsizes), there are two possible scalings.                   */
205  /*                                                                       */
206  /* A first try was to implement a `lazy' scheme where all values were    */
207  /* scaled when first used.  However, while some values are always used   */
208  /* in the same direction, some others are used under many different      */
209  /* circumstances and orientations.                                       */
210  /*                                                                       */
211  /* I have found a simpler way to do the same, and it even seems to work  */
212  /* in most of the cases:                                                 */
213  /*                                                                       */
214  /* - All CVT values are scaled to the maximum ppem size.                 */
215  /*                                                                       */
216  /* - When performing a read or write in the CVT, a ratio factor is used  */
217  /*   to perform adequate scaling.  Example:                              */
218  /*                                                                       */
219  /*     x_ppem = 14                                                       */
220  /*     y_ppem = 10                                                       */
221  /*                                                                       */
222  /*   We choose ppem = x_ppem = 14 as the CVT scaling size.  All cvt      */
223  /*   entries are scaled to it.                                           */
224  /*                                                                       */
225  /*     x_ratio = 1.0                                                     */
226  /*     y_ratio = y_ppem/ppem (< 1.0)                                     */
227  /*                                                                       */
228  /*   We compute the current ratio like:                                  */
229  /*                                                                       */
230  /*   - If projVector is horizontal,                                      */
231  /*       ratio = x_ratio = 1.0                                           */
232  /*                                                                       */
233  /*   - if projVector is vertical,                                        */
234  /*       ratio = y_ratio                                                 */
235  /*                                                                       */
236  /*   - else,                                                             */
237  /*       ratio = sqrt( (proj.x * x_ratio) ^ 2 + (proj.y * y_ratio) ^ 2 ) */
238  /*                                                                       */
239  /*   Reading a cvt value returns                                         */
240  /*     ratio * cvt[index]                                                */
241  /*                                                                       */
242  /*   Writing a cvt value in pixels:                                      */
243  /*     cvt[index] / ratio                                                */
244  /*                                                                       */
245  /*   The current ppem is simply                                          */
246  /*     ratio * ppem                                                      */
247  /*                                                                       */
248  /*************************************************************************/
249
250
251  /*************************************************************************/
252  /*                                                                       */
253  /* Metrics used by the TrueType size and context objects.                */
254  /*                                                                       */
255  typedef struct  TT_Size_Metrics_
256  {
257    /* for non-square pixels */
258    FT_Long     x_ratio;
259    FT_Long     y_ratio;
260
261    FT_UShort   ppem;               /* maximum ppem size              */
262    FT_Long     ratio;              /* current ratio                  */
263    FT_Fixed    scale;
264
265    FT_F26Dot6  compensations[4];   /* device-specific compensations  */
266
267    FT_Bool     valid;
268
269    FT_Bool     rotated;            /* `is the glyph rotated?'-flag   */
270    FT_Bool     stretched;          /* `is the glyph stretched?'-flag */
271
272  } TT_Size_Metrics;
273
274
275  /*************************************************************************/
276  /*                                                                       */
277  /* TrueType size class.                                                  */
278  /*                                                                       */
279  typedef struct  TT_SizeRec_
280  {
281    FT_SizeRec         root;
282
283    /* we have our own copy of metrics so that we can modify */
284    /* it without affecting auto-hinting (when used)         */
285    FT_Size_Metrics    metrics;
286
287    TT_Size_Metrics    ttmetrics;
288
289    FT_ULong           strike_index;      /* 0xFFFFFFFF to indicate invalid */
290
291#ifdef TT_USE_BYTECODE_INTERPRETER
292
293    FT_UInt            num_function_defs; /* number of function definitions */
294    FT_UInt            max_function_defs;
295    TT_DefArray        function_defs;     /* table of function definitions  */
296
297    FT_UInt            num_instruction_defs;  /* number of ins. definitions */
298    FT_UInt            max_instruction_defs;
299    TT_DefArray        instruction_defs;      /* table of ins. definitions  */
300
301    FT_UInt            max_func;
302    FT_UInt            max_ins;
303
304    TT_CodeRangeTable  codeRangeTable;
305
306    TT_GraphicsState   GS;
307
308    FT_ULong           cvt_size;      /* the scaled control value table */
309    FT_Long*           cvt;
310
311    FT_UShort          storage_size; /* The storage area is now part of */
312    FT_Long*           storage;      /* the instance                    */
313
314    TT_GlyphZoneRec    twilight;     /* The instance's twilight zone    */
315
316    TT_ExecContext     context;
317
318    /* if negative, `fpgm' (resp. `prep'), wasn't executed yet; */
319    /* otherwise it is the returned error code                  */
320    FT_Error           bytecode_ready;
321    FT_Error           cvt_ready;
322
323#endif /* TT_USE_BYTECODE_INTERPRETER */
324
325  } TT_SizeRec;
326
327
328  /*************************************************************************/
329  /*                                                                       */
330  /* TrueType driver class.                                                */
331  /*                                                                       */
332  typedef struct  TT_DriverRec_
333  {
334    FT_DriverRec  root;
335
336    TT_GlyphZoneRec  zone;     /* glyph loader points zone */
337
338    FT_UInt  interpreter_version;
339
340  } TT_DriverRec;
341
342
343  /* Note: All of the functions below (except tt_size_reset()) are used    */
344  /* as function pointers in a FT_Driver_ClassRec.  Therefore their        */
345  /* parameters are of types FT_Face, FT_Size, etc., rather than TT_Face,  */
346  /* TT_Size, etc., so that the compiler can confirm that the types and    */
347  /* number of parameters are correct.  In all cases the FT_xxx types are  */
348  /* cast to their TT_xxx counterparts inside the functions since FreeType */
349  /* will always use the TT driver to create them.                         */
350
351
352  /*************************************************************************/
353  /*                                                                       */
354  /* Face functions                                                        */
355  /*                                                                       */
356  FT_LOCAL( FT_Error )
357  tt_face_init( FT_Stream      stream,
358                FT_Face        ttface,      /* TT_Face */
359                FT_Int         face_index,
360                FT_Int         num_params,
361                FT_Parameter*  params );
362
363  FT_LOCAL( void )
364  tt_face_done( FT_Face  ttface );          /* TT_Face */
365
366
367  /*************************************************************************/
368  /*                                                                       */
369  /* Size functions                                                        */
370  /*                                                                       */
371  FT_LOCAL( FT_Error )
372  tt_size_init( FT_Size  ttsize );          /* TT_Size */
373
374  FT_LOCAL( void )
375  tt_size_done( FT_Size  ttsize );          /* TT_Size */
376
377#ifdef TT_USE_BYTECODE_INTERPRETER
378
379  FT_LOCAL( FT_Error )
380  tt_size_run_fpgm( TT_Size  size,
381                    FT_Bool  pedantic );
382
383  FT_LOCAL( FT_Error )
384  tt_size_run_prep( TT_Size  size,
385                    FT_Bool  pedantic );
386
387  FT_LOCAL( FT_Error )
388  tt_size_ready_bytecode( TT_Size  size,
389                          FT_Bool  pedantic );
390
391#endif /* TT_USE_BYTECODE_INTERPRETER */
392
393  FT_LOCAL( FT_Error )
394  tt_size_reset( TT_Size  size );
395
396
397  /*************************************************************************/
398  /*                                                                       */
399  /* Driver functions                                                      */
400  /*                                                                       */
401  FT_LOCAL( FT_Error )
402  tt_driver_init( FT_Module  ttdriver );    /* TT_Driver */
403
404  FT_LOCAL( void )
405  tt_driver_done( FT_Module  ttdriver );    /* TT_Driver */
406
407
408  /*************************************************************************/
409  /*                                                                       */
410  /* Slot functions                                                        */
411  /*                                                                       */
412  FT_LOCAL( FT_Error )
413  tt_slot_init( FT_GlyphSlot  slot );
414
415
416  /* auxiliary */
417#define IS_HINTED( flags )  ( ( flags & FT_LOAD_NO_HINTING ) == 0 )
418
419
420FT_END_HEADER
421
422#endif /* __TTOBJS_H__ */
423
424
425/* END */
426