diff --git a/demos/src/memtest.c b/demos/src/memtest.c index b78010164..b37afb7c9 100644 --- a/demos/src/memtest.c +++ b/demos/src/memtest.c @@ -184,7 +184,7 @@ static void dump_mem( void ) } } if (!bad) - fprintf( stderr, "no leaked memory block, congratulations ;-)" ); + fprintf( stderr, "no leaked memory block\n\n" ); } /****************************************************************************/ @@ -302,7 +302,7 @@ int main( int argc, char** argv ) { for ( id = 0; id < num_glyphs; id++ ) { - error = FT_Load_Glyph( face, id, FT_LOAD_DEFAULT ); + error = FT_Load_Glyph( face, id, FT_LOAD_RENDER | FT_LOAD_ANTI_ALIAS ); if (error) { if ( Fail < 10 ) diff --git a/docs/design/index.html b/docs/design/index.html index f52953d41..50f7f290a 100644 --- a/docs/design/index.html +++ b/docs/design/index.html @@ -20,19 +20,22 @@ FreeType 2.0 Internals

-Version 1.0

+Version 1.2

-© 1999 David Turner (david@freetype.org)
-© 1999 The FreeType Development Team (devel@freetype.org)

+© 1999-2000 David Turner (david@freetype.org)
+© 1999-2000 The FreeType Development Team (devel@freetype.org)




  -

-Introduction:

+

Introduction:

+

This document describes in great deatils the internals of FreeType 2. + It is a must read for porters and developers alike. Its purpose is to + + present the

This document describes in great details the internals of the FreeType 2.0 library. It is a must read for porters and developers alike. Its purpose is to present the engine's objects, their roles and interactions. diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h index 023e0f14b..884089a64 100644 --- a/include/freetype/freetype.h +++ b/include/freetype/freetype.h @@ -645,7 +645,7 @@ FT_CharMap charmap; FT_ListRec sizes_list; - void* autohint_globals; + FT_Generic autohint; void* extensions; FT_UShort max_points; diff --git a/include/freetype/ftmodule.h b/include/freetype/ftmodule.h index bc8e96100..6175b2a0e 100644 --- a/include/freetype/ftmodule.h +++ b/include/freetype/ftmodule.h @@ -23,11 +23,15 @@ /* module bit flags */ typedef enum FT_Module_Flags_ { - ft_module_font_driver = 1, /* this module is a font driver */ - ft_module_renderer = 2, /* this module is a renderer */ + ft_module_font_driver = 1, /* this module is a font driver */ + ft_module_renderer = 2, /* this module is a renderer */ + ft_module_hinter = 4, /* this module is a glyph hinter */ + ft_module_styler = 8, /* this module is a styler */ - ft_module_driver_scalable = 4, /* this driver supports scalable fonts */ - ft_module_driver_no_outlines = 8 /* this driver does not support vector outlines */ + ft_module_driver_scalable = 0x100, /* the driver supports scalable fonts */ + ft_module_driver_no_outlines = 0x200, /* the driver does not support vector outlines */ + + ft_module_driver_has_hinter = 0x400 /* the driver provides its own hinter */ } FT_Module_Flags; diff --git a/include/freetype/internal/autohint.h b/include/freetype/internal/autohint.h index 277461b9f..b3409f532 100644 --- a/include/freetype/internal/autohint.h +++ b/include/freetype/internal/autohint.h @@ -2,7 +2,7 @@ /* */ /* autohint.h */ /* */ -/* High-level `autohint" driver interface (specification) */ +/* High-level `autohint" module-specific interface (specification) */ /* */ /* Copyright 1996-2000 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ @@ -108,47 +108,6 @@ typedef void (*FT_AutoHinter_Done_Global_Func)( FT_AutoHinter hinter, void* global ); - /*********************************************************************** - * - * - * FT_AutoHinter_Init_Func - * - * - * Compute or set the global hints for a given face object. - * - * - * hinter :: handle to source auto-hinter module - * face :: handle to target face object. - * global_hints :: typeless pointer to global hints. If 0, the - * hints are computed for the face - * - * - * it is up to client applications to ensure that the global hints - * were retrieved for the same face object. Strange results may occur - * otherwise.. - * - */ - typedef FT_Error (*FT_AutoHinter_Init_Func)( FT_AutoHinter hinter, - FT_Face face, - void* global_hints ); - - /*********************************************************************** - * - * - * FT_AutoHinter_Done_Func - * - * - * Discards the global hints for a given face.. - * - * - * hinter :: handle to source auto-hinter module - * face :: handle to target face object. - * - */ - typedef FT_Error (*FT_AutoHinter_Done_Func)( FT_AutoHinter hinter, - FT_Face face ); - - /*********************************************************************** * * @@ -165,8 +124,8 @@ * * */ - typedef FT_Error (*FT_AutoHinter_Reset_Func)( FT_AutoHinter hinter, - FT_Face face ); + typedef void (*FT_AutoHinter_Reset_Func)( FT_AutoHinter hinter, + FT_Face face ); /*********************************************************************** * @@ -190,9 +149,12 @@ * set.. * */ - typedef FT_Error (*FT_AutoHinter_Load_Func)( FT_Face face, - FT_UInt glyph_index, - FT_ULong load_flags ); + typedef FT_Error (*FT_AutoHinter_Load_Func)( + FT_AutoHinter hinter, + FT_GlyphSlot slot, + FT_Size size, + FT_UInt glyph_index, + FT_ULong load_flags ); /*********************************************************************** * @@ -205,10 +167,8 @@ */ typedef struct FT_AutoHinter_Interface { - FT_AutoHinter_Init_Func init_autohinter; - FT_AutoHinter_Done_Func done_autohinter; - FT_AutoHinter_Reset_Func reset_face; - FT_AutoHinter_Load_Func load_glyph; + FT_AutoHinter_Reset_Func reset_face; + FT_AutoHinter_Load_Func load_glyph; FT_AutoHinter_Get_Global_Func get_global_hints; FT_AutoHinter_Done_Global_Func done_global_hints; diff --git a/include/freetype/internal/ftobjs.h b/include/freetype/internal/ftobjs.h index a1ed6c25d..bb8c24c9a 100644 --- a/include/freetype/internal/ftobjs.h +++ b/include/freetype/internal/ftobjs.h @@ -28,6 +28,7 @@ #include #include #include +#include /*************************************************************************/ /* */ @@ -120,12 +121,20 @@ #define FT_MODULE_IS_RENDERER(x) (FT_MODULE_CLASS(x)->module_flags & \ ft_module_renderer ) +#define FT_MODULE_IS_HINTER(x) (FT_MODULE_CLASS(x)->module_flags & \ + ft_module_hinter ) + +#define FT_MODULE_IS_STYLER(x) (FT_MODULE_CLASS(x)->module_flags & \ + ft_module_styler ) + #define FT_DRIVER_IS_SCALABLE(x) (FT_MODULE_CLASS(x)->module_flags & \ ft_module_driver_scalable ) #define FT_DRIVER_USES_OUTLINES(x) !(FT_MODULE_CLASS(x)->module_flags & \ ft_module_driver_no_outlines ) +#define FT_DRIVER_HAS_HINTER(x) (FT_MODULE_CLASS(x)->module_flags & \ + ft_module_driver_has_hinter ) /*************************************************************************/ /*************************************************************************/ @@ -389,6 +398,7 @@ FT_ListRec renderers; /* list of renderers */ FT_Renderer cur_renderer; /* current outline renderer */ + FT_Module auto_hinter; void* raster_pool; /* scan-line conversion render pool */ unsigned long raster_pool_size; /* size of render pool in bytes */ diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c index e4b727158..1df4ec7a1 100644 --- a/src/base/ftobjs.c +++ b/src/base/ftobjs.c @@ -678,8 +678,15 @@ static void ft_glyphslot_clear( FT_GlyphSlot slot ) { + /* free bitmap if needed */ + if ( slot->flags & ft_glyph_own_bitmap ) + { + FT_Memory memory = FT_FACE_MEMORY( slot->face ); + FREE( slot->bitmap.buffer ); + slot->flags &= ~ft_glyph_own_bitmap; + } + /* clear all public fields in the glyph slot */ - MEM_Set( &slot->metrics, 0, sizeof ( slot->metrics ) ); MEM_Set( &slot->outline, 0, sizeof ( slot->outline ) ); MEM_Set( &slot->bitmap, 0, sizeof ( slot->bitmap ) ); @@ -931,6 +938,9 @@ FT_Error error; FT_Driver driver; FT_GlyphSlot slot; + FT_Library library; + FT_Bool autohint; + FT_Module hinter; if ( !face || !face->size || !face->glyph ) @@ -948,10 +958,31 @@ if ( load_flags & FT_LOAD_NO_RECURSE ) load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING; - error = driver->clazz->load_glyph( slot, - face->size, - glyph_index, - load_flags ); + /* do we need to load the glyph through the auto-hinter ?? */ + library = driver->root.library; + hinter = library->auto_hinter; + autohint = hinter && + !(load_flags & (FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING)); + if (autohint) + { + if ( FT_DRIVER_HAS_HINTER( driver ) && + !(load_flags & FT_LOAD_FORCE_AUTOHINT) ) + autohint = 0; + } + + if (autohint) + { + FT_AutoHinter_Interface* hinting; + + hinting = (FT_AutoHinter_Interface*)hinter->clazz->module_interface; + error = hinting->load_glyph( (FT_AutoHinter)hinter, slot, face->size, + glyph_index, load_flags ); + } + else + error = driver->clazz->load_glyph( slot, + face->size, + glyph_index, + load_flags ); if ( error ) goto Exit; @@ -982,6 +1013,16 @@ FT_Vector_Transform( &slot->advance, &face->transform_matrix ); } + /* do we need to render the image now ? */ + if ( !error && + slot->format != ft_glyph_format_bitmap && + slot->format != ft_glyph_format_composite && + load_flags & FT_LOAD_RENDER ) + { + error = FT_Render_Glyph( slot, (load_flags & FT_LOAD_ANTI_ALIAS) ? + ft_render_mode_antialias : 0 ); + } + Exit: return error; } @@ -1039,8 +1080,7 @@ if ( face->charmap ) glyph_index = FT_Get_Char_Index( face, char_code ); - return glyph_index ? FT_Load_Glyph( face, glyph_index, load_flags ) - : FT_Err_Invalid_Character_Code; + return FT_Load_Glyph( face, glyph_index, load_flags ); } @@ -2618,14 +2658,18 @@ static void Destroy_Module( FT_Module module ) { - FT_Memory memory = module->memory; - FT_Module_Class* clazz = module->clazz; + FT_Memory memory = module->memory; + FT_Module_Class* clazz = module->clazz; + FT_Library library = module->library; /* finalize client-data - before anything else */ if ( module->generic.finalizer ) module->generic.finalizer( module ); + if ( library && library->auto_hinter == module ) + library->auto_hinter = 0; + /* if the module is a renderer */ if ( FT_MODULE_IS_RENDERER( module ) ) ft_remove_renderer( module ); @@ -2729,6 +2773,10 @@ goto Fail; } + /* is the module a auto-hinter ? */ + if ( FT_MODULE_IS_HINTER(module) ) + library->auto_hinter = module; + /* if the module is a font driver */ if ( FT_MODULE_IS_DRIVER( module ) ) { diff --git a/src/cid/cidgload.c b/src/cid/cidgload.c index 3501990d8..756fb87c6 100644 --- a/src/cid/cidgload.c +++ b/src/cid/cidgload.c @@ -491,6 +491,7 @@ /* set up remaining glyph fields */ glyph->num_subglyphs = 2; + glyph->subglyphs = loader->current.subglyphs; glyph->format = ft_glyph_format_composite; loader->current.num_subglyphs = 2; diff --git a/src/smooth/ftsmooth.c b/src/smooth/ftsmooth.c index 0b25d44e1..7cd4929d9 100644 --- a/src/smooth/ftsmooth.c +++ b/src/smooth/ftsmooth.c @@ -84,7 +84,7 @@ } /* check mode */ - if ( !(mode & ft_render_mode_antialias) ) + if ( mode != ft_render_mode_antialias ) return FT_Err_Cannot_Render_Glyph; outline = &slot->outline; diff --git a/src/truetype/ttdriver.c b/src/truetype/ttdriver.c index 07c0b208a..d43220d92 100644 --- a/src/truetype/ttdriver.c +++ b/src/truetype/ttdriver.c @@ -423,7 +423,10 @@ const FT_Driver_Class tt_driver_class = { { - ft_module_font_driver | ft_module_driver_scalable, + ft_module_font_driver | + ft_module_driver_scalable | + ft_module_driver_has_hinter, + sizeof ( TT_DriverRec ), "truetype", /* driver name */ diff --git a/src/type1/t1gload.c b/src/type1/t1gload.c index bef4a4a6e..f0e6782cf 100644 --- a/src/type1/t1gload.c +++ b/src/type1/t1gload.c @@ -313,6 +313,7 @@ /* set up remaining glyph fields */ glyph->num_subglyphs = 2; + glyph->subglyphs = loader->current.subglyphs; glyph->format = ft_glyph_format_composite; loader->current.num_subglyphs = 2; diff --git a/src/type1z/z1gload.c b/src/type1z/z1gload.c index ababad15d..25c126441 100644 --- a/src/type1z/z1gload.c +++ b/src/type1z/z1gload.c @@ -455,6 +455,7 @@ /* set up remaining glyph fields */ glyph->num_subglyphs = 2; + glyph->subglyphs = loader->base.subglyphs; glyph->format = ft_glyph_format_composite; loader->current.num_subglyphs = 2;