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

📄 ftxgpos.c

📁 Trolltech公司发布的基于C++图形开发环境
💻 C
📖 第 1 页 / 共 5 页
字号:
/******************************************************************* * *  ftxgpos.c * *    TrueType Open GPOS table support. * *  Copyright 1996-2000 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. * ******************************************************************//* XXX There is *a lot* of duplicated code (cf. formats 7 and 8), but       I don't care currently.  I believe that it would be possible to       save about 50% of TTO code by carefully designing the structures,       sharing as much as possible with extensive use of macros.  This       is something for a volunteer :-)                                  */#define TTAG_GPOS  FT_MAKE_TAG( 'G', 'P', 'O', 'S' )#include <freetype/tttags.h>#include <freetype/internal/ftstream.h>#include <freetype/internal/ftmemory.h>#include <freetype/internal/tttypes.h>#include "fterrcompat.h"#include "ftxopen.h"#include "ftxgsub.h"#include "ftxopenf.h"  struct  GPOS_Instance_  {    TTO_GPOSHeader*  gpos;    FT_Face          face;    FT_Bool          dvi;    FT_UShort        load_flags;  /* how the glyph should be loaded */    FT_Bool          r2l;    FT_UShort        first;       /* the first glyph in a chain of                                     cursive connections           */    FT_UShort        last;        /* the last valid glyph -- used                                     with cursive positioning     */    FT_Pos           anchor_x;    /* the coordinates of the anchor point */    FT_Pos           anchor_y;    /* of the last valid glyph             */  };  typedef struct GPOS_Instance_  GPOS_Instance;  static FT_Error  GPos_Do_Glyph_Lookup( GPOS_Instance*    gpi,                                    FT_UShort         lookup_index,                                    TTO_GSUB_String*  in,                                    TTO_GPOS_Data*    out,                                    FT_UShort         context_length,                                    int               nesting_level );  /* the client application must replace this with something more     meaningful if multiple master fonts are to be supported.     */static FT_Error  default_mmfunc( FT_Face      face,				 FT_UShort    metric_id,				 FT_Pos*      metric_value,				 void*        data ){    (void)face;    (void)metric_id;    (void)metric_value;    (void)data;    return TTO_Err_No_MM_Interpreter;}#if 0#define GPOS_ID  Build_Extension_ID( 'G', 'P', 'O', 'S' )  /**********************   * Extension Functions   **********************/  static FT_Error  GPOS_Create( void*      ext,                                FT_Stream stream )  {    FT_Error  error;    FT_Memory memory = stream->memory;    TTO_GPOSHeader*  gpos = (TTO_GPOSHeader*)ext;    FT_Long          table;    /* by convention */    if ( !gpos )      return TT_Err_Ok;    /* a null offset indicates that there is no GPOS table */    gpos->offset = 0;    /* we store the start offset and the size of the subtable */    table = face->lookup_table ( face, TTAG_GPOS );    if ( table < 0 )      return TT_Err_Ok;             /* The table is optional */    if ( FILE_Seek( face->dirTables[table].Offset ) ||         ACCESS_Frame( 4L ) )      return error;    gpos->offset  = FILE_Pos() - 4L;    /* undo ACCESS_Frame() */    gpos->Version = GET_ULong();    FORGET_Frame();    /* a default mmfunc() handler which just returns an error */    gpos->mmfunc = default_mmfunc;    /* the default glyph function is TT_Load_Glyph() */    gpos->gfunc = FT_Load_Glyph;    gpos->loaded = FALSE;    return TT_Err_Ok;  }  static FT_Error  GPOS_Destroy( void*  ext,                                 PFace  face )  {    TTO_GPOSHeader*  gpos = (TTO_GPOSHeader*)ext;    /* by convention */    if ( !gpos )      return TT_Err_Ok;    if ( gpos->loaded )    {      Free_LookupList( &gpos->LookupList, GPOS );      Free_FeatureList( &gpos->FeatureList );      Free_ScriptList( &gpos->ScriptList );    }    return TT_Err_Ok;  }  EXPORT_FUNC  FT_Error  TT_Init_GPOS_Extension( TT_Engine  engine )  {    PEngine_Instance  _engine = HANDLE_Engine( engine );    if ( !_engine )      return TT_Err_Invalid_Engine;    return  TT_Register_Extension( _engine,                                   GPOS_ID,                                   sizeof ( TTO_GPOSHeader ),                                   GPOS_Create,                                   GPOS_Destroy );  }#endif  EXPORT_FUNC  FT_Error  TT_Load_GPOS_Table( FT_Face          face,                                TTO_GPOSHeader** retptr,                                TTO_GDEFHeader*  gdef )  {    FT_ULong         cur_offset, new_offset, base_offset;    /*    FT_UShort        i, num_lookups; */    TTO_GPOSHeader*  gpos;    /*    TTO_Lookup*      lo; */    TT_Face          tt_face = (TT_Face)face;    FT_Stream  stream = face->stream;    FT_Error   error;    FT_Memory  memory = face->memory;    if ( !retptr )      return TT_Err_Invalid_Argument;    if ( !stream )      return TT_Err_Invalid_Face_Handle;    if (( error = tt_face->goto_table( tt_face, TTAG_GPOS, stream, 0 ) ))      return error;    base_offset = FILE_Pos();    if ( ALLOC ( gpos, sizeof( *gpos ) ) )      return error;    gpos->memory = memory;    gpos->gfunc = FT_Load_Glyph;    gpos->mmfunc = default_mmfunc;    /* skip version */    if ( FILE_Seek( base_offset + 4L ) ||         ACCESS_Frame( 2L ) )      goto Fail4;    new_offset = GET_UShort() + base_offset;    FORGET_Frame();    cur_offset = FILE_Pos();    if ( FILE_Seek( new_offset ) ||         ( error = Load_ScriptList( &gpos->ScriptList,                                    stream ) ) != TT_Err_Ok )      goto Fail4;    (void)FILE_Seek( cur_offset );    if ( ACCESS_Frame( 2L ) )      goto Fail3;    new_offset = GET_UShort() + base_offset;    FORGET_Frame();    cur_offset = FILE_Pos();    if ( FILE_Seek( new_offset ) ||         ( error = Load_FeatureList( &gpos->FeatureList,                                     stream ) ) != TT_Err_Ok )      goto Fail3;    (void)FILE_Seek( cur_offset );    if ( ACCESS_Frame( 2L ) )      goto Fail2;    new_offset = GET_UShort() + base_offset;    FORGET_Frame();    cur_offset = FILE_Pos();    if ( FILE_Seek( new_offset ) ||         ( error = Load_LookupList( &gpos->LookupList,                                    stream, GPOS ) ) != TT_Err_Ok )      goto Fail2;    gpos->gdef = gdef;      /* can be NULL */    /* We now check the LookupFlags for values larger than 0xFF to find       out whether we need to load the `MarkAttachClassDef' field of the       GDEF table -- this hack is necessary for OpenType 1.2 tables since       the version field of the GDEF table hasn't been incremented.       For constructed GDEF tables, we only load it if       `MarkAttachClassDef_offset' is not zero (nevertheless, a build of       a constructed mark attach table is not supported currently).       */#if 0    if ( gdef &&         gdef->MarkAttachClassDef_offset && !gdef->MarkAttachClassDef.loaded )    {      lo          = gpos->LookupList.Lookup;      num_lookups = gpos->LookupList.LookupCount;      for ( i = 0; i < num_lookups; i++ )      {        if ( lo[i].LookupFlag & IGNORE_SPECIAL_MARKS )        {          if ( FILE_Seek( gdef->MarkAttachClassDef_offset ) ||               ACCESS_Frame( 2L ) )            goto Fail1;          new_offset = GET_UShort();          FORGET_Frame();          if ( !new_offset )            return TTO_Err_Invalid_GDEF_SubTable;          new_offset += base_offset;          if ( FILE_Seek( new_offset ) ||               ( error = Load_ClassDefinition( &gdef->MarkAttachClassDef,                                               256, stream ) ) != TT_Err_Ok )            goto Fail1;          break;        }      }    }#endif    *retptr = gpos;    return TT_Err_Ok;#if 0  Fail1:    Free_LookupList( &gpos->LookupList, GPOS, memory );#endif  Fail2:    Free_FeatureList( &gpos->FeatureList, memory );  Fail3:    Free_ScriptList( &gpos->ScriptList, memory );  Fail4:    FREE( gpos );    return error;  }  EXPORT_FUNC  FT_Error  TT_Done_GPOS_Table( TTO_GPOSHeader* gpos )  {    FT_Memory memory = gpos->memory;    Free_LookupList( &gpos->LookupList, GPOS, memory );    Free_FeatureList( &gpos->FeatureList, memory );    Free_ScriptList( &gpos->ScriptList, memory );    return FT_Err_Ok;  }  /*****************************   * SubTable related functions   *****************************/  /* shared tables */  /* ValueRecord */  /* There is a subtle difference in the specs between a `table' and a     `record' -- offsets for device tables in ValueRecords are taken from     the parent table and not the parent record.                          */  static FT_Error  Load_ValueRecord( TTO_ValueRecord*  vr,                                     FT_UShort         format,                                     FT_ULong          base_offset,                                     FT_Stream         stream )  {    FT_Error  error;    FT_Memory memory = stream->memory;    FT_ULong cur_offset, new_offset;    if ( format & HAVE_X_PLACEMENT )    {      if ( ACCESS_Frame( 2L ) )        return error;      vr->XPlacement = GET_Short();      FORGET_Frame();    }    else      vr->XPlacement = 0;    if ( format & HAVE_Y_PLACEMENT )    {      if ( ACCESS_Frame( 2L ) )        return error;      vr->YPlacement = GET_Short();      FORGET_Frame();    }    else      vr->YPlacement = 0;    if ( format & HAVE_X_ADVANCE )    {      if ( ACCESS_Frame( 2L ) )        return error;      vr->XAdvance = GET_Short();      FORGET_Frame();    }    else      vr->XAdvance = 0;    if ( format & HAVE_Y_ADVANCE )    {      if ( ACCESS_Frame( 2L ) )        return error;      vr->YAdvance = GET_Short();      FORGET_Frame();    }    else      vr->YAdvance = 0;    if ( format & HAVE_X_PLACEMENT_DEVICE )    {      if ( ACCESS_Frame( 2L ) )        return error;      new_offset = GET_UShort();      FORGET_Frame();      if ( new_offset )      {        new_offset += base_offset;        cur_offset = FILE_Pos();        if ( FILE_Seek( new_offset ) ||             ( error = Load_Device( &vr->XPlacementDevice,                                    stream ) ) != TT_Err_Ok )          return error;        (void)FILE_Seek( cur_offset );      }      else        goto empty1;    }    else    {    empty1:      vr->XPlacementDevice.StartSize  = 0;      vr->XPlacementDevice.EndSize    = 0;      vr->XPlacementDevice.DeltaValue = NULL;    }    if ( format & HAVE_Y_PLACEMENT_DEVICE )    {      if ( ACCESS_Frame( 2L ) )        goto Fail3;      new_offset = GET_UShort();      FORGET_Frame();      if ( new_offset )      {        new_offset += base_offset;        cur_offset = FILE_Pos();        if ( FILE_Seek( new_offset ) ||             ( error = Load_Device( &vr->YPlacementDevice,                                    stream ) ) != TT_Err_Ok )          goto Fail3;        (void)FILE_Seek( cur_offset );      }      else        goto empty2;    }    else    {    empty2:      vr->YPlacementDevice.StartSize  = 0;      vr->YPlacementDevice.EndSize    = 0;      vr->YPlacementDevice.DeltaValue = NULL;    }    if ( format & HAVE_X_ADVANCE_DEVICE )    {      if ( ACCESS_Frame( 2L ) )        goto Fail2;      new_offset = GET_UShort();      FORGET_Frame();      if ( new_offset )      {        new_offset += base_offset;        cur_offset = FILE_Pos();        if ( FILE_Seek( new_offset ) ||             ( error = Load_Device( &vr->XAdvanceDevice,                                    stream ) ) != TT_Err_Ok )          goto Fail2;        (void)FILE_Seek( cur_offset );      }      else        goto empty3;    }    else    {    empty3:      vr->XAdvanceDevice.StartSize  = 0;      vr->XAdvanceDevice.EndSize    = 0;      vr->XAdvanceDevice.DeltaValue = NULL;    }    if ( format & HAVE_Y_ADVANCE_DEVICE )    {      if ( ACCESS_Frame( 2L ) )        goto Fail1;      new_offset = GET_UShort();      FORGET_Frame();      if ( new_offset )      {        new_offset += base_offset;        cur_offset = FILE_Pos();        if ( FILE_Seek( new_offset ) ||             ( error = Load_Device( &vr->YAdvanceDevice,                                    stream ) ) != TT_Err_Ok )          goto Fail1;        (void)FILE_Seek( cur_offset );      }      else        goto empty4;    }    else    {    empty4:      vr->YAdvanceDevice.StartSize  = 0;      vr->YAdvanceDevice.EndSize    = 0;      vr->YAdvanceDevice.DeltaValue = NULL;    }    if ( format & HAVE_X_ID_PLACEMENT )    {      if ( ACCESS_Frame( 2L ) )        goto Fail1;      vr->XIdPlacement = GET_UShort();      FORGET_Frame();    }    else      vr->XIdPlacement = 0;

⌨️ 快捷键说明

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