⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ttapi.c

📁 神龙卡开发原代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/******************************************************************* * *  ttapi.c * *    High-level interface implementation * *  Copyright 1996-1999 by *  David Turner, Robert Wilhelm, and Werner Lemberg. * *  This file is part of the FreeType project, and may only be used, *  modified, and distributed under the terms of the FreeType project *  license, LICENSE.TXT.  By continuing to use, modify, or distribute *  this file you indicate that you have read the license and *  understand and accept it fully. * *  Notes: * *    This file is used to implement most of the functions that are *    defined in the file "freetype.h". However, two functions are *    implemented elsewhere : * *     TT_MulDiv and TT_MulFix  are in ttcalc.h/ttcalc.c * ******************************************************************/#include "ttconfig.h"#include "freetype.h"#include "ttengine.h"#include "ttcalc.h"#include "ttmemory.h"#include "ttcache.h"#include "ttfile.h"#include "ttobjs.h"#include "ttload.h"#include "ttgload.h"#include "ttraster.h"#include "ttextend.h"/* required by the tracing mode */#undef  TT_COMPONENT#define TT_COMPONENT  trace_api#ifdef TT_STATIC_RASTER#define RAS_OPS  /* void */#define RAS_OP   /* void */#else#define RAS_OPS  ((TRaster_Instance*)_engine->raster_component),#define RAS_OP   ((TRaster_Instance*)_engine->raster_component)#endif /* TT_STATIC_RASTER */#define RENDER_Glyph( glyph, target ) \          Render_Glyph( RAS_OPS  glyph, target )#define RENDER_Gray_Glyph( glyph, target, palette ) \          Render_Gray_Glyph( RAS_OPS  glyph, target, palette )/******************************************************************* * *  Function    :  TT_FreeType_Version * *  Description :  Returns the major and minor version of the library. * *  Input  :  major, minor addresses * *  Output :  Error code. * *  MT-Note : YES! * ******************************************************************/  EXPORT_FUNC  TT_Error  TT_FreeType_Version( int  *major, int  *minor )  {    if ( !major || !minor )      return TT_Err_Invalid_Argument;    *major = TT_FREETYPE_MAJOR;    *minor = TT_FREETYPE_MINOR;    return TT_Err_Ok;  }/******************************************************************* * *  Function    : TT_Init_FreeType * *  Description : The library's engine initializer.  This function *                must be called prior to any call. * *  Input  :  engine        pointer to a FreeType engine instance * *  Output :  Error code. * *  MT-Note : This function should be called each time you want *            to create a TT_Engine.  It is not necessarily thread *            safe depending on the implementations of ttmemory, *            ttfile and ttmutex, so take care.  Their default *            implementations are safe, however. * ******************************************************************/  EXPORT_FUNC  TT_Error  TT_Init_FreeType( TT_Engine*  engine )  {    PEngine_Instance  _engine;    TT_Error  error;    int       n;    /* first of all, initialize memory sub-system */    error = TTMemory_Init();    if ( error )      return error;    /* Allocate engine instance */    if ( ALLOC( _engine, sizeof ( TEngine_Instance ) ) )      return error;#undef  TT_FAIL#define TT_FAIL( x )  ( error = x (_engine) ) != TT_Err_Ok    /* Initalize components */    if ( TT_FAIL( TTFile_Init  )  ||         TT_FAIL( TTCache_Init )  ||#ifdef TT_CONFIG_OPTION_EXTEND_ENGINE         TT_FAIL( TTExtend_Init ) ||#endif         TT_FAIL( TTObjs_Init )   ||         TT_FAIL( TTRaster_Init ) )       goto Fail;#undef TT_FAIL    /* set the gray palette defaults: 0 to 4 */    for ( n = 0; n < 5; n++ )      _engine->raster_palette[n] = (Byte)n;  /* Conversion ok, some warn */    /* create the engine lock */    MUTEX_Create( _engine->lock );    HANDLE_Set( *engine, _engine );    return TT_Err_Ok;  Fail:    TT_Done_FreeType( *engine );    HANDLE_Set( *engine, NULL );    return error;  }/******************************************************************* * *  Function    : TT_Done_FreeType * *  Description : The library's engine finalizer.  This function *                will discard all active face and glyph objects *                from the heap. * *  Input  :  engine        FreeType engine instance * *  Output :  Error code. * *  MT-Note : Destroys an engine.  Not necessarily thread-safe *            depending on the implementations of ttmemory, *            ttfile and ttmutex.  The default implementations *            are safe, however. * ******************************************************************/  EXPORT_FUNC  TT_Error  TT_Done_FreeType( TT_Engine  engine )  {    PEngine_Instance  _engine = HANDLE_Engine( engine );    if ( !_engine )      return TT_Err_Ok;    MUTEX_Destroy( _engine->lock );    TTRaster_Done( _engine );    TTObjs_Done  ( _engine );#ifdef TT_CONFIG_OPTION_EXTEND_ENGINE    TTExtend_Done( _engine );#endif    TTCache_Done ( _engine );    TTFile_Done  ( _engine );    FREE( _engine );    TTMemory_Done();    return TT_Err_Ok;  }#ifdef TT_CONFIG_OPTION_GRAY_SCALING/******************************************************************* * *  Function    :  TT_Set_Raster_Gray_Palette * *  Description :  Sets the gray-levels palette used for font *                 smoothing. * *  Input  :  engine        FreeType engine instance *            palette       address of palette (a 5 byte array) * *  Output :  Invalid argument if 'palette' is NULL. * *  MT-Note:  NO!  Unprotected modification of an engine's palette. * ******************************************************************/  EXPORT_FUNC  TT_Error  TT_Set_Raster_Gray_Palette( TT_Engine  engine,                                        Byte*      palette )  {    int  i;    if ( !palette )      return TT_Err_Invalid_Argument;    for ( i = 0; i < 5; i++ )      HANDLE_Engine( engine )->raster_palette[i] = (Byte)palette[i];    return TT_Err_Ok;  }#endif /* TT_CONFIG_OPTION_GRAY_SCALING *//******************************************************************* * *  Function    :  TT_Open_Face * *  Description :  Creates a new face object from a given font file. * *  Input  :  engine        FreeType engine instance *            fontPathName  the font file's pathname *            face          adress of returned face handle * *  Output :  Error code. * *  Note :    The face handle is set to NULL in case of failure. * *  MT-Note : YES! * ******************************************************************/  EXPORT_FUNC  TT_Error  TT_Open_Face( TT_Engine       engine,                          const TT_Text*  fontPathName,                          TT_Face*        face )  {    PEngine_Instance  _engine = HANDLE_Engine( engine );    TFont_Input  input;    TT_Error     error;    TT_Stream    stream;    PFace        _face;    if ( !_engine )      return TT_Err_Invalid_Engine;    /* open the file */    error = TT_Open_Stream( fontPathName, &stream );    if ( error )      return error;    input.stream    = stream;    input.fontIndex = 0;    input.engine    = _engine;    /* Create and load the new face object - this is thread-safe */    error = CACHE_New( _engine->objs_face_cache,                       _face,                       &input );    /* Set the handle */    HANDLE_Set( *face, _face );    if ( error )      goto Fail;    return TT_Err_Ok;  Fail:    TT_Close_Stream( &stream );    return error;  }/******************************************************************* * *  Function    :  TT_Open_Collection * *  Description :  Creates a new face object from a given font file. * *  Input  :  engine                FreeType engine instance *            collectionPathName    the font file's pathname *            fontIndex             index of font in TrueType collection *            face                  adress of returned face handle * *  Output :  Error code. * *  Note :    The face handle is set to NULL in case of failure. * *  MT-Note : YES! * ******************************************************************/  EXPORT_FUNC  TT_Error  TT_Open_Collection( TT_Engine       engine,                                const TT_Text*  collectionPathName,                                TT_ULong        fontIndex,                                TT_Face*        face )  {    PEngine_Instance  _engine = HANDLE_Engine( engine );    TFont_Input  input;    TT_Error     error;    TT_Stream    stream;    PFace        _face;    if ( !_engine )      return TT_Err_Invalid_Engine;    /* open the file */    error = TT_Open_Stream( collectionPathName, &stream );    if ( error )      return error;    input.stream    = stream;    input.fontIndex = fontIndex;    input.engine    = _engine;    /* Create and load the new face object - this is thread-safe */    error = CACHE_New( _engine->objs_face_cache,                       _face,                       &input );    /* Set the handle */    HANDLE_Set( *face, _face );    if ( error )      goto Fail;    return TT_Err_Ok;  Fail:    TT_Close_Stream( &stream );    return error;  }/******************************************************************* * *  Function    :  TT_Get_Face_Properties * *  Description :  Returns face properties. * *  Input  :  face          the face handle *            properties    address of target properties record * *  Output :  Error code. * *  Note :    Currently, max_Faces is always set to 0. * *  MT-Note : YES!  Reads only permanent data. * ******************************************************************/  EXPORT_FUNC  TT_Error  TT_Get_Face_Properties( TT_Face              face,                                    TT_Face_Properties*  properties )  {    PFace _face = HANDLE_Face( face );    if ( !_face )      return TT_Err_Invalid_Face_Handle;    properties->num_Glyphs   = _face->numGlyphs;    properties->max_Points   = _face->maxPoints;    properties->max_Contours = _face->maxContours;    properties->num_CharMaps = _face->numCMaps;    properties->num_Names    = _face->nameTable.numNameRecords;    if ( _face->ttcHeader.DirCount == 0 )      properties->num_Faces = 1;    else      properties->num_Faces = _face->ttcHeader.DirCount;    properties->header       = &_face->fontHeader;    properties->horizontal   = &_face->horizontalHeader;    if ( _face->verticalInfo )      properties->vertical   = &_face->verticalHeader;    else      properties->vertical   = NULL;    properties->os2          = &_face->os2;    properties->postscript   = &_face->postscript;    properties->hdmx         = &_face->hdmx;    return TT_Err_Ok;  }/******************************************************************* * *  Function    :  TT_Set_Face_Pointer * *  Description :  Each face object 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!  But this function is reserved to "enlightened" *            developers, so it shouldn't be a problem. * ******************************************************************/  EXPORT_FUNC  TT_Error  TT_Set_Face_Pointer( TT_Face  face,                                 void*    data )  {    PFace  faze = HANDLE_Face( face );    if ( !faze )      return TT_Err_Invalid_Face_Handle;    else      faze->generic = data;    return TT_Err_Ok;  }/******************************************************************* * *  Function    :  TT_Get_Face_Pointer * *  Description :  Each face object has one pointer, which use is *                 reserved to client applications.  The TrueType *                 engine never access or use 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-Note : NO!  But this function is reserved to "enlightened" *            developers, so it shouldn't be a problem. * ******************************************************************/  EXPORT_FUNC  void*  TT_Get_Face_Pointer( TT_Face  face )  {    PFace  faze = HANDLE_Face( face );    if ( !faze )      return NULL;    else      return faze->generic;  }/******************************************************************* * *  Function    :  TT_Get_Face_Metrics * *  Description :  This function returns the original horizontal AND *                 vertical metrics as found in the "hmtx" and "vmtx" *                 tables.  These are the glyphs' left-side-bearings *                 and advance widths (horizontal), as well as top *                 side bearings and advance heights (vertical). * *                 All are expressed in FONT UNITS, a.k.a. EM *                 units. * *  Input  :     face  The given face handle. *              first  Index of first glyph in table. *               last  Index of last glyph in table. * *       leftBearings  A pointer to an array of TT_Shorts where the *                     left side bearings for the glyphs 'first' *                     to 'last' will be returned.  If these metrics *                     don't interest you, simply set it to NULL. * *             widths  A pointer to an array of TT_UShorts *                     where the advance widths for the glyphs *                     'first' to 'last' will be returned.  If these *                     metrics don't interest you, simply set it *                     to NULL. * *        topBearings  A pointer to an array of TT_Shorts where the *                     top side bearings for the glyphs 'first' *                     to 'last' will be returned.  If these metrics *                     don't interest you, simply set it to NULL. * *            heights  A pointer to an array of TT_UShorts *                     where the advance heights for the glyphs *                     'first' to 'last' will be returned.  If these *                     metrics don't interest you, simply set it *                     to NULL. * *  Output :  Error code. * *  IMPORTANT NOTE : * *  As vertical metrics are optional in a TrueType font, this *  function will return an error ( TT_Err_No_Vertical_Data ) *  whenever this function is called on such a face with non-NULL *  'topBearings' or 'heights' arguments. * *  When a font has no vertical data, the 'vertical' field in its *  properties structure is set to NULL. * *  MT-Note : YES!  Reads only permanent data. * ******************************************************************/  EXPORT_FUNC  TT_Error  TT_Get_Face_Metrics( TT_Face     face,                                 TT_UShort   firstGlyph,                                 TT_UShort   lastGlyph,                                 TT_Short*   leftBearings,                                 TT_UShort*  widths,                                 TT_Short*   topBearings,                                 TT_UShort*  heights )  {    PFace   _face = HANDLE_Face( face );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -