📄 ttapi.c
字号:
* * matrix simple matrix with 16.16 fixed floats * * Output : Error code (always TT_Err_Ok). * * MT-Safe : YES! * ******************************************************************/ EXPORT_FUNC void TT_Transform_Outline( TT_Outline* outline, TT_Matrix* matrix ) { UShort n; TT_F26Dot6 x, y; TT_Vector* vec; vec = outline->points; for ( n = 0; n < outline->n_points; n++ ) { x = TT_MulFix( vec->x, matrix->xx ) + TT_MulFix( vec->y, matrix->xy ); y = TT_MulFix( vec->x, matrix->yx ) + TT_MulFix( vec->y, matrix->yy ); vec->x = x; vec->y = y; vec++; } }/******************************************************************* * * Function : TT_Transform_Vector * * Description : Apply a simple transform to a vector * * Input : x, y the vector. * * matrix simple matrix with 16.16 fixed floats * * Output : None. * * MT-Safe : YES! * ******************************************************************/ EXPORT_FUNC void TT_Transform_Vector( TT_F26Dot6* x, TT_F26Dot6* y, TT_Matrix* matrix ) { TT_F26Dot6 xz, yz; xz = TT_MulFix( *x, matrix->xx ) + TT_MulFix( *y, matrix->xy ); yz = TT_MulFix( *x, matrix->yx ) + TT_MulFix( *y, matrix->yy ); *x = xz; *y = yz; }/******************************************************************* * * Function : TT_Translate_Outline * * Description : Applies a simple translation. * * Input : outline no comment :) * xOffset * yOffset * * Output : Error code. * * MT-Safe : YES! * ******************************************************************/ EXPORT_FUNC void TT_Translate_Outline( TT_Outline* outline, TT_F26Dot6 xOffset, TT_F26Dot6 yOffset ) { UShort n; TT_Vector* vec = outline->points; for ( n = 0; n < outline->n_points; n++ ) { vec->x += xOffset; vec->y += yOffset; vec++; } }/******************************************************************* * * Function : TT_Get_Outline_BBox * * Description : Returns an outline's bounding box. * * Input : outline no comment :) * bbox address where the bounding box is returned * * Output : Error code. * * MT-Safe : YES! * ******************************************************************/ EXPORT_FUNC TT_Error TT_Get_Outline_BBox( TT_Outline* outline, TT_BBox* bbox ) { TT_F26Dot6 x, y; UShort k; if ( outline && bbox ) { if ( outline->n_points == 0 ) { bbox->xMin = 0; bbox->yMin = 0; bbox->xMax = 0; bbox->yMax = 0; } else { TT_Vector* vec = outline->points; bbox->xMin = bbox->xMax = vec->x; bbox->yMin = bbox->yMax = vec->y; vec++; for ( k = 1; k < outline->n_points; k++ ) { x = vec->x; if ( x < bbox->xMin ) bbox->xMin = x; if ( x > bbox->xMax ) bbox->xMax = x; y = vec->y; if ( y < bbox->yMin ) bbox->yMin = y; if ( y > bbox->yMax ) bbox->yMax = y; vec++; } } return TT_Err_Ok; } else return TT_Err_Invalid_Argument; } /* ----------------- character mappings support ------------- *//******************************************************************* * * Function : TT_Get_CharMap_Count * * Description : Returns the number of charmaps in a given face. * * Input : face face object handle * * Output : Number of tables. -1 in case of error (bad handle). * * Note : DON'T USE THIS FUNCTION! IT HAS BEEN DEPRECATED! * * It is retained for backwards compatibility only and will * fail on 16bit systems. * * MT-Safe : YES ! * ******************************************************************/ EXPORT_FUNC int TT_Get_CharMap_Count( TT_Face face ) { PFace faze = HANDLE_Face( face ); return ( faze ? faze->numCMaps : -1 ); }/******************************************************************* * * Function : TT_Get_CharMap_ID * * Description : Returns the ID of a given charmap. * * Input : face face object handle * charmapIndex index of charmap in directory * platformID address of returned platform ID * encodingID address of returned encoding ID * * Output : error code * * MT-Safe : YES ! * ******************************************************************/ EXPORT_FUNC TT_Error TT_Get_CharMap_ID( TT_Face face, TT_UShort charmapIndex, TT_UShort* platformID, TT_UShort* encodingID ) { PCMapTable cmap; PFace faze = HANDLE_Face( face ); if ( !faze ) return TT_Err_Invalid_Face_Handle; if ( charmapIndex >= faze->numCMaps ) return TT_Err_Invalid_Argument; cmap = faze->cMaps + charmapIndex; *platformID = cmap->platformID; *encodingID = cmap->platformEncodingID; return TT_Err_Ok; }/******************************************************************* * * Function : TT_Get_CharMap * * Description : Looks up a charmap. * * Input : face face object handle * charmapIndex index of charmap in directory * charMap address of returned charmap handle * * Output : Error code. * * MT-Safe : YES! * ******************************************************************/ EXPORT_FUNC TT_Error TT_Get_CharMap( TT_Face face, TT_UShort charmapIndex, TT_CharMap* charMap ) { TT_Error error; TT_Stream stream; PCMapTable cmap; PFace faze = HANDLE_Face( face ); if ( !faze ) return TT_Err_Invalid_Face_Handle; if ( charmapIndex >= faze->numCMaps ) return TT_Err_Invalid_Argument; cmap = faze->cMaps + charmapIndex; /* Load table if needed */ error = TT_Err_Ok; /* MT-NOTE: We're modifying the face object, so protect it. */ MUTEX_Lock( faze->lock ); if ( !cmap->loaded ) { (void)USE_Stream( faze->stream, stream ); if ( !error ) { error = CharMap_Load( cmap, stream ); DONE_Stream( stream ); } if ( error ) cmap = NULL; else cmap->loaded = TRUE; } MUTEX_Release( faze->lock ); HANDLE_Set( *charMap, cmap ); return error; }/******************************************************************* * * Function : TT_Char_Index * * Description : Returns the glyph index corresponding to * a given character code defined for the 'charmap'. * * Input : charMap charmap handle * charcode character code * * Output : glyph index. * * Notes : Character code 0 is the unknown glyph, which should never * be displayed. * * MT-Safe : YES! * ******************************************************************/ EXPORT_FUNC TT_UShort TT_Char_Index( TT_CharMap charMap, TT_UShort charCode ) { PCMapTable cmap = HANDLE_CharMap( charMap ); if ( !cmap ) return 0; /* we return 0 in case of invalid char map */ return CharMap_Index( cmap, charCode ); }/******************************************************************* * * Function : TT_Get_Name_Count * * Description : Returns the number of strings found in the * name table. * * Input : face face handle * * Output : number of strings. * * Notes : Returns -1 on error (invalid handle). * * DON'T USE THIS FUNCTION! IT HAS BEEN DEPRECATED! * * It is retained for backwards compatibility only and will * fail on 16bit systems. * * MT-Safe : YES! * ******************************************************************/ EXPORT_FUNC int TT_Get_Name_Count( TT_Face face ) { PFace faze = HANDLE_Face( face ); if ( !faze ) return -1; return faze->nameTable.numNameRecords; }/******************************************************************* * * Function : TT_Get_Name_ID * * Description : Returns the IDs of the string number 'nameIndex' * in the name table of a given face. * * Input : face face handle * nameIndex index of string. First is 0 * platformID addresses of returned IDs * encodingID * languageID * nameID * * Output : Error code. * * Notes : Some files have a corrupt or unusual name table, with some * entries having a platformID > 3. These can usually * be ignored by a client application. * * MT-Safe : YES! * ******************************************************************/ EXPORT_FUNC TT_Error TT_Get_Name_ID( TT_Face face, TT_UShort nameIndex, TT_UShort* platformID, TT_UShort* encodingID, TT_UShort* languageID, TT_UShort* nameID ) { TNameRec* namerec; PFace faze = HANDLE_Face( face ); if ( !faze ) return TT_Err_Invalid_Face_Handle; if ( nameIndex >= faze->nameTable.numNameRecords ) return TT_Err_Invalid_Argument; namerec = faze->nameTable.names + nameIndex; *platformID = namerec->platformID; *encodingID = namerec->encodingID; *languageID = namerec->languageID; *nameID = namerec->nameID; return TT_Err_Ok; }/******************************************************************* * * Function : TT_Get_Name_String * * Description : Returns the address and length of a given * string found in the name table. * * Input : face face handle * nameIndex string index * stringPtr address of returned pointer to string * length address of returned string length * * Output : Error code. * * Notes : If the string's platformID is invalid, * stringPtr is NULL, and length is 0. * * MT-Safe : YES! * ******************************************************************/ EXPORT_FUNC TT_Error TT_Get_Name_String( TT_Face face, TT_UShort nameIndex, TT_String** stringPtr, TT_UShort* length ) { TNameRec* namerec; PFace faze = HANDLE_Face( face ); if ( !faze ) return TT_Err_Invalid_Face_Handle; if ( nameIndex >= faze->nameTable.numNameRecords ) return TT_Err_Invalid_Argument; namerec = faze->nameTable.names + nameIndex; *stringPtr = (String*)namerec->string; *length = namerec->stringLength; return TT_Err_Ok; }/******************************************************************* * * Function : TT_Get_Font_Data * * Description : Loads any font table into client memory. * * Input : face Face object to look for. * * tag Tag of table to load. Use the value 0 if you * want to access the whole font file, else set * this parameter to a valid TrueType table tag * that you can forge with the MAKE_TT_TAG * macro. * * offset Starting offset in the table (or the file * if tag == 0). * * buffer Address of target buffer * * length Address of decision variable: * * if length == NULL: * Load the whole table. Returns an * error if 'offset' != 0. * * if *length == 0 : * Exit immediately, returning the * length of the given table, or of * the font file, depending on the * value of 'tag'. * * if *length != 0 : * Load the next 'length' bytes of * table or font, starting at offset * 'offset' (in table or font too). * * Output : Error code. * * MT-Safe : YES! * ******************************************************************/ EXPORT_FUNC TT_Error TT_Get_Font_Data( TT_Face face, TT_ULong tag, TT_Long offset, void* buffer, TT_Long* length ) { PFace faze = HANDLE_Face( face ); if ( !faze ) return TT_Err_Invalid_Face_Handle; return Load_TrueType_Any( faze, tag, offset, buffer, length ); } /************************ callback definition ******************/ /* Register a new callback to the TrueType engine -- this should */ /* only be used by higher-level libraries, not typical clients */ /* */ /* This is not part of the current FreeType release, thus */ /* undefined... */#if 0 EXPORT_FUNC TT_Error TT_Register_Callback( TT_Engine engine, int callback_id, void* callback_ptr ) { PEngine_Instance eng = HANDLE_Engine( engine ); if ( !eng ) return TT_Err_Invalid_Argument; /* currently, we only support one callback */ if (callback_id != TT_Callback_Glyph_Outline_Load) return TT_Err_Invalid_Argument; eng->glCallback = (TT_Glyph_Loader_Callback)callback_ptr; return TT_Err_Ok; }#endif /* 0 *//* END */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -