ftcimage.c (3584B)
1 /**************************************************************************** 2 * 3 * ftcimage.c 4 * 5 * FreeType Image cache (body). 6 * 7 * Copyright (C) 2000-2025 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 <freetype/ftcache.h> 20 #include "ftcimage.h" 21 #include <freetype/internal/ftmemory.h> 22 #include <freetype/internal/ftobjs.h> 23 24 #include "ftccback.h" 25 #include "ftcerror.h" 26 27 28 /* finalize a given glyph image node */ 29 FT_LOCAL_DEF( void ) 30 ftc_inode_free( FTC_Node ftcinode, 31 FTC_Cache cache ) 32 { 33 FTC_INode inode = (FTC_INode)ftcinode; 34 FT_Memory memory = cache->memory; 35 36 37 FT_Done_Glyph( inode->glyph ); 38 39 FTC_GNode_Done( FTC_GNODE( inode ), cache ); 40 FT_FREE( inode ); 41 } 42 43 44 FT_LOCAL_DEF( void ) 45 FTC_INode_Free( FTC_INode inode, 46 FTC_Cache cache ) 47 { 48 ftc_inode_free( FTC_NODE( inode ), cache ); 49 } 50 51 52 /* initialize a new glyph image node */ 53 FT_LOCAL_DEF( FT_Error ) 54 FTC_INode_New( FTC_INode *pinode, 55 FTC_GQuery gquery, 56 FTC_Cache cache ) 57 { 58 FT_Memory memory = cache->memory; 59 FT_Error error; 60 FTC_INode inode = NULL; 61 62 63 if ( !FT_QNEW( inode ) ) 64 { 65 FTC_GNode gnode = FTC_GNODE( inode ); 66 FTC_Family family = gquery->family; 67 FT_UInt gindex = gquery->gindex; 68 FTC_IFamilyClass clazz = FTC_CACHE_IFAMILY_CLASS( cache ); 69 70 71 /* initialize its inner fields */ 72 FTC_GNode_Init( gnode, gindex, family ); 73 inode->glyph = NULL; 74 75 /* we will now load the glyph image */ 76 error = clazz->family_load_glyph( family, gindex, cache, 77 &inode->glyph ); 78 if ( error ) 79 { 80 FTC_INode_Free( inode, cache ); 81 inode = NULL; 82 } 83 } 84 85 *pinode = inode; 86 return error; 87 } 88 89 90 FT_LOCAL_DEF( FT_Error ) 91 ftc_inode_new( FTC_Node *ftcpinode, 92 FT_Pointer ftcgquery, 93 FTC_Cache cache ) 94 { 95 FTC_INode *pinode = (FTC_INode*)ftcpinode; 96 FTC_GQuery gquery = (FTC_GQuery)ftcgquery; 97 98 99 return FTC_INode_New( pinode, gquery, cache ); 100 } 101 102 103 FT_LOCAL_DEF( FT_Offset ) 104 ftc_inode_weight( FTC_Node ftcinode, 105 FTC_Cache ftccache ) 106 { 107 FTC_INode inode = (FTC_INode)ftcinode; 108 FT_Offset size = 0; 109 FT_Glyph glyph = inode->glyph; 110 111 FT_UNUSED( ftccache ); 112 113 114 switch ( glyph->format ) 115 { 116 case FT_GLYPH_FORMAT_BITMAP: 117 { 118 FT_BitmapGlyph bitg = (FT_BitmapGlyph)glyph; 119 120 121 size = bitg->bitmap.rows * (FT_Offset)FT_ABS( bitg->bitmap.pitch ) + 122 sizeof ( *bitg ); 123 } 124 break; 125 126 case FT_GLYPH_FORMAT_OUTLINE: 127 { 128 FT_OutlineGlyph outg = (FT_OutlineGlyph)glyph; 129 130 131 size = (FT_Offset)outg->outline.n_points * 132 ( sizeof ( FT_Vector ) + sizeof ( FT_Byte ) ) + 133 (FT_Offset)outg->outline.n_contours * sizeof ( FT_Short ) + 134 sizeof ( *outg ); 135 } 136 break; 137 138 default: 139 ; 140 } 141 142 size += sizeof ( *inode ); 143 return size; 144 } 145 146 147 #if 0 148 149 FT_LOCAL_DEF( FT_Offset ) 150 FTC_INode_Weight( FTC_INode inode ) 151 { 152 return ftc_inode_weight( FTC_NODE( inode ), NULL ); 153 } 154 155 #endif /* 0 */ 156 157 158 /* END */