1
/*******************************************************************
5
* Objects definition unit.
7
* Copyright 1996-1999 by
8
* David Turner, Robert Wilhelm, and Werner Lemberg.
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.
16
******************************************************************/
33
/* This file contains the definitions and methods of the four */
34
/* kinds of objects managed by the FreeType engine. These are: */
39
/* There is always one face object per opened TrueType font */
40
/* file, and only one. The face object contains data that is */
41
/* independent of current transform/scaling/rotation and */
42
/* pointsize, or glyph index. This data is made of several */
43
/* critical tables that are loaded on face object creation. */
45
/* A face object tracks all active and recycled objects of */
46
/* the instance and execution context classes. Destroying a face */
47
/* object will automatically destroy all associated instances. */
50
/* Instance objects: */
52
/* An instance object always relates to a given face object, */
53
/* known as its 'parent' or 'owner', and contains only the */
54
/* data that is specific to one given pointsize/transform of */
55
/* the face. You can only create an instance from a face object. */
57
/* An instance's current transform/pointsize can be changed */
58
/* at any time using a single high-level API call, */
59
/* TT_Reset_Instance(). */
61
/* Execution Context objects: */
63
/* An execution context (or context in short) relates to a face. */
64
/* It contains the data and tables that are necessary to load */
65
/* and hint (i.e. execute the glyph instructions of) one glyph. */
66
/* A context is a transient object that is queried/created on */
67
/* the fly: client applications never deal with them directly. */
72
/* A glyph object contains only the minimal glyph information */
73
/* needed to render one glyph correctly. This means that a glyph */
74
/* object really contains tables that are sized to hold the */
75
/* contents of _any_ glyph of a given face. A client application */
76
/* can usually create one glyph object for a given face, then use */
77
/* it for all subsequent loads. */
79
/* Here is an example of a client application : */
80
/* (NOTE: No error checking performed here!) */
83
/* TT_Face face; -- face handle */
84
/* TT_Instance ins1, ins2; -- two instance handles */
85
/* TT_Glyph glyph; -- glyph handle */
87
/* TT_Init_FreeType(); */
89
/* -- Initialize the engine. This must be done prior to _any_ */
92
/* TT_Open_Face( "/some/face/name.ttf", &face ); */
94
/* -- create the face object. This call opens the font file */
96
/* TT_New_Instance( face, &ins1 ); */
97
/* TT_New_Instance( face, &ins2 ); */
99
/* TT_Set_Instance_PointSize( ins1, 8 ); */
100
/* TT_Set_Instance_PointSize( ins2, 12 ); */
102
/* -- create two distinct instances of the same face */
103
/* -- ins1 is pointsize 8 at resolution 96 dpi */
104
/* -- ins2 is pointsize 12 at resolution 96 dpi */
106
/* TT_New_Glyph( face, &glyph ); */
108
/* -- create a new glyph object which will receive the contents */
109
/* of any glyph of 'face' */
111
/* TT_Load_Glyph( ins1, glyph, 64, DEFAULT_GLYPH_LOAD ); */
113
/* -- load glyph indexed 64 at pointsize 8 in the 'glyph' object */
114
/* -- NOTE: This call will fail if the instance and the glyph */
115
/* do not relate to the same face object. */
117
/* TT_Get_Outline( glyph, &outline ); */
119
/* -- extract the glyph outline from the object and copies it */
120
/* to the 'outline' record */
122
/* TT_Get_Metrics( glyph, &metrics ); */
124
/* -- extract the glyph metrics and put them into the 'metrics' */
127
/* TT_Load_Glyph( ins2, glyph, 64, DEFAULT_GLYPH_LOAD ); */
129
/* -- load the same glyph at pointsize 12 in the 'glyph' object */
132
/* TT_Close_Face( &face ); */
134
/* -- destroy the face object. This will destroy 'ins1' and */
135
/* 'ins2'. However, the glyph object will still be available */
137
/* TT_Done_FreeType(); */
139
/* -- Finalize the engine. This will also destroy all pending */
140
/* glyph objects (here 'glyph'). */
144
struct TExecution_Context_;
147
typedef struct TFace_ TFace;
148
typedef TFace* PFace;
150
typedef struct TInstance_ TInstance;
151
typedef TInstance* PInstance;
153
typedef struct TExecution_Context_ TExecution_Context;
154
typedef TExecution_Context* PExecution_Context;
156
typedef struct TGlyph_ TGlyph;
157
typedef TGlyph* PGlyph;
160
/*************************************************************/
162
/* ADDITIONAL SUBTABLES */
164
/* These tables are not precisely defined by the specs */
165
/* but their structures is implied by the TrueType font */
168
/*************************************************************/
172
/* The Graphics State (GS) is managed by the */
173
/* instruction field, but does not come from */
174
/* the font file. Thus, we can use 'int's */
177
struct TGraphicsState_
183
TT_UnitVector dualVector;
184
TT_UnitVector projVector;
185
TT_UnitVector freeVector;
188
TT_F26Dot6 minimum_distance;
192
TT_F26Dot6 control_value_cutin;
193
TT_F26Dot6 single_width_cutin;
194
TT_F26Dot6 single_width_value;
198
Byte instruct_control;
207
typedef struct TGraphicsState_ TGraphicsState;
211
const TGraphicsState Default_GraphicsState;
214
/*************************************************************/
216
/* EXECUTION SUBTABLES */
218
/* These sub-tables relate to instruction execution. */
220
/*************************************************************/
222
#define MAX_CODE_RANGES 3
224
/* There can only be 3 active code ranges at once: */
225
/* - the Font Program */
226
/* - the CVT Program */
227
/* - a glyph's instructions set */
229
#define TT_CodeRange_Font 1
230
#define TT_CodeRange_Cvt 2
231
#define TT_CodeRange_Glyph 3
240
typedef struct TCodeRange_ TCodeRange;
241
typedef TCodeRange* PCodeRange;
244
/* Defintion of a code range */
246
/* Code ranges can be resident to a glyph (i.e. the Font Program) */
247
/* while some others are volatile (Glyph instructions). */
248
/* Tracking the state and presence of code ranges allows function */
249
/* and instruction definitions within a code range to be forgotten */
250
/* when the range is discarded. */
252
typedef TCodeRange TCodeRangeTable[MAX_CODE_RANGES];
254
/* defines a function/instruction definition record */
258
Int Range; /* in which code range is it located ? */
259
ULong Start; /* where does it start ? */
260
Int Opc; /* function #, or instruction code */
261
Bool Active; /* is it active ? */
264
typedef struct TDefRecord_ TDefRecord;
265
typedef TDefRecord* PDefRecord;
266
typedef TDefRecord* PDefArray;
268
/* defines a call record, used to manage function calls. */
278
typedef struct TCallRecord_ TCallRecord;
279
typedef TCallRecord* PCallRecord;
280
typedef TCallRecord* PCallStack; /* defines a simple call stack */
283
/* This type defining a set of glyph points will be used to represent */
284
/* each zone (regular and twilight) during instructions decoding. */
287
UShort n_points; /* number of points in zone */
288
Short n_contours; /* number of contours */
290
TT_Vector* org; /* original points coordinates */
291
TT_Vector* cur; /* current points coordinates */
293
Byte* touch; /* current touch flags */
294
UShort* contours; /* contour end points */
297
typedef struct TGlyph_Zone_ TGlyph_Zone;
298
typedef TGlyph_Zone* PGlyph_Zone;
302
#ifndef TT_STATIC_INTEPRETER /* indirect implementation */
304
#define EXEC_OPS PExecution_Context exc,
305
#define EXEC_OP PExecution_Context exc
306
#define EXEC_ARGS exc,
309
#else /* static implementation */
311
#define EXEC_OPS /* void */
312
#define EXEC_OP /* void */
313
#define EXEC_ARGS /* void */
314
#define EXEC_ARG /* void */
318
/* Rounding function, as used by the interpreter */
319
typedef TT_F26Dot6 (*TRound_Function)( EXEC_OPS TT_F26Dot6 distance,
320
TT_F26Dot6 compensation );
322
/* Point displacement along the freedom vector routine, as */
323
/* used by the interpreter */
324
typedef void (*TMove_Function)( EXEC_OPS PGlyph_Zone zone,
326
TT_F26Dot6 distance );
328
/* Distance projection along one of the proj. vectors, as used */
329
/* by the interpreter */
330
typedef TT_F26Dot6 (*TProject_Function)( EXEC_OPS TT_Vector* v1,
333
/* reading a cvt value. Take care of non-square pixels when needed */
334
typedef TT_F26Dot6 (*TGet_CVT_Function)( EXEC_OPS ULong index );
336
/* setting or moving a cvt value. Take care of non-square pixels */
338
typedef void (*TSet_CVT_Function)( EXEC_OPS ULong index,
341
/* subglyph transformation record */
344
TT_Fixed xx, xy; /* transformation */
345
TT_Fixed yx, yy; /* matrix */
346
TT_F26Dot6 ox, oy; /* offsets */
349
typedef struct TTransform_ TTransform;
350
typedef TTransform* PTransform;
352
/* subglyph loading record. Used to load composite components */
353
struct TSubglyph_Record_
355
Long index; /* subglyph index; initialized with -1 */
356
Bool is_scaled; /* is the subglyph scaled? */
357
Bool is_hinted; /* should it be hinted? */
358
Bool preserve_pps; /* preserve phantom points? */
362
TT_Big_Glyph_Metrics metrics;
366
Long arg1; /* first argument */
367
Long arg2; /* second argument */
369
UShort element_flag; /* current load element flag */
371
TTransform transform; /* transform */
373
TT_Vector pp1, pp2; /* phantom points */
377
typedef struct TSubglyph_Record_ TSubglyph_Record;
378
typedef TSubglyph_Record* PSubglyph_Record;
379
typedef TSubglyph_Record* PSubglyph_Stack;
381
/* A note regarding non-squared pixels: */
383
/* (This text will probably go into some docs at some time, for */
384
/* now, it is kept there to explain some definitions in the */
385
/* TIns_Metrics record). */
387
/* The CVT is a one-dimensional array containing values that */
388
/* control certain important characteristics in a font, like */
389
/* the height of all capitals, all lowercase letter, default */
390
/* spacing or stem width/height. */
392
/* These values are found in FUnits in the font file, and must be */
393
/* scaled to pixel coordinates before being used by the CVT and */
394
/* glyph programs. Unfortunately, when using distinct x and y */
395
/* resolutions (or distinct x and y pointsizes), there are two */
396
/* possible scalings. */
398
/* A first try was to implement a 'lazy' scheme where all values */
399
/* were scaled when first used. However, while some values are always */
400
/* used in the same direction, and some other are used in many */
401
/* different circumstances and orientations. */
403
/* I have found a simpler way to do the same, and it even seems to */
404
/* work in most of the cases: */
406
/* - all CVT values are scaled to the maximum ppem size */
408
/* - when performing a read or write in the CVT, a ratio factor */
409
/* is used to perform adequate scaling. Example: */
414
/* we choose ppem = x_ppem = 14 as the CVT scaling size. All cvt */
415
/* entries are scaled to it. */
418
/* y_ratio = y_ppem/ppem (< 1.0) */
420
/* we compute the current ratio like: */
422
/* - if projVector is horizontal, */
423
/* ratio = x_ratio = 1.0 */
424
/* - if projVector is vertical, */
425
/* ratop = y_ratio */
427
/* ratio = sqrt((proj.x*x_ratio)^2 + (proj.y*y_ratio)^2) */
429
/* reading a cvt value returns ratio * cvt[index] */
430
/* writing a cvt value in pixels cvt[index] / ratio */
432
/* the current ppem is simply ratio * ppem */
435
/* metrics used by the instance and execution context objects */
438
TT_F26Dot6 pointSize; /* point size. 1 point = 1/72 inch. */
440
UShort x_resolution; /* device horizontal resolution in dpi. */
441
UShort y_resolution; /* device vertical resolution in dpi. */
443
UShort x_ppem; /* horizontal pixels per EM */
444
UShort y_ppem; /* vertical pixels per EM */
447
Long x_scale2; /* used to scale FUnits to fractional pixels */
450
Long y_scale2; /* used to scale FUnits to fractional pixels */
452
/* for non-square pixels */
456
UShort ppem; /* maximum ppem size */
457
Long ratio; /* current ratio */
459
Long scale2; /* scale for ppem */
461
TT_F26Dot6 compensations[4]; /* device-specific compensations */
463
Bool rotated; /* `is the glyph rotated?'-flag */
464
Bool stretched; /* `is the glyph stretched?'-flag */
467
typedef struct TIns_Metrics_ TIns_Metrics;
468
typedef TIns_Metrics* PIns_Metrics;
472
/***********************************************************************/
474
/* FreeType Face Type */
476
/***********************************************************************/
480
/* parent engine instance for the face object */
481
PEngine_Instance engine;
486
/* used only by the threaded builds of the library */
489
/* TrueType collection header, if any was found */
490
TTTCHeader ttcHeader;
492
/* maximum profile table, as found in the TrueType file */
493
TMaxProfile maxProfile;
496
/* it seems that some maximum values cannot be */
497
/* taken directly from this table, but rather by */
498
/* combining some of its fields; e.g. the max. */
499
/* number of points seems to be given by */
500
/* MAX( maxPoints, maxCompositePoints ) */
502
/* For this reason, we define later our own */
503
/* max values that are used to load and allocate */
504
/* further tables. */
506
TT_Header fontHeader; /* the font header, as */
507
/* found in the TTF file */
508
TT_Horizontal_Header horizontalHeader; /* the horizontal header */
510
Bool verticalInfo; /* True when vertical table */
511
TT_Vertical_Header verticalHeader; /* is present in the font */
513
TT_OS2 os2; /* 'OS/2' table */
515
TT_Postscript postscript; /* 'Post' table */
517
TT_Hdmx hdmx; /* 'Hdmx' table */
519
TName_Table nameTable; /* name table */
521
TGasp gasp; /* the 'gasp' table */
523
/* The directory of TrueType tables for this typeface */
525
PTableDirEntry dirTables;
527
/* The directory of character mappings table for */
532
/* The glyph locations table */
533
ULong numLocations; /* UShort is not enough */
535
PStorage glyphLocations;
537
Storage TT_HUGE_PTR * glyphLocations;
540
/* NOTE : The "hmtx" is now part of the horizontal header */
542
/* the font program, if any */
546
/* the cvt program, if any */
550
/* the original, unscaled, control value table */
554
/* The following values _must_ be set by the */
555
/* maximum profile loader */
557
UShort numGlyphs; /* the face's total number of glyphs */
558
UShort maxPoints; /* max glyph points number, simple and composite */
559
UShort maxContours; /* max glyph contours numb, simple and composite */
560
UShort maxComponents; /* max components in a composite glyph */
562
/* the following are object caches to track active */
563
/* and recycled instances and execution contexts */
564
/* objects. See 'ttcache.h' */
566
TCache instances; /* current instances for this face */
567
TCache glyphs; /* current glyph containers for this face */
570
/* A typeless pointer to the face object extensions defined */
571
/* in the 'ttextend.*' files. */
573
Int n_extensions; /* number of extensions */
575
/* Use extensions to provide additional capabilities to the */
576
/* engine. Read the developer's guide in the documentation */
577
/* directory to know how to do that. */
579
/* a generic pointer for client use - see TT_Set/Get_Face_Pointer */
585
/***********************************************************************/
587
/* FreeType Instance Type */
589
/***********************************************************************/
593
PFace owner; /* face object */
597
TIns_Metrics metrics;
599
UShort numFDefs; /* number of function definitions */
601
PDefArray FDefs; /* table of FDefs entries */
603
UShort numIDefs; /* number of instruction definitions */
605
PDefArray IDefs; /* table of IDefs entries */
607
Int maxFunc; /* maximum function definition id */
608
Int maxIns; /* maximum instruction definition id */
610
TCodeRangeTable codeRangeTable;
613
TGraphicsState default_GS;
615
ULong cvtSize; /* the scaled control value table */
618
ULong storeSize; /* The storage area is now part of the */
619
PLong storage; /* instance */
621
TGlyph_Zone twilight; /* The instance's twilight zone */
623
/* debugging variables */
625
/* When using the debugger, we must keep the */
626
/* execution context tied to the instance */
627
/* object rather than asking it on demand */
630
PExecution_Context context;
632
/* a generic pointer for client use - see TT_Set/Get_Instance_Pointer */
637
/***********************************************************************/
639
/* FreeType Execution Context Type */
641
/***********************************************************************/
643
struct TExecution_Context_
648
/* instructions state */
650
TT_Error error; /* last execution error */
652
Long top; /* top of exec. stack */
654
ULong stackSize; /* size of exec. stack */
655
PStorage stack; /* current exec. stack */
658
ULong new_top; /* new top after exec. */
660
TGlyph_Zone zp0, /* zone records */
666
TIns_Metrics metrics; /* instance metrics */
668
TGraphicsState GS; /* current graphics state */
670
Int curRange; /* current code range number */
671
PByte code; /* current code range */
672
ULong IP; /* current instruction pointer */
673
ULong codeSize; /* size of current range */
675
Byte opcode; /* current opcode */
676
Int length; /* length of current opcode */
678
Bool step_ins; /* true if the interpreter must */
679
/* increment IP after ins. exec */
683
ULong glyphSize; /* glyph instructions buffer size */
684
PByte glyphIns; /* glyph instructions buffer */
686
UShort numFDefs; /* number of function defs */
687
UShort maxFDefs; /* maximum number of function defs */
688
PDefRecord FDefs; /* table of FDefs entries */
690
UShort numIDefs; /* number of instruction defs */
691
UShort maxIDefs; /* maximum number of instruction defs */
692
PDefRecord IDefs; /* table of IDefs entries */
697
Int callTop, /* top of call stack during execution */
698
callSize; /* size of call stack */
699
PCallStack callStack; /* call stack */
701
UShort maxPoints; /* capacity of this context's "pts" */
702
UShort maxContours; /* record, expressed in points and */
705
TCodeRangeTable codeRangeTable; /* table of valid coderanges */
706
/* useful for the debugger */
708
ULong storeSize; /* size of current storage */
709
PLong storage; /* storage area */
711
TT_F26Dot6 period; /* values used for the */
712
TT_F26Dot6 phase; /* 'SuperRounding' */
713
TT_F26Dot6 threshold;
715
/* this seems to be unused */
717
Int cur_ppem; /* ppem along the current proj vector */
719
Long scale1; /* scaling values along the current */
720
Long scale2; /* projection vector too.. */
721
Bool cached_metrics; /* the ppem is computed lazily. used */
722
/* to trigger computation when needed */
724
Bool instruction_trap; /* If True, the interpreter will */
725
/* exit after each instruction */
727
TGraphicsState default_GS; /* graphics state resulting from */
728
/* the prep program */
729
Bool is_composite; /* ture if the glyph is composite */
731
Bool pedantic_hinting; /* if true, read and write array */
732
/* bounds faults halt the hinting */
734
/* latest interpreter additions */
736
Long F_dot_P; /* dot product of freedom and projection */
738
TRound_Function func_round; /* current rounding function */
740
TProject_Function func_project, /* current projection function */
741
func_dualproj, /* current dual proj. function */
742
func_freeProj; /* current freedom proj. func */
744
TMove_Function func_move; /* current point move function */
746
TGet_CVT_Function func_read_cvt; /* read a cvt entry */
747
TSet_CVT_Function func_write_cvt; /* write a cvt entry (in pixels) */
748
TSet_CVT_Function func_move_cvt; /* incr a cvt entry (in pixels) */
751
PSubglyph_Stack loadStack; /* loading subglyph stack */
756
/***********************************************************************/
758
/* FreeType Glyph Object Type */
760
/***********************************************************************/
765
TT_Big_Glyph_Metrics metrics;
770
/* The following type is used to load a font from a collection. */
771
/* See Face_Create in ttobjs.c */
775
TT_Stream stream; /* input stream */
776
ULong fontIndex; /* index of font in collection */
777
PEngine_Instance engine; /* parent engine instance */
781
typedef struct TFont_Input_ TFont_Input;
784
/********************************************************************/
786
/* Code Range Functions */
788
/********************************************************************/
790
/* Goto a specified coderange */
792
TT_Error Goto_CodeRange( PExecution_Context exec,
797
/* Return a pointer to a given coderange record. */
798
/* Used only by the debugger. */
800
PCodeRange Get_CodeRange( PExecution_Context exec,
804
/* Set a given code range properties */
806
TT_Error Set_CodeRange( PExecution_Context exec,
811
/* Clear a given coderange */
813
TT_Error Clear_CodeRange( PExecution_Context exec, Int range );
817
PExecution_Context New_Context( PFace face );
820
TT_Error Done_Context( PExecution_Context exec );
824
TT_Error Context_Load( PExecution_Context exec,
829
TT_Error Context_Save( PExecution_Context exec,
833
TT_Error Context_Run( PExecution_Context exec,
837
TT_Error Instance_Init( PInstance ins );
840
TT_Error Instance_Reset( PInstance ins );
843
/********************************************************************/
845
/* Handy scaling functions */
847
/********************************************************************/
849
LOCAL_DEF TT_Pos Scale_X( PIns_Metrics metrics, TT_Pos x );
850
LOCAL_DEF TT_Pos Scale_Y( PIns_Metrics metrics, TT_Pos y );
852
/********************************************************************/
854
/* Component Initializer/Finalizer */
856
/* Called from 'freetype.c' */
857
/* The component must create and register the face, instance and */
858
/* execution context cache classes before any object can be */
861
/********************************************************************/
863
LOCAL_DEF TT_Error TTObjs_Init( PEngine_Instance engine );
864
LOCAL_DEF TT_Error TTObjs_Done( PEngine_Instance engine );
870
#endif /* TTOBJS_H */