📄 ftobjs.c
字号:
FT_New_Size( FT_Face face, FT_Size *asize ) { FT_Error error; FT_Memory memory; FT_Driver driver; FT_Driver_Class clazz; FT_Size size = 0; FT_ListNode node = 0; if ( !face ) return FT_Err_Invalid_Face_Handle; if ( !asize ) return FT_Err_Invalid_Size_Handle; if ( !face->driver ) return FT_Err_Invalid_Driver_Handle; *asize = 0; driver = face->driver; clazz = driver->clazz; memory = face->memory; /* Allocate new size object and perform basic initialisation */ if ( FT_ALLOC( size, clazz->size_object_size ) || FT_NEW( node ) ) goto Exit; size->face = face; /* for now, do not use any internal fields in size objects */ size->internal = 0; if ( clazz->init_size ) error = clazz->init_size( size ); /* in case of success, add to the face's list */ if ( !error ) { *asize = size; node->data = size; FT_List_Add( &face->sizes_list, node ); } Exit: if ( error ) { FT_FREE( node ); FT_FREE( size ); } return error; } /* documentation is in ftobjs.h */ FT_EXPORT_DEF( FT_Error ) FT_Done_Size( FT_Size size ) { FT_Error error; FT_Driver driver; FT_Memory memory; FT_Face face; FT_ListNode node; if ( !size ) return FT_Err_Invalid_Size_Handle; face = size->face; if ( !face ) return FT_Err_Invalid_Face_Handle; driver = face->driver; if ( !driver ) return FT_Err_Invalid_Driver_Handle; memory = driver->root.memory; error = FT_Err_Ok; node = FT_List_Find( &face->sizes_list, size ); if ( node ) { FT_List_Remove( &face->sizes_list, node ); FT_FREE( node ); if ( face->size == size ) { face->size = 0; if ( face->sizes_list.head ) face->size = (FT_Size)(face->sizes_list.head->data); } destroy_size( memory, size, driver ); } else error = FT_Err_Invalid_Size_Handle; return error; } static void ft_recompute_scaled_metrics( FT_Face face, FT_Size_Metrics* metrics ) { /* Compute root ascender, descender, test height, and max_advance */ metrics->ascender = FT_PIX_CEIL( FT_MulFix( face->ascender, metrics->y_scale ) ); metrics->descender = FT_PIX_FLOOR( FT_MulFix( face->descender, metrics->y_scale ) ); metrics->height = FT_PIX_ROUND( FT_MulFix( face->height, metrics->y_scale ) ); metrics->max_advance = FT_PIX_ROUND( FT_MulFix( face->max_advance_width, metrics->x_scale ) ); } /* documentation is in freetype.h */ FT_EXPORT_DEF( FT_Error ) FT_Set_Char_Size( FT_Face face, FT_F26Dot6 char_width, FT_F26Dot6 char_height, FT_UInt horz_resolution, FT_UInt vert_resolution ) { FT_Error error = FT_Err_Ok; FT_Driver driver; FT_Driver_Class clazz; FT_Size_Metrics* metrics; FT_Long dim_x, dim_y; if ( !face || !face->size || !face->driver ) return FT_Err_Invalid_Face_Handle; driver = face->driver; metrics = &face->size->metrics; clazz = driver->clazz; if ( !char_width ) char_width = char_height; else if ( !char_height ) char_height = char_width; if ( !horz_resolution ) horz_resolution = 72; if ( !vert_resolution ) vert_resolution = 72; /* default processing -- this can be overridden by the driver */ if ( char_width < 1 * 64 ) char_width = 1 * 64; if ( char_height < 1 * 64 ) char_height = 1 * 64; /* Compute pixel sizes in 26.6 units */ dim_x = ( char_width * horz_resolution + 36 ) / 72; dim_y = ( char_height * vert_resolution + 36 ) / 72; { FT_UShort x_ppem = (FT_UShort)( ( dim_x + 32 ) >> 6 ); FT_UShort y_ppem = (FT_UShort)( ( dim_y + 32 ) >> 6 ); /* Don't take, say, 12.5x12.5 equal to 13x13. If working with */ /* fractional font sizes this would hide slightly different */ /* font metrics. Consequently, the next two lines are */ /* disabled. */#if 0 if ( x_ppem == metrics->x_ppem && y_ppem == metrics->y_ppem ) return FT_Err_Ok;#endif metrics->x_ppem = x_ppem; metrics->y_ppem = y_ppem; } metrics->x_scale = 0x10000L; metrics->y_scale = 0x10000L; if ( face->face_flags & FT_FACE_FLAG_SCALABLE ) { metrics->x_scale = FT_DivFix( dim_x, face->units_per_EM ); metrics->y_scale = FT_DivFix( dim_y, face->units_per_EM ); ft_recompute_scaled_metrics( face, metrics ); } if ( clazz->set_char_sizes ) error = clazz->set_char_sizes( face->size, char_width, char_height, horz_resolution, vert_resolution ); return error; } /* documentation is in freetype.h */ FT_EXPORT_DEF( FT_Error ) FT_Set_Pixel_Sizes( FT_Face face, FT_UInt pixel_width, FT_UInt pixel_height ) { FT_Error error = FT_Err_Ok; FT_Driver driver; FT_Driver_Class clazz; FT_Size_Metrics* metrics; if ( !face || !face->size || !face->driver ) return FT_Err_Invalid_Face_Handle; driver = face->driver; metrics = &face->size->metrics; clazz = driver->clazz; if ( pixel_width == 0 ) pixel_width = pixel_height; else if ( pixel_height == 0 ) pixel_height = pixel_width; if ( pixel_width < 1 ) pixel_width = 1; if ( pixel_height < 1 ) pixel_height = 1; /* use `>=' to avoid potention compiler warning on 16bit platforms */ if ( pixel_width >= 0xFFFFU ) pixel_width = 0xFFFFU; if ( pixel_height >= 0xFFFFU ) pixel_height = 0xFFFFU; metrics->x_ppem = (FT_UShort)pixel_width; metrics->y_ppem = (FT_UShort)pixel_height; if ( face->face_flags & FT_FACE_FLAG_SCALABLE ) { metrics->x_scale = FT_DivFix( metrics->x_ppem << 6, face->units_per_EM ); metrics->y_scale = FT_DivFix( metrics->y_ppem << 6, face->units_per_EM ); ft_recompute_scaled_metrics( face, metrics ); } if ( clazz->set_pixel_sizes ) error = clazz->set_pixel_sizes( face->size, pixel_width, pixel_height ); return error; } /* documentation is in freetype.h */ FT_EXPORT_DEF( FT_Error ) FT_Get_Kerning( FT_Face face, FT_UInt left_glyph, FT_UInt right_glyph, FT_UInt kern_mode, FT_Vector *akerning ) { FT_Error error = FT_Err_Ok; FT_Driver driver; if ( !face ) return FT_Err_Invalid_Face_Handle; if ( !akerning ) return FT_Err_Invalid_Argument; driver = face->driver; akerning->x = 0; akerning->y = 0; if ( driver->clazz->get_kerning ) { error = driver->clazz->get_kerning( face, left_glyph, right_glyph, akerning ); if ( !error ) { if ( kern_mode != FT_KERNING_UNSCALED ) { akerning->x = FT_MulFix( akerning->x, face->size->metrics.x_scale ); akerning->y = FT_MulFix( akerning->y, face->size->metrics.y_scale ); if ( kern_mode != FT_KERNING_UNFITTED ) { /* we scale down kerning values for small ppem values */ /* to avoid that rounding makes them too big. */ /* `25' has been determined heuristically. */ if ( face->size->metrics.x_ppem < 25 ) akerning->x = FT_MulDiv( akerning->x, face->size->metrics.x_ppem, 25 ); if ( face->size->metrics.y_ppem < 25 ) akerning->y = FT_MulDiv( akerning->y, face->size->metrics.y_ppem, 25 ); akerning->x = FT_PIX_ROUND( akerning->x ); akerning->y = FT_PIX_ROUND( akerning->y ); } } } } return error; } /* documentation is in freetype.h */ FT_EXPORT_DEF( FT_Error ) FT_Select_Charmap( FT_Face face, FT_Encoding encoding ) { FT_CharMap* cur; FT_CharMap* limit; if ( !face ) return FT_Err_Invalid_Face_Handle; /* FT_ENCODING_UNICODE is special. We try to find the `best' Unicode */ /* charmap available, i.e., one with UCS-4 characters, if possible. */ /* */ /* This is done by find_unicode_charmap() above, to share code. */ if ( encoding == FT_ENCODING_UNICODE ) return find_unicode_charmap( face ); cur = face->charmaps; if ( !cur ) return FT_Err_Invalid_CharMap_Handle; limit = cur + face->num_charmaps; for ( ; cur < limit; cur++ ) { if ( cur[0]->encoding == encoding ) { face->charmap = cur[0]; return 0; } } return FT_Err_Invalid_Argument; } /* documentation is in freetype.h */ FT_EXPORT_DEF( FT_Error ) FT_Set_Charmap( FT_Face face, FT_CharMap charmap ) { FT_CharMap* cur; FT_CharMap* limit; if ( !face ) return FT_Err_Invalid_Face_Handle; cur = face->charmaps; if ( !cur ) return FT_Err_Invalid_CharMap_Handle; limit = cur + face->num_charmaps; for ( ; cur < limit; cur++ ) { if ( cur[0] == charmap ) { face->charmap = cur[0]; return 0; } } return FT_Err_Invalid_Argument; } /* documentation is in freetype.h */ FT_EXPORT_DEF( FT_Int ) FT_Get_Charmap_Index( FT_CharMap charmap ) { FT_Int i; for ( i = 0; i < charmap->face->num_charmaps; i++ ) if ( charmap->face->charmaps[i] == charmap ) break; FT_ASSERT( i < charmap->face->num_charmaps ); return i; } static void ft_cmap_done_internal( FT_CMap cmap ) { FT_CMap_Class clazz = cmap->clazz; FT_Face face = cmap->charmap.face; FT_Memory memory = FT_FACE_MEMORY(face); if ( clazz->done ) clazz->done( cmap ); FT_FREE( cmap ); } FT_BASE_DEF( void ) FT_CMap_Done( FT_CMap cmap ) { if ( cmap ) { FT_Face face = cmap->charmap.face; FT_Memory memory = FT_FACE_MEMORY( face ); FT_Error error; FT_Int i, j; for ( i = 0; i < face->num_charmaps; i++ ) { if ( (FT_CMap)face->charmaps[i] == cmap ) { FT_CharMap last_charmap = face->charmaps[face->num_charmaps - 1]; if ( FT_RENEW_ARRAY( face->charmaps, face->num_charmaps, face->num_charmaps - 1 ) ) return; /* remove it from our list of charmaps */ for ( j = i + 1; j < face->num_charmaps; j++ ) { if ( j == face->num_charmaps - 1 ) face->charmaps[j - 1] =
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -