1 /***************************************************************************/
5 /* The FreeType private base classes (specification). */
7 /* Copyright 1996-2001, 2002, 2003, 2004, 2005 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 /*************************************************************************/
32 #include FT_INTERNAL_MEMORY_H
33 #include FT_INTERNAL_GLYPH_LOADER_H
34 #include FT_INTERNAL_DRIVER_H
35 #include FT_INTERNAL_AUTOHINT_H
36 #include FT_INTERNAL_SERVICE_H
38 #ifdef FT_CONFIG_OPTION_INCREMENTAL
39 #include FT_INCREMENTAL_H
46 /*************************************************************************/
48 /* Some generic definitions. */
63 /*************************************************************************/
65 /* The min and max functions missing in C. As usual, be careful not to */
66 /* write things like FT_MIN( a++, b++ ) to avoid side effects. */
68 #define FT_MIN( a, b ) ( (a) < (b) ? (a) : (b) )
69 #define FT_MAX( a, b ) ( (a) > (b) ? (a) : (b) )
71 #define FT_ABS( a ) ( (a) < 0 ? -(a) : (a) )
74 #define FT_PAD_FLOOR( x, n ) ( (x) & ~((n)-1) )
75 #define FT_PAD_ROUND( x, n ) FT_PAD_FLOOR( (x) + ((n)/2), n )
76 #define FT_PAD_CEIL( x, n ) FT_PAD_FLOOR( (x) + ((n)-1), n )
78 #define FT_PIX_FLOOR( x ) ( (x) & ~63 )
79 #define FT_PIX_ROUND( x ) FT_PIX_FLOOR( (x) + 32 )
80 #define FT_PIX_CEIL( x ) FT_PIX_FLOOR( (x) + 63 )
84 * Return the highest power of 2 that is <= value; this correspond to
85 * the highest bit in a given 32-bit value.
88 ft_highpow2( FT_UInt32 value );
91 /*************************************************************************/
92 /*************************************************************************/
93 /*************************************************************************/
96 /**** C H A R M A P S ****/
99 /*************************************************************************/
100 /*************************************************************************/
101 /*************************************************************************/
103 /* handle to internal charmap object */
104 typedef struct FT_CMapRec_* FT_CMap;
106 /* handle to charmap class structure */
107 typedef const struct FT_CMap_ClassRec_* FT_CMap_Class;
109 /* internal charmap object structure */
110 typedef struct FT_CMapRec_
112 FT_CharMapRec charmap;
117 /* typecase any pointer to a charmap handle */
118 #define FT_CMAP( x ) ((FT_CMap)( x ))
121 #define FT_CMAP_PLATFORM_ID( x ) FT_CMAP( x )->charmap.platform_id
122 #define FT_CMAP_ENCODING_ID( x ) FT_CMAP( x )->charmap.encoding_id
123 #define FT_CMAP_ENCODING( x ) FT_CMAP( x )->charmap.encoding
124 #define FT_CMAP_FACE( x ) FT_CMAP( x )->charmap.face
127 /* class method definitions */
129 (*FT_CMap_InitFunc)( FT_CMap cmap,
130 FT_Pointer init_data );
133 (*FT_CMap_DoneFunc)( FT_CMap cmap );
136 (*FT_CMap_CharIndexFunc)( FT_CMap cmap,
137 FT_UInt32 char_code );
140 (*FT_CMap_CharNextFunc)( FT_CMap cmap,
141 FT_UInt32 *achar_code );
144 typedef struct FT_CMap_ClassRec_
147 FT_CMap_InitFunc init;
148 FT_CMap_DoneFunc done;
149 FT_CMap_CharIndexFunc char_index;
150 FT_CMap_CharNextFunc char_next;
155 /* create a new charmap and add it to charmap->face */
157 FT_CMap_New( FT_CMap_Class clazz,
158 FT_Pointer init_data,
162 /* destroy a charmap and remove it from face's list */
164 FT_CMap_Done( FT_CMap cmap );
167 /*************************************************************************/
170 /* FT_Face_InternalRec */
173 /* This structure contains the internal fields of each FT_Face */
174 /* object. These fields may change between different releases of */
179 /* The maximal number of points used to store the vectorial outline */
180 /* of any glyph in this face. If this value cannot be known in */
181 /* advance, or if the face isn't scalable, this should be set to 0. */
182 /* Only relevant for scalable formats. */
184 /* max_contours :: */
185 /* The maximal number of contours used to store the vectorial */
186 /* outline of any glyph in this face. If this value cannot be */
187 /* known in advance, or if the face isn't scalable, this should be */
188 /* set to 0. Only relevant for scalable formats. */
190 /* transform_matrix :: */
191 /* A 2x2 matrix of 16.16 coefficients used to transform glyph */
192 /* outlines after they are loaded from the font. Only used by the */
193 /* convenience functions. */
195 /* transform_delta :: */
196 /* A translation vector used to transform glyph outlines after they */
197 /* are loaded from the font. Only used by the convenience */
200 /* transform_flags :: */
201 /* Some flags used to classify the transform. Only used by the */
202 /* convenience functions. */
205 /* A cache for frequently used services. It should be only */
206 /* accessed with the macro `FT_FACE_LOOKUP_SERVICE'. */
208 /* incremental_interface :: */
209 /* If non-null, the interface through which glyph data and metrics */
210 /* are loaded incrementally for faces that do not provide all of */
211 /* this data when first opened. This field exists only if */
212 /* @FT_CONFIG_OPTION_INCREMENTAL is defined. */
214 typedef struct FT_Face_InternalRec_
216 FT_UShort max_points;
217 FT_Short max_contours;
219 FT_Matrix transform_matrix;
220 FT_Vector transform_delta;
221 FT_Int transform_flags;
223 FT_ServiceCacheRec services;
225 #ifdef FT_CONFIG_OPTION_INCREMENTAL
226 FT_Incremental_InterfaceRec* incremental_interface;
229 } FT_Face_InternalRec;
232 /*************************************************************************/
235 /* FT_Slot_InternalRec */
238 /* This structure contains the internal fields of each FT_GlyphSlot */
239 /* object. These fields may change between different releases of */
243 /* loader :: The glyph loader object used to load outlines */
244 /* into the glyph slot. */
246 /* flags :: Possible values are zero or */
247 /* FT_GLYPH_OWN_BITMAP. The latter indicates */
248 /* that the FT_GlyphSlot structure owns the */
251 /* glyph_transformed :: Boolean. Set to TRUE when the loaded glyph */
252 /* must be transformed through a specific */
253 /* font transformation. This is _not_ the same */
254 /* as the face transform set through */
255 /* FT_Set_Transform(). */
257 /* glyph_matrix :: The 2x2 matrix corresponding to the glyph */
258 /* transformation, if necessary. */
260 /* glyph_delta :: The 2d translation vector corresponding to */
261 /* the glyph transformation, if necessary. */
263 /* glyph_hints :: Format-specific glyph hints management. */
266 #define FT_GLYPH_OWN_BITMAP 0x1
268 typedef struct FT_Slot_InternalRec_
270 FT_GlyphLoader loader;
272 FT_Bool glyph_transformed;
273 FT_Matrix glyph_matrix;
274 FT_Vector glyph_delta;
277 } FT_GlyphSlot_InternalRec;
280 /*************************************************************************/
281 /*************************************************************************/
282 /*************************************************************************/
285 /**** M O D U L E S ****/
288 /*************************************************************************/
289 /*************************************************************************/
290 /*************************************************************************/
293 /*************************************************************************/
299 /* A module object instance. */
302 /* clazz :: A pointer to the module's class. */
304 /* library :: A handle to the parent library object. */
306 /* memory :: A handle to the memory manager. */
308 /* generic :: A generic structure for user-level extensibility (?). */
310 typedef struct FT_ModuleRec_
312 FT_Module_Class* clazz;
320 /* typecast an object to a FT_Module */
321 #define FT_MODULE( x ) ((FT_Module)( x ))
322 #define FT_MODULE_CLASS( x ) FT_MODULE( x )->clazz
323 #define FT_MODULE_LIBRARY( x ) FT_MODULE( x )->library
324 #define FT_MODULE_MEMORY( x ) FT_MODULE( x )->memory
327 #define FT_MODULE_IS_DRIVER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
328 FT_MODULE_FONT_DRIVER )
330 #define FT_MODULE_IS_RENDERER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
333 #define FT_MODULE_IS_HINTER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
336 #define FT_MODULE_IS_STYLER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
339 #define FT_DRIVER_IS_SCALABLE( x ) ( FT_MODULE_CLASS( x )->module_flags & \
340 FT_MODULE_DRIVER_SCALABLE )
342 #define FT_DRIVER_USES_OUTLINES( x ) !( FT_MODULE_CLASS( x )->module_flags & \
343 FT_MODULE_DRIVER_NO_OUTLINES )
345 #define FT_DRIVER_HAS_HINTER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
346 FT_MODULE_DRIVER_HAS_HINTER )
349 /*************************************************************************/
352 /* FT_Get_Module_Interface */
355 /* Finds a module and returns its specific interface as a typeless */
359 /* library :: A handle to the library object. */
361 /* module_name :: The module's name (as an ASCII string). */
364 /* A module-specific interface if available, 0 otherwise. */
367 /* You should better be familiar with FreeType internals to know */
368 /* which module to look for, and what its interface is :-) */
370 FT_BASE( const void* )
371 FT_Get_Module_Interface( FT_Library library,
372 const char* mod_name );
374 FT_BASE( FT_Pointer )
375 ft_module_get_service( FT_Module module,
376 const char* service_id );
381 /*************************************************************************/
382 /*************************************************************************/
383 /*************************************************************************/
386 /**** FACE, SIZE & GLYPH SLOT OBJECTS ****/
389 /*************************************************************************/
390 /*************************************************************************/
391 /*************************************************************************/
393 /* a few macros used to perform easy typecasts with minimal brain damage */
395 #define FT_FACE( x ) ((FT_Face)(x))
396 #define FT_SIZE( x ) ((FT_Size)(x))
397 #define FT_SLOT( x ) ((FT_GlyphSlot)(x))
399 #define FT_FACE_DRIVER( x ) FT_FACE( x )->driver
400 #define FT_FACE_LIBRARY( x ) FT_FACE_DRIVER( x )->root.library
401 #define FT_FACE_MEMORY( x ) FT_FACE( x )->memory
402 #define FT_FACE_STREAM( x ) FT_FACE( x )->stream
404 #define FT_SIZE_FACE( x ) FT_SIZE( x )->face
405 #define FT_SLOT_FACE( x ) FT_SLOT( x )->face
407 #define FT_FACE_SLOT( x ) FT_FACE( x )->glyph
408 #define FT_FACE_SIZE( x ) FT_FACE( x )->size
411 /*************************************************************************/
414 /* FT_New_GlyphSlot */
417 /* It is sometimes useful to have more than one glyph slot for a */
418 /* given face object. This function is used to create additional */
419 /* slots. All of them are automatically discarded when the face is */
423 /* face :: A handle to a parent face object. */
426 /* aslot :: A handle to a new glyph slot object. */
429 /* FreeType error code. 0 means success. */
432 FT_New_GlyphSlot( FT_Face face,
433 FT_GlyphSlot *aslot );
436 /*************************************************************************/
439 /* FT_Done_GlyphSlot */
442 /* Destroys a given glyph slot. Remember however that all slots are */
443 /* automatically destroyed with its parent. Using this function is */
444 /* not always mandatory. */
447 /* slot :: A handle to a target glyph slot. */
450 FT_Done_GlyphSlot( FT_GlyphSlot slot );
455 * Free the bitmap of a given glyphslot when needed
456 * (i.e., only when it was allocated with ft_glyphslot_alloc_bitmap).
459 ft_glyphslot_free_bitmap( FT_GlyphSlot slot );
463 * Allocate a new bitmap buffer in a glyph slot.
466 ft_glyphslot_alloc_bitmap( FT_GlyphSlot slot,
471 * Set the bitmap buffer in a glyph slot to a given pointer.
472 * The buffer will not be freed by a later call to ft_glyphslot_free_bitmap.
475 ft_glyphslot_set_bitmap( FT_GlyphSlot slot,
479 /*************************************************************************/
480 /*************************************************************************/
481 /*************************************************************************/
484 /**** R E N D E R E R S ****/
487 /*************************************************************************/
488 /*************************************************************************/
489 /*************************************************************************/
492 #define FT_RENDERER( x ) ((FT_Renderer)( x ))
493 #define FT_GLYPH( x ) ((FT_Glyph)( x ))
494 #define FT_BITMAP_GLYPH( x ) ((FT_BitmapGlyph)( x ))
495 #define FT_OUTLINE_GLYPH( x ) ((FT_OutlineGlyph)( x ))
498 typedef struct FT_RendererRec_
501 FT_Renderer_Class* clazz;
502 FT_Glyph_Format glyph_format;
503 FT_Glyph_Class glyph_class;
506 FT_Raster_Render_Func raster_render;
507 FT_Renderer_RenderFunc render;
512 /*************************************************************************/
513 /*************************************************************************/
514 /*************************************************************************/
517 /**** F O N T D R I V E R S ****/
520 /*************************************************************************/
521 /*************************************************************************/
522 /*************************************************************************/
525 /* typecast a module into a driver easily */
526 #define FT_DRIVER( x ) ((FT_Driver)(x))
528 /* typecast a module as a driver, and get its driver class */
529 #define FT_DRIVER_CLASS( x ) FT_DRIVER( x )->clazz
532 /*************************************************************************/
538 /* The root font driver class. A font driver is responsible for */
539 /* managing and loading font files of a given format. */
542 /* root :: Contains the fields of the root module class. */
544 /* clazz :: A pointer to the font driver's class. Note that */
545 /* this is NOT root.clazz. `class' wasn't used */
546 /* as it is a reserved word in C++. */
548 /* faces_list :: The list of faces currently opened by this */
551 /* extensions :: A typeless pointer to the driver's extensions */
552 /* registry, if they are supported through the */
553 /* configuration macro FT_CONFIG_OPTION_EXTENSIONS. */
555 /* glyph_loader :: The glyph loader for all faces managed by this */
556 /* driver. This object isn't defined for unscalable */
559 typedef struct FT_DriverRec_
562 FT_Driver_Class clazz;
564 FT_ListRec faces_list;
567 FT_GlyphLoader glyph_loader;
572 /*************************************************************************/
573 /*************************************************************************/
574 /*************************************************************************/
577 /**** L I B R A R I E S ****/
580 /*************************************************************************/
581 /*************************************************************************/
582 /*************************************************************************/
585 /* this hook is used by the TrueType debugger. It must be set to an alternate
586 * truetype bytecode interpreter function
588 #define FT_DEBUG_HOOK_TRUETYPE 0
591 /* set this debug hook to a non-null pointer to force unpatented hinting
592 * for all faces when both TT_CONFIG_OPTION_BYTECODE_INTERPRETER and
593 * TT_CONFIG_OPTION_UNPATENTED_HINTING are defined. this is only used
596 #define FT_DEBUG_HOOK_UNPATENTED_HINTING 1
599 /*************************************************************************/
605 /* The FreeType library class. This is the root of all FreeType */
606 /* data. Use FT_New_Library() to create a library object, and */
607 /* FT_Done_Library() to discard it and all child objects. */
610 /* memory :: The library's memory object. Manages memory */
613 /* generic :: Client data variable. Used to extend the */
614 /* Library class by higher levels and clients. */
616 /* version_major :: The major version number of the library. */
618 /* version_minor :: The minor version number of the library. */
620 /* version_patch :: The current patch level of the library. */
622 /* num_modules :: The number of modules currently registered */
623 /* within this library. This is set to 0 for new */
624 /* libraries. New modules are added through the */
625 /* FT_Add_Module() API function. */
627 /* modules :: A table used to store handles to the currently */
628 /* registered modules. Note that each font driver */
629 /* contains a list of its opened faces. */
631 /* renderers :: The list of renderers currently registered */
632 /* within the library. */
634 /* cur_renderer :: The current outline renderer. This is a */
635 /* shortcut used to avoid parsing the list on */
636 /* each call to FT_Outline_Render(). It is a */
637 /* handle to the current renderer for the */
638 /* FT_GLYPH_FORMAT_OUTLINE format. */
640 /* auto_hinter :: XXX */
642 /* raster_pool :: The raster object's render pool. This can */
643 /* ideally be changed dynamically at run-time. */
645 /* raster_pool_size :: The size of the render pool in bytes. */
647 /* debug_hooks :: XXX */
649 typedef struct FT_LibraryRec_
651 FT_Memory memory; /* library's memory manager */
655 FT_Int version_major;
656 FT_Int version_minor;
657 FT_Int version_patch;
660 FT_Module modules[FT_MAX_MODULES]; /* module objects */
662 FT_ListRec renderers; /* list of renderers */
663 FT_Renderer cur_renderer; /* current outline renderer */
664 FT_Module auto_hinter;
666 FT_Byte* raster_pool; /* scan-line conversion */
668 FT_ULong raster_pool_size; /* size of render pool in bytes */
670 FT_DebugHook_Func debug_hooks[4];
675 FT_BASE( FT_Renderer )
676 FT_Lookup_Renderer( FT_Library library,
677 FT_Glyph_Format format,
681 FT_Render_Glyph_Internal( FT_Library library,
683 FT_Render_Mode render_mode );
686 (*FT_Face_GetPostscriptNameFunc)( FT_Face face );
689 (*FT_Face_GetGlyphNameFunc)( FT_Face face,
692 FT_UInt buffer_max );
695 (*FT_Face_GetGlyphNameIndexFunc)( FT_Face face,
696 FT_String* glyph_name );
699 #ifndef FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM
701 /*************************************************************************/
707 /* Creates a new memory object. */
710 /* A pointer to the new memory object. 0 in case of error. */
712 FT_EXPORT( FT_Memory )
713 FT_New_Memory( void );
716 /*************************************************************************/
722 /* Discards memory manager. */
725 /* memory :: A handle to the memory manager. */
728 FT_Done_Memory( FT_Memory memory );
730 #endif /* !FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM */
733 /* Define default raster's interface. The default raster is located in */
734 /* `src/base/ftraster.c'. */
736 /* Client applications can register new rasters through the */
737 /* FT_Set_Raster() API. */
739 #ifndef FT_NO_DEFAULT_RASTER
740 FT_EXPORT_VAR( FT_Raster_Funcs ) ft_default_raster;
746 #endif /* __FTOBJS_H__ */