1 /***************************************************************************/
5 /* The FreeType private base classes (specification). */
7 /* Copyright 1996-2000 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 /*************************************************************************/
29 #include <freetype/internal/ftmemory.h>
30 #include <freetype/ftrender.h>
31 #include <freetype/internal/ftdriver.h>
32 #include <freetype/internal/autohint.h>
40 /*************************************************************************/
42 /* Some generic definitions. */
57 #define UNUSED( arg ) ( (arg)=(arg) )
61 /*************************************************************************/
63 /* The min and max functions missing in C. As usual, be careful not to */
64 /* write things like MIN( a++, b++ ) to avoid side effects. */
67 #define MIN( a, b ) ( (a) < (b) ? (a) : (b) )
71 #define MAX( a, b ) ( (a) > (b) ? (a) : (b) )
75 #define ABS( a ) ( (a) < 0 ? -(a) : (a) )
79 /*************************************************************************/
80 /*************************************************************************/
81 /*************************************************************************/
84 /**** M O D U L E S ****/
87 /*************************************************************************/
88 /*************************************************************************/
89 /*************************************************************************/
92 /*************************************************************************/
98 /* A module object instance. */
101 /* clazz :: A pointer to the module's class. */
103 /* library :: A handle to the parent library object. */
105 /* memory :: A handle to the memory manager. */
107 /* generic :: A generic structure for user-level extensibility (?). */
109 typedef struct FT_ModuleRec_
111 FT_Module_Class
* clazz
;
119 /* typecast an object to a FT_Module */
120 #define FT_MODULE( x ) ((FT_Module)(x))
121 #define FT_MODULE_CLASS( x ) FT_MODULE(x)->clazz
122 #define FT_MODULE_LIBRARY( x ) FT_MODULE(x)->library
123 #define FT_MODULE_MEMORY( x ) FT_MODULE(x)->memory
125 #define FT_MODULE_IS_DRIVER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
126 ft_module_font_driver )
128 #define FT_MODULE_IS_RENDERER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
131 #define FT_MODULE_IS_HINTER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
134 #define FT_MODULE_IS_STYLER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
137 #define FT_DRIVER_IS_SCALABLE( x ) ( FT_MODULE_CLASS(x)->module_flags & \
138 ft_module_driver_scalable )
140 #define FT_DRIVER_USES_OUTLINES( x ) !( FT_MODULE_CLASS(x)->module_flags & \
141 ft_module_driver_no_outlines )
143 #define FT_DRIVER_HAS_HINTER( x ) ( FT_MODULE_CLASS(x)->module_flags & \
144 ft_module_driver_has_hinter )
147 /*************************************************************************/
150 /* FT_Get_Module_Interface */
153 /* Finds a module and returns its specific interface as a typeless */
157 /* library :: A handle to the library object. */
159 /* module_name :: The module's name (as an ASCII string). */
162 /* A module-specific interface if available, 0 otherwise. */
165 /* You should better be familiar with FreeType internals to know */
166 /* which module to look for, and what its interface is :-) */
168 BASE_DEF( const void* ) FT_Get_Module_Interface( FT_Library library
,
169 const char* mod_name
);
172 /*************************************************************************/
173 /*************************************************************************/
174 /*************************************************************************/
177 /**** FACE, SIZE & GLYPH SLOT OBJECTS ****/
180 /*************************************************************************/
181 /*************************************************************************/
182 /*************************************************************************/
184 /* a few macros used to perform easy typecasts with minimal brain damage */
186 #define FT_FACE( x ) ((FT_Face)(x))
187 #define FT_SIZE( x ) ((FT_Size)(x))
188 #define FT_SLOT( x ) ((FT_GlyphSlot)(x))
190 #define FT_FACE_DRIVER( x ) FT_FACE( x )->driver
191 #define FT_FACE_LIBRARY( x ) FT_FACE_DRIVER( x )->root.library
192 #define FT_FACE_MEMORY( x ) FT_FACE( x )->memory
194 #define FT_SIZE_FACE( x ) FT_SIZE( x )->face
195 #define FT_SLOT_FACE( x ) FT_SLOT( x )->face
197 #define FT_FACE_SLOT( x ) FT_FACE( x )->glyph
198 #define FT_FACE_SIZE( x ) FT_FACE( x )->size
201 /* this must be kept exported -- tt will be used later in our own */
202 /* high-level caching font manager called SemTex (way after the */
203 /* 2.0 release though */
204 FT_EXPORT_DEF( FT_Error
) FT_New_Size( FT_Face face
,
207 FT_EXPORT_DEF( FT_Error
) FT_Done_Size( FT_Size size
);
210 FT_EXPORT_DEF( FT_Error
) FT_New_GlyphSlot( FT_Face face
,
211 FT_GlyphSlot
* aslot
);
213 FT_EXPORT_DEF( void ) FT_Done_GlyphSlot( FT_GlyphSlot slot
);
216 /*************************************************************************/
217 /*************************************************************************/
218 /*************************************************************************/
221 /**** G L Y P H L O A D E R ****/
224 /*************************************************************************/
225 /*************************************************************************/
226 /*************************************************************************/
229 #define FT_SUBGLYPH_FLAG_ARGS_ARE_WORDS 1
230 #define FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES 2
231 #define FT_SUBGLYPH_FLAG_ROUND_XY_TO_GRID 4
232 #define FT_SUBGLYPH_FLAG_SCALE 8
233 #define FT_SUBGLYPH_FLAG_XY_SCALE 0x40
234 #define FT_SUBGLYPH_FLAG_2X2 0x80
235 #define FT_SUBGLYPH_FLAG_USE_MY_METRICS 0x200
240 ft_glyph_own_bitmap
= 1
254 typedef struct FT_GlyphLoad_
256 FT_Outline outline
; /* outline */
257 FT_UInt num_subglyphs
; /* number of subglyphs */
258 FT_SubGlyph
* subglyphs
; /* subglyphs */
259 FT_Vector
* extra_points
; /* extra points table */
264 struct FT_GlyphLoader_
268 FT_UInt max_contours
;
269 FT_UInt max_subglyphs
;
273 FT_GlyphLoad current
;
275 void* other
; /* for possible future extension? */
280 BASE_DEF( FT_Error
) FT_GlyphLoader_New( FT_Memory memory
,
281 FT_GlyphLoader
** aloader
);
283 BASE_DEF( FT_Error
) FT_GlyphLoader_Create_Extra(
284 FT_GlyphLoader
* loader
);
286 BASE_DEF( void ) FT_GlyphLoader_Done( FT_GlyphLoader
* loader
);
288 BASE_DEF( void ) FT_GlyphLoader_Reset( FT_GlyphLoader
* loader
);
290 BASE_DEF( void ) FT_GlyphLoader_Rewind( FT_GlyphLoader
* loader
);
292 BASE_DEF( FT_Error
) FT_GlyphLoader_Check_Points(
293 FT_GlyphLoader
* loader
,
295 FT_UInt n_contours
);
297 BASE_DEF( FT_Error
) FT_GlyphLoader_Check_Subglyphs(
298 FT_GlyphLoader
* loader
,
301 BASE_DEF( void ) FT_GlyphLoader_Prepare( FT_GlyphLoader
* loader
);
303 BASE_DEF( void ) FT_GlyphLoader_Add( FT_GlyphLoader
* loader
);
305 BASE_DEF( FT_Error
) FT_GlyphLoader_Copy_Points( FT_GlyphLoader
* target
,
306 FT_GlyphLoader
* source
);
309 /*************************************************************************/
310 /*************************************************************************/
311 /*************************************************************************/
314 /**** R E N D E R E R S ****/
317 /*************************************************************************/
318 /*************************************************************************/
319 /*************************************************************************/
322 #define FT_RENDERER( x ) ((FT_Renderer)( x ))
323 #define FT_GLYPH( x ) ((FT_Glyph)( x ))
324 #define FT_BITMAP_GLYPH( x ) ((FT_BitmapGlyph)( x ))
325 #define FT_OUTLINE_GLYPH( x ) ((FT_OutlineGlyph)( x ))
328 typedef struct FT_RendererRec_
331 FT_Renderer_Class
* clazz
;
332 FT_Glyph_Format glyph_format
;
333 const FT_Glyph_Class glyph_class
;
336 FT_Raster_Render_Func raster_render
;
337 FTRenderer_render render
;
342 /*************************************************************************/
343 /*************************************************************************/
344 /*************************************************************************/
347 /**** F O N T D R I V E R S ****/
350 /*************************************************************************/
351 /*************************************************************************/
352 /*************************************************************************/
355 /* typecast a module into a driver easily */
356 #define FT_DRIVER( x ) ((FT_Driver)(x))
358 /* typecast a module as a driver, and get its driver class */
359 #define FT_DRIVER_CLASS( x ) FT_DRIVER( x )->clazz
362 /*************************************************************************/
368 /* The root font driver class. A font driver is responsible for */
369 /* managing and loading font files of a given format. */
372 /* root :: Contains the fields of the root module class. */
374 /* clazz :: A pointer to the font driver's class. Note that */
375 /* this is NOT root.clazz. `class' wasn't used */
376 /* as it is a reserved word in C++. */
378 /* faces_list :: The list of faces currently opened by this */
381 /* extensions :: A typeless pointer to the driver's extensions */
382 /* registry, if they are supported through the */
383 /* configuration macro FT_CONFIG_OPTION_EXTENSIONS. */
385 /* glyph_loader :: The glyph loader for all faces managed by this */
386 /* driver. This object isn't defined for unscalable */
389 typedef struct FT_DriverRec_
392 FT_Driver_Class
* clazz
;
394 FT_ListRec faces_list
;
397 FT_GlyphLoader
* glyph_loader
;
402 /*************************************************************************/
403 /*************************************************************************/
404 /*************************************************************************/
407 /**** L I B R A R I E S ****/
410 /*************************************************************************/
411 /*************************************************************************/
412 /*************************************************************************/
415 #define FT_DEBUG_HOOK_TRUETYPE 0
416 #define FT_DEBUG_HOOK_TYPE1 1
419 /*************************************************************************/
425 /* The FreeType library class. This is the root of all FreeType */
426 /* data. Use FT_New_Library() to create a library object, and */
427 /* FT_Done_Library() to discard it and all child objects. */
430 /* memory :: The library's memory object. Manages memory */
433 /* generic :: Client data variable. Used to extend the */
434 /* Library class by higher levels and clients. */
436 /* num_modules :: The number of modules currently registered */
437 /* within this library. This is set to 0 for new */
438 /* libraries. New modules are added through the */
439 /* FT_Add_Module() API function. */
441 /* modules :: A table used to store handles to the currently */
442 /* registered modules. Note that each font driver */
443 /* contains a list of its opened faces. */
445 /* renderers :: The list of renderers currently registered */
446 /* within the library. */
448 /* cur_renderer :: The current outline renderer. This is a */
449 /* shortcut used to avoid parsing the list on */
450 /* each call to FT_Outline_Render(). It is a */
451 /* handle to the current renderer for the */
452 /* ft_glyph_format_outline format. */
454 /* auto_hinter :: XXX */
456 /* raster_pool :: The raster object's render pool. This can */
457 /* ideally be changed dynamically at run-time. */
459 /* raster_pool_size :: The size of the render pool in bytes. */
461 /* debug_hooks :: XXX */
463 typedef struct FT_LibraryRec_
465 FT_Memory memory
; /* library's memory manager */
470 FT_Module modules
[FT_MAX_MODULES
]; /* module objects */
472 FT_ListRec renderers
; /* list of renderers */
473 FT_Renderer cur_renderer
; /* current outline renderer */
474 FT_Module auto_hinter
;
476 FT_Byte
* raster_pool
; /* scan-line conversion */
478 FT_ULong raster_pool_size
; /* size of render pool in bytes */
480 FT_DebugHook_Func debug_hooks
[4];
485 BASE_DEF( FT_Renderer
) FT_Lookup_Renderer( FT_Library library
,
486 FT_Glyph_Format format
,
489 BASE_DEF( FT_Error
) FT_Render_Glyph_Internal( FT_Library library
,
491 FT_UInt render_mode
);
493 typedef FT_Error (*FT_Glyph_Name_Requester
)( FT_Face face
,
496 FT_UInt buffer_max
);
499 #ifndef FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM
502 FT_EXPORT_DEF( FT_Error
) FT_New_Stream( const char* filepathname
,
505 FT_EXPORT_DEF( void ) FT_Done_Stream( FT_Stream stream
);
507 FT_EXPORT_DEF( FT_Memory
) FT_New_Memory( void );
510 #endif /* !FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM */
513 /* Define default raster's interface. The default raster is located in */
514 /* `src/base/ftraster.c' */
516 /* Client applications can register new rasters through the */
517 /* FT_Set_Raster() API. */
519 #ifndef FT_NO_DEFAULT_RASTER
520 FT_EXPORT_VAR( FT_Raster_Funcs
) ft_default_raster
;
529 #endif /* FTOBJS_H */