?? ftobjs.c
字號:
/* test for valid `parameters' delayed to ft_input_stream_new() */ if ( !face ) return FT_Err_Invalid_Face_Handle; driver = face->driver; if ( !driver ) return FT_Err_Invalid_Driver_Handle; error = ft_input_stream_new( driver->root.library, parameters, &stream ); if ( error ) goto Exit; /* we implement FT_Attach_Stream in each driver through the */ /* `attach_file' interface */ error = FT_Err_Unimplemented_Feature; clazz = driver->clazz; if ( clazz->attach_file ) error = clazz->attach_file( face, stream ); /* close the attached stream */ ft_input_stream_free( stream, (FT_Bool)( parameters->stream && ( parameters->flags & ft_open_stream ) ) ); Exit: return error; } /* documentation is in freetype.h */ FT_EXPORT_DEF( FT_Error ) FT_Done_Face( FT_Face face ) { FT_Error error; FT_Driver driver; FT_Memory memory; FT_ListNode node; error = FT_Err_Invalid_Face_Handle; if ( face && face->driver ) { driver = face->driver; memory = driver->root.memory; /* find face in driver's list */ node = FT_List_Find( &driver->faces_list, face ); if ( node ) { /* remove face object from the driver's list */ FT_List_Remove( &driver->faces_list, node ); FT_FREE( node ); /* now destroy the object proper */ destroy_face( memory, face, driver ); error = FT_Err_Ok; } } return error; } /* documentation is in ftobjs.h */ FT_EXPORT_DEF( FT_Error ) 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_MulFix( face->ascender, metrics->y_scale ) + 32 ) & -64; metrics->descender = ( FT_MulFix( face->descender, metrics->y_scale ) + 32 ) & -64; metrics->height = ( FT_MulFix( face->height, metrics->y_scale ) + 32 ) & -64; metrics->max_advance = ( FT_MulFix( face->max_advance_width, metrics->x_scale ) + 32 ) & -64; } /* 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; 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; driver = face->driver; clazz = driver->clazz; /* 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 ) / 72 ) + 32 ) & -64; dim_y = ( ( ( char_height * vert_resolution ) / 72 ) + 32 ) & -64; metrics->x_ppem = (FT_UShort)( dim_x >> 6 ); metrics->y_ppem = (FT_UShort)( dim_y >> 6 ); 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 = &face->size->metrics; if ( !face || !face->size || !face->driver ) return FT_Err_Invalid_Face_Handle; driver = face->driver; clazz = driver->clazz; /* default processing -- this can be overridden by the driver */ 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; 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 ) { akerning->x = ( akerning->x + 32 ) & -64; akerning->y = ( akerning->y + 32 ) & -64; } } } } 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; 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; } FT_BASE_DEF( void ) FT_CMap_Done( FT_CMap cmap ) { if ( 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( FT_Error ) FT_CMap_New( FT_CMap_Class clazz, FT_Pointer init_data, FT_CharMap charmap, FT_CMap *acmap ) { FT_Error error = 0; FT_Face face; FT_Memory memory; FT_CMap cmap; if ( clazz == NULL || charmap == NULL || charmap->face == NULL ) return FT_Err_Invalid_Argument; face = charmap->face; memory = FT_FACE_MEMORY(face); if ( !FT_ALLOC( cmap, clazz->size ) ) { cmap->charmap = *charmap; cmap->clazz = clazz; if ( clazz->init ) { error = clazz->init( cmap, init_data ); if ( error ) goto Fail; } /* add it to our list of charmaps */ if ( FT_RENEW_ARRAY( face->charmaps, face->num_charmaps, face->num_charmaps+1 ) ) goto Fail; face->charmaps[face->num_charmaps++] = (FT_CharMap)cmap; } Exit: if ( acmap ) *acmap = cmap; return error; Fail: FT_CMap_Done( cmap ); cmap = NULL; goto Exit;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -