📄 ftobjs.c
字号:
FT_Driver_Class* clazz; /* test for valid `parameters' delayed to ft_new_input_stream() */ if ( !face ) return FT_Err_Invalid_Face_Handle; driver = face->driver; if ( !driver ) return FT_Err_Invalid_Driver_Handle; error = ft_new_input_stream( 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_done_stream( &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 ); 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 ( ALLOC( size, clazz->size_object_size ) || ALLOC( node, sizeof ( FT_ListNodeRec ) ) ) 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 ) { FREE( node ); 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 ); 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 FT_Err_Ok; } 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_Memory memory; 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; memory = driver->root.memory; /* 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_Memory memory; 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; memory = driver->root.memory; /* 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 = pixel_width; metrics->y_ppem = 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; FT_Memory memory; if ( !face ) return FT_Err_Invalid_Face_Handle; if ( !akerning ) return FT_Err_Invalid_Argument; driver = face->driver; memory = driver->root.memory; 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; } /* documentation is in freetype.h */ FT_EXPORT_DEF( FT_UInt ) FT_Get_Char_Index( FT_Face face, FT_ULong charcode ) { FT_UInt result; FT_Driver driver; result = 0; if ( face && face->charmap ) { driver = face->driver; result = driver->clazz->get_char_index( face->charmap, charcode ); } return result; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -