📄 ftxsbit.c
字号:
case 8: case 9: { /* Now, load composite sbit glyphs */ /* This code is not sophisticated */ TT_SBit_Component* component_array; UShort num_components; Int i = 0; if ( ACCESS_Frame( 2L ) ) return error; num_components = GET_UShort(); FORGET_Frame(); MEM_Alloc( component_array, sizeof ( TT_SBit_Component ) * num_components ); if ( ACCESS_Frame( 4L * num_components ) ) return error; for ( i = 0; i < num_components; i++ ) { component_array[i].glyph_code = GET_UShort(); component_array[i].x_offset = GET_Char(); component_array[i].y_offset = GET_Char(); } FORGET_Frame(); component_depth++; for ( i = 0; i < num_components; i++ ) { error = Load_SBit_Image( strike, component_array[i].glyph_code, component_array[i].x_offset, component_array[i].y_offset, ebdt_offset, image, component_depth ); if ( error ) return error; } FREE( component_array ); break; default: return TT_Err_Invalid_File_Format; } } return TT_Err_Ok; }/******************************************************************* * * Function: Load_TrueType_Ebdt * ******************************************************************/ static TT_Error Load_TrueType_Ebdt( PFace face, TT_SBit_Strike strike, ULong glyph_index, TT_SBit_Image* image ) { DEFINE_LOCALS; ULong ebdt_offset; ULong version; Long i; /* Try to find the `EBDT' or `bdat' table in the font files. */ /* Both tags describe the same table, `EBDT' is for OpenType */ /* fonts, while `bdat' is for TrueType GX fonts. Many fonts */ /* contain both tags pointing to the same table */ i = TT_LookUp_Table( face, TTAG_EBDT ); if ( i < 0 ) i = TT_LookUp_Table( face, TTAG_bdat ); if ( i < 0 ) return TT_Err_Table_Missing; ebdt_offset = face->dirTables[i].Offset; if ( FILE_Seek( ebdt_offset ) || ACCESS_Frame( 4L ) ) /* read into frame */ return error; version = GET_ULong(); FORGET_Frame(); PTRACE2(( "-- Format version : %08lx\n", version )); if ( version != 0x00020000 ) { PERROR(( "Invalid file format!\n" )); return TT_Err_Invalid_File_Format; } /* This doesn't compile, I simply commented it out ?? - David */ /* PTRACE4(( "-- Format: %d\n", range->image_format )); */ error = Load_SBit_Image( strike, glyph_index, 0, 0, ebdt_offset, image, 0 ); if ( error ) return error; return TT_Err_Ok; } static TT_Error EBLC_Create( void* ext, PFace face ) { TT_EBLC* eblc = (TT_EBLC*)ext; /* by convention */ if ( !eblc ) return TT_Err_Ok; return Load_TrueType_Eblc( face, eblc ); } static TT_Error EBLC_Destroy( void* ext, PFace face ) { TT_EBLC* eblc = (TT_EBLC*)ext; (void)face; if ( eblc ) Free_TrueType_Eblc( eblc ); return TT_Err_Ok; } /*************************************************************/ /* */ /* <Function> */ /* TT_Init_SBit_Extension */ /* */ /* <Description> */ /* Initialize the embedded bitmaps extension for the */ /* FreeType engine. */ /* */ /* <Input> */ /* engine :: handle to current FreeType library instance */ /* */ /* <Return> */ /* Error code. 0 means success. */ /* */ EXPORT_FUNC TT_Error TT_Init_SBit_Extension( TT_Engine engine ) { PEngine_Instance _engine = HANDLE_Engine( engine ); TT_Error error; if ( !_engine ) return TT_Err_Invalid_Engine; error = TT_Register_Extension( _engine, SBIT_ID, sizeof ( TT_EBLC ), EBLC_Create, EBLC_Destroy ); return error; } /*************************************************************/ /* */ /* <Function> */ /* TT_Get_Face_Bitmaps */ /* */ /* <Description> */ /* Loads the `EBLC' table from a font file, if any. */ /* */ /* <Input> */ /* face :: handle to the source TrueType font/face */ /* */ /* <Output> */ /* eblc_table :: a descriptor for the EBLC table */ /* */ /* <Return> */ /* Error code. 0 means success. */ /* */ /* <Note> */ /* This function returns TT_Err_Table_Missing if the */ /* font contains no embedded bitmaps. All fields in */ /* `eblc_table' will then be set to 0. */ /* */ EXPORT_FUNC TT_Error TT_Get_Face_Bitmaps( TT_Face face, TT_EBLC* eblc_table ) { PFace faze = HANDLE_Face( face ); TT_EBLC* eblc; TT_Error error; error = TT_Extension_Get( faze, SBIT_ID, (void**)&eblc ); if ( !error ) { if ( eblc->version ) { *eblc_table = *eblc; return TT_Err_Ok; } error = TT_Err_Table_Missing; } eblc_table->version = 0; eblc_table->num_strikes = 0; eblc_table->strikes = 0; return error; }/******************************************************************* * * <Function> TT_Get_SBit_Strike * * <Description> * Loads suitable strike (bitmap sizetable) for given instance. * This strike includes sbitLineMetrics. * * <Input> * face :: the source face * instance :: the current size instance * * <Output> * strike :: the bitmap strike descriptor * * <Return> * TrueType error code. 0 means success. * ******************************************************************/ EXPORT_FUNC TT_Error TT_Get_SBit_Strike( TT_Face face, TT_Instance instance, TT_SBit_Strike* strike ) { TT_Error error; PFace faze = HANDLE_Face( face ); PInstance ins = HANDLE_Instance( instance ); TT_EBLC* eblc; TT_Int x_ppem, y_ppem; if ( !strike || !ins || ins->owner != faze ) return TT_Err_Invalid_Argument; error = TT_Extension_Get( faze, SBIT_ID, (void**)&eblc ); if ( error ) goto Exit; /********************************************************************/ /* */ /* Look for an sbit strike that matches the current x and y ppms */ /* */ { UShort count = eblc->num_strikes; TT_SBit_Strike* cur = eblc->strikes; x_ppem = ins->metrics.x_ppem; y_ppem = ins->metrics.y_ppem; MEM_Set( strike, 0, sizeof ( TT_SBit_Strike ) ); for ( ; count > 0; count--, cur++ ) if ( cur->x_ppem == x_ppem && cur->y_ppem == y_ppem ) { *strike = *cur; break; } /* return immediately if we didn't find an appropriate strike */ if ( !strike->num_ranges ) error = TT_Err_Invalid_PPem; } Exit: return error; } /*************************************************************/ /* */ /* <Function> */ /* TT_Load_Glyph_Bitmap */ /* */ /* <Description> */ /* Loads a given glyph embedded bitmap. */ /* */ /* <Input> */ /* face :: handle to the source TrueType font/face */ /* instance :: current size/transform instance */ /* glyph_index :: index of source glyph */ /* bitmap :: target embedded bitmap descriptor */ /* */ /* <Return> */ /* Error code. 0 means success. */ /* */ /* <Note> */ /* This function returns an error if there is no */ /* embedded bitmap for the glyph at the given */ /* instance. */ /* */ EXPORT_FUNC TT_Error TT_Load_Glyph_Bitmap( TT_Face face, TT_Instance instance, TT_UShort glyph_index, TT_SBit_Image* image ) { TT_Stream stream; TT_Error error; PFace faze = HANDLE_Face( face ); PInstance ins = HANDLE_Instance( instance ); TT_SBit_Strike strike; if ( ins->owner != faze ) { error = TT_Err_Invalid_Argument; goto Fail; } /********************************************************************/ /* */ /* Look for an sbit strike that matches the current x and y ppms */ /* */ error = TT_Get_SBit_Strike( face, instance, &strike ); if ( error ) goto Fail; /* return immediately if the glyph index isn't in the strike extent */ if ( glyph_index < strike.start_glyph || glyph_index > strike.end_glyph ) { error = TT_Err_Invalid_Glyph_Index; goto Fail; } { image->bit_depth = 1; if ( !USE_Stream( faze->stream, stream ) ) { error = Load_TrueType_Ebdt( faze, strike, glyph_index, image ); DONE_Stream( stream ); /* exit successfully if we can */ if ( !error ) { image->map.flow = TT_Flow_Down; Crop_Bitmap( image ); /* correct sbit metrics */ { TT_Big_Glyph_Metrics* metrics = &image->metrics; metrics->bbox.xMin *= 64; metrics->bbox.xMax *= 64; metrics->bbox.yMax *= 64; metrics->bbox.yMin *= 64; metrics->horiBearingX *= 64; metrics->horiBearingY *= 64; metrics->horiAdvance *= 64; metrics->vertBearingX *= 64; metrics->vertBearingY *= 64; metrics->vertAdvance *= 64; } goto Exit; } } } Fail: image->map.width = 0; image->map.rows = 0; image->map.cols = 0; image->map.size = 0; image->map.bitmap = 0; image->map.flow = 0; image->bit_depth = 0; Exit: return error; } /*************************************************************/ /* */ /* <Function> */ /* TT_New_SBit_Image */ /* */ /* <Description> */ /* Allocates a new embedded bitmap container. */ /* */ /* <Output> */ /* image :: sbit image */ /* */ /* <Return> */ /* Error code. 0 means success. */ /* */ EXPORT_FUNC TT_Error TT_New_SBit_Image( TT_SBit_Image** image ) { return MEM_Alloc( *image, sizeof ( **image ) ); } /*************************************************************/ /* */ /* <Function> */ /* TT_Done_SBit_Image */ /* */ /* <Description> */ /* Releases an embedded bitmap container. */ /* */ /* <Input> */ /* image :: sbit image */ /* */ EXPORT_FUNC void TT_Done_SBit_Image( TT_SBit_Image* image ) { FREE( image->map.bitmap ); FREE( image ); }/* END */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -