changes used to implement the auto-hinting support

This commit is contained in:
David Turner 2000-06-30 01:31:22 +00:00
parent 203bb47cfe
commit 5ae831c101
12 changed files with 105 additions and 74 deletions

View File

@ -184,7 +184,7 @@ static void dump_mem( void )
} }
} }
if (!bad) 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++ ) 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 (error)
{ {
if ( Fail < 10 ) if ( Fail < 10 )

View File

@ -20,19 +20,22 @@ FreeType 2.0 Internals</h1></center>
<center> <center>
<h2> <h2>
Version 1.0</h2></center> Version 1.2</h2></center>
<center> <center>
<h3> <h3>
&copy; 1999 David Turner (<a href="fichier :///david@freetype.org">david@freetype.org</a>)<br> &copy; 1999-2000 David Turner (<a href="fichier :///david@freetype.org">david@freetype.org</a>)<br>
&copy; 1999 The FreeType Development Team (<a href="fichier :///devel@freetype.org">devel@freetype.org</a>)</h3></center> &copy; 1999-2000 The FreeType Development Team (<a href="fichier :///devel@freetype.org">devel@freetype.org</a>)</h3></center>
<p><br> <p><br>
<hr WIDTH="100%"> <hr WIDTH="100%">
<br>&nbsp; <br>&nbsp;
<h2> <h2>Introduction:</h2>
Introduction:</h2>
<p>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
<blockquote>This document describes in great details the internals of the <blockquote>This document describes in great details the internals of the
FreeType 2.0 library. It is a must read for porters and developers alike. 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. Its purpose is to present the engine's objects, their roles and interactions.

View File

@ -645,7 +645,7 @@
FT_CharMap charmap; FT_CharMap charmap;
FT_ListRec sizes_list; FT_ListRec sizes_list;
void* autohint_globals; FT_Generic autohint;
void* extensions; void* extensions;
FT_UShort max_points; FT_UShort max_points;

View File

@ -23,11 +23,15 @@
/* module bit flags */ /* module bit flags */
typedef enum FT_Module_Flags_ typedef enum FT_Module_Flags_
{ {
ft_module_font_driver = 1, /* this module is a font driver */ ft_module_font_driver = 1, /* this module is a font driver */
ft_module_renderer = 2, /* this module is a renderer */ 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_scalable = 0x100, /* the driver supports scalable fonts */
ft_module_driver_no_outlines = 8 /* this driver does not support vector outlines */ 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; } FT_Module_Flags;

View File

@ -2,7 +2,7 @@
/* */ /* */
/* autohint.h */ /* autohint.h */
/* */ /* */
/* High-level `autohint" driver interface (specification) */ /* High-level `autohint" module-specific interface (specification) */
/* */ /* */
/* Copyright 1996-2000 by */ /* Copyright 1996-2000 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */
@ -108,47 +108,6 @@
typedef void (*FT_AutoHinter_Done_Global_Func)( FT_AutoHinter hinter, typedef void (*FT_AutoHinter_Done_Global_Func)( FT_AutoHinter hinter,
void* global ); void* global );
/***********************************************************************
*
* <FuncType>
* FT_AutoHinter_Init_Func
*
* <Description>
* Compute or set the global hints for a given face object.
*
* <Input>
* 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
*
* <Note>
* 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 );
/***********************************************************************
*
* <FuncType>
* FT_AutoHinter_Done_Func
*
* <Description>
* Discards the global hints for a given face..
*
* <Input>
* 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 );
/*********************************************************************** /***********************************************************************
* *
* <FuncType> * <FuncType>
@ -165,8 +124,8 @@
* *
* *
*/ */
typedef FT_Error (*FT_AutoHinter_Reset_Func)( FT_AutoHinter hinter, typedef void (*FT_AutoHinter_Reset_Func)( FT_AutoHinter hinter,
FT_Face face ); FT_Face face );
/*********************************************************************** /***********************************************************************
* *
@ -190,9 +149,12 @@
* set.. * set..
* *
*/ */
typedef FT_Error (*FT_AutoHinter_Load_Func)( FT_Face face, typedef FT_Error (*FT_AutoHinter_Load_Func)(
FT_UInt glyph_index, FT_AutoHinter hinter,
FT_ULong load_flags ); FT_GlyphSlot slot,
FT_Size size,
FT_UInt glyph_index,
FT_ULong load_flags );
/*********************************************************************** /***********************************************************************
* *
@ -205,10 +167,8 @@
*/ */
typedef struct FT_AutoHinter_Interface typedef struct FT_AutoHinter_Interface
{ {
FT_AutoHinter_Init_Func init_autohinter; FT_AutoHinter_Reset_Func reset_face;
FT_AutoHinter_Done_Func done_autohinter; 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_Get_Global_Func get_global_hints;
FT_AutoHinter_Done_Global_Func done_global_hints; FT_AutoHinter_Done_Global_Func done_global_hints;

View File

@ -28,6 +28,7 @@
#include <freetype/internal/ftmemory.h> #include <freetype/internal/ftmemory.h>
#include <freetype/ftrender.h> #include <freetype/ftrender.h>
#include <freetype/internal/ftdriver.h> #include <freetype/internal/ftdriver.h>
#include <freetype/internal/autohint.h>
/*************************************************************************/ /*************************************************************************/
/* */ /* */
@ -120,12 +121,20 @@
#define FT_MODULE_IS_RENDERER(x) (FT_MODULE_CLASS(x)->module_flags & \ #define FT_MODULE_IS_RENDERER(x) (FT_MODULE_CLASS(x)->module_flags & \
ft_module_renderer ) 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 & \ #define FT_DRIVER_IS_SCALABLE(x) (FT_MODULE_CLASS(x)->module_flags & \
ft_module_driver_scalable ) ft_module_driver_scalable )
#define FT_DRIVER_USES_OUTLINES(x) !(FT_MODULE_CLASS(x)->module_flags & \ #define FT_DRIVER_USES_OUTLINES(x) !(FT_MODULE_CLASS(x)->module_flags & \
ft_module_driver_no_outlines ) 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_ListRec renderers; /* list of renderers */
FT_Renderer cur_renderer; /* current outline renderer */ FT_Renderer cur_renderer; /* current outline renderer */
FT_Module auto_hinter;
void* raster_pool; /* scan-line conversion render pool */ void* raster_pool; /* scan-line conversion render pool */
unsigned long raster_pool_size; /* size of render pool in bytes */ unsigned long raster_pool_size; /* size of render pool in bytes */

View File

@ -678,8 +678,15 @@
static static
void ft_glyphslot_clear( FT_GlyphSlot slot ) 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 */ /* clear all public fields in the glyph slot */
MEM_Set( &slot->metrics, 0, sizeof ( slot->metrics ) ); MEM_Set( &slot->metrics, 0, sizeof ( slot->metrics ) );
MEM_Set( &slot->outline, 0, sizeof ( slot->outline ) ); MEM_Set( &slot->outline, 0, sizeof ( slot->outline ) );
MEM_Set( &slot->bitmap, 0, sizeof ( slot->bitmap ) ); MEM_Set( &slot->bitmap, 0, sizeof ( slot->bitmap ) );
@ -931,6 +938,9 @@
FT_Error error; FT_Error error;
FT_Driver driver; FT_Driver driver;
FT_GlyphSlot slot; FT_GlyphSlot slot;
FT_Library library;
FT_Bool autohint;
FT_Module hinter;
if ( !face || !face->size || !face->glyph ) if ( !face || !face->size || !face->glyph )
@ -948,10 +958,31 @@
if ( load_flags & FT_LOAD_NO_RECURSE ) if ( load_flags & FT_LOAD_NO_RECURSE )
load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING; load_flags |= FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING;
error = driver->clazz->load_glyph( slot, /* do we need to load the glyph through the auto-hinter ?? */
face->size, library = driver->root.library;
glyph_index, hinter = library->auto_hinter;
load_flags ); 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 ) if ( error )
goto Exit; goto Exit;
@ -982,6 +1013,16 @@
FT_Vector_Transform( &slot->advance, &face->transform_matrix ); 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: Exit:
return error; return error;
} }
@ -1039,8 +1080,7 @@
if ( face->charmap ) if ( face->charmap )
glyph_index = FT_Get_Char_Index( face, char_code ); glyph_index = FT_Get_Char_Index( face, char_code );
return glyph_index ? FT_Load_Glyph( face, glyph_index, load_flags ) return FT_Load_Glyph( face, glyph_index, load_flags );
: FT_Err_Invalid_Character_Code;
} }
@ -2618,14 +2658,18 @@
static static
void Destroy_Module( FT_Module module ) void Destroy_Module( FT_Module module )
{ {
FT_Memory memory = module->memory; FT_Memory memory = module->memory;
FT_Module_Class* clazz = module->clazz; FT_Module_Class* clazz = module->clazz;
FT_Library library = module->library;
/* finalize client-data - before anything else */ /* finalize client-data - before anything else */
if ( module->generic.finalizer ) if ( module->generic.finalizer )
module->generic.finalizer( module ); module->generic.finalizer( module );
if ( library && library->auto_hinter == module )
library->auto_hinter = 0;
/* if the module is a renderer */ /* if the module is a renderer */
if ( FT_MODULE_IS_RENDERER( module ) ) if ( FT_MODULE_IS_RENDERER( module ) )
ft_remove_renderer( module ); ft_remove_renderer( module );
@ -2729,6 +2773,10 @@
goto Fail; 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 the module is a font driver */
if ( FT_MODULE_IS_DRIVER( module ) ) if ( FT_MODULE_IS_DRIVER( module ) )
{ {

View File

@ -491,6 +491,7 @@
/* set up remaining glyph fields */ /* set up remaining glyph fields */
glyph->num_subglyphs = 2; glyph->num_subglyphs = 2;
glyph->subglyphs = loader->current.subglyphs;
glyph->format = ft_glyph_format_composite; glyph->format = ft_glyph_format_composite;
loader->current.num_subglyphs = 2; loader->current.num_subglyphs = 2;

View File

@ -84,7 +84,7 @@
} }
/* check mode */ /* check mode */
if ( !(mode & ft_render_mode_antialias) ) if ( mode != ft_render_mode_antialias )
return FT_Err_Cannot_Render_Glyph; return FT_Err_Cannot_Render_Glyph;
outline = &slot->outline; outline = &slot->outline;

View File

@ -423,7 +423,10 @@
const FT_Driver_Class tt_driver_class = 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 ), sizeof ( TT_DriverRec ),
"truetype", /* driver name */ "truetype", /* driver name */

View File

@ -313,6 +313,7 @@
/* set up remaining glyph fields */ /* set up remaining glyph fields */
glyph->num_subglyphs = 2; glyph->num_subglyphs = 2;
glyph->subglyphs = loader->current.subglyphs;
glyph->format = ft_glyph_format_composite; glyph->format = ft_glyph_format_composite;
loader->current.num_subglyphs = 2; loader->current.num_subglyphs = 2;

View File

@ -455,6 +455,7 @@
/* set up remaining glyph fields */ /* set up remaining glyph fields */
glyph->num_subglyphs = 2; glyph->num_subglyphs = 2;
glyph->subglyphs = loader->base.subglyphs;
glyph->format = ft_glyph_format_composite; glyph->format = ft_glyph_format_composite;
loader->current.num_subglyphs = 2; loader->current.num_subglyphs = 2;