1
/***************************************************************************/
5
/* The FreeType private base classes (specification). */
7
/* Copyright 1996-2001, 2002, 2003, 2004 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
/***************************************************************************/
19
/*************************************************************************/
21
/* This file contains the definition of all internal FreeType classes. */
23
/*************************************************************************/
30
#include FT_CONFIG_STANDARD_LIBRARY_H /* for ft_setjmp and ft_longjmp */
33
#include FT_INTERNAL_MEMORY_H
34
#include FT_INTERNAL_GLYPH_LOADER_H
35
#include FT_INTERNAL_DRIVER_H
36
#include FT_INTERNAL_AUTOHINT_H
37
#include FT_INTERNAL_SERVICE_H
39
#ifdef FT_CONFIG_OPTION_INCREMENTAL
40
#include FT_INCREMENTAL_H
47
/*************************************************************************/
49
/* Some generic definitions. */
64
/*************************************************************************/
66
/* The min and max functions missing in C. As usual, be careful not to */
67
/* write things like FT_MIN( a++, b++ ) to avoid side effects. */
69
#define FT_MIN( a, b ) ( (a) < (b) ? (a) : (b) )
70
#define FT_MAX( a, b ) ( (a) > (b) ? (a) : (b) )
72
#define FT_ABS( a ) ( (a) < 0 ? -(a) : (a) )
75
#define FT_PAD_FLOOR( x, n ) ( (x) & ~((n)-1) )
76
#define FT_PAD_ROUND( x, n ) FT_PAD_FLOOR( (x) + ((n)/2), n )
77
#define FT_PAD_CEIL( x, n ) FT_PAD_FLOOR( (x) + ((n)-1), n )
79
#define FT_PIX_FLOOR( x ) ( (x) & ~63 )
80
#define FT_PIX_ROUND( x ) FT_PIX_FLOOR( (x) + 32 )
81
#define FT_PIX_CEIL( x ) FT_PIX_FLOOR( (x) + 63 )
84
/*************************************************************************/
85
/*************************************************************************/
86
/*************************************************************************/
89
/**** V A L I D A T I O N ****/
92
/*************************************************************************/
93
/*************************************************************************/
94
/*************************************************************************/
96
/* handle to a validation object */
97
typedef struct FT_ValidatorRec_* FT_Validator;
100
/*************************************************************************/
102
/* There are three distinct validation levels defined here: */
104
/* FT_VALIDATE_DEFAULT :: */
105
/* A table that passes this validation level can be used reliably by */
106
/* FreeType. It generally means that all offsets have been checked to */
107
/* prevent out-of-bound reads, array counts are correct, etc. */
109
/* FT_VALIDATE_TIGHT :: */
110
/* A table that passes this validation level can be used reliably and */
111
/* doesn't contain invalid data. For example, a charmap table that */
112
/* returns invalid glyph indices will not pass, even though it can */
113
/* be used with FreeType in default mode (the library will simply */
114
/* return an error later when trying to load the glyph). */
116
/* It also check that fields that must be a multiple of 2, 4, or 8 */
117
/* don't have incorrect values, etc. */
119
/* FT_VALIDATE_PARANOID :: */
120
/* Only for font debugging. Checks that a table follows the */
121
/* specification by 100%. Very few fonts will be able to pass this */
122
/* level anyway but it can be useful for certain tools like font */
123
/* editors/converters. */
125
typedef enum FT_ValidationLevel_
127
FT_VALIDATE_DEFAULT = 0,
131
} FT_ValidationLevel;
134
/* validator structure */
135
typedef struct FT_ValidatorRec_
137
const FT_Byte* base; /* address of table in memory */
138
const FT_Byte* limit; /* `base' + sizeof(table) in memory */
139
FT_ValidationLevel level; /* validation level */
140
FT_Error error; /* error returned. 0 means success */
142
ft_jmp_buf jump_buffer; /* used for exception handling */
147
#define FT_VALIDATOR( x ) ((FT_Validator)( x ))
151
ft_validator_init( FT_Validator valid,
153
const FT_Byte* limit,
154
FT_ValidationLevel level );
157
ft_validator_run( FT_Validator valid );
159
/* Sets the error field in a validator, then calls `longjmp' to return */
160
/* to high-level caller. Using `setjmp/longjmp' avoids many stupid */
161
/* error checks within the validation routines. */
164
ft_validator_error( FT_Validator valid,
168
/* Calls ft_validate_error. Assumes that the `valid' local variable */
169
/* holds a pointer to the current validator object. */
171
#define FT_INVALID( _error ) ft_validator_error( valid, _error )
173
/* called when a broken table is detected */
174
#define FT_INVALID_TOO_SHORT FT_INVALID( FT_Err_Invalid_Table )
176
/* called when an invalid offset is detected */
177
#define FT_INVALID_OFFSET FT_INVALID( FT_Err_Invalid_Offset )
179
/* called when an invalid format/value is detected */
180
#define FT_INVALID_FORMAT FT_INVALID( FT_Err_Invalid_Table )
182
/* called when an invalid glyph index is detected */
183
#define FT_INVALID_GLYPH_ID FT_INVALID( FT_Err_Invalid_Glyph_Index )
185
/* called when an invalid field value is detected */
186
#define FT_INVALID_DATA FT_INVALID( FT_Err_Invalid_Table )
189
/*************************************************************************/
190
/*************************************************************************/
191
/*************************************************************************/
194
/**** C H A R M A P S ****/
197
/*************************************************************************/
198
/*************************************************************************/
199
/*************************************************************************/
201
/* handle to internal charmap object */
202
typedef struct FT_CMapRec_* FT_CMap;
204
/* handle to charmap class structure */
205
typedef const struct FT_CMap_ClassRec_* FT_CMap_Class;
207
/* internal charmap object structure */
208
typedef struct FT_CMapRec_
210
FT_CharMapRec charmap;
215
/* typecase any pointer to a charmap handle */
216
#define FT_CMAP( x ) ((FT_CMap)( x ))
219
#define FT_CMAP_PLATFORM_ID( x ) FT_CMAP( x )->charmap.platform_id
220
#define FT_CMAP_ENCODING_ID( x ) FT_CMAP( x )->charmap.encoding_id
221
#define FT_CMAP_ENCODING( x ) FT_CMAP( x )->charmap.encoding
222
#define FT_CMAP_FACE( x ) FT_CMAP( x )->charmap.face
225
/* class method definitions */
227
(*FT_CMap_InitFunc)( FT_CMap cmap,
228
FT_Pointer init_data );
231
(*FT_CMap_DoneFunc)( FT_CMap cmap );
234
(*FT_CMap_CharIndexFunc)( FT_CMap cmap,
235
FT_UInt32 char_code );
238
(*FT_CMap_CharNextFunc)( FT_CMap cmap,
239
FT_UInt32 *achar_code );
242
typedef struct FT_CMap_ClassRec_
245
FT_CMap_InitFunc init;
246
FT_CMap_DoneFunc done;
247
FT_CMap_CharIndexFunc char_index;
248
FT_CMap_CharNextFunc char_next;
253
/* create a new charmap and add it to charmap->face */
255
FT_CMap_New( FT_CMap_Class clazz,
256
FT_Pointer init_data,
260
/* destroy a charmap (don't remove it from face's list though) */
262
FT_CMap_Done( FT_CMap cmap );
265
/*************************************************************************/
268
/* FT_Face_InternalRec */
271
/* This structure contains the internal fields of each FT_Face */
272
/* object. These fields may change between different releases of */
277
/* The maximal number of points used to store the vectorial outline */
278
/* of any glyph in this face. If this value cannot be known in */
279
/* advance, or if the face isn't scalable, this should be set to 0. */
280
/* Only relevant for scalable formats. */
282
/* max_contours :: */
283
/* The maximal number of contours used to store the vectorial */
284
/* outline of any glyph in this face. If this value cannot be */
285
/* known in advance, or if the face isn't scalable, this should be */
286
/* set to 0. Only relevant for scalable formats. */
288
/* transform_matrix :: */
289
/* A 2x2 matrix of 16.16 coefficients used to transform glyph */
290
/* outlines after they are loaded from the font. Only used by the */
291
/* convenience functions. */
293
/* transform_delta :: */
294
/* A translation vector used to transform glyph outlines after they */
295
/* are loaded from the font. Only used by the convenience */
298
/* transform_flags :: */
299
/* Some flags used to classify the transform. Only used by the */
300
/* convenience functions. */
303
/* A cache for frequently used services. It should be only */
304
/* accessed with the macro `FT_FACE_LOOKUP_SERVICE'. */
306
/* incremental_interface :: */
307
/* If non-null, the interface through which glyph data and metrics */
308
/* are loaded incrementally for faces that do not provide all of */
309
/* this data when first opened. This field exists only if */
310
/* @FT_CONFIG_OPTION_INCREMENTAL is defined. */
312
typedef struct FT_Face_InternalRec_
314
FT_UShort max_points;
315
FT_Short max_contours;
317
FT_Matrix transform_matrix;
318
FT_Vector transform_delta;
319
FT_Int transform_flags;
321
FT_ServiceCacheRec services;
323
#ifdef FT_CONFIG_OPTION_INCREMENTAL
324
FT_Incremental_InterfaceRec* incremental_interface;
327
} FT_Face_InternalRec;
330
/*************************************************************************/
333
/* FT_Slot_InternalRec */
336
/* This structure contains the internal fields of each FT_GlyphSlot */
337
/* object. These fields may change between different releases of */
341
/* loader :: The glyph loader object used to load outlines */
342
/* into the glyph slot. */
344
/* flags :: Possible values are zero or */
345
/* FT_GLYPH_OWN_BITMAP. The latter indicates */
346
/* that the FT_GlyphSlot structure owns the */
349
/* glyph_transformed :: Boolean. Set to TRUE when the loaded glyph */
350
/* must be transformed through a specific */
351
/* font transformation. This is _not_ the same */
352
/* as the face transform set through */
353
/* FT_Set_Transform(). */
355
/* glyph_matrix :: The 2x2 matrix corresponding to the glyph */
356
/* transformation, if necessary. */
358
/* glyph_delta :: The 2d translation vector corresponding to */
359
/* the glyph transformation, if necessary. */
361
/* glyph_hints :: Format-specific glyph hints management. */
364
#define FT_GLYPH_OWN_BITMAP 0x1
366
typedef struct FT_Slot_InternalRec_
368
FT_GlyphLoader loader;
370
FT_Bool glyph_transformed;
371
FT_Matrix glyph_matrix;
372
FT_Vector glyph_delta;
375
} FT_GlyphSlot_InternalRec;
378
/*************************************************************************/
379
/*************************************************************************/
380
/*************************************************************************/
383
/**** M O D U L E S ****/
386
/*************************************************************************/
387
/*************************************************************************/
388
/*************************************************************************/
391
/*************************************************************************/
397
/* A module object instance. */
400
/* clazz :: A pointer to the module's class. */
402
/* library :: A handle to the parent library object. */
404
/* memory :: A handle to the memory manager. */
406
/* generic :: A generic structure for user-level extensibility (?). */
408
typedef struct FT_ModuleRec_
410
FT_Module_Class* clazz;
418
/* typecast an object to a FT_Module */
419
#define FT_MODULE( x ) ((FT_Module)( x ))
420
#define FT_MODULE_CLASS( x ) FT_MODULE( x )->clazz
421
#define FT_MODULE_LIBRARY( x ) FT_MODULE( x )->library
422
#define FT_MODULE_MEMORY( x ) FT_MODULE( x )->memory
425
#define FT_MODULE_IS_DRIVER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
426
FT_MODULE_FONT_DRIVER )
428
#define FT_MODULE_IS_RENDERER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
431
#define FT_MODULE_IS_HINTER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
434
#define FT_MODULE_IS_STYLER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
437
#define FT_DRIVER_IS_SCALABLE( x ) ( FT_MODULE_CLASS( x )->module_flags & \
438
FT_MODULE_DRIVER_SCALABLE )
440
#define FT_DRIVER_USES_OUTLINES( x ) !( FT_MODULE_CLASS( x )->module_flags & \
441
FT_MODULE_DRIVER_NO_OUTLINES )
443
#define FT_DRIVER_HAS_HINTER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
444
FT_MODULE_DRIVER_HAS_HINTER )
447
/*************************************************************************/
450
/* FT_Get_Module_Interface */
453
/* Finds a module and returns its specific interface as a typeless */
457
/* library :: A handle to the library object. */
459
/* module_name :: The module's name (as an ASCII string). */
462
/* A module-specific interface if available, 0 otherwise. */
465
/* You should better be familiar with FreeType internals to know */
466
/* which module to look for, and what its interface is :-) */
468
FT_BASE( const void* )
469
FT_Get_Module_Interface( FT_Library library,
470
const char* mod_name );
472
FT_BASE( FT_Pointer )
473
ft_module_get_service( FT_Module module,
474
const char* service_id );
479
/*************************************************************************/
480
/*************************************************************************/
481
/*************************************************************************/
484
/**** FACE, SIZE & GLYPH SLOT OBJECTS ****/
487
/*************************************************************************/
488
/*************************************************************************/
489
/*************************************************************************/
491
/* a few macros used to perform easy typecasts with minimal brain damage */
493
#define FT_FACE( x ) ((FT_Face)(x))
494
#define FT_SIZE( x ) ((FT_Size)(x))
495
#define FT_SLOT( x ) ((FT_GlyphSlot)(x))
497
#define FT_FACE_DRIVER( x ) FT_FACE( x )->driver
498
#define FT_FACE_LIBRARY( x ) FT_FACE_DRIVER( x )->root.library
499
#define FT_FACE_MEMORY( x ) FT_FACE( x )->memory
500
#define FT_FACE_STREAM( x ) FT_FACE( x )->stream
502
#define FT_SIZE_FACE( x ) FT_SIZE( x )->face
503
#define FT_SLOT_FACE( x ) FT_SLOT( x )->face
505
#define FT_FACE_SLOT( x ) FT_FACE( x )->glyph
506
#define FT_FACE_SIZE( x ) FT_FACE( x )->size
509
/*************************************************************************/
512
/* FT_New_GlyphSlot */
515
/* It is sometimes useful to have more than one glyph slot for a */
516
/* given face object. This function is used to create additional */
517
/* slots. All of them are automatically discarded when the face is */
521
/* face :: A handle to a parent face object. */
524
/* aslot :: A handle to a new glyph slot object. */
527
/* FreeType error code. 0 means success. */
530
FT_New_GlyphSlot( FT_Face face,
531
FT_GlyphSlot *aslot );
534
/*************************************************************************/
537
/* FT_Done_GlyphSlot */
540
/* Destroys a given glyph slot. Remember however that all slots are */
541
/* automatically destroyed with its parent. Using this function is */
542
/* not always mandatory. */
545
/* slot :: A handle to a target glyph slot. */
548
FT_Done_GlyphSlot( FT_GlyphSlot slot );
553
* Free the bitmap of a given glyphslot when needed
554
* (i.e., only when it was allocated with ft_glyphslot_alloc_bitmap).
557
ft_glyphslot_free_bitmap( FT_GlyphSlot slot );
561
* Allocate a new bitmap buffer in a glyph slot.
564
ft_glyphslot_alloc_bitmap( FT_GlyphSlot slot,
569
* Set the bitmap buffer in a glyph slot to a given pointer.
570
* The buffer will not be freed by a later call to ft_glyphslot_free_bitmap.
573
ft_glyphslot_set_bitmap( FT_GlyphSlot slot,
577
/*************************************************************************/
578
/*************************************************************************/
579
/*************************************************************************/
582
/**** R E N D E R E R S ****/
585
/*************************************************************************/
586
/*************************************************************************/
587
/*************************************************************************/
590
#define FT_RENDERER( x ) ((FT_Renderer)( x ))
591
#define FT_GLYPH( x ) ((FT_Glyph)( x ))
592
#define FT_BITMAP_GLYPH( x ) ((FT_BitmapGlyph)( x ))
593
#define FT_OUTLINE_GLYPH( x ) ((FT_OutlineGlyph)( x ))
596
typedef struct FT_RendererRec_
599
FT_Renderer_Class* clazz;
600
FT_Glyph_Format glyph_format;
601
FT_Glyph_Class glyph_class;
604
FT_Raster_Render_Func raster_render;
605
FT_Renderer_RenderFunc render;
610
/*************************************************************************/
611
/*************************************************************************/
612
/*************************************************************************/
615
/**** F O N T D R I V E R S ****/
618
/*************************************************************************/
619
/*************************************************************************/
620
/*************************************************************************/
623
/* typecast a module into a driver easily */
624
#define FT_DRIVER( x ) ((FT_Driver)(x))
626
/* typecast a module as a driver, and get its driver class */
627
#define FT_DRIVER_CLASS( x ) FT_DRIVER( x )->clazz
630
/*************************************************************************/
636
/* The root font driver class. A font driver is responsible for */
637
/* managing and loading font files of a given format. */
640
/* root :: Contains the fields of the root module class. */
642
/* clazz :: A pointer to the font driver's class. Note that */
643
/* this is NOT root.clazz. `class' wasn't used */
644
/* as it is a reserved word in C++. */
646
/* faces_list :: The list of faces currently opened by this */
649
/* extensions :: A typeless pointer to the driver's extensions */
650
/* registry, if they are supported through the */
651
/* configuration macro FT_CONFIG_OPTION_EXTENSIONS. */
653
/* glyph_loader :: The glyph loader for all faces managed by this */
654
/* driver. This object isn't defined for unscalable */
657
typedef struct FT_DriverRec_
660
FT_Driver_Class clazz;
662
FT_ListRec faces_list;
665
FT_GlyphLoader glyph_loader;
670
/*************************************************************************/
671
/*************************************************************************/
672
/*************************************************************************/
675
/**** L I B R A R I E S ****/
678
/*************************************************************************/
679
/*************************************************************************/
680
/*************************************************************************/
683
/* this hook is used by the TrueType debugger. It must be set to an alternate
684
* truetype bytecode interpreter function
686
#define FT_DEBUG_HOOK_TRUETYPE 0
689
/* set this debug hook to a non-null pointer to force unpatented hinting
690
* for all faces when both TT_CONFIG_OPTION_BYTECODE_INTERPRETER and
691
* TT_CONFIG_OPTION_UNPATENTED_HINTING are defined. this is only used
694
#define FT_DEBUG_HOOK_UNPATENTED_HINTING 1
697
/*************************************************************************/
703
/* The FreeType library class. This is the root of all FreeType */
704
/* data. Use FT_New_Library() to create a library object, and */
705
/* FT_Done_Library() to discard it and all child objects. */
708
/* memory :: The library's memory object. Manages memory */
711
/* generic :: Client data variable. Used to extend the */
712
/* Library class by higher levels and clients. */
714
/* version_major :: The major version number of the library. */
716
/* version_minor :: The minor version number of the library. */
718
/* version_patch :: The current patch level of the library. */
720
/* num_modules :: The number of modules currently registered */
721
/* within this library. This is set to 0 for new */
722
/* libraries. New modules are added through the */
723
/* FT_Add_Module() API function. */
725
/* modules :: A table used to store handles to the currently */
726
/* registered modules. Note that each font driver */
727
/* contains a list of its opened faces. */
729
/* renderers :: The list of renderers currently registered */
730
/* within the library. */
732
/* cur_renderer :: The current outline renderer. This is a */
733
/* shortcut used to avoid parsing the list on */
734
/* each call to FT_Outline_Render(). It is a */
735
/* handle to the current renderer for the */
736
/* FT_GLYPH_FORMAT_OUTLINE format. */
738
/* auto_hinter :: XXX */
740
/* raster_pool :: The raster object's render pool. This can */
741
/* ideally be changed dynamically at run-time. */
743
/* raster_pool_size :: The size of the render pool in bytes. */
745
/* debug_hooks :: XXX */
747
typedef struct FT_LibraryRec_
749
FT_Memory memory; /* library's memory manager */
753
FT_Int version_major;
754
FT_Int version_minor;
755
FT_Int version_patch;
758
FT_Module modules[FT_MAX_MODULES]; /* module objects */
760
FT_ListRec renderers; /* list of renderers */
761
FT_Renderer cur_renderer; /* current outline renderer */
762
FT_Module auto_hinter;
764
FT_Byte* raster_pool; /* scan-line conversion */
766
FT_ULong raster_pool_size; /* size of render pool in bytes */
768
FT_DebugHook_Func debug_hooks[4];
773
FT_BASE( FT_Renderer )
774
FT_Lookup_Renderer( FT_Library library,
775
FT_Glyph_Format format,
779
FT_Render_Glyph_Internal( FT_Library library,
781
FT_Render_Mode render_mode );
784
(*FT_Face_GetPostscriptNameFunc)( FT_Face face );
787
(*FT_Face_GetGlyphNameFunc)( FT_Face face,
790
FT_UInt buffer_max );
793
(*FT_Face_GetGlyphNameIndexFunc)( FT_Face face,
794
FT_String* glyph_name );
797
#ifndef FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM
799
/*************************************************************************/
805
/* Creates a new memory object. */
808
/* A pointer to the new memory object. 0 in case of error. */
810
FT_EXPORT( FT_Memory )
811
FT_New_Memory( void );
814
/*************************************************************************/
820
/* Discards memory manager. */
823
/* memory :: A handle to the memory manager. */
826
FT_Done_Memory( FT_Memory memory );
828
#endif /* !FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM */
831
/* Define default raster's interface. The default raster is located in */
832
/* `src/base/ftraster.c'. */
834
/* Client applications can register new rasters through the */
835
/* FT_Set_Raster() API. */
837
#ifndef FT_NO_DEFAULT_RASTER
838
FT_EXPORT_VAR( FT_Raster_Funcs ) ft_default_raster;
844
#endif /* __FTOBJS_H__ */