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

📄 ttapi.c

📁 神龙卡开发原代码
💻 C
📖 第 1 页 / 共 4 页
字号:
 *            glyph      address of target glyph handle * *  Output :  Error code. * *  MT-Safe : YES! * ******************************************************************/  EXPORT_FUNC  TT_Error  TT_New_Glyph( TT_Face    face,                          TT_Glyph*  glyph )  {    TT_Error  error;    PFace     _face = HANDLE_Face( face );    PGlyph    _glyph;    if ( !_face )      return TT_Err_Invalid_Face_Handle;    /* get a new glyph from the face's cache -- this is thread-safe */    error = CACHE_New( &_face->glyphs, _glyph, _face );    HANDLE_Set( *glyph, _glyph );    return error;  }/******************************************************************* * *  Function    :  TT_Done_Glyph * *  Description :  Destroys a given glyph object. * *  Input  :  glyph  the glyph handle * *  Output :  Error code. * *  MT-Safe : YES! * ******************************************************************/  EXPORT_FUNC  TT_Error  TT_Done_Glyph( TT_Glyph  glyph )  {    PGlyph  _glyph = HANDLE_Glyph( glyph );    if ( !_glyph )      return TT_Err_Invalid_Glyph_Handle;    /* delete the engine -- this is thread-safe */    return CACHE_Done( &_glyph->face->glyphs, _glyph );  }/******************************************************************* * *  Function    :  TT_Load_Glyph * *  Description :  Loads a glyph. * *  Input  :  instance      the instance handle *            glyph         the glyph handle *            glyphIndex    the glyph index *            loadFlags     flags controlling how to load the glyph *                          (none, scaled, hinted, both) * *  Output :  Error code. * *  MT-Safe : YES! * ******************************************************************/  EXPORT_FUNC  TT_Error  TT_Load_Glyph( TT_Instance  instance,                           TT_Glyph     glyph,                           TT_UShort    glyphIndex,                           TT_UShort    loadFlags   )  {    PInstance  _ins;    PGlyph     _glyph;    TT_Error   error;    _ins = HANDLE_Instance( instance );    if ( !_ins )      loadFlags &= ~(TTLOAD_SCALE_GLYPH | TTLOAD_HINT_GLYPH);    if ( (loadFlags & TTLOAD_SCALE_GLYPH) == 0 )      _ins = 0;    _glyph = HANDLE_Glyph( glyph );    if ( !_glyph )      return TT_Err_Invalid_Glyph_Handle;    if ( _ins )    {      if ( _ins->owner != _glyph->face )        return TT_Err_Invalid_Face_Handle;      if ( !_ins->valid )      {        /* This code can only be called in non thread-safe builds */        error = Instance_Reset( _ins );        if ( error )          return error;      }    }    return Load_TrueType_Glyph( _ins, _glyph, glyphIndex, loadFlags );  }/******************************************************************* * *  Function    :  TT_Get_Glyph_Outline * *  Description :  Returns the glyph's outline data. * *  Input  :  glyph     the glyph handle *            outline   address where the glyph outline will be returned * *  Output :  Error code. * *  MT-Safe : YES!  Reads only semi-permanent data. * ******************************************************************/  EXPORT_FUNC  TT_Error  TT_Get_Glyph_Outline( TT_Glyph     glyph,                                  TT_Outline*  outline )  {    PGlyph  _glyph = HANDLE_Glyph( glyph );    if ( !_glyph )      return TT_Err_Invalid_Glyph_Handle;    *outline = _glyph->outline;    outline->owner = FALSE;    return TT_Err_Ok;  }/******************************************************************* * *  Function    :  TT_Get_Glyph_Metrics * *  Description :  Extracts the glyph's horizontal metrics information. * *  Input  :  glyph       glyph object handle *            metrics     address where metrics will be returned * *  Output :  Error code. * *  MT-Safe : NO!  Glyph containers can't be shared. * ******************************************************************/  EXPORT_FUNC  TT_Error  TT_Get_Glyph_Metrics( TT_Glyph           glyph,                                  TT_Glyph_Metrics*  metrics )  {    PGlyph  _glyph = HANDLE_Glyph( glyph );    if ( !_glyph )      return TT_Err_Invalid_Glyph_Handle;    metrics->bbox     = _glyph->metrics.bbox;    metrics->bearingX = _glyph->metrics.horiBearingX;    metrics->bearingY = _glyph->metrics.horiBearingY;    metrics->advance  = _glyph->metrics.horiAdvance;    return TT_Err_Ok;  }/******************************************************************* * *  Function    :  TT_Get_Glyph_Big_Metrics * *  Description :  Extracts the glyph's big metrics information. * *  Input  :  glyph       glyph object handle *            metrics     address where big metrics will be returned * *  Output :  Error code. * *  MT-Safe : NO!  Glyph containers can't be shared. * ******************************************************************/  EXPORT_FUNC  TT_Error  TT_Get_Glyph_Big_Metrics( TT_Glyph               glyph,                                      TT_Big_Glyph_Metrics*  metrics )  {    PGlyph  _glyph = HANDLE_Glyph( glyph );    if ( !_glyph )      return TT_Err_Invalid_Glyph_Handle;    *metrics = _glyph->metrics;    return TT_Err_Ok;  }/******************************************************************* * *  Function    :  TT_Get_Glyph_Bitmap * *  Description :  Produces a bitmap from a glyph outline. * *  Input  :  glyph      the glyph container's handle *            map        target pixmap description block *            xOffset    x offset in fractional pixels (26.6 format) *            yOffset    y offset in fractional pixels (26.6 format) * *  Output :  Error code. * *  Note : Only use integer pixel offsets if you want to preserve *         the fine hints applied to the outline.  This means that *         xOffset and yOffset must be multiples of 64! * *  MT-Safe : NO!  Glyph containers can't be shared. * ******************************************************************/  EXPORT_FUNC  TT_Error  TT_Get_Glyph_Bitmap( TT_Glyph        glyph,                                 TT_Raster_Map*  map,                                 TT_F26Dot6      xOffset,                                 TT_F26Dot6      yOffset )  {    PEngine_Instance  _engine;    TT_Engine         engine;    TT_Error          error;    PGlyph            _glyph = HANDLE_Glyph( glyph );    TT_Outline  outline;    if ( !_glyph )      return TT_Err_Invalid_Glyph_Handle;    _engine = _glyph->face->engine;    HANDLE_Set( engine, _engine );    outline = _glyph->outline;    /* XXX : For now, use only dropout mode 2    */    /* outline.dropout_mode = _glyph->scan_type; */    outline.dropout_mode = 2;    TT_Translate_Outline( &outline, xOffset, yOffset );    error = TT_Get_Outline_Bitmap( engine, &outline, map );    TT_Translate_Outline( &outline, -xOffset, -yOffset );    return error;  }#ifdef TT_CONFIG_OPTION_GRAY_SCALING/******************************************************************* * *  Function    :  TT_Get_Glyph_Pixmap * *  Description :  Produces a grayscaled pixmap from a glyph *                 outline. * *  Input  :  glyph      the glyph container's handle *            map        target pixmap description block *            xOffset    x offset in fractional pixels (26.6 format) *            yOffset    y offset in fractional pixels (26.6 format) * *  Output :  Error code. * *  Note : Only use integer pixel offsets to preserve the fine *         hinting of the glyph and the 'correct' anti-aliasing *         (where vertical and horizontal stems aren't grayed). *         This means that xOffset and yOffset must be multiples *         of 64! * *         You can experiment with offsets of +32 to get 'blurred' *         versions of the glyphs (a nice effect at large sizes that *         some graphic designers may appreciate :) * *  MT-Safe : NO!  Glyph containers can't be shared. * ******************************************************************/  EXPORT_FUNC  TT_Error  TT_Get_Glyph_Pixmap( TT_Glyph        glyph,                                 TT_Raster_Map*  map,                                 TT_F26Dot6      xOffset,                                 TT_F26Dot6      yOffset )  {    PEngine_Instance  _engine;    TT_Engine         engine;    TT_Error          error;    PGlyph            _glyph = HANDLE_Glyph( glyph );    TT_Outline  outline;    if ( !_glyph )      return TT_Err_Invalid_Glyph_Handle;    _engine = _glyph->face->engine;    HANDLE_Set(engine,_engine);    outline = _glyph->outline;    /* XXX : For now, use only dropout mode 2    */    /* outline.dropout_mode = _glyph->scan_type; */    outline.dropout_mode = 2;    TT_Translate_Outline( &outline, xOffset, yOffset );    error = TT_Get_Outline_Pixmap( engine, &outline, map );    TT_Translate_Outline( &outline, -xOffset, -yOffset );    return error;  }#endif /* TT_CONFIG_OPTION_GRAY_SCALING */  static const TT_Outline  null_outline      = { 0, 0, NULL, NULL, NULL, 0, 0, 0, 0 };/******************************************************************* * *  Function    :  TT_New_Outline * *  Description :  Creates a new TrueType outline, reserving *                 array space for a given number of points and *                 contours. * *  Input  :  numPoints         number of points *            numContours       number of contours *            outline           address of target outline structure * *  Output :  Error code * *  MT-Safe : YES! * ******************************************************************/  EXPORT_FUNC  TT_Error  TT_New_Outline( TT_UShort    numPoints,                            TT_Short     numContours,                            TT_Outline*  outline )  {    TT_Error  error;    if ( !outline )      return TT_Err_Invalid_Argument;    *outline = null_outline;    if ( ALLOC( outline->points,   numPoints*2*sizeof ( TT_F26Dot6 ) ) ||         ALLOC( outline->flags,    numPoints  *sizeof ( Byte )       ) ||         ALLOC( outline->contours, numContours*sizeof ( UShort )     ) )      goto Fail;    outline->n_points   = numPoints;    outline->n_contours = numContours;    outline->owner      = TRUE;    return TT_Err_Ok;  Fail:    outline->owner = TRUE;    TT_Done_Outline( outline );    return error;  }/******************************************************************* * *  Function    :  TT_Done_Outline * *  Description :  Deletes an outline created through TT_New_Outline(). *                 Calling this function for outlines returned *                 by TT_Get_Glyph_Outline() yields an error. * *  Input  :  outline        address of outline * *  Output :  Error code. * *  MT-Safe : YES! * ******************************************************************/  EXPORT_FUNC  TT_Error  TT_Done_Outline( TT_Outline*  outline )  {    if ( outline )    {      if ( outline->owner )      {        FREE( outline->points   );        FREE( outline->flags    );        FREE( outline->contours );      }      *outline = null_outline;      return TT_Err_Ok;    }    else      return TT_Err_Invalid_Argument;  }/******************************************************************* * *  Function    :  TT_Get_Outline_Bitmap * *  Description :  Render a TrueType outline into a bitmap. *                 Note that the bitmap must be created by the caller. * *  Input  :  outline        the outline to render *            map            the target bitmap * *  Output :  Error code. * *  MT-Safe : YES! * ******************************************************************/  EXPORT_FUNC  TT_Error  TT_Get_Outline_Bitmap( TT_Engine       engine,                                   TT_Outline*     outline,                                   TT_Raster_Map*  map )  {    PEngine_Instance  _engine = HANDLE_Engine( engine );    TT_Error          error;    if ( !_engine )      return TT_Err_Invalid_Engine;    if ( !outline || !map )      return TT_Err_Invalid_Argument;    MUTEX_Lock( _engine->raster_lock );    error = RENDER_Glyph( outline, map );    MUTEX_Release( _engine->raster_lock );    return error;  }#ifdef TT_CONFIG_OPTION_GRAY_SCALING/******************************************************************* * *  Function    :  TT_Get_Outline_Pixmap * *  Description :  Render a TrueType outline into a pixmap. *                 Note that the pixmap must be created by the caller. * *  Input  :  outline       the outline to render *            map           the target bitmap * *  Output :  Error code * *  MT-Safe : YES! * ******************************************************************/  EXPORT_FUNC  TT_Error  TT_Get_Outline_Pixmap( TT_Engine       engine,                                   TT_Outline*     outline,                                   TT_Raster_Map*  map )  {    PEngine_Instance  _engine = HANDLE_Engine( engine );    TT_Error          error;    if ( !_engine )      return TT_Err_Invalid_Engine;    if ( !outline || !map )      return TT_Err_Invalid_Argument;    MUTEX_Lock( _engine->raster_lock );    error = RENDER_Gray_Glyph( outline, map, _engine->raster_palette );    MUTEX_Release( _engine->raster_lock );    return error;  }#endif /* TT_CONFIG_OPTION_GRAY_SCALING *//******************************************************************* * *  Function    :  TT_Copy_Outline * *  Description :  Copy an outline into another.  The source and *                 target outlines must have the same points and *                 contours numbers. * *  Input  :  source         address of source outline *            target         address of target outline * *  Output :  Error code * *  Note :    This function doesn't touch the target outline's 'owner' *            field. * *  MT-Safe : YES! * ******************************************************************/  EXPORT_FUNC  TT_Error  TT_Copy_Outline( TT_Outline*  source,                             TT_Outline*  target )  {    if ( !source            || !target            ||         source->n_points   != target->n_points   ||         source->n_contours != target->n_contours )      return TT_Err_Invalid_Argument;    MEM_Copy( target->points, source->points,              source->n_points * 2 * sizeof ( TT_F26Dot6 ) );    MEM_Copy( target->flags, source->flags,              source->n_points * sizeof ( Byte ) );    MEM_Copy( target->contours, source->contours,              source->n_contours * sizeof ( Short ) );    target->high_precision = source->high_precision;    target->second_pass    = target->second_pass;    target->dropout_mode   = source->dropout_mode;    return TT_Err_Ok;  }/******************************************************************* * *  Function    :  TT_Transform_Outline * *  Description :  Applies a simple transformation to an outline. * *  Input  :  outline     the glyph's outline.  Can be extracted *                        from a glyph container through *                        TT_Get_Glyph_Outline().

⌨️ 快捷键说明

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