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

📄 cffload.c

📁 source code: Covert TXT to PDF
💻 C
📖 第 1 页 / 共 3 页
字号:
    0,    140,    141,    142,    143,    0,    0,    0,    0,    0,    144,    0,    0,    0,    145,    0,    0,    146,    147,    148,    149,    0,    0,    0,    0  };  static const FT_UShort  cff_expert_encoding[256] =  {    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    1,    229,    230,    0,    231,    232,    233,    234,    235,    236,    237,    238,    13,    14,    15,    99,    239,    240,    241,    242,    243,    244,    245,    246,    247,    248,    27,    28,    249,    250,    251,    252,    0,    253,    254,    255,    256,    257,    0,    0,    0,    258,    0,    0,    259,    260,    261,    262,    0,    0,    263,    264,    265,    0,    266,    109,    110,    267,    268,    269,    0,    270,    271,    272,    273,    274,    275,    276,    277,    278,    279,    280,    281,    282,    283,    284,    285,    286,    287,    288,    289,    290,    291,    292,    293,    294,    295,    296,    297,    298,    299,    300,    301,    302,    303,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    304,    305,    306,    0,    0,    307,    308,    309,    310,    311,    0,    312,    0,    0,    312,    0,    0,    314,    315,    0,    0,    316,    317,    318,    0,    0,    0,    158,    155,    163,    319,    320,    321,    322,    323,    324,    325,    0,    0,    326,    150,    164,    169,    327,    328,    329,    330,    331,    332,    333,    334,    335,    336,    337,    338,    339,    340,    341,    342,    343,    344,    345,    346,    347,    348,    349,    350,    351,    352,    353,    354,    355,    356,    357,    358,    359,    360,    361,    362,    363,    364,    365,    366,    367,    368,    369,    370,    371,    372,    373,    374,    375,    376,    377,    378  };#endif  FT_LOCAL_DEF FT_UShort  CFF_Get_Standard_Encoding( FT_UInt  charcode )  {    return  (FT_UShort)(charcode < 256 ? cff_standard_encoding[charcode] : 0);  }  /*************************************************************************/  /*                                                                       */  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */  /* messages during execution.                                            */  /*                                                                       */#undef  FT_COMPONENT#define FT_COMPONENT  trace_cffload  /* read a CFF offset from memory */  static FT_ULong  cff_get_offset( FT_Byte*  p,                  FT_Byte   off_size )  {    FT_ULong  result;    for ( result = 0; off_size > 0; off_size-- )    {      result <<= 8;      result  |= *p++;    }    return result;  }  static FT_Error  cff_new_index( CFF_Index*  index,                 FT_Stream   stream,                 FT_Bool     load )  {    FT_Error   error;    FT_Memory  memory = stream->memory;    FT_UShort  count;    MEM_Set( index, 0, sizeof ( *index ) );    index->stream = stream;    if ( !READ_UShort( count ) &&         count > 0             )    {      FT_Byte*   p;      FT_Byte    offsize;      FT_ULong   data_size;      FT_ULong*  poff;      /* there is at least one element; read the offset size,           */      /* then access the offset table to compute the index's total size */      if ( READ_Byte( offsize ) )        goto Exit;      index->stream   = stream;      index->count    = count;      index->off_size = offsize;      data_size       = (FT_ULong)( count + 1 ) * offsize;      if ( ALLOC_ARRAY( index->offsets, count + 1, FT_ULong ) ||           ACCESS_Frame( data_size )                          )        goto Exit;      poff = index->offsets;      p    = (FT_Byte*)stream->cursor;      for ( ; (FT_Short)count >= 0; count-- )      {        poff[0] = cff_get_offset( p, offsize );        poff++;        p += offsize;      }      FORGET_Frame();      index->data_offset = FILE_Pos();      data_size          = poff[-1] - 1;      if ( load )      {        /* load the data */        if ( EXTRACT_Frame( data_size, index->bytes ) )          goto Exit;      }      else      {        /* skip the data */        if ( FILE_Skip( data_size ) )          goto Exit;      }    }  Exit:    if ( error )      FREE( index->offsets );    return error;  }  static void  cff_done_index( CFF_Index*  index )  {    if ( index->stream )    {      FT_Stream  stream = index->stream;      FT_Memory  memory = stream->memory;      if ( index->bytes )        RELEASE_Frame( index->bytes );      FREE( index->offsets );      MEM_Set( index, 0, sizeof ( *index ) );    }  }  static FT_Error  cff_explicit_index( CFF_Index*  index,                      FT_Byte***  table )  {    FT_Error   error  = 0;    FT_Memory  memory = index->stream->memory;    FT_UInt    n, offset, old_offset;    FT_Byte**  t;    *table = 0;    if ( index->count > 0 && !ALLOC_ARRAY( t, index->count + 1, FT_Byte* ) )    {      old_offset = 1;      for ( n = 0; n <= index->count; n++ )      {        offset = index->offsets[n];        if ( !offset )          offset = old_offset;        t[n] = index->bytes + offset - 1;        old_offset = offset;      }      *table = t;    }    return error;  }  FT_LOCAL_DEF FT_Error  CFF_Access_Element( CFF_Index*  index,                      FT_UInt     element,                      FT_Byte**   pbytes,                      FT_ULong*   pbyte_len )  {    FT_Error  error = 0;    if ( index && index->count > element )    {      /* compute start and end offsets */      FT_ULong  off1, off2 = 0;      off1 = index->offsets[element];      if ( off1 )      {        do        {          element++;          off2 = index->offsets[element];        } while ( off2 == 0 && element < index->count );        if ( !off2 )          off1 = 0;      }      /* access element */      if ( off1 )      {        *pbyte_len = off2 - off1;        if ( index->bytes )        {          /* this index was completely loaded in memory, that's easy */          *pbytes = index->bytes + off1 - 1;        }        else        {          /* this index is still on disk/file, access it through a frame */          FT_Stream  stream = index->stream;          if ( FILE_Seek( index->data_offset + off1 - 1 ) ||               EXTRACT_Frame( off2 - off1, *pbytes )      )            goto Exit;        }      }      else      {        /* empty index element */        *pbytes    = 0;        *pbyte_len = 0;      }    }    else      error = CFF_Err_Invalid_Argument;  Exit:    return error;  }  FT_LOCAL_DEF void  CFF_Forget_Element( CFF_Index*  index,                      FT_Byte**   pbytes )  {    if ( index->bytes == 0 )    {      FT_Stream  stream = index->stream;      RELEASE_Frame( *pbytes );    }  }  FT_LOCAL_DEF FT_String*  CFF_Get_Name( CFF_Index*  index,                FT_UInt     element )  {    FT_Memory   memory = index->stream->memory;    FT_Byte*    bytes;    FT_ULong    byte_len;    FT_Error    error;    FT_String*  name = 0;    error = CFF_Access_Element( index, element, &bytes, &byte_len );    if ( error )      goto Exit;    if ( !ALLOC( name, byte_len + 1 ) )    {      MEM_Copy( name, bytes, byte_len );      name[byte_len] = 0;    }    CFF_Forget_Element( index, &bytes );  Exit:    return name;  }  FT_LOCAL_DEF FT_String*  CFF_Get_String( CFF_Index*          index,                  FT_UInt             sid,                  PSNames_Interface*  interface )  {    /* if it is not a standard string, return it */    if ( sid > 390 )      return CFF_Get_Name( index, sid - 391 );    /* that's a standard string, fetch a copy from the PSName module */    {      FT_String*   name       = 0;      const char*  adobe_name = interface->adobe_std_strings( sid );      FT_UInt      len;      if ( adobe_name )      {        FT_Memory memory = index->stream->memory;        FT_Error  error;        len = (FT_UInt)strlen( adobe_name );        if ( !ALLOC( name, len + 1 ) )        {          MEM_Copy( name, adobe_name, len );          name[len] = 0;        }      }      return name;    }  }  /*************************************************************************/  /*************************************************************************/  /***                                                                   ***/  /***   FD Select table support                                         ***/  /***                                                                   ***/  /*************************************************************************/  /*************************************************************************/  static void  CFF_Done_FD_Select( CFF_FD_Select*  select,                      FT_Stream       stream )  {    if ( select->data )      RELEASE_Frame( select->data );    select->data_size   = 0;    select->format      = 0;    select->range_count = 0;  }  static FT_Error  CFF_Load_FD_Select( CFF_FD_Select*  select,                      FT_UInt         num_glyphs,                      FT_Stream       stream,                      FT_ULong        offset )  {    FT_Error  error;    FT_Byte   format;    FT_UInt   num_ranges;    /* read format */    if ( FILE_Seek( offset ) || READ_Byte( format ) )      goto Exit;    select->format      = format;    select->cache_count = 0;   /* clear cache */    switch ( format )    {    case 0:     /* format 0, that's simple */      select->data_size = num_glyphs;      goto Load_Data;    case 3:     /* format 3, a tad more complex */      if ( READ_UShort( num_ranges ) )        goto Exit;      select->data_size = num_ranges * 3 + 2;    Load_Data:      if ( EXTRACT_Frame( select->data_size, select->data ) )        goto Exit;      break;    default:    /* hmm... that's wrong */      error = CFF_Err_Invalid_File_Format;    }  Exit:    return error;  }  FT_LOCAL_DEF FT_Byte  CFF_Get_FD( CFF_FD_Select*  select,              FT_UInt         glyph_index )  {    FT_Byte  fd = 0;    switch ( select->format )    {    case 0:      fd = select->data[glyph_index];      break;    case 3:      /* first, compare to cache */      if ( (FT_UInt)(glyph_index-select->cache_first) < select->cache_count )      {        fd = select->cache_fd;        break;      }      /* then, lookup the ranges array */      {        FT_Byte*  p       = select->data;        FT_Byte*  p_limit = p + select->data_size;        FT_Byte   fd2;        FT_UInt   first, limit;        first = NEXT_UShort( p );        do        {          if ( glyph_index < first )            break;          fd2   = *p++;          limit = NEXT_UShort( p );          if ( glyph_index < limit )          {            fd = fd2;            /* update cache */            select->cache_first = first;            select->cache_count = limit-first;            select->cache_fd    = fd2;            break;          }          first = limit;        } while ( p < p_limit );      }      break;    default:      ;    }    return fd;  }  /*************************************************************************/  /*************************************************************************/  /***                                                                   ***/  /***   CFF font support                                                ***/  /***                                                                   ***/  /*************************************************************************/  /*************************************************************************/  static void  CFF_Done_Encoding( CFF_Encoding*  encoding,                     FT_Stream      stream )  {    FT_Memory  memory = stream->memory;    FREE( encoding->codes );    FREE( encoding->sids  );    encoding->format = 0;    encoding->offset = 0;    encoding->codes  = 0;    encoding->sids   = 0;  }  static void  CFF_Done_Charset( CFF_Charset*  charset,                    FT_Stream     stream )  {    FT_Memory  memory = stream->memory;    FREE( charset->sids );    charset->format = 0;    charset->offset = 0;    charset->sids   = 0;  }  static FT_Error  CFF_Load_Charset( CFF_Charset*  charset,                    FT_UInt       num_glyphs,                    FT_Stream     stream,                    FT_ULong      base_offset,

⌨️ 快捷键说明

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