ftcimage.c

Go to the documentation of this file.
00001 /***************************************************************************/
00002 /*                                                                         */
00003 /*  ftcimage.c                                                             */
00004 /*                                                                         */
00005 /*    FreeType Image cache (body).                                         */
00006 /*                                                                         */
00007 /*  Copyright 2000-2001, 2003, 2004, 2006 by                               */
00008 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
00009 /*                                                                         */
00010 /*  This file is part of the FreeType project, and may only be used,       */
00011 /*  modified, and distributed under the terms of the FreeType project      */
00012 /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
00013 /*  this file you indicate that you have read the license and              */
00014 /*  understand and accept it fully.                                        */
00015 /*                                                                         */
00016 /***************************************************************************/
00017 
00018 
00019 #include <ft2build.h>
00020 #include FT_CACHE_H
00021 #include "ftcimage.h"
00022 #include FT_INTERNAL_MEMORY_H
00023 
00024 #include "ftccback.h"
00025 #include "ftcerror.h"
00026 
00027 
00028   /* finalize a given glyph image node */
00029   FT_LOCAL_DEF( void )
00030   ftc_inode_free( FTC_Node   ftcinode,
00031                   FTC_Cache  cache )
00032   {
00033     FTC_INode  inode = (FTC_INode)ftcinode;
00034     FT_Memory  memory = cache->memory;
00035 
00036 
00037     if ( inode->glyph )
00038     {
00039       FT_Done_Glyph( inode->glyph );
00040       inode->glyph = NULL;
00041     }
00042 
00043     FTC_GNode_Done( FTC_GNODE( inode ), cache );
00044     FT_FREE( inode );
00045   }
00046 
00047 
00048   FT_LOCAL_DEF( void )
00049   FTC_INode_Free( FTC_INode  inode,
00050                   FTC_Cache  cache )
00051   {
00052     ftc_inode_free( FTC_NODE( inode ), cache );
00053   }
00054 
00055 
00056   /* initialize a new glyph image node */
00057   FT_LOCAL_DEF( FT_Error )
00058   FTC_INode_New( FTC_INode   *pinode,
00059                  FTC_GQuery   gquery,
00060                  FTC_Cache    cache )
00061   {
00062     FT_Memory  memory = cache->memory;
00063     FT_Error   error;
00064     FTC_INode  inode;
00065 
00066 
00067     if ( !FT_NEW( inode ) )
00068     {
00069       FTC_GNode         gnode  = FTC_GNODE( inode );
00070       FTC_Family        family = gquery->family;
00071       FT_UInt           gindex = gquery->gindex;
00072       FTC_IFamilyClass  clazz  = FTC_CACHE__IFAMILY_CLASS( cache );
00073 
00074 
00075       /* initialize its inner fields */
00076       FTC_GNode_Init( gnode, gindex, family );
00077 
00078       /* we will now load the glyph image */
00079       error = clazz->family_load_glyph( family, gindex, cache,
00080                                         &inode->glyph );
00081       if ( error )
00082       {
00083         FTC_INode_Free( inode, cache );
00084         inode = NULL;
00085       }
00086     }
00087 
00088     *pinode = inode;
00089     return error;
00090   }
00091 
00092 
00093   FT_LOCAL_DEF( FT_Error )
00094   ftc_inode_new( FTC_Node   *ftcpinode,
00095                  FT_Pointer  ftcgquery,
00096                  FTC_Cache   cache )
00097   {
00098     FTC_INode  *pinode = (FTC_INode*)ftcpinode;
00099     FTC_GQuery  gquery = (FTC_GQuery)ftcgquery;
00100 
00101 
00102     return FTC_INode_New( pinode, gquery, cache );
00103   }
00104 
00105 
00106   FT_LOCAL_DEF( FT_Offset )
00107   ftc_inode_weight( FTC_Node   ftcinode,
00108                     FTC_Cache  ftccache )
00109   {
00110     FTC_INode  inode = (FTC_INode)ftcinode;
00111     FT_Offset  size  = 0;
00112     FT_Glyph   glyph = inode->glyph;
00113 
00114     FT_UNUSED( ftccache );
00115 
00116 
00117     switch ( glyph->format )
00118     {
00119     case FT_GLYPH_FORMAT_BITMAP:
00120       {
00121         FT_BitmapGlyph  bitg;
00122 
00123 
00124         bitg = (FT_BitmapGlyph)glyph;
00125         size = bitg->bitmap.rows * ft_labs( bitg->bitmap.pitch ) +
00126                sizeof ( *bitg );
00127       }
00128       break;
00129 
00130     case FT_GLYPH_FORMAT_OUTLINE:
00131       {
00132         FT_OutlineGlyph  outg;
00133 
00134 
00135         outg = (FT_OutlineGlyph)glyph;
00136         size = outg->outline.n_points *
00137                  ( sizeof ( FT_Vector ) + sizeof ( FT_Byte ) ) +
00138                outg->outline.n_contours * sizeof ( FT_Short ) +
00139                sizeof ( *outg );
00140       }
00141       break;
00142 
00143     default:
00144       ;
00145     }
00146 
00147     size += sizeof ( *inode );
00148     return size;
00149   }
00150 
00151 
00152 #if 0
00153 
00154   FT_LOCAL_DEF( FT_Offset )
00155   FTC_INode_Weight( FTC_INode  inode )
00156   {
00157     return ftc_inode_weight( FTC_NODE( inode ), NULL );
00158   }
00159 
00160 #endif /* 0 */
00161 
00162 
00163 /* END */

Generated on Tue Jul 5 14:13:45 2011 for ROOT_528-00b_version by  doxygen 1.5.1