* include/freetype/internal/ftobject.h: updating the object sub-system

definitions (still experimental)

    * src/base/fthash.c (ft_hash_remove): fixing a small reallocation bug

    * include/freetype/fttrigon.h, src/base/fttrigon.c: adding
    FT_Vector_From_Polar and FT_Angle_Diff to the trigonometric functions

    * include/freetype/ftstroker.h, src/base/ftstroker.c: adding path stroker
    component (work in progress)
This commit is contained in:
David Turner 2002-06-26 23:45:21 +00:00
parent b7e18efcd2
commit 0d73b0c49a
9 changed files with 1277 additions and 174 deletions

View File

@ -1,9 +1,20 @@
2002-06-26 David Turner
* src/truetype/ttgload.c (TT_Load_Composite_Glyph),
src/base/ftoutln.c (FT_Vector_Transform): fixed Werner's latest
fix. FT_Vector_Transform wasn't buggy, the TrueType composite loader
was...
* include/freetype/internal/ftobject.h: updating the object sub-system
definitions (still experimental)
* src/base/fthash.c (ft_hash_remove): fixing a small reallocation bug
* include/freetype/fttrigon.h, src/base/fttrigon.c: adding
FT_Vector_From_Polar and FT_Angle_Diff to the trigonometric functions
* include/freetype/ftstroker.h, src/base/ftstroker.c: adding path stroker
component (work in progress)
* src/truetype/ttgload.c (TT_Load_Composite_Glyph),
src/base/ftoutln.c (FT_Vector_Transform): fixed Werner's latest
fix. FT_Vector_Transform wasn't buggy, the TrueType composite loader
was...
2002-06-24 Werner Lemberg <wl@gnu.org>

View File

@ -44,7 +44,7 @@ FT_BEGIN_HEADER
FT_STROKER_LINEJOIN_ROUND = 0,
FT_STROKER_LINEJOIN_BEVEL,
FT_STROKER_LINEJOIN_MITER
} FT_Stroker_LineJoin;
@ -74,10 +74,10 @@ FT_BEGIN_HEADER
FT_STROKER_LINECAP_BUTT = 0,
FT_STROKER_LINECAP_ROUND,
FT_STROKER_LINECAP_SQUARE
} FT_Stroker_LineCap;
FT_EXPORT( FT_Error )
FT_Stroker_New( FT_Memory memory,
FT_Stroker *astroker );
@ -89,10 +89,15 @@ FT_BEGIN_HEADER
FT_Stroker_LineJoin line_join,
FT_Fixed miter_limit );
FT_EXPORT( FT_Error )
FT_Stroker_ParseOutline( FT_Stroker stroker,
FT_Outline* outline,
FT_Bool opened );
FT_EXPORT( FT_Error )
FT_Stroker_BeginSubPath( FT_Stroker stroker,
FT_Pos x,
FT_Pos y,
FT_Vector* to,
FT_Bool open );
FT_EXPORT( FT_Error )
@ -101,24 +106,18 @@ FT_BEGIN_HEADER
FT_EXPORT( FT_Error )
FT_Stroker_LineTo( FT_Stroker stroker,
FT_Pos to_x,
FT_Pos to_y );
FT_Vector* to );
FT_EXPORT( FT_Error )
FT_Stroker_ConicTo( FT_Stroker stroker,
FT_Pos control_x,
FT_Pos control_y,
FT_Pos to_x,
FT_Pos to_y );
FT_Vector* control,
FT_Vector* to );
FT_EXPORT( FT_Error )
FT_Stroker_CubicTo( FT_Stroker stroker,
FT_Pos control1_x,
FT_Pos control1_y,
FT_Pos control2_x,
FT_Pos control2_y,
FT_Pos to_x,
FT_Pos to_y );
FT_Vector* control1,
FT_Vector* control2,
FT_Vector* to );
FT_EXPORT( FT_Error )
@ -134,11 +133,6 @@ FT_BEGIN_HEADER
FT_Stroker_Done( FT_Stroker stroker );
FT_EXPORT( FT_Error )
FT_Stroker_ParseOutline( FT_Stroker stroker,
FT_Outline* outline,
FT_Bool opened );
FT_END_HEADER
#endif /* __FT_STROKER_H__ */

View File

@ -291,6 +291,28 @@ FT_BEGIN_HEADER
FT_Vector_Polarize( FT_Vector* vec,
FT_Fixed *length,
FT_Angle *angle );
/*************************************************************************/
/* */
/* @function: */
/* FT_Vector_From_Polar */
/* */
/* @description: */
/* Compute vector coordinates from a length and angle. */
/* */
/* @output: */
/* vec :: The address of source vector. */
/* */
/* @input: */
/* length :: The vector length. */
/* angle :: The vector angle. */
/* */
FT_EXPORT( void )
FT_Vector_From_Polar( FT_Vector* vec,
FT_Fixed length,
FT_Angle angle );
/* */

View File

@ -59,7 +59,19 @@ FT_BEGIN_HEADER
/***********************************************************
*
* @type: FT_Hash_CompareFunc
* @type: FT_HashLookup
*
* @description:
* handle to a @FT_HashNode pointer. This is returned by
* the @ft_hash_lookup function and can later be used by
* @ft_hash_add or @ft_hash_remove
*/
typedef FT_HashNode* FT_HashLookup;
/***********************************************************
*
* @type: FT_Hash_EqualFunc
*
* @description:
* a function used to compare two nodes of the hash table
@ -72,8 +84,8 @@ FT_BEGIN_HEADER
* 1 iff the 'keys' in 'node1' and 'node2' are identical.
* 0 otherwise.
*/
typedef FT_Int (*FT_Hash_CompareFunc)( const FT_HashNode node1,
const FT_HashNode node2 );
typedef FT_Int (*FT_Hash_EqualFunc)( FT_HashNode node1,
FT_HashNode node2 );
/***********************************************************
@ -106,16 +118,12 @@ FT_BEGIN_HEADER
*/
typedef struct FT_HashRec_
{
FT_Memory memory;
FT_HashNode* buckets;
FT_UInt p;
FT_UInt mask; /* really maxp-1 */
FT_UInt slack;
FT_UInt node_size;
FT_Hash_CompareFunc node_compare;
FT_Hash_ComputeFunc node_hash;
FT_Long slack;
FT_Hash_EqualFunc node_equal;
FT_Memory memory;
} FT_HashRec, *FT_Hash;
@ -168,36 +176,39 @@ FT_BEGIN_HEADER
* initialize a dynamic hash table
*
* @input:
* table :: handle to target hash table structure
* compare :: node comparison function
* memory :: memory manager handle used to allocate the
* buckets array within the hash table
* table :: handle to target hash table structure
* node_equal :: node comparison function
* memory :: memory manager handle used to allocate the
* buckets array within the hash table
*
* @return:
* error code. 0 means success
*
* @note:
* the node comparison function should only compare node _keys_
* and ignore values !! with good hashing computation (which the
* user must perform itself), the comparison function should be
* pretty selfom called.
* pretty seldom called.
*
* here is a simple example:
*
* {
* static int my_compare( const MyNode node1,
* const MyNode node2 )
* static int my_equal( MyNode node1,
* MyNode node2 )
* {
* // compare keys of 'node1' and 'node2'
* return strcmp( node1->key, node2->key );
* return (strcmp( node1->key, node2->key ) == 0);
* }
*
* ....
*
* ft_hash_init( &hash, (FT_Hash_CompareFunc) my_compare, memory );
* ft_hash_init( &hash, (FT_Hash_EqualFunc) my_compare, memory );
* ....
* }
*/
FT_BASE( void )
FT_BASE( FT_Error )
ft_hash_init( FT_Hash table,
FT_Hash_CompareFunc compare,
FT_Hash_EqualFunc compare,
FT_Memory memory );
@ -257,7 +268,7 @@ FT_BEGIN_HEADER
* }
* }
*/
FT_BASE_DEF( FT_HashNode* )
FT_BASE_DEF( FT_HashLookup )
ft_hash_lookup( FT_Hash table,
FT_HashNode keynode )
@ -273,10 +284,13 @@ FT_BEGIN_HEADER
*
* @input:
* table :: hash table handle
* pnode :: pointer-to-hash-node value returned by @ft_hash_lookup
* lookup :: pointer-to-hash-node value returned by @ft_hash_lookup
* new_node :: handle to new hash node. All its fields must be correctly
* set, including 'hash'.
*
* @return:
* error code. 0 means success
*
* @note:
* this function should always be used _after_ a call to @ft_hash_lookup
* that returns a pointer to a NULL handle. Here's an example:
@ -308,18 +322,21 @@ FT_BEGIN_HEADER
*
* // allocate a new node - and set it up
* node = (MyNode) malloc( sizeof(*node) );
* if ( node == NULL ) .....
*
* node->hnode.hash = noderec.hnode.hash;
* node->key = key;
* node->value = value;
*
* // add it to the hash table
* ft_hash_add( table, pnode, node );
* error = ft_hash_add( table, pnode, node );
* if (error) ....
* }
*/
FT_BASE( void )
ft_hash_add( FT_Hash table,
FT_HashNode* pnode,
FT_HashNode new_node );
FT_BASE( FT_Error )
ft_hash_add( FT_Hash table,
FT_HashLookup lookup,
FT_HashNode new_node );
/****************************************************************
@ -332,7 +349,7 @@ FT_BEGIN_HEADER
*
* @input:
* table :: hash table handle
* pnode :: pointer-to-hash-node value returned by @ft_hash_lookup
* lookup :: pointer-to-hash-node value returned by @ft_hash_lookup
*
* @note:
* this function doesn't free the node itself !! Here's an example:
@ -354,15 +371,16 @@ FT_BEGIN_HEADER
* node = *pnode;
* if ( node != NULL )
* {
* ft_hash_remove( table, pnode );
* free( node );
* error = ft_hash_remove( table, pnode );
* if ( !error )
* free( node );
* }
* }
* }
*/
FT_BASE( void )
ft_hash_remove( FT_Hash table,
FT_HashNode* pnode );
FT_BASE( FT_Error )
ft_hash_remove( FT_Hash table,
FT_HashLookup lookup )

View File

@ -140,14 +140,11 @@ FT_BEGIN_HEADER
* object :: target object handle
* init_data :: optional pointer to initialization data
*
* @throws: any
*
* the object is _assumed_ to be reachable from the cleanup
* stack when the constructor is called. This means that
* any exception can be thrown safely in it.
* @return:
* error code. 0 means success
*/
typedef void (*FT_Object_InitFunc)( FT_Object object,
FT_Pointer init_data );
typedef FT_Error (*FT_Object_InitFunc)( FT_Object object,
FT_Pointer init_data );
/**************************************************************
*
@ -158,8 +155,6 @@ FT_BEGIN_HEADER
*
* @input:
* object :: handle to target object
*
* @throws: *never* !!
*/
typedef void (*FT_Object_DoneFunc)( FT_Object object );
@ -179,12 +174,15 @@ FT_BEGIN_HEADER
* object sub-system.)
*
* magic :: a 32-bit magic number used for decoding
* super :: pointer to super class
* type :: the @FT_Type descriptor of this class
* memory :: the current memory manager handle
* library :: the current library handle
* info :: an opaque pointer to class-specific information
* managed by the FreeType object sub-system
*
* class_done :: the class destructor function
*
* obj_size :: size of class instances in bytes
* obj_init :: class instance constructor
* obj_done :: class instance destructor
@ -193,11 +191,14 @@ FT_BEGIN_HEADER
{
FT_ObjectRec object;
FT_UInt32 magic;
FT_Class super;
FT_Type type;
FT_Memory memory;
FT_Library library;
FT_Pointer info;
FT_Object_DoneFunc class_done;
FT_UInt obj_size;
FT_Object_InitFunc obj_init;
FT_Object_DoneFunc obj_done;
@ -363,80 +364,193 @@ FT_BEGIN_HEADER
/**************************************************************
*
* @function: ft_object_new
* @function: ft_object_create
*
* @description:
* create a new object (class instance)
*
* @output:
* aobject :: new object handle. NULL in case of error
*
* @input:
* clazz :: object's class pointer
* init_data :: optional pointer to initialization data
*
* @return:
* handle to new object. Cannot be NULL !
* error code. 0 means success
*/
FT_BASE_DEF( FT_Object )
ft_object_new( FT_Class clazz,
FT_Pointer init_data );
FT_BASE_DEF( FT_Error )
ft_object_create( FT_Object *aobject,
FT_Class clazz,
FT_Pointer init_data );
/**************************************************************
*
* @function: ft_object_create
* @function: ft_object_create_from_type
*
* @description:
* a variation of @ft_object_new that should be used when
* creating a new object that is owned by another object
* which is reachable from the cleanup stack.
*
* this function is a bit more akward to use but completely
* avoids push/pop pairs during object construction and is
* therefore faster.
* create a new object (class instance) from a @FT_Type
*
* @output:
* pobject :: new object handle
* aobject :: new object handle. NULL in case of error
*
* @input:
* clazz :: object's class pointer
* type :: object's type descriptor
* init_data :: optional pointer to initialization data
* push :: boolean. If true, the new object is pushed
* on top of the cleanup stack.
*
* @return:
* error code. 0 means success
*
* @note:
* this function is slower than @ft_object_create
*
* this is equivalent to calling @ft_class_from_type followed by
* @ft_object_create
*/
FT_BASE_DEF( void )
ft_object_create( FT_Object *pobject,
FT_Class clazz,
FT_Pointer init_data );
FT_BASE_DEF( FT_Error )
ft_object_create_from_type( FT_Object *aobject,
FT_Type type,
FT_Pointer init_data,
FT_Library library );
/**************************************************************
*
* @macro FT_OBJ_CREATE (object,class,init)
*
* @description:
* a convenient macro used to create new objects. see
* @ft_object_create for details
*/
#define FT_OBJ_CREATE( _obj, _clazz, _init ) \
ft_object_create( FT_OBJECT_P(&(_obj)), _clazz, _init )
/**************************************************************
*
* @macro FT_CREATE (object,class,init)
*
* @description:
* a convenient macro used to create new objects. It also
* sets an _implicit_ local variable named "error" to the error
* code returned by the object constructor.
*/
#define FT_CREATE( _obj, _clazz, _init ) \
FT_MEM_SET( FT_OBJ_CREATE( _obj, _clazz, _init ) )
/**************************************************************
*
* @macro FT_OBJ_CREATE_FROM_TYPE (object,type,init)
*
* @description:
* a convenient macro used to create new objects. see
* @ft_object_create_from_type for details
*/
#define FT_OBJ_CREATE_FROM_TYPE( _obj, _type, _init, _lib ) \
ft_object_create_from_type( FT_OBJECT_P(&(_obj)), _type, _init, _lib )
/**************************************************************
*
* @macro FT_CREATE_FROM_TYPE (object,type,init)
*
* @description:
* a convenient macro used to create new objects. It also
* sets an _implicit_ local variable named "error" to the error
* code returned by the object constructor.
*/
#define FT_CREATE_FROM_TYPE( _obj, _type, _init, _lib ) \
FT_MEM_SET( FT_OBJ_CREATE( _obj, _type, _init, _lib ) )
/* */
FT_BASE_DEF( FT_Class )
ft_class_find_by_type( FT_Type type,
FT_Memory memory );
/**************************************************************
*
* @function: ft_class_from_type
*
* @description:
* retrieves the class object corresponding to a given type
* descriptor. The class is created when needed
*
* @output:
* aclass :: handle to corresponding class object. NULL in
* case of error
*
* @input:
* type :: type descriptor handle
* library :: library handle
*
* @return:
* error code. 0 means success
*/
FT_BASE_DEF( FT_Error )
ft_class_from_type( FT_Class *aclass,
FT_Type type,
FT_Library library );
FT_BASE_DEF( FT_Class )
ft_class_find_by_name( FT_CString class_name,
FT_Memory memory );
FT_BASE_DEF( FT_Object )
ft_object_new_from_type( FT_Type type,
FT_Pointer data,
FT_Memory memory );
/**************************************************************
*
* @function: ft_class_from_name
*
* @description:
* retrieves the class object corresponding to a given type
* name. The class is created when needed
*
* @output:
* aclass :: handle to corresponding class object. NULL
* in case of error
*
* @input:
* name :: class name
* library :: library handle
*
* @return:
* error code. 0 means success
*
* @note:
* this function is _very_ slow. You should only use it for
* debugging purposes..
*/
FT_BASE_DEF( FT_Error )
ft_class_from_name( FT_Class *aclass,
FT_CString class_name,
FT_Library library );
/* */
#include FT_INTERNAL_HASH_H
typedef struct FT_ClassHNodeRec_* FT_ClassHNode;
typedef struct FT_ClassHNodeRec_
{
FT_HashNodeRec hnode;
FT_Type type;
FT_Class clazz;
} FT_ClassHNodeRec;
typedef struct FT_MetaClassRec_
{
FT_ClassRec clazz; /* the meta-class is a class itself */
FT_HashRec type_to_class; /* the type => class hash table */
} FT_MetaClassRec, *FT_MetaClass;
/* initialize meta class */
FT_BASE_DEF( FT_Error )
ft_metaclass_init( FT_MetaClass meta,
FT_Library library );
/* finalize meta class - destroy all registered class objects */
FT_BASE_DEF( void )
ft_object_create_from_type( FT_Object *pobject,
FT_Type type,
FT_Pointer init_data,
FT_Memory memory );
FT_BASE_DEF( void )
ft_object_push( FT_Object object );
FT_BASE_DEF( void )
ft_object_pop( FT_Object object );
FT_BASE_DEF( void )
ft_object_pop_destroy( FT_Object object );
ft_metaclass_done( FT_MetaClass meta );
/* */
FT_END_HEADER

View File

@ -815,7 +815,7 @@
segment_dir = point->out_dir;
/* clear all segment fields */
FT_MEM_SET( segment, 0, sizeof ( *segment ) );
FT_ZERO( segment );
segment->dir = segment_dir;
segment->flags = ah_edge_normal;
@ -877,7 +877,7 @@
if ( min_point )
{
/* clear all segment fields */
FT_MEM_SET( segment, 0, sizeof ( *segment ) );
FT_ZERO( segment );
segment->dir = segment_dir;
segment->flags = ah_edge_normal;
@ -893,7 +893,7 @@
if ( max_point )
{
/* clear all segment fields */
FT_MEM_SET( segment, 0, sizeof ( *segment ) );
FT_ZERO( segment );
segment->dir = segment_dir;
segment->flags = ah_edge_normal;

View File

@ -45,7 +45,7 @@
FT_BASE_DEF( void )
FT_BASE_DEF( FT_Error )
ft_hash_init( FT_Hash table,
FT_Hash_CompareFunc compare,
FT_Memory memory )
@ -196,7 +196,7 @@
table->mask >>= 1;
p = table->mask;
FT_RENEW_ARRAY( hash->buckets, (mask+1)*2, (mask) );
FT_RENEW_ARRAY( hash->buckets, (mask+1)*2, (mask+1) );
}
else
p--;

File diff suppressed because it is too large Load Diff

View File

@ -451,6 +451,20 @@
}
/* documentation is in fttrigon.h */
FT_EXPORT_DEF( void )
FT_Vector_From_Polar( FT_Vector* vec,
FT_Fixed length,
FT_Angle angle )
{
vec->x = length;
vec->y = 0;
FT_Vector_Rotate( vec, angle );
}
/* documentation is in fttrigon.h */
FT_EXPORT_DEF( FT_Angle )
@ -458,14 +472,14 @@
FT_Angle angle2 )
{
FT_Angle delta = angle2 - angle1;
delta %= FT_ANGLE_2PI;
if ( delta > FT_ANGLE_PI )
delta -= FT_ANGLE_2PI;
return delta;
}
}
/* END */