freetype2/src/cache/ftcimage.c

146 lines
3.8 KiB
C
Raw Normal View History

2000-10-12 07:05:40 +02:00
/***************************************************************************/
/* */
/* ftcimage.c */
/* */
/* FreeType Image cache (body). */
/* */
/* Copyright 2000-2001, 2003, 2004 by */
2000-10-12 07:05:40 +02:00
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
/* */
/* This file is part of the FreeType project, and may only be used, */
/* modified, and distributed under the terms of the FreeType project */
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
/* this file you indicate that you have read the license and */
/* understand and accept it fully. */
/* */
/***************************************************************************/
2000-12-08 17:17:16 +01:00
#include <ft2build.h>
#include FT_CACHE_H
#include FT_CACHE_INTERNAL_IMAGE_H
2000-12-08 17:17:16 +01:00
#include FT_INTERNAL_MEMORY_H
#include "ftccback.h"
Complete redesign of error codes. Please check ftmoderr.h for more details. * include/freetype/internal/cfferrs.h, include/freetype/internal/tterrors.h, include/freetype/internal/t1errors.h: Removed. Replaced with files local to the module. All extra error codes have been moved to `fterrors.h'. * src/sfnt/ttpost.h: Move error codes to `fterrors.h'. * src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h, src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h, src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h, src/smooth/ftsmerrs.h, src/truetype/tterrors.h, src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the error names for the module it belongs to. * include/freetype/ftmoderr.h: New file, defining the module error offsets. Its structure is similar to `fterrors.h'. * include/freetype/fterrors.h (FT_NOERRORDEF): New macro. (FT_ERRORDEF): Redefined to use module error offsets. All internal error codes are now public; unused error codes have been removed, some are new. * include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New macro. * include/freetype/config/ftoption.h (FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro. All other source files have been updated to use the new error codes; some already existing (internal) error codes local to a module have been renamed to give them the same name as in the base module. All make files have been updated to include the local error files. * src/cid/cidtokens.h: Replaced with... * src/cid/cidtoken.h: This file for 8+3 consistency. * src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
#include "ftcerror.h"
/* finalize a given glyph image node */
FT_EXPORT_DEF( void )
FTC_INode_Free( FTC_INode inode,
FTC_Cache cache )
{
FT_Memory memory = cache->memory;
if ( inode->glyph )
{
FT_Done_Glyph( inode->glyph );
inode->glyph = NULL;
}
FTC_GNode_Done( FTC_GNODE( inode ), cache );
FT_FREE( inode );
}
FT_LOCAL_DEF( void )
ftc_inode_free( FTC_INode inode,
FTC_Cache cache )
{
FTC_INode_Free( inode, cache );
}
/* initialize a new glyph image node */
FT_EXPORT_DEF( FT_Error )
FTC_INode_New( FTC_INode *pinode,
FTC_GQuery gquery,
FTC_Cache cache )
2000-10-12 07:05:40 +02:00
{
FT_Memory memory = cache->memory;
FT_Error error;
FTC_INode inode;
if ( !FT_NEW( inode ) )
{
FTC_GNode gnode = FTC_GNODE( inode );
FTC_Family family = gquery->family;
FT_UInt gindex = gquery->gindex;
FTC_IFamilyClass clazz = FTC_CACHE__IFAMILY_CLASS( cache );
2002-09-18 13:32:12 +02:00
/* initialize its inner fields */
FTC_GNode_Init( gnode, gindex, family );
2000-10-12 07:05:40 +02:00
/* we will now load the glyph image */
error = clazz->family_load_glyph( family, gindex, cache,
&inode->glyph );
}
*pinode = inode;
return error;
}
FT_LOCAL_DEF( FT_Error )
ftc_inode_new( FTC_INode *pinode,
FTC_GQuery gquery,
FTC_Cache cache )
{
return FTC_INode_New( pinode, gquery, cache );
}
FT_EXPORT_DEF( FT_ULong )
FTC_INode_Weight( FTC_INode inode )
{
2000-10-12 07:05:40 +02:00
FT_ULong size = 0;
FT_Glyph glyph = inode->glyph;
2000-10-12 07:05:40 +02:00
2000-10-12 07:05:40 +02:00
switch ( glyph->format )
{
case FT_GLYPH_FORMAT_BITMAP:
2000-10-12 07:05:40 +02:00
{
FT_BitmapGlyph bitg;
bitg = (FT_BitmapGlyph)glyph;
size = bitg->bitmap.rows * labs( bitg->bitmap.pitch ) +
sizeof ( *bitg );
}
break;
case FT_GLYPH_FORMAT_OUTLINE:
2000-10-12 07:05:40 +02:00
{
FT_OutlineGlyph outg;
outg = (FT_OutlineGlyph)glyph;
size = outg->outline.n_points *
( sizeof ( FT_Vector ) + sizeof ( FT_Byte ) ) +
2000-10-12 07:05:40 +02:00
outg->outline.n_contours * sizeof ( FT_Short ) +
sizeof ( *outg );
}
break;
default:
;
}
2000-10-12 07:05:40 +02:00
size += sizeof ( *inode );
return size;
}
FT_LOCAL_DEF( FT_ULong )
ftc_inode_weight( FTC_INode inode )
{
return FTC_INode_Weight( inode );
}
2000-10-12 07:05:40 +02:00
/* END */