📄 ttapi.c
字号:
UShort num; if ( !_face ) return TT_Err_Invalid_Face_Handle; /* Check the glyph range */ if ( lastGlyph >= _face->numGlyphs || firstGlyph > lastGlyph ) return TT_Err_Invalid_Argument; num = lastGlyph - firstGlyph; /* number of elements-1 in each array */ /* store the left side bearings and advance widths first */ { UShort n; Short left_bearing; UShort advance_width; for ( n = 0; n <= num; n++ ) { TT_Get_Metrics( &_face->horizontalHeader, firstGlyph + n, &left_bearing, &advance_width ); if ( leftBearings ) leftBearings[n] = left_bearing; if ( widths ) widths[n] = advance_width; } } /* check for vertical data if topBearings or heights is non-NULL */ if ( !topBearings && !heights ) return TT_Err_Ok; if ( !_face->verticalInfo ) return TT_Err_No_Vertical_Data; /* store the top side bearings */ { UShort n; Short top_bearing; UShort advance_height; for ( n = 0; n <= num; n++ ) { TT_Get_Metrics( (TT_Horizontal_Header*)&_face->verticalHeader, firstGlyph + n, &top_bearing, &advance_height ); if ( topBearings ) topBearings[n] = top_bearing; if ( heights ) heights[n] = advance_height; } } return TT_Err_Ok; }/******************************************************************* * * Function : TT_Flush_Face * * Description : This function is used to close an active face's * file handle or descriptor. This is useful to save * system resources, if your application uses tons * of fonts. * * Input : face the given face handle * * Output : Error code. * * MT-Note : YES! (If ttfile is.) * ******************************************************************/ EXPORT_FUNC TT_Error TT_Flush_Face( TT_Face face ) { PFace faze = HANDLE_Face( face ); if ( !faze ) return TT_Err_Invalid_Face_Handle; else return TT_Flush_Stream( &faze->stream ); }/******************************************************************* * * Function : TT_Close_Face * * Description : Closes an opened face object. This function * will destroy all objects associated to the * face, except the glyphs. * * Input : face the given face handle * * Output : Error code. * * NOTE : The handle is set to NULL on exit. * * MT-Note : YES! * ******************************************************************/ EXPORT_FUNC TT_Error TT_Close_Face( TT_Face face ) { PFace _face = HANDLE_Face( face ); if ( !_face ) return TT_Err_Invalid_Face_Handle; TT_Close_Stream( &_face->stream ); /* delete the face object -- this is thread-safe */ return CACHE_Done( _face->engine->objs_face_cache, _face ); }/******************************************************************* * * Function : TT_New_Instance * * Description : Creates a new instance from a given face. * * Input : face parent face handle * instance address of instance handle * * Output : Error code. * * Note : The handle is set to NULL in case of failure. * * MT-Note : YES! * ******************************************************************/ EXPORT_FUNC TT_Error TT_New_Instance( TT_Face face, TT_Instance* instance ) { TT_Error error; PFace _face = HANDLE_Face( face ); PInstance _ins; if ( !_face ) return TT_Err_Invalid_Face_Handle; /* get a new instance from the face's cache -- this is thread-safe */ error = CACHE_New( &_face->instances, _ins, _face ); HANDLE_Set( *instance, _ins ); if ( !error ) { error = Instance_Init( _ins ); if ( error ) { HANDLE_Set( *instance, NULL ); CACHE_Done( &_face->instances, _ins ); } } return error; }/******************************************************************* * * Function : TT_Set_Instance_Resolutions * * Description : Resets an instance to a new device resolution. * * Input : instance the instance handle * xResolution new horizontal device resolution in dpi * yResolution new vertical device resolution in dpi * * Output : Error code. * * Note : There is no check for overflow; with other words, * the product of glyph dimensions times the device * resolutions must have reasonable values. * * MT-Note : You should set the charsize or pixel size immediately * after this call in multi-threaded programs. This will * force the instance data to be resetted. Otherwise, you * may encounter corruption when loading two glyphs from * the same instance concurrently! * * Happily, 99.99% will do just that :-) * ******************************************************************/ EXPORT_FUNC TT_Error TT_Set_Instance_Resolutions( TT_Instance instance, TT_UShort xResolution, TT_UShort yResolution ) { PInstance ins = HANDLE_Instance( instance ); if ( !ins ) return TT_Err_Invalid_Instance_Handle; ins->metrics.x_resolution = xResolution; ins->metrics.y_resolution = yResolution; ins->valid = FALSE; /* In the case of a thread-safe implementation, we immediately */ /* call Instance_Reset in order to change the instance's variable */ /* In the case of a non-threaded build, we simply set the 'valid' */ /* flag to FALSE, which will force the instance's resetting at */ /* the next glyph loading */ return TT_Err_Ok; }/******************************************************************* * * Function : TT_Set_Instance_CharSizes * * Description : Resets an instance to new point size. * * Input : instance the instance handle * charWidth the new width in 26.6 char points * charHeight the new height in 26.6 char points * * Output : Error code. * * Note : There is no check for overflow; with other words, * the product of glyph dimensions times the device * resolution must have reasonable values. * * MT-Note : NO! This should be called only when setting/resetting * instances, so there is no need to protect. * ******************************************************************/ EXPORT_FUNC TT_Error TT_Set_Instance_CharSizes( TT_Instance instance, TT_F26Dot6 charWidth, TT_F26Dot6 charHeight ) { PInstance ins = HANDLE_Instance( instance ); if ( !ins ) return TT_Err_Invalid_Instance_Handle; if ( charWidth < 1 * 64 ) charWidth = 1 * 64; if ( charHeight < 1 * 64 ) charHeight = 1 * 64; ins->metrics.x_scale1 = ( charWidth * ins->metrics.x_resolution ) / 72; ins->metrics.x_scale2 = ins->owner->fontHeader.Units_Per_EM; ins->metrics.y_scale1 = ( charHeight * ins->metrics.y_resolution ) / 72; ins->metrics.y_scale2 = ins->owner->fontHeader.Units_Per_EM; if ( ins->owner->fontHeader.Flags & 8 ) { ins->metrics.x_scale1 = (ins->metrics.x_scale1+32) & -64; ins->metrics.y_scale1 = (ins->metrics.y_scale1+32) & -64; } ins->metrics.x_ppem = ins->metrics.x_scale1 / 64; ins->metrics.y_ppem = ins->metrics.y_scale1 / 64; if ( charWidth > charHeight ) ins->metrics.pointSize = charWidth; else ins->metrics.pointSize = charHeight; ins->valid = FALSE; return Instance_Reset( ins ); }/******************************************************************* * * Function : TT_Set_Instance_CharSize * * Description : Resets an instance to new point size. * * Input : instance the instance handle * charSize the new character size in 26.6 char points * * Output : Error code. * * Note : There is no check for overflow; with other words, * the product of glyph dimensions times the device * resolution must have reasonable values. * * MT-Note : NO! This should be called only when setting/resetting * instances, so there is no need to protect. * ******************************************************************/ EXPORT_FUNC TT_Error TT_Set_Instance_CharSize( TT_Instance instance, TT_F26Dot6 charSize ) { return TT_Set_Instance_CharSizes( instance, charSize, charSize ); }/******************************************************************* * * Function : TT_Set_Instance_PixelSizes * * Description : Resets an instance to new pixel sizes * * Input : instance the instance handle * pixelWidth the new width in pixels * pixelHeight the new height in pixels * * Output : Error code. * * Note : There is no check for overflow; with other words, * the product of glyph dimensions times the device * resolution must have reasonable values. * * MT-Note : NO! This should be called only when setting/resetting * instances, so there is no need to protect. * ******************************************************************/ EXPORT_FUNC TT_Error TT_Set_Instance_PixelSizes( TT_Instance instance, TT_UShort pixelWidth, TT_UShort pixelHeight, TT_F26Dot6 pointSize ) { PInstance ins = HANDLE_Instance( instance ); if ( !ins ) return TT_Err_Invalid_Instance_Handle; if ( pixelWidth < 1 ) pixelWidth = 1; if ( pixelHeight < 1 ) pixelHeight = 1; ins->metrics.x_ppem = pixelWidth; ins->metrics.y_ppem = pixelHeight; ins->metrics.pointSize = pointSize; ins->metrics.x_scale1 = ins->metrics.x_ppem * 64L; ins->metrics.x_scale2 = ins->owner->fontHeader.Units_Per_EM; ins->metrics.y_scale1 = ins->metrics.y_ppem * 64L; ins->metrics.y_scale2 = ins->owner->fontHeader.Units_Per_EM; ins->valid = FALSE; return Instance_Reset( ins ); }/******************************************************************* * * Function : TT_Set_Instance_Transform_Flags * * Description : Informs the interpreter about the transformations * that will be applied to the rendered glyphs. * * Input : instance the instance handle * rotated set to TRUE if the glyph are rotated * stretched set to TRUE if the glyph are stretched * * Output : Error code. * * Note : This function is deprecated! It's much better to * control hinting manually when calling TT_Load_Glyph * than relying on the font programs... * * Never use it, unless calling for trouble ;-) * * MT-Note : NO! This should be called only when setting/resetting * instances, so there is no need to protect. * ******************************************************************/ EXPORT_FUNC TT_Error TT_Set_Instance_Transform_Flags( TT_Instance instance, TT_Bool rotated, TT_Bool stretched ) { PInstance ins = HANDLE_Instance( instance ); if ( !ins ) return TT_Err_Invalid_Instance_Handle; ins->metrics.rotated = rotated; ins->metrics.stretched = stretched; ins->valid = FALSE; return TT_Err_Ok; }/******************************************************************* * * Function : TT_Get_Instance_Metrics * * Description : Returns instance metrics. * * Input : instance the instance handle * metrics address of target instance metrics record * * Output : Error code. * * MT-Note : YES! Reads only semi-permanent data. * ******************************************************************/ EXPORT_FUNC TT_Error TT_Get_Instance_Metrics( TT_Instance instance, TT_Instance_Metrics* metrics ) { PInstance ins = HANDLE_Instance( instance ); if ( !ins ) return TT_Err_Invalid_Instance_Handle; if ( !ins->valid ) Instance_Reset( ins ); metrics->pointSize = ins->metrics.pointSize; metrics->x_scale = TT_MulDiv( 0x10000, ins->metrics.x_scale1, ins->metrics.x_scale2 ); metrics->y_scale = TT_MulDiv( 0x10000, ins->metrics.y_scale1, ins->metrics.y_scale2 ); metrics->x_resolution = ins->metrics.x_resolution; metrics->y_resolution = ins->metrics.y_resolution; metrics->x_ppem = ins->metrics.x_ppem; metrics->y_ppem = ins->metrics.y_ppem; return TT_Err_Ok; }/******************************************************************* * * Function : TT_Set_Instance_Pointer * * Description : Each instance has one pointer, which use is * reserved to client applications. The TrueType * engine never accesses or uses this field. * * This function is used to set the pointer. * * Input : face the given face handle * data the generic pointer value * * Output : Error code. * * MT-Note : NO! * ******************************************************************/ EXPORT_FUNC TT_Error TT_Set_Instance_Pointer( TT_Instance instance, void* data ) { PInstance ins = HANDLE_Instance( instance ); if ( !ins ) return TT_Err_Invalid_Instance_Handle; else ins->generic = data; return TT_Err_Ok; }/******************************************************************* * * Function : TT_Get_Instance_Pointer * * Description : Each instance has one pointer, which use is * reserved to client applications. The TrueType * engine never accesses or uses this field. * * This function is used to read the pointer. * * Input : face the given face handle * data the generic pointer value * * Output : Error code. * * MT-Safe : NO! * ******************************************************************/ EXPORT_FUNC void* TT_Get_Instance_Pointer( TT_Instance instance ) { PInstance ins = HANDLE_Instance( instance ); if ( !ins ) return NULL; else return ins->generic; }/******************************************************************* * * Function : TT_Done_Instance * * Description : Closes a given instance. * * Input : instance address of instance handle * * Output : Error code. * * MT-Safe : YES! * ******************************************************************/ EXPORT_FUNC TT_Error TT_Done_Instance( TT_Instance instance ) { PInstance ins = HANDLE_Instance( instance ); if ( !ins ) return TT_Err_Invalid_Instance_Handle; /* delete the instance -- this is thread-safe */ return CACHE_Done( &ins->owner->instances, ins ); }/******************************************************************* * * Function : TT_New_Glyph * * Description : Creates a new glyph object related to a given * face. * * Input : face the face handle
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -