1 /***************************************************************************/
5 /* The FreeType private base classes (specification). */
7 /* Copyright 1996-2001, 2002 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_OBJECT_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 MIN( a++, b++ ) to avoid side effects. */
70 #define MIN( a, b ) ( (a) < (b) ? (a) : (b) )
74 #define MAX( a, b ) ( (a) > (b) ? (a) : (b) )
78 #define ABS( a ) ( (a) < 0 ? -(a) : (a) )
82 /*************************************************************************/
83 /*************************************************************************/
84 /*************************************************************************/
87 /**** V A L I D A T I O N ****/
90 /*************************************************************************/
91 /*************************************************************************/
92 /*************************************************************************/
94 /* handle to a validation object */
95 typedef struct FT_ValidatorRec_* FT_Validator;
98 /*************************************************************************/
100 /* There are three distinct validation levels defined here: */
102 /* FT_VALIDATE_DEFAULT :: */
103 /* A table that passes this validation level can be used reliably by */
104 /* FreeType. It generally means that all offsets have been checked to */
105 /* prevent out-of-bound reads, array counts are correct, etc. */
107 /* FT_VALIDATE_TIGHT :: */
108 /* A table that passes this validation level can be used reliably and */
109 /* doesn't contain invalid data. For example, a charmap table that */
110 /* returns invalid glyph indices will not pass, even though it can */
111 /* be used with FreeType in default mode (the library will simply */
112 /* return an error later when trying to load the glyph). */
114 /* It also check that fields that must be a multiple of 2, 4, or 8 */
115 /* dont' have incorrect values, etc. */
117 /* FT_VALIDATE_PARANOID :: */
118 /* Only for font debugging. Checks that a table follows the */
119 /* specification by 100%. Very few fonts will be able to pass this */
120 /* level anyway but it can be useful for certain tools like font */
121 /* editors/converters. */
123 typedef enum FT_ValidationLevel_
125 FT_VALIDATE_DEFAULT = 0,
129 } FT_ValidationLevel;
132 /* validator structure */
133 typedef struct FT_ValidatorRec_
135 const FT_Byte* base; /* address of table in memory */
136 const FT_Byte* limit; /* `base' + sizeof(table) in memory */
137 FT_ValidationLevel level; /* validation level */
138 FT_Error error; /* error returned. 0 means success */
140 ft_jmp_buf jump_buffer; /* used for exception handling */
145 #define FT_VALIDATOR( x ) ((FT_Validator)( x ))
149 ft_validator_init( FT_Validator valid,
151 const FT_Byte* limit,
152 FT_ValidationLevel level );
155 ft_validator_run( FT_Validator valid );
157 /* Sets the error field in a validator, then calls `longjmp' to return */
158 /* to high-level caller. Using `setjmp/longjmp' avoids many stupid */
159 /* error checks within the validation routines. */
162 ft_validator_error( FT_Validator valid,
166 /* Calls ft_validate_error. Assumes that the `valid' local variable */
167 /* holds a pointer to the current validator object. */
169 #define FT_INVALID( _error ) ft_validator_error( valid, _error )
171 /* called when a broken table is detected */
172 #define FT_INVALID_TOO_SHORT FT_INVALID( FT_Err_Invalid_Table )
174 /* called when an invalid offset is detected */
175 #define FT_INVALID_OFFSET FT_INVALID( FT_Err_Invalid_Offset )
177 /* called when an invalid format/value is detected */
178 #define FT_INVALID_FORMAT FT_INVALID( FT_Err_Invalid_Table )
180 /* called when an invalid glyph index is detected */
181 #define FT_INVALID_GLYPH_ID FT_INVALID( FT_Err_Invalid_Glyph_Index )
183 /* called when an invalid field value is detected */
184 #define FT_INVALID_DATA FT_INVALID( FT_Err_Invalid_Table )
187 /*************************************************************************/
188 /*************************************************************************/
189 /*************************************************************************/
192 /**** C H A R M A P S ****/
195 /*************************************************************************/
196 /*************************************************************************/
197 /*************************************************************************/
199 /* handle to internal charmap object */
200 typedef struct FT_CMapRec_* FT_CMap;
202 /* handle to charmap class structure */
203 typedef const struct FT_CMap_ClassRec_* FT_CMap_Class;
205 /* internal charmap object structure */
206 typedef struct FT_CMapRec_
208 FT_CharMapRec charmap;
213 /* typecase any pointer to a charmap handle */
214 #define FT_CMAP( x ) ((FT_CMap)( x ))
217 #define FT_CMAP_PLATFORM_ID( x ) FT_CMAP( x )->charmap.platform_id
218 #define FT_CMAP_ENCODING_ID( x ) FT_CMAP( x )->charmap.encoding_id
219 #define FT_CMAP_ENCODING( x ) FT_CMAP( x )->charmap.encoding
220 #define FT_CMAP_FACE( x ) FT_CMAP( x )->charmap.face
223 /* class method definitions */
225 (*FT_CMap_InitFunc)( FT_CMap cmap,
226 FT_Pointer init_data );
229 (*FT_CMap_DoneFunc)( FT_CMap cmap );
232 (*FT_CMap_CharIndexFunc)( FT_CMap cmap,
233 FT_UInt32 char_code );
236 (*FT_CMap_CharNextFunc)( FT_CMap cmap,
237 FT_UInt32 *achar_code );
240 typedef struct FT_CMap_ClassRec_
243 FT_CMap_InitFunc init;
244 FT_CMap_DoneFunc done;
245 FT_CMap_CharIndexFunc char_index;
246 FT_CMap_CharNextFunc char_next;
251 /* create a new charmap and add it to charmap->face */
253 FT_CMap_New( FT_CMap_Class clazz,
254 FT_Pointer init_data,
258 /* destroy a charmap (don't remove it from face's list though) */
260 FT_CMap_Done( FT_CMap cmap );
263 /*************************************************************************/
266 /* FT_Face_InternalRec */
269 /* This structure contains the internal fields of each FT_Face */
270 /* object. These fields may change between different releases of */
274 /* max_points :: The maximal number of points used to store the */
275 /* vectorial outline of any glyph in this face. */
276 /* If this value cannot be known in advance, or */
277 /* if the face isn't scalable, this should be set */
278 /* to 0. Only relevant for scalable formats. */
280 /* max_contours :: The maximal number of contours used to store */
281 /* the vectorial outline of any glyph in this */
282 /* face. If this value cannot be known in */
283 /* advance, or if the face isn't scalable, this */
284 /* should be set to 0. Only relevant for */
285 /* scalable formats. */
287 /* transform_matrix :: A 2x2 matrix of 16.16 coefficients used to */
288 /* transform glyph outlines after they are loaded */
289 /* from the font. Only used by the convenience */
292 /* transform_delta :: A translation vector used to transform glyph */
293 /* outlines after they are loaded from the font. */
294 /* Only used by the convenience functions. */
296 /* transform_flags :: Some flags used to classify the transform. */
297 /* Only used by the convenience functions. */
299 /* hint_flags :: Some flags used to change the hinters' */
300 /* behaviour. Only used for debugging for now. */
302 /* postscript_name :: Postscript font name for this face. */
304 /* incremental_interface :: */
305 /* If non-null, the interface through */
306 /* which glyph data and metrics are loaded */
307 /* incrementally for faces that do not provide */
308 /* all of this data when first opened. */
309 /* 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_UInt32 hint_flags;
323 const char* postscript_name;
325 #ifdef FT_CONFIG_OPTION_INCREMENTAL
326 FT_Incremental_InterfaceRec* incremental_interface;
329 } FT_Face_InternalRec;
332 /*************************************************************************/
335 /* FT_Slot_InternalRec */
338 /* This structure contains the internal fields of each FT_GlyphSlot */
339 /* object. These fields may change between different releases of */
343 /* loader :: The glyph loader object used to load outlines */
344 /* into the glyph slot. */
346 /* glyph_transformed :: Boolean. Set to TRUE when the loaded glyph */
347 /* must be transformed through a specific */
348 /* font transformation. This is _not_ the same */
349 /* as the face transform set through */
350 /* FT_Set_Transform(). */
352 /* glyph_matrix :: The 2x2 matrix corresponding to the glyph */
353 /* transformation, if necessary. */
355 /* glyph_delta :: The 2d translation vector corresponding to */
356 /* the glyph transformation, if necessary. */
358 /* glyph_hints :: Format-specific glyph hints management. */
360 typedef struct FT_Slot_InternalRec_
362 FT_GlyphLoader loader;
363 FT_Bool glyph_transformed;
364 FT_Matrix glyph_matrix;
365 FT_Vector glyph_delta;
368 } FT_GlyphSlot_InternalRec;
371 /*************************************************************************/
372 /*************************************************************************/
373 /*************************************************************************/
376 /**** M O D U L E S ****/
379 /*************************************************************************/
380 /*************************************************************************/
381 /*************************************************************************/
384 /*************************************************************************/
390 /* A module object instance. */
393 /* clazz :: A pointer to the module's class. */
395 /* library :: A handle to the parent library object. */
397 /* memory :: A handle to the memory manager. */
399 /* generic :: A generic structure for user-level extensibility (?). */
401 typedef struct FT_ModuleRec_
403 FT_Module_Class* clazz;
411 /* typecast an object to a FT_Module */
412 #define FT_MODULE( x ) ((FT_Module)( x ))
413 #define FT_MODULE_CLASS( x ) FT_MODULE( x )->clazz
414 #define FT_MODULE_LIBRARY( x ) FT_MODULE( x )->library
415 #define FT_MODULE_MEMORY( x ) FT_MODULE( x )->memory
418 #define FT_MODULE_IS_DRIVER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
419 ft_module_font_driver )
421 #define FT_MODULE_IS_RENDERER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
424 #define FT_MODULE_IS_HINTER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
427 #define FT_MODULE_IS_STYLER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
430 #define FT_DRIVER_IS_SCALABLE( x ) ( FT_MODULE_CLASS( x )->module_flags & \
431 ft_module_driver_scalable )
433 #define FT_DRIVER_USES_OUTLINES( x ) !( FT_MODULE_CLASS( x )->module_flags & \
434 ft_module_driver_no_outlines )
436 #define FT_DRIVER_HAS_HINTER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
437 ft_module_driver_has_hinter )
440 /*************************************************************************/
443 /* FT_Get_Module_Interface */
446 /* Finds a module and returns its specific interface as a typeless */
450 /* library :: A handle to the library object. */
452 /* module_name :: The module's name (as an ASCII string). */
455 /* A module-specific interface if available, 0 otherwise. */
458 /* You should better be familiar with FreeType internals to know */
459 /* which module to look for, and what its interface is :-) */
461 FT_BASE( const void* )
462 FT_Get_Module_Interface( FT_Library library,
463 const char* mod_name );
468 /*************************************************************************/
469 /*************************************************************************/
470 /*************************************************************************/
473 /**** FACE, SIZE & GLYPH SLOT OBJECTS ****/
476 /*************************************************************************/
477 /*************************************************************************/
478 /*************************************************************************/
480 /* a few macros used to perform easy typecasts with minimal brain damage */
482 #define FT_FACE( x ) ((FT_Face)(x))
483 #define FT_SIZE( x ) ((FT_Size)(x))
484 #define FT_SLOT( x ) ((FT_GlyphSlot)(x))
486 #define FT_FACE_DRIVER( x ) FT_FACE( x )->driver
487 #define FT_FACE_LIBRARY( x ) FT_FACE_DRIVER( x )->root.library
488 #define FT_FACE_MEMORY( x ) FT_FACE( x )->memory
489 #define FT_FACE_STREAM( x ) FT_FACE( x )->stream
491 #define FT_SIZE_FACE( x ) FT_SIZE( x )->face
492 #define FT_SLOT_FACE( x ) FT_SLOT( x )->face
494 #define FT_FACE_SLOT( x ) FT_FACE( x )->glyph
495 #define FT_FACE_SIZE( x ) FT_FACE( x )->size
498 /*************************************************************************/
501 /* FT_New_GlyphSlot */
504 /* It is sometimes useful to have more than one glyph slot for a */
505 /* given face object. This function is used to create additional */
506 /* slots. All of them are automatically discarded when the face is */
510 /* face :: A handle to a parent face object. */
513 /* aslot :: A handle to a new glyph slot object. */
516 /* FreeType error code. 0 means success. */
519 FT_New_GlyphSlot( FT_Face face,
520 FT_GlyphSlot *aslot );
523 /*************************************************************************/
526 /* FT_Done_GlyphSlot */
529 /* Destroys a given glyph slot. Remember however that all slots are */
530 /* automatically destroyed with its parent. Using this function is */
531 /* not always mandatory. */
534 /* slot :: A handle to a target glyph slot. */
537 FT_Done_GlyphSlot( FT_GlyphSlot slot );
542 * free the bitmap of a given glyphslot when needed
543 * (i.e. only when it was allocated with ft_glyphslot_alloc_bitmap)
546 ft_glyphslot_free_bitmap( FT_GlyphSlot slot );
549 * allocate a new bitmap buffer in a glyph slot
552 ft_glyphslot_alloc_bitmap( FT_GlyphSlot slot,
556 * set the bitmap buffer in a glyph slot to a given pointer.
557 * the buffer will not be freed by a later call to ft_glyphslot_free_bitmap
560 ft_glyphslot_set_bitmap( FT_GlyphSlot slot,
564 /*************************************************************************/
565 /*************************************************************************/
566 /*************************************************************************/
569 /**** R E N D E R E R S ****/
572 /*************************************************************************/
573 /*************************************************************************/
574 /*************************************************************************/
577 #define FT_RENDERER( x ) ((FT_Renderer)( x ))
578 #define FT_GLYPH( x ) ((FT_Glyph)( x ))
579 #define FT_BITMAP_GLYPH( x ) ((FT_BitmapGlyph)( x ))
580 #define FT_OUTLINE_GLYPH( x ) ((FT_OutlineGlyph)( x ))
583 typedef struct FT_RendererRec_
586 FT_Renderer_Class* clazz;
587 FT_Glyph_Format glyph_format;
588 FT_Glyph_Class glyph_class;
591 FT_Raster_Render_Func raster_render;
592 FT_Renderer_RenderFunc render;
597 /*************************************************************************/
598 /*************************************************************************/
599 /*************************************************************************/
602 /**** F O N T D R I V E R S ****/
605 /*************************************************************************/
606 /*************************************************************************/
607 /*************************************************************************/
610 /* typecast a module into a driver easily */
611 #define FT_DRIVER( x ) ((FT_Driver)(x))
613 /* typecast a module as a driver, and get its driver class */
614 #define FT_DRIVER_CLASS( x ) FT_DRIVER( x )->clazz
617 /*************************************************************************/
623 /* The root font driver class. A font driver is responsible for */
624 /* managing and loading font files of a given format. */
627 /* root :: Contains the fields of the root module class. */
629 /* clazz :: A pointer to the font driver's class. Note that */
630 /* this is NOT root.clazz. `class' wasn't used */
631 /* as it is a reserved word in C++. */
633 /* faces_list :: The list of faces currently opened by this */
636 /* extensions :: A typeless pointer to the driver's extensions */
637 /* registry, if they are supported through the */
638 /* configuration macro FT_CONFIG_OPTION_EXTENSIONS. */
640 /* glyph_loader :: The glyph loader for all faces managed by this */
641 /* driver. This object isn't defined for unscalable */
644 typedef struct FT_DriverRec_
647 FT_Driver_Class clazz;
649 FT_ListRec faces_list;
652 FT_GlyphLoader glyph_loader;
657 /*************************************************************************/
658 /*************************************************************************/
659 /*************************************************************************/
662 /**** L I B R A R I E S ****/
665 /*************************************************************************/
666 /*************************************************************************/
667 /*************************************************************************/
670 #define FT_DEBUG_HOOK_TRUETYPE 0
671 #define FT_DEBUG_HOOK_TYPE1 1
674 /*************************************************************************/
680 /* The FreeType library class. This is the root of all FreeType */
681 /* data. Use FT_New_Library() to create a library object, and */
682 /* FT_Done_Library() to discard it and all child objects. */
685 /* memory :: The library's memory object. Manages memory */
688 /* generic :: Client data variable. Used to extend the */
689 /* Library class by higher levels and clients. */
691 /* num_modules :: The number of modules currently registered */
692 /* within this library. This is set to 0 for new */
693 /* libraries. New modules are added through the */
694 /* FT_Add_Module() API function. */
696 /* modules :: A table used to store handles to the currently */
697 /* registered modules. Note that each font driver */
698 /* contains a list of its opened faces. */
700 /* renderers :: The list of renderers currently registered */
701 /* within the library. */
703 /* cur_renderer :: The current outline renderer. This is a */
704 /* shortcut used to avoid parsing the list on */
705 /* each call to FT_Outline_Render(). It is a */
706 /* handle to the current renderer for the */
707 /* FT_GLYPH_FORMAT_OUTLINE format. */
709 /* auto_hinter :: XXX */
711 /* raster_pool :: The raster object's render pool. This can */
712 /* ideally be changed dynamically at run-time. */
714 /* raster_pool_size :: The size of the render pool in bytes. */
716 /* debug_hooks :: XXX */
718 typedef struct FT_LibraryRec_
720 FT_Memory memory; /* library's memory manager */
724 FT_Int version_major;
725 FT_Int version_minor;
726 FT_Int version_patch;
729 FT_Module modules[FT_MAX_MODULES]; /* module objects */
731 FT_ListRec renderers; /* list of renderers */
732 FT_Renderer cur_renderer; /* current outline renderer */
733 FT_Module auto_hinter;
735 FT_Byte* raster_pool; /* scan-line conversion */
737 FT_ULong raster_pool_size; /* size of render pool in bytes */
739 FT_DebugHook_Func debug_hooks[4];
741 FT_MetaClassRec meta_class;
746 FT_BASE( FT_Renderer )
747 FT_Lookup_Renderer( FT_Library library,
748 FT_Glyph_Format format,
752 FT_Render_Glyph_Internal( FT_Library library,
754 FT_Render_Mode render_mode );
757 (*FT_Face_GetPostscriptNameFunc)( FT_Face face );
760 (*FT_Face_GetGlyphNameFunc)( FT_Face face,
763 FT_UInt buffer_max );
766 (*FT_Face_GetGlyphNameIndexFunc)( FT_Face face,
767 FT_String* glyph_name );
770 #ifndef FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM
772 /*************************************************************************/
778 /* Creates a new memory object. */
781 /* A pointer to the new memory object. 0 in case of error. */
783 FT_EXPORT( FT_Memory )
784 FT_New_Memory( void );
787 /*************************************************************************/
793 /* Discards memory manager. */
796 /* memory :: A handle to the memory manager. */
799 FT_Done_Memory( FT_Memory memory );
801 #endif /* !FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM */
804 /* Define default raster's interface. The default raster is located in */
805 /* `src/base/ftraster.c'. */
807 /* Client applications can register new rasters through the */
808 /* FT_Set_Raster() API. */
810 #ifndef FT_NO_DEFAULT_RASTER
811 FT_EXPORT_VAR( FT_Raster_Funcs ) ft_default_raster;
817 #endif /* __FTOBJS_H__ */