2000-09-19 03:11:11 +02:00
|
|
|
#ifdef FT_FLAT_COMPILE
|
|
|
|
# include "ftcimage.h"
|
|
|
|
#else
|
|
|
|
# include <cache/ftcimage.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** GLYPH IMAGE NODES *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
2000-08-23 23:11:13 +02:00
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
/* this is a simple glyph image destructor, which is called exclusively */
|
|
|
|
/* from the CacheQueue object */
|
2000-08-29 18:50:01 +02:00
|
|
|
LOCAL_FUNC_X
|
2000-09-19 03:11:11 +02:00
|
|
|
void ftc_glyph_image_node_destroy( FTC_GlyphNode node,
|
|
|
|
FTC_Glyph_Queue queue )
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
2000-09-19 03:11:11 +02:00
|
|
|
FT_Memory memory = queue->memory;
|
2000-08-23 13:22:30 +02:00
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
FT_Done_Glyph( FTC_GLYPHNODE_GET_GLYPH( node ) );
|
|
|
|
FREE( node );
|
2000-08-23 13:22:30 +02:00
|
|
|
}
|
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
|
2000-08-29 18:50:01 +02:00
|
|
|
LOCAL_FUNC_X
|
2000-09-19 03:11:11 +02:00
|
|
|
FT_Error ftc_glyph_image_node_new( FTC_Glyph_Queue queue,
|
|
|
|
FT_UInt glyph_index,
|
|
|
|
FTC_GlyphNode *anode )
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
2000-09-19 03:11:11 +02:00
|
|
|
FT_Memory memory = queue->memory;
|
|
|
|
FTC_Image_Queue imageq = (FTC_Image_Queue)queue;
|
|
|
|
FT_Error error;
|
|
|
|
FTC_GlyphNode node = 0;
|
|
|
|
FT_Face face;
|
|
|
|
FT_Size size;
|
2000-08-23 13:22:30 +02:00
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
/* allocate node */
|
|
|
|
if ( ALLOC( node, sizeof(*node) ) )
|
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
/* init its inner fields */
|
|
|
|
FTC_GlyphNode_Init( node, queue, glyph_index );
|
2000-08-29 18:50:01 +02:00
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
/* we will now load the glyph image */
|
2000-08-23 13:22:30 +02:00
|
|
|
error = FTC_Manager_Lookup_Size( queue->manager,
|
2000-09-19 03:11:11 +02:00
|
|
|
&imageq->description.font,
|
2000-08-23 13:22:30 +02:00
|
|
|
&face, &size );
|
2000-08-23 19:32:42 +02:00
|
|
|
if ( !error )
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
2000-09-19 03:11:11 +02:00
|
|
|
FT_UInt glyph_index = node->glyph_index;
|
2000-08-29 18:04:28 +02:00
|
|
|
FT_UInt load_flags = FT_LOAD_DEFAULT;
|
2000-09-19 03:11:11 +02:00
|
|
|
FT_UInt image_type = imageq->description.image_type;
|
2000-08-23 13:22:30 +02:00
|
|
|
|
2000-08-29 18:50:01 +02:00
|
|
|
if ( FTC_IMAGE_FORMAT( image_type ) == ftc_image_format_bitmap )
|
2000-08-29 18:04:28 +02:00
|
|
|
{
|
|
|
|
load_flags |= FT_LOAD_RENDER;
|
|
|
|
if ( image_type & ftc_image_flag_monochrome )
|
|
|
|
load_flags |= FT_LOAD_MONOCHROME;
|
2000-08-23 13:22:30 +02:00
|
|
|
|
2000-08-29 18:04:28 +02:00
|
|
|
/* disable embedded bitmaps loading if necessary */
|
2000-08-29 18:50:01 +02:00
|
|
|
if ( load_flags & ftc_image_flag_no_sbits )
|
2000-08-29 18:04:28 +02:00
|
|
|
load_flags |= FT_LOAD_NO_BITMAP;
|
2000-08-23 13:22:30 +02:00
|
|
|
}
|
2000-08-29 18:50:01 +02:00
|
|
|
else if ( FTC_IMAGE_FORMAT( image_type ) == ftc_image_format_outline )
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
2000-08-29 18:04:28 +02:00
|
|
|
/* disable embedded bitmaps loading */
|
|
|
|
load_flags |= FT_LOAD_NO_BITMAP;
|
|
|
|
|
2000-08-29 18:50:01 +02:00
|
|
|
if ( image_type & ftc_image_flag_unscaled )
|
2000-08-29 18:04:28 +02:00
|
|
|
load_flags |= FT_LOAD_NO_SCALE;
|
|
|
|
}
|
2000-08-23 23:11:13 +02:00
|
|
|
|
2000-08-29 18:50:01 +02:00
|
|
|
if ( image_type & ftc_image_flag_unhinted )
|
2000-08-29 18:04:28 +02:00
|
|
|
load_flags |= FT_LOAD_NO_HINTING;
|
2000-08-23 23:11:13 +02:00
|
|
|
|
2000-08-29 18:50:01 +02:00
|
|
|
if ( image_type & ftc_image_flag_autohinted )
|
2000-08-29 18:04:28 +02:00
|
|
|
load_flags |= FT_LOAD_FORCE_AUTOHINT;
|
2000-08-23 23:11:13 +02:00
|
|
|
|
2000-08-29 18:04:28 +02:00
|
|
|
error = FT_Load_Glyph( face, glyph_index, load_flags );
|
2000-08-23 23:11:13 +02:00
|
|
|
if ( !error )
|
|
|
|
{
|
2000-08-29 18:04:28 +02:00
|
|
|
if ( face->glyph->format == ft_glyph_format_bitmap ||
|
|
|
|
face->glyph->format == ft_glyph_format_outline )
|
|
|
|
{
|
2000-08-23 23:11:13 +02:00
|
|
|
/* ok, copy it */
|
|
|
|
FT_Glyph glyph;
|
|
|
|
|
|
|
|
|
|
|
|
error = FT_Get_Glyph( face->glyph, &glyph );
|
|
|
|
if ( !error )
|
2000-09-19 03:11:11 +02:00
|
|
|
FTC_GLYPHNODE_SET_GLYPH( node, glyph );
|
2000-08-23 23:11:13 +02:00
|
|
|
}
|
2000-08-29 18:04:28 +02:00
|
|
|
else
|
|
|
|
error = FT_Err_Invalid_Argument;
|
2000-08-23 23:11:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Exit:
|
2000-09-19 03:11:11 +02:00
|
|
|
if (error && node)
|
|
|
|
FREE(node);
|
2000-08-23 23:11:13 +02:00
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
*anode = node;
|
2000-08-23 23:11:13 +02:00
|
|
|
return error;
|
2000-09-19 03:11:11 +02:00
|
|
|
}
|
2000-08-23 23:11:13 +02:00
|
|
|
|
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
/* this function is important, because it is both part of */
|
|
|
|
/* a FTC_Glyph_Queue_Class and a FTC_CacheNode_Class */
|
|
|
|
/* */
|
|
|
|
LOCAL_FUNC_X
|
|
|
|
FT_ULong ftc_glyph_image_node_size( FTC_GlyphNode node )
|
2000-08-23 23:11:13 +02:00
|
|
|
{
|
2000-09-19 03:11:11 +02:00
|
|
|
FT_ULong size = 0;
|
|
|
|
FT_Glyph glyph = FTC_GLYPHNODE_GET_GLYPH(node);
|
2000-08-23 23:11:13 +02:00
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
switch (glyph->format)
|
2000-08-23 23:11:13 +02:00
|
|
|
{
|
2000-09-19 03:11:11 +02:00
|
|
|
case ft_glyph_format_bitmap:
|
|
|
|
{
|
|
|
|
FT_BitmapGlyph bitg;
|
|
|
|
|
|
|
|
bitg = (FT_BitmapGlyph)glyph;
|
|
|
|
size = bitg->bitmap.rows * labs(bitg->bitmap.pitch) +
|
|
|
|
sizeof(*bitg);
|
|
|
|
}
|
|
|
|
break;
|
2000-08-29 18:04:28 +02:00
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
case ft_glyph_format_outline:
|
|
|
|
{
|
|
|
|
FT_OutlineGlyph outg;
|
|
|
|
|
|
|
|
outg = (FT_OutlineGlyph)glyph;
|
|
|
|
size = outg->outline.n_points *
|
|
|
|
( sizeof( FT_Vector ) + sizeof( FT_Byte ) ) +
|
|
|
|
outg->outline.n_contours *
|
|
|
|
sizeof( FT_Short ) +
|
|
|
|
sizeof(*outg);
|
|
|
|
}
|
|
|
|
break;
|
2000-08-30 23:40:45 +02:00
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
default:
|
|
|
|
;
|
2000-08-23 23:11:13 +02:00
|
|
|
}
|
2000-09-19 03:11:11 +02:00
|
|
|
size += sizeof(*node);
|
|
|
|
return size;
|
2000-08-23 23:11:13 +02:00
|
|
|
}
|
|
|
|
|
2000-08-24 18:29:15 +02:00
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** GLYPH IMAGE QUEUES *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
2000-08-24 18:29:15 +02:00
|
|
|
|
2000-08-23 23:11:13 +02:00
|
|
|
|
2000-08-29 18:50:01 +02:00
|
|
|
LOCAL_FUNC_X
|
2000-09-19 03:11:11 +02:00
|
|
|
FT_Error ftc_image_queue_init( FTC_Image_Queue queue,
|
|
|
|
FTC_Image_Desc* type )
|
2000-08-23 23:11:13 +02:00
|
|
|
{
|
2000-09-19 03:11:11 +02:00
|
|
|
queue->description = *type;
|
|
|
|
return 0;
|
2000-08-23 23:11:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-29 18:50:01 +02:00
|
|
|
LOCAL_FUNC_X
|
2000-09-19 03:11:11 +02:00
|
|
|
FT_Bool ftc_image_queue_compare( FTC_Image_Queue queue,
|
|
|
|
FTC_Image_Desc* type )
|
2000-08-23 23:11:13 +02:00
|
|
|
{
|
2000-09-19 03:11:11 +02:00
|
|
|
return !memcmp( &queue->description, type, sizeof(*type) );
|
2000-08-23 23:11:13 +02:00
|
|
|
}
|
2000-09-19 03:11:11 +02:00
|
|
|
|
2000-08-23 23:11:13 +02:00
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
FT_CPLUSPLUS(const FTC_Glyph_Queue_Class) ftc_glyph_image_queue_class =
|
2000-08-23 23:11:13 +02:00
|
|
|
{
|
2000-09-19 03:11:11 +02:00
|
|
|
sizeof( FTC_Image_QueueRec ),
|
2000-08-23 23:11:13 +02:00
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
(FTC_Glyph_Queue_InitFunc) ftc_image_queue_init,
|
|
|
|
(FTC_Glyph_Queue_DoneFunc) 0,
|
|
|
|
(FTC_Glyph_Queue_CompareFunc) ftc_image_queue_compare,
|
|
|
|
|
|
|
|
(FTC_Glyph_Queue_NewNodeFunc) ftc_glyph_image_node_new,
|
|
|
|
(FTC_Glyph_Queue_SizeNodeFunc) ftc_glyph_image_node_size,
|
|
|
|
(FTC_Glyph_Queue_DestroyNodeFunc) ftc_glyph_image_node_destroy
|
2000-08-23 23:11:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** GLYPH IMAGE CACHE *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
2000-08-24 18:29:15 +02:00
|
|
|
|
2000-08-29 18:04:28 +02:00
|
|
|
|
2000-08-23 23:11:13 +02:00
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
FT_CPLUSPLUS(const FTC_Glyph_Cache_Class) ftc_glyph_image_cache_class =
|
2000-08-23 23:11:13 +02:00
|
|
|
{
|
2000-09-19 03:11:11 +02:00
|
|
|
{
|
|
|
|
sizeof( FTC_Glyph_CacheRec ),
|
|
|
|
(FTC_Cache_InitFunc) FTC_Glyph_Cache_Init,
|
|
|
|
(FTC_Cache_DoneFunc) FTC_Glyph_Cache_Done
|
|
|
|
},
|
|
|
|
(FTC_Glyph_Queue_Class*) &ftc_glyph_image_queue_class
|
|
|
|
};
|
2000-08-23 23:11:13 +02:00
|
|
|
|
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
FT_EXPORT_FUNC( FT_Error ) FTC_Image_Cache_New( FTC_Manager manager,
|
|
|
|
FTC_Image_Cache* acache )
|
2000-08-23 23:11:13 +02:00
|
|
|
{
|
2000-09-19 03:11:11 +02:00
|
|
|
return FTC_Manager_Register_Cache(
|
|
|
|
manager,
|
|
|
|
(FTC_Cache_Class*)&ftc_glyph_image_cache_class,
|
|
|
|
(FTC_Cache*)acache );
|
2000-08-23 23:11:13 +02:00
|
|
|
}
|
2000-09-19 03:11:11 +02:00
|
|
|
|
2000-08-23 23:11:13 +02:00
|
|
|
|
|
|
|
FT_EXPORT_DEF( FT_Error ) FTC_Image_Cache_Lookup(
|
|
|
|
FTC_Image_Cache cache,
|
|
|
|
FTC_Image_Desc* desc,
|
|
|
|
FT_UInt gindex,
|
|
|
|
FT_Glyph* aglyph )
|
|
|
|
{
|
|
|
|
FT_Error error;
|
2000-09-19 03:11:11 +02:00
|
|
|
FTC_Glyph_Queue queue;
|
|
|
|
FTC_GlyphNode inode;
|
|
|
|
FTC_Manager manager;
|
2000-08-23 23:11:13 +02:00
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
FTC_Image_Queue img_queue;
|
2000-08-24 18:29:15 +02:00
|
|
|
|
|
|
|
/* check for valid `desc' delayed to FT_Lru_Lookup() */
|
|
|
|
|
|
|
|
if ( !cache || !aglyph )
|
|
|
|
return FT_Err_Invalid_Argument;
|
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
*aglyph = 0;
|
|
|
|
queue = cache->root.last_queue;
|
|
|
|
img_queue = (FTC_Image_Queue)queue;
|
|
|
|
if ( !queue || memcmp( &img_queue->description, desc, sizeof(*desc) ) )
|
2000-08-24 14:39:40 +02:00
|
|
|
{
|
2000-09-19 03:11:11 +02:00
|
|
|
error = FT_Lru_Lookup( cache->root.queues_lru,
|
2000-08-24 18:29:15 +02:00
|
|
|
(FT_LruKey)desc,
|
|
|
|
(FT_Pointer*)&queue );
|
2000-09-19 03:11:11 +02:00
|
|
|
cache->root.last_queue = queue;
|
2000-08-24 18:29:15 +02:00
|
|
|
if ( error )
|
2000-08-24 14:39:40 +02:00
|
|
|
goto Exit;
|
|
|
|
}
|
2000-08-23 23:11:13 +02:00
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
error = FTC_Glyph_Queue_Lookup_Node( queue, gindex, &inode );
|
2000-08-24 18:29:15 +02:00
|
|
|
if ( error )
|
2000-08-23 23:11:13 +02:00
|
|
|
goto Exit;
|
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
/* now compress the manager's cache pool if needed */
|
|
|
|
manager = cache->root.root.manager;
|
|
|
|
if (manager->num_bytes > manager->max_bytes)
|
|
|
|
{
|
|
|
|
FTC_GlyphNode_Ref(inode);
|
|
|
|
FTC_Manager_Compress( manager );
|
|
|
|
FTC_GlyphNode_Unref(inode);
|
|
|
|
}
|
2000-08-29 18:04:28 +02:00
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
*aglyph = FTC_GLYPHNODE_GET_GLYPH( inode );
|
2000-08-23 23:11:13 +02:00
|
|
|
|
|
|
|
Exit:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|