1 /**************************************************************************** 2 * 3 * ftcimage.c 4 * 5 * FreeType Image cache (body). 6 * 7 * Copyright 2000-2018 by 8 * David Turner, Robert Wilhelm, and Werner Lemberg. 9 * 10 * This file is part of the FreeType project, and may only be used, 11 * modified, and distributed under the terms of the FreeType project 12 * license, LICENSE.TXT. By continuing to use, modify, or distribute 13 * this file you indicate that you have read the license and 14 * understand and accept it fully. 15 * 16 */ 17 18 19 #include <ft2build.h> 20 #include FT_CACHE_H 21 #include "ftcimage.h" 22 #include FT_INTERNAL_MEMORY_H 23 #include FT_INTERNAL_OBJECTS_H 24 25 #include "ftccback.h" 26 #include "ftcerror.h" 27 28 29 /* finalize a given glyph image node */ 30 FT_LOCAL_DEF( void ) ftc_inode_free(FTC_Node ftcinode,FTC_Cache cache)31 ftc_inode_free( FTC_Node ftcinode, 32 FTC_Cache cache ) 33 { 34 FTC_INode inode = (FTC_INode)ftcinode; 35 FT_Memory memory = cache->memory; 36 37 38 if ( inode->glyph ) 39 { 40 FT_Done_Glyph( inode->glyph ); 41 inode->glyph = NULL; 42 } 43 44 FTC_GNode_Done( FTC_GNODE( inode ), cache ); 45 FT_FREE( inode ); 46 } 47 48 49 FT_LOCAL_DEF( void ) FTC_INode_Free(FTC_INode inode,FTC_Cache cache)50 FTC_INode_Free( FTC_INode inode, 51 FTC_Cache cache ) 52 { 53 ftc_inode_free( FTC_NODE( inode ), cache ); 54 } 55 56 57 /* initialize a new glyph image node */ 58 FT_LOCAL_DEF( FT_Error ) FTC_INode_New(FTC_INode * pinode,FTC_GQuery gquery,FTC_Cache cache)59 FTC_INode_New( FTC_INode *pinode, 60 FTC_GQuery gquery, 61 FTC_Cache cache ) 62 { 63 FT_Memory memory = cache->memory; 64 FT_Error error; 65 FTC_INode inode = NULL; 66 67 68 if ( !FT_NEW( inode ) ) 69 { 70 FTC_GNode gnode = FTC_GNODE( inode ); 71 FTC_Family family = gquery->family; 72 FT_UInt gindex = gquery->gindex; 73 FTC_IFamilyClass clazz = FTC_CACHE_IFAMILY_CLASS( cache ); 74 75 76 /* initialize its inner fields */ 77 FTC_GNode_Init( gnode, gindex, family ); 78 79 /* we will now load the glyph image */ 80 error = clazz->family_load_glyph( family, gindex, cache, 81 &inode->glyph ); 82 if ( error ) 83 { 84 FTC_INode_Free( inode, cache ); 85 inode = NULL; 86 } 87 } 88 89 *pinode = inode; 90 return error; 91 } 92 93 94 FT_LOCAL_DEF( FT_Error ) ftc_inode_new(FTC_Node * ftcpinode,FT_Pointer ftcgquery,FTC_Cache cache)95 ftc_inode_new( FTC_Node *ftcpinode, 96 FT_Pointer ftcgquery, 97 FTC_Cache cache ) 98 { 99 FTC_INode *pinode = (FTC_INode*)ftcpinode; 100 FTC_GQuery gquery = (FTC_GQuery)ftcgquery; 101 102 103 return FTC_INode_New( pinode, gquery, cache ); 104 } 105 106 107 FT_LOCAL_DEF( FT_Offset ) ftc_inode_weight(FTC_Node ftcinode,FTC_Cache ftccache)108 ftc_inode_weight( FTC_Node ftcinode, 109 FTC_Cache ftccache ) 110 { 111 FTC_INode inode = (FTC_INode)ftcinode; 112 FT_Offset size = 0; 113 FT_Glyph glyph = inode->glyph; 114 115 FT_UNUSED( ftccache ); 116 117 118 switch ( glyph->format ) 119 { 120 case FT_GLYPH_FORMAT_BITMAP: 121 { 122 FT_BitmapGlyph bitg; 123 124 125 bitg = (FT_BitmapGlyph)glyph; 126 size = bitg->bitmap.rows * (FT_Offset)FT_ABS( bitg->bitmap.pitch ) + 127 sizeof ( *bitg ); 128 } 129 break; 130 131 case FT_GLYPH_FORMAT_OUTLINE: 132 { 133 FT_OutlineGlyph outg; 134 135 136 outg = (FT_OutlineGlyph)glyph; 137 size = (FT_Offset)outg->outline.n_points * 138 ( sizeof ( FT_Vector ) + sizeof ( FT_Byte ) ) + 139 (FT_Offset)outg->outline.n_contours * sizeof ( FT_Short ) + 140 sizeof ( *outg ); 141 } 142 break; 143 144 default: 145 ; 146 } 147 148 size += sizeof ( *inode ); 149 return size; 150 } 151 152 153 #if 0 154 155 FT_LOCAL_DEF( FT_Offset ) 156 FTC_INode_Weight( FTC_INode inode ) 157 { 158 return ftc_inode_weight( FTC_NODE( inode ), NULL ); 159 } 160 161 #endif /* 0 */ 162 163 164 /* END */ 165