1 /***************************************************************************/
5 /* The FreeType private base classes (specification). */
7 /* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006 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_LCD_FILTER_H
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 )
85 * Return the highest power of 2 that is <= value; this correspond to
86 * the highest bit in a given 32-bit value.
89 ft_highpow2( FT_UInt32 value
);
93 * character classification functions -- since these are used to parse
94 * font files, we must not use those in <ctypes.h> which are
97 #define ft_isdigit( x ) ( ( (unsigned)(x) - '0' ) < 10U )
99 #define ft_isxdigit( x ) ( ( (unsigned)(x) - '0' ) < 10U || \
100 ( (unsigned)(x) - 'a' ) < 6U || \
101 ( (unsigned)(x) - 'A' ) < 6U )
103 /* the next two macros assume ASCII representation */
104 #define ft_isupper( x ) ( ( (unsigned)(x) - 'A' ) < 26U )
105 #define ft_islower( x ) ( ( (unsigned)(x) - 'a' ) < 26U )
107 #define ft_isalpha( x ) ( ft_isupper( x ) || ft_islower( x ) )
108 #define ft_isalnum( x ) ( ft_isdigit( x ) || ft_isalpha( x ) )
111 /*************************************************************************/
112 /*************************************************************************/
113 /*************************************************************************/
116 /**** C H A R M A P S ****/
119 /*************************************************************************/
120 /*************************************************************************/
121 /*************************************************************************/
123 /* handle to internal charmap object */
124 typedef struct FT_CMapRec_
* FT_CMap
;
126 /* handle to charmap class structure */
127 typedef const struct FT_CMap_ClassRec_
* FT_CMap_Class
;
129 /* internal charmap object structure */
130 typedef struct FT_CMapRec_
132 FT_CharMapRec charmap
;
137 /* typecase any pointer to a charmap handle */
138 #define FT_CMAP( x ) ((FT_CMap)( x ))
141 #define FT_CMAP_PLATFORM_ID( x ) FT_CMAP( x )->charmap.platform_id
142 #define FT_CMAP_ENCODING_ID( x ) FT_CMAP( x )->charmap.encoding_id
143 #define FT_CMAP_ENCODING( x ) FT_CMAP( x )->charmap.encoding
144 #define FT_CMAP_FACE( x ) FT_CMAP( x )->charmap.face
147 /* class method definitions */
149 (*FT_CMap_InitFunc
)( FT_CMap cmap
,
150 FT_Pointer init_data
);
153 (*FT_CMap_DoneFunc
)( FT_CMap cmap
);
156 (*FT_CMap_CharIndexFunc
)( FT_CMap cmap
,
157 FT_UInt32 char_code
);
160 (*FT_CMap_CharNextFunc
)( FT_CMap cmap
,
161 FT_UInt32
*achar_code
);
164 typedef struct FT_CMap_ClassRec_
167 FT_CMap_InitFunc init
;
168 FT_CMap_DoneFunc done
;
169 FT_CMap_CharIndexFunc char_index
;
170 FT_CMap_CharNextFunc char_next
;
175 /* create a new charmap and add it to charmap->face */
177 FT_CMap_New( FT_CMap_Class clazz
,
178 FT_Pointer init_data
,
182 /* destroy a charmap and remove it from face's list */
184 FT_CMap_Done( FT_CMap cmap
);
187 /*************************************************************************/
190 /* FT_Face_InternalRec */
193 /* This structure contains the internal fields of each FT_Face */
194 /* object. These fields may change between different releases of */
199 /* The maximal number of points used to store the vectorial outline */
200 /* of any glyph in this face. If this value cannot be known in */
201 /* advance, or if the face isn't scalable, this should be set to 0. */
202 /* Only relevant for scalable formats. */
204 /* max_contours :: */
205 /* The maximal number of contours used to store the vectorial */
206 /* outline of any glyph in this face. If this value cannot be */
207 /* known in advance, or if the face isn't scalable, this should be */
208 /* set to 0. Only relevant for scalable formats. */
210 /* transform_matrix :: */
211 /* A 2x2 matrix of 16.16 coefficients used to transform glyph */
212 /* outlines after they are loaded from the font. Only used by the */
213 /* convenience functions. */
215 /* transform_delta :: */
216 /* A translation vector used to transform glyph outlines after they */
217 /* are loaded from the font. Only used by the convenience */
220 /* transform_flags :: */
221 /* Some flags used to classify the transform. Only used by the */
222 /* convenience functions. */
225 /* A cache for frequently used services. It should be only */
226 /* accessed with the macro `FT_FACE_LOOKUP_SERVICE'. */
228 /* incremental_interface :: */
229 /* If non-null, the interface through which glyph data and metrics */
230 /* are loaded incrementally for faces that do not provide all of */
231 /* this data when first opened. This field exists only if */
232 /* @FT_CONFIG_OPTION_INCREMENTAL is defined. */
234 /* ignore_unpatented_hinter :: */
235 /* This boolean flag instructs the glyph loader to ignore the */
236 /* native font hinter, if one is found. This is exclusively used */
237 /* in the case when the unpatented hinter is compiled within the */
240 typedef struct FT_Face_InternalRec_
242 #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
246 FT_Matrix transform_matrix
;
247 FT_Vector transform_delta
;
248 FT_Int transform_flags
;
250 FT_ServiceCacheRec services
;
252 #ifdef FT_CONFIG_OPTION_INCREMENTAL
253 FT_Incremental_InterfaceRec
* incremental_interface
;
256 FT_Bool ignore_unpatented_hinter
;
258 } FT_Face_InternalRec
;
261 /*************************************************************************/
264 /* FT_Slot_InternalRec */
267 /* This structure contains the internal fields of each FT_GlyphSlot */
268 /* object. These fields may change between different releases of */
272 /* loader :: The glyph loader object used to load outlines */
273 /* into the glyph slot. */
275 /* flags :: Possible values are zero or */
276 /* FT_GLYPH_OWN_BITMAP. The latter indicates */
277 /* that the FT_GlyphSlot structure owns the */
280 /* glyph_transformed :: Boolean. Set to TRUE when the loaded glyph */
281 /* must be transformed through a specific */
282 /* font transformation. This is _not_ the same */
283 /* as the face transform set through */
284 /* FT_Set_Transform(). */
286 /* glyph_matrix :: The 2x2 matrix corresponding to the glyph */
287 /* transformation, if necessary. */
289 /* glyph_delta :: The 2d translation vector corresponding to */
290 /* the glyph transformation, if necessary. */
292 /* glyph_hints :: Format-specific glyph hints management. */
295 #define FT_GLYPH_OWN_BITMAP 0x1
297 typedef struct FT_Slot_InternalRec_
299 FT_GlyphLoader loader
;
301 FT_Bool glyph_transformed
;
302 FT_Matrix glyph_matrix
;
303 FT_Vector glyph_delta
;
306 } FT_GlyphSlot_InternalRec
;
309 /*************************************************************************/
310 /*************************************************************************/
311 /*************************************************************************/
314 /**** M O D U L E S ****/
317 /*************************************************************************/
318 /*************************************************************************/
319 /*************************************************************************/
322 /*************************************************************************/
328 /* A module object instance. */
331 /* clazz :: A pointer to the module's class. */
333 /* library :: A handle to the parent library object. */
335 /* memory :: A handle to the memory manager. */
337 /* generic :: A generic structure for user-level extensibility (?). */
339 typedef struct FT_ModuleRec_
341 FT_Module_Class
* clazz
;
349 /* typecast an object to a FT_Module */
350 #define FT_MODULE( x ) ((FT_Module)( x ))
351 #define FT_MODULE_CLASS( x ) FT_MODULE( x )->clazz
352 #define FT_MODULE_LIBRARY( x ) FT_MODULE( x )->library
353 #define FT_MODULE_MEMORY( x ) FT_MODULE( x )->memory
356 #define FT_MODULE_IS_DRIVER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
357 FT_MODULE_FONT_DRIVER )
359 #define FT_MODULE_IS_RENDERER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
362 #define FT_MODULE_IS_HINTER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
365 #define FT_MODULE_IS_STYLER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
368 #define FT_DRIVER_IS_SCALABLE( x ) ( FT_MODULE_CLASS( x )->module_flags & \
369 FT_MODULE_DRIVER_SCALABLE )
371 #define FT_DRIVER_USES_OUTLINES( x ) !( FT_MODULE_CLASS( x )->module_flags & \
372 FT_MODULE_DRIVER_NO_OUTLINES )
374 #define FT_DRIVER_HAS_HINTER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
375 FT_MODULE_DRIVER_HAS_HINTER )
378 /*************************************************************************/
381 /* FT_Get_Module_Interface */
384 /* Finds a module and returns its specific interface as a typeless */
388 /* library :: A handle to the library object. */
390 /* module_name :: The module's name (as an ASCII string). */
393 /* A module-specific interface if available, 0 otherwise. */
396 /* You should better be familiar with FreeType internals to know */
397 /* which module to look for, and what its interface is :-) */
399 FT_BASE( const void* )
400 FT_Get_Module_Interface( FT_Library library
,
401 const char* mod_name
);
403 FT_BASE( FT_Pointer
)
404 ft_module_get_service( FT_Module module
,
405 const char* service_id
);
410 /*************************************************************************/
411 /*************************************************************************/
412 /*************************************************************************/
415 /**** FACE, SIZE & GLYPH SLOT OBJECTS ****/
418 /*************************************************************************/
419 /*************************************************************************/
420 /*************************************************************************/
422 /* a few macros used to perform easy typecasts with minimal brain damage */
424 #define FT_FACE( x ) ((FT_Face)(x))
425 #define FT_SIZE( x ) ((FT_Size)(x))
426 #define FT_SLOT( x ) ((FT_GlyphSlot)(x))
428 #define FT_FACE_DRIVER( x ) FT_FACE( x )->driver
429 #define FT_FACE_LIBRARY( x ) FT_FACE_DRIVER( x )->root.library
430 #define FT_FACE_MEMORY( x ) FT_FACE( x )->memory
431 #define FT_FACE_STREAM( x ) FT_FACE( x )->stream
433 #define FT_SIZE_FACE( x ) FT_SIZE( x )->face
434 #define FT_SLOT_FACE( x ) FT_SLOT( x )->face
436 #define FT_FACE_SLOT( x ) FT_FACE( x )->glyph
437 #define FT_FACE_SIZE( x ) FT_FACE( x )->size
440 /*************************************************************************/
443 /* FT_New_GlyphSlot */
446 /* It is sometimes useful to have more than one glyph slot for a */
447 /* given face object. This function is used to create additional */
448 /* slots. All of them are automatically discarded when the face is */
452 /* face :: A handle to a parent face object. */
455 /* aslot :: A handle to a new glyph slot object. */
458 /* FreeType error code. 0 means success. */
461 FT_New_GlyphSlot( FT_Face face
,
462 FT_GlyphSlot
*aslot
);
465 /*************************************************************************/
468 /* FT_Done_GlyphSlot */
471 /* Destroys a given glyph slot. Remember however that all slots are */
472 /* automatically destroyed with its parent. Using this function is */
473 /* not always mandatory. */
476 /* slot :: A handle to a target glyph slot. */
479 FT_Done_GlyphSlot( FT_GlyphSlot slot
);
483 #define FT_REQUEST_WIDTH( req ) \
484 ( (req)->horiResolution \
485 ? (FT_Pos)( (req)->width * (req)->horiResolution + 36 ) / 72 \
488 #define FT_REQUEST_HEIGHT( req ) \
489 ( (req)->vertResolution \
490 ? (FT_Pos)( (req)->height * (req)->vertResolution + 36 ) / 72 \
494 /* Set the metrics according to a bitmap strike. */
496 FT_Select_Metrics( FT_Face face
,
497 FT_ULong strike_index
);
500 /* Set the metrics according to a size request. */
502 FT_Request_Metrics( FT_Face face
,
503 FT_Size_Request req
);
506 /* Match a size request against `available_sizes'. */
508 FT_Match_Size( FT_Face face
,
510 FT_Bool ignore_width
,
511 FT_ULong
* size_index
);
514 /* Use the horizontal metrics to synthesize the vertical metrics. */
515 /* If `advance' is zero, it is also synthesized. */
517 ft_synthesize_vertical_metrics( FT_Glyph_Metrics
* metrics
,
521 /* Free the bitmap of a given glyphslot when needed (i.e., only when it */
522 /* was allocated with ft_glyphslot_alloc_bitmap). */
524 ft_glyphslot_free_bitmap( FT_GlyphSlot slot
);
527 /* Allocate a new bitmap buffer in a glyph slot. */
529 ft_glyphslot_alloc_bitmap( FT_GlyphSlot slot
,
533 /* Set the bitmap buffer in a glyph slot to a given pointer. The buffer */
534 /* will not be freed by a later call to ft_glyphslot_free_bitmap. */
536 ft_glyphslot_set_bitmap( FT_GlyphSlot slot
,
540 /*************************************************************************/
541 /*************************************************************************/
542 /*************************************************************************/
545 /**** R E N D E R E R S ****/
548 /*************************************************************************/
549 /*************************************************************************/
550 /*************************************************************************/
553 #define FT_RENDERER( x ) ((FT_Renderer)( x ))
554 #define FT_GLYPH( x ) ((FT_Glyph)( x ))
555 #define FT_BITMAP_GLYPH( x ) ((FT_BitmapGlyph)( x ))
556 #define FT_OUTLINE_GLYPH( x ) ((FT_OutlineGlyph)( x ))
559 typedef struct FT_RendererRec_
562 FT_Renderer_Class
* clazz
;
563 FT_Glyph_Format glyph_format
;
564 FT_Glyph_Class glyph_class
;
567 FT_Raster_Render_Func raster_render
;
568 FT_Renderer_RenderFunc render
;
573 /*************************************************************************/
574 /*************************************************************************/
575 /*************************************************************************/
578 /**** F O N T D R I V E R S ****/
581 /*************************************************************************/
582 /*************************************************************************/
583 /*************************************************************************/
586 /* typecast a module into a driver easily */
587 #define FT_DRIVER( x ) ((FT_Driver)(x))
589 /* typecast a module as a driver, and get its driver class */
590 #define FT_DRIVER_CLASS( x ) FT_DRIVER( x )->clazz
593 /*************************************************************************/
599 /* The root font driver class. A font driver is responsible for */
600 /* managing and loading font files of a given format. */
603 /* root :: Contains the fields of the root module class. */
605 /* clazz :: A pointer to the font driver's class. Note that */
606 /* this is NOT root.clazz. `class' wasn't used */
607 /* as it is a reserved word in C++. */
609 /* faces_list :: The list of faces currently opened by this */
612 /* extensions :: A typeless pointer to the driver's extensions */
613 /* registry, if they are supported through the */
614 /* configuration macro FT_CONFIG_OPTION_EXTENSIONS. */
616 /* glyph_loader :: The glyph loader for all faces managed by this */
617 /* driver. This object isn't defined for unscalable */
620 typedef struct FT_DriverRec_
623 FT_Driver_Class clazz
;
625 FT_ListRec faces_list
;
628 FT_GlyphLoader glyph_loader
;
633 /*************************************************************************/
634 /*************************************************************************/
635 /*************************************************************************/
638 /**** L I B R A R I E S ****/
641 /*************************************************************************/
642 /*************************************************************************/
643 /*************************************************************************/
646 /* This hook is used by the TrueType debugger. It must be set to an */
647 /* alternate truetype bytecode interpreter function. */
648 #define FT_DEBUG_HOOK_TRUETYPE 0
651 /* Set this debug hook to a non-null pointer to force unpatented hinting */
652 /* for all faces when both TT_USE_BYTECODE_INTERPRETER and */
653 /* TT_CONFIG_OPTION_UNPATENTED_HINTING are defined. This is only used */
654 /* during debugging. */
655 #define FT_DEBUG_HOOK_UNPATENTED_HINTING 1
658 typedef void (*FT_Bitmap_LcdFilterFunc
)( FT_Bitmap
* bitmap
,
659 FT_Render_Mode render_mode
,
660 FT_Library library
);
663 /*************************************************************************/
669 /* The FreeType library class. This is the root of all FreeType */
670 /* data. Use FT_New_Library() to create a library object, and */
671 /* FT_Done_Library() to discard it and all child objects. */
674 /* memory :: The library's memory object. Manages memory */
677 /* generic :: Client data variable. Used to extend the */
678 /* Library class by higher levels and clients. */
680 /* version_major :: The major version number of the library. */
682 /* version_minor :: The minor version number of the library. */
684 /* version_patch :: The current patch level of the library. */
686 /* num_modules :: The number of modules currently registered */
687 /* within this library. This is set to 0 for new */
688 /* libraries. New modules are added through the */
689 /* FT_Add_Module() API function. */
691 /* modules :: A table used to store handles to the currently */
692 /* registered modules. Note that each font driver */
693 /* contains a list of its opened faces. */
695 /* renderers :: The list of renderers currently registered */
696 /* within the library. */
698 /* cur_renderer :: The current outline renderer. This is a */
699 /* shortcut used to avoid parsing the list on */
700 /* each call to FT_Outline_Render(). It is a */
701 /* handle to the current renderer for the */
702 /* FT_GLYPH_FORMAT_OUTLINE format. */
704 /* auto_hinter :: XXX */
706 /* raster_pool :: The raster object's render pool. This can */
707 /* ideally be changed dynamically at run-time. */
709 /* raster_pool_size :: The size of the render pool in bytes. */
711 /* debug_hooks :: XXX */
713 typedef struct FT_LibraryRec_
715 FT_Memory memory
; /* library's memory manager */
719 FT_Int version_major
;
720 FT_Int version_minor
;
721 FT_Int version_patch
;
724 FT_Module modules
[FT_MAX_MODULES
]; /* module objects */
726 FT_ListRec renderers
; /* list of renderers */
727 FT_Renderer cur_renderer
; /* current outline renderer */
728 FT_Module auto_hinter
;
730 FT_Byte
* raster_pool
; /* scan-line conversion */
732 FT_ULong raster_pool_size
; /* size of render pool in bytes */
734 FT_DebugHook_Func debug_hooks
[4];
736 #ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
737 FT_LcdFilter lcd_filter
;
738 FT_Int lcd_extra
; /* number of extra pixels */
739 FT_Byte lcd_weights
[7]; /* filter weights, if any */
740 FT_Bitmap_LcdFilterFunc lcd_filter_func
; /* filtering callback */
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. */
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__ */