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

📄 ttobjs.c

📁 神龙卡开发原代码
💻 C
📖 第 1 页 / 共 3 页
字号:
      ins->storage[i] = 0;    ins->GS = Default_GraphicsState;    /* get execution context and run prep program */    if ( ins->debug )      exec = ins->context;    else      exec = New_Context(face);    /* debugging instances have their own context */    if ( !exec )      return TT_Err_Could_Not_Find_Context;    Context_Load( exec, face, ins );    Set_CodeRange( exec,                   TT_CodeRange_Cvt,                   face->cvtProgram,                   face->cvtPgmSize );    Clear_CodeRange( exec, TT_CodeRange_Glyph );    exec->instruction_trap = FALSE;    exec->top     = 0;    exec->callTop = 0;    if ( face->cvtPgmSize > 0 )    {      error = Goto_CodeRange( exec, TT_CodeRange_Cvt, 0 );      if ( error )        goto Fin;      if ( !ins->debug )        error = RunIns( exec );    }    else      error = TT_Err_Ok;    ins->GS = exec->GS;    /* save default graphics state */  Fin:    Context_Save( exec, ins );    if ( !ins->debug )      Done_Context( exec );    /* debugging instances keep their context */    if ( !error )      ins->valid = TRUE;    return error;  }/******************************************************************* *                                                                 * *                         FACE  FUNCTIONS                         * *                                                                 * *                                                                 * *******************************************************************//******************************************************************* * *  Function    :  Face_Destroy * *  Description :  The face object destructor. * *  Input  :  _face   typeless pointer to the face object to destroy * *  Output :  Error code. * ******************************************************************/  LOCAL_FUNC  TT_Error  Face_Destroy( void*  _face )  {    PFace   face = (PFace)_face;    UShort  n;    if ( !face )      return TT_Err_Ok;    /* well, we assume that no other thread is using the face */    /* at this moment, but one is never sure enough.          */    MUTEX_Lock( face->lock );    /* first of all, destroys the cached sub-objects */    Cache_Destroy( &face->instances );    Cache_Destroy( &face->glyphs );    /* destroy the extensions */#ifdef TT_CONFIG_OPTION_EXTEND_ENGINE    Extension_Destroy( face );#endif    /* freeing the collection table */    FREE( face->ttcHeader.TableDirectory );    face->ttcHeader.DirCount = 0;    /* freeing table directory */    FREE( face->dirTables );    face->numTables = 0;    /* freeing the locations table */    FREE( face->glyphLocations );    face->numLocations = 0;    /* freeing the character mapping tables */    for ( n = 0; n < face->numCMaps; n++ )      CharMap_Free( face->cMaps + n );    FREE( face->cMaps );    face->numCMaps = 0;    /* freeing the CVT */    FREE( face->cvt );    face->cvtSize = 0;    /* freeing the horizontal metrics */    FREE( face->horizontalHeader.long_metrics );    FREE( face->horizontalHeader.short_metrics );    /* freeing the vertical ones, if any */    if (face->verticalInfo)    {      FREE( face->verticalHeader.long_metrics  );      FREE( face->verticalHeader.short_metrics );      face->verticalInfo = 0;    }    /* freeing the programs */    FREE( face->fontProgram );    FREE( face->cvtProgram );    face->fontPgmSize = 0;    face->cvtPgmSize  = 0;    /* freeing the gasp table */    FREE( face->gasp.gaspRanges );    face->gasp.numRanges = 0;    /* freeing the name table */    Free_TrueType_Names( face );    /* freeing the hdmx table */    Free_TrueType_Hdmx( face );    /* TT_Close_Stream( &face->stream ); -- this is performed by the API */    /* destroy the mutex */    MUTEX_Destroy(face->lock);    return TT_Err_Ok;  }/******************************************************************* * *  Function    :  Face_Create * *  Description :  The face object constructor. * *  Input  :  _face    face record to build *            _input   input stream where to load font data * *  Output :  Error code. * *  NOTE : The input stream is kept in the face object.  The *         caller shouldn't destroy it after calling Face_Create(). * ******************************************************************/#undef  LOAD_#define LOAD_( table ) \          (error = Load_TrueType_##table (face)) != TT_Err_Ok  LOCAL_FUNC  TT_Error  Face_Create( void*  _face,                         void*  _input )  {    PEngine_Instance  engine;    TFont_Input*  input = (TFont_Input*)_input;    PFace         face  = (PFace)_face;    TT_Error      error;    face->stream = input->stream;    face->engine = input->engine;    engine = face->engine;    MUTEX_Create( face->lock );    Cache_Create( engine,                  engine->objs_instance_class,                  &face->instances,                  &face->lock );    Cache_Create( engine,                  engine->objs_glyph_class,                  &face->glyphs,                  &face->lock );    /* Load collection directory if present, then font directory */    error = Load_TrueType_Directory( face, input->fontIndex );    if ( error )      goto Fail;    /* Load tables */    if ( LOAD_( Header )        ||         LOAD_( MaxProfile )    ||         LOAD_( Locations )     ||         (error = Load_TrueType_Metrics_Header( face, 0 )) != TT_Err_Ok  ||         /* load the 'hhea' & 'hmtx' tables at once */         LOAD_( CMap )          ||         LOAD_( CVT )           ||         LOAD_( Programs )      ||         LOAD_( Gasp )          ||         LOAD_( Names )         ||         LOAD_( OS2 )           ||         LOAD_( PostScript )    ||         (error = Load_TrueType_Metrics_Header( face, 1 )) != TT_Err_Ok ||         /* try to load the 'vhea' & 'vmtx' at once if present */         LOAD_( Hdmx )          )      goto Fail;#ifdef TT_CONFIG_OPTION_EXTEND_ENGINE    if ( ( error = Extension_Create( face ) ) != TT_Err_Ok )      return error;#endif    return TT_Err_Ok;  Fail :    Face_Destroy( face );    return error;  }#undef LOAD_/******************************************************************* * *  Function    :  Glyph_Destroy * *  Description :  The glyph object destructor. * *  Input  :  _glyph  typeless pointer to the glyph record to destroy * *  Output :  Error code. * ******************************************************************/  LOCAL_FUNC  TT_Error  Glyph_Destroy( void*  _glyph )  {    PGlyph  glyph = (PGlyph)_glyph;    if ( !glyph )      return TT_Err_Ok;    glyph->outline.owner = TRUE;    return TT_Done_Outline( &glyph->outline );  }/******************************************************************* * *  Function    :  Glyph_Create * *  Description :  The glyph object constructor. * *  Input  :  _glyph   glyph record to build. *            _face    the glyph's parent face. * *  Output :  Error code. * ******************************************************************/  LOCAL_FUNC  TT_Error  Glyph_Create( void*  _glyph,                          void*  _face )  {    PFace     face  = (PFace)_face;    PGlyph    glyph = (PGlyph)_glyph;    if ( !face )      return TT_Err_Invalid_Face_Handle;    if ( !glyph )      return TT_Err_Invalid_Glyph_Handle;    glyph->face = face;    /* XXX: Don't forget the space for the 2 phantom points */    return TT_New_Outline( glyph->face->maxPoints + 2,                           glyph->face->maxContours,                           &glyph->outline );  }/******************************************************************* * *  Function    :  Scale_X * *  Description :  scale an horizontal distance from font *                 units to 26.6 pixels * *  Input  :  metrics  pointer to metrics *            x        value to scale * *  Output :  scaled value * ******************************************************************/  LOCAL_FUNC  TT_Pos  Scale_X( PIns_Metrics  metrics, TT_Pos  x )  {    return TT_MulDiv( x, metrics->x_scale1, metrics->x_scale2 );  }/******************************************************************* * *  Function    :  Scale_Y * *  Description :  scale a vertical distance from font *                 units to 26.6 pixels * *  Input  :  metrics  pointer to metrics *            y        value to scale * *  Output :  scaled value * ******************************************************************/  LOCAL_FUNC  TT_Pos  Scale_Y( PIns_Metrics  metrics, TT_Pos  y )  {    return TT_MulDiv( y, metrics->y_scale1, metrics->y_scale2 );  }/******************************************************************* * *  Function    :  TTObjs_Init * *  Description :  The TTObjs component initializer.  Creates the *                 object cache classes, as well as the face record *                 cache. * *  Input  :  engine    engine instance * *  Output :  Error code. * ******************************************************************/  static  const TCache_Class  objs_face_class =  {    sizeof ( TFace ),    -1,    Face_Create,    Face_Destroy,    NULL,    NULL  };  static  const TCache_Class  objs_instance_class =  {    sizeof ( TInstance ),    -1,    Instance_Create,    Instance_Destroy,    NULL,    NULL  };  /* Note that we use a cache size of 1 for the execution context.  */  /* This is to avoid re-creating a new context each time we        */  /* change one instance's attribute (resolution and/or char sizes) */  /* or when we load a glyph.                                       */  static  const TCache_Class  objs_exec_class =  {    sizeof ( TExecution_Context ),    1,    Context_Create,    Context_Destroy,    NULL,    NULL  };  static  const TCache_Class  objs_glyph_class =  {    sizeof ( TGlyph ),    -1,    Glyph_Create,    Glyph_Destroy,    NULL,    NULL  };  LOCAL_FUNC  TT_Error  TTObjs_Init( PEngine_Instance  engine )  {    PCache        face_cache, exec_cache;    TT_Error      error;    face_cache = 0;    exec_cache = 0;    if ( ALLOC( face_cache, sizeof ( TCache ) ) ||         ALLOC( exec_cache, sizeof ( TCache ) ) )      goto Fail;      /* create face cache */    error = Cache_Create( engine, (PCache_Class)&objs_face_class,                          face_cache, &engine->lock );    if ( error )      goto Fail;    engine->objs_face_cache = face_cache;    error = Cache_Create( engine, (PCache_Class)&objs_exec_class,                          exec_cache, &engine->lock );    if ( error )      goto Fail;    engine->objs_exec_cache = exec_cache;    engine->objs_face_class      = (PCache_Class)&objs_face_class;    engine->objs_instance_class  = (PCache_Class)&objs_instance_class;    engine->objs_execution_class = (PCache_Class)&objs_exec_class;    engine->objs_glyph_class     = (PCache_Class)&objs_glyph_class;    goto Exit;  Fail:    FREE( face_cache );    FREE( exec_cache );  Exit:    return error;  }/******************************************************************* * *  Function    :  TTObjs_Done * *  Description :  The TTObjs component finalizer. * *  Input  :  engine    engine instance * *  Output :  Error code. * ******************************************************************/  LOCAL_FUNC  TT_Error  TTObjs_Done( PEngine_Instance  engine )  {    /* destroy all active faces and contexts before releasing the */    /* caches                                                     */    Cache_Destroy( (TCache*)engine->objs_exec_cache );    Cache_Destroy( (TCache*)engine->objs_face_cache );    /* Now frees caches and cache classes */    FREE( engine->objs_exec_cache );    FREE( engine->objs_face_cache );    return TT_Err_Ok;  }/* END */

⌨️ 快捷键说明

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