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

📄 t42parse.c

📁 下载来的一个看图软件的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    d = 0;  Exit:    return d;  }  static void  t42_parse_sfnts( T42_Face    face,                   T42_Loader  loader )  {    T42_Parser  parser = &loader->parser;    FT_Memory   memory = parser->root.memory;    FT_Byte*    cur    = parser->root.cursor;    FT_Byte*    limit  = parser->root.limit;    FT_Error    error;    FT_Int      num_tables = 0, status;    FT_ULong    count, ttf_size = 0, string_size = 0;    FT_Bool     in_string  = 0;    FT_Byte     v = 0;    /* The format is `/sfnts [ <...> <...> ... ] def' */    while ( t42_is_space( *cur ) )      cur++;    if (*cur++ == '[')    {      status = 0;      count = 0;    }    else    {      FT_ERROR(( "t42_parse_sfnts: can't find begin of sfnts vector!\n" ));      error = T42_Err_Invalid_File_Format;      goto Fail;    }    while ( cur < limit - 2 )    {      while ( t42_is_space( *cur ) )        cur++;      switch ( *cur )      {      case ']':        parser->root.cursor = cur++;        return;      case '<':        in_string   = 1;        string_size = 0;        cur++;        continue;      case '>':        if ( !in_string )        {          FT_ERROR(( "t42_parse_sfnts: found unpaired `>'!\n" ));          error = T42_Err_Invalid_File_Format;          goto Fail;        }        /* A string can have, as a last byte,         */        /* a zero byte for padding.  If so, ignore it */        if ( ( v == 0 ) && ( string_size % 2 == 1 ) )          count--;        in_string = 0;        cur++;        continue;      case '%':        if ( !in_string )        {          /* Comment found; skip till end of line */          while ( *cur != '\n' )            cur++;          continue;        }        else        {          FT_ERROR(( "t42_parse_sfnts: found `%' in string!\n" ));          error = T42_Err_Invalid_File_Format;          goto Fail;        }      default:        if ( !ft_xdigit( *cur ) || !ft_xdigit( *(cur + 1) ) )        {          FT_ERROR(( "t42_parse_sfnts: found non-hex characters in string" ));          error = T42_Err_Invalid_File_Format;          goto Fail;        }        v = (FT_Byte)( 16 * t42_hexval( cur[0] ) + t42_hexval( cur[1] ) );        cur += 2;        string_size++;      }      switch ( status )      {      case 0: /* The '[' was read, so load offset table, 12 bytes */        if ( count < 12 )        {          face->ttf_data[count++] = v;          continue;        }        else        {          num_tables = 16 * face->ttf_data[4] + face->ttf_data[5];          status     = 1;          ttf_size   = 12 + 16 * num_tables;          if ( FT_REALLOC( face->ttf_data, 12, ttf_size ) )            goto Fail;        }        /* No break, fall-through */      case 1: /* The offset table is read; read now the table directory */        if ( count < ttf_size )        {          face->ttf_data[count++] = v;          continue;        }        else        {          int      i;          FT_ULong len;          for ( i = 0; i < num_tables; i++ )          {            FT_Byte*  p = face->ttf_data + 12 + 16*i + 12;            len = FT_PEEK_ULONG( p );            /* Pad to a 4-byte boundary length */            ttf_size += ( len + 3 ) & ~3;          }          status         = 2;          face->ttf_size = ttf_size;          if ( FT_REALLOC( face->ttf_data, 12 + 16 * num_tables,                           ttf_size + 1 ) )            goto Fail;        }        /* No break, fall-through */      case 2: /* We are reading normal tables; just swallow them */        face->ttf_data[count++] = v;      }    }    /* If control reaches this point, the format was not valid */    error = T42_Err_Invalid_File_Format;  Fail:    parser->root.error = error;  }  static void  t42_parse_charstrings( T42_Face    face,                         T42_Loader  loader )  {    T42_Parser     parser     = &loader->parser;    PS_Table       code_table = &loader->charstrings;    PS_Table       name_table = &loader->glyph_names;    FT_Memory      memory     = parser->root.memory;    FT_Error       error;    PSAux_Service  psaux      = (PSAux_Service)face->psaux;    FT_Byte*       cur;    FT_Byte*       limit      = parser->root.limit;    FT_Int         n;    loader->num_glyphs = (FT_Int)T1_ToInt( parser );    if ( parser->root.error )      return;    /* initialize tables */    error = psaux->ps_table_funcs->init( code_table,                                         loader->num_glyphs,                                         memory );    if ( error )      goto Fail;    error = psaux->ps_table_funcs->init( name_table,                                         loader->num_glyphs,                                         memory );    if ( error )      goto Fail;    n = 0;    for (;;)    {      /* the format is simple:                    */      /*   `/glyphname' + index + def             */      /*                                          */      /* note that we stop when we find an `end'  */      /*                                          */      T1_Skip_Spaces( parser );      cur = parser->root.cursor;      if ( cur >= limit )        break;      /* we stop when we find an `end' keyword */      if ( *cur   == 'e'   &&           cur + 3 < limit &&           cur[1] == 'n'   &&           cur[2] == 'd'   )        break;      if ( *cur != '/' )        T1_Skip_Alpha( parser );      else      {        FT_Byte*  cur2 = cur + 1;        FT_Int    len;        while ( cur2 < limit && t42_is_alpha( *cur2 ) )          cur2++;        len = (FT_Int)( cur2 - cur - 1 );        error = T1_Add_Table( name_table, n, cur + 1, len + 1 );        if ( error )          goto Fail;        /* add a trailing zero to the name table */        name_table->elements[n][len] = '\0';        parser->root.cursor = cur2;        T1_Skip_Spaces( parser );        cur2 = cur = parser->root.cursor;        if ( cur >= limit )          break;        while ( cur2 < limit && t42_is_alpha( *cur2 ) )          cur2++;        len = (FT_Int)( cur2 - cur );        error = T1_Add_Table( code_table, n, cur, len + 1 );        if ( error )          goto Fail;        code_table->elements[n][len] = '\0';        n++;        if ( n >= loader->num_glyphs )          break;      }    }    /* Index 0 must be a .notdef element */    if ( ft_strcmp( (char *)name_table->elements[0], ".notdef" ) )    {      FT_ERROR(( "t42_parse_charstrings: Index 0 is not `.notdef'!\n" ));      error = T42_Err_Invalid_File_Format;      goto Fail;    }    loader->num_glyphs = n;    return;  Fail:    parser->root.error = error;  }  static FT_Error  t42_load_keyword( T42_Face    face,                    T42_Loader  loader,                    T1_Field    field )  {    FT_Error  error;    void*     dummy_object;    void**    objects;    FT_UInt   max_objects = 0;    /* if the keyword has a dedicated callback, call it */    if ( field->type == T1_FIELD_TYPE_CALLBACK ) {      field->reader( (FT_Face)face, loader );      error = loader->parser.root.error;      goto Exit;    }    /* now, the keyword is either a simple field, or a table of fields; */    /* we are now going to take care of it                              */    switch ( field->location )    {    case T1_FIELD_LOCATION_FONT_INFO:      dummy_object = &face->type1.font_info;      break;    case T1_FIELD_LOCATION_BBOX:      dummy_object = &face->type1.font_bbox;      break;    default:      dummy_object = &face->type1;    }    objects = &dummy_object;    if ( field->type == T1_FIELD_TYPE_INTEGER_ARRAY ||         field->type == T1_FIELD_TYPE_FIXED_ARRAY   )      error = T1_Load_Field_Table( &loader->parser, field,                                   objects, max_objects, 0 );    else      error = T1_Load_Field( &loader->parser, field,                             objects, max_objects, 0 );   Exit:    return error;  }  FT_LOCAL_DEF( FT_Error )  t42_parse_dict( T42_Face    face,                  T42_Loader  loader,                  FT_Byte*    base,                  FT_Long     size )  {    T42_Parser  parser     = &loader->parser;    FT_Byte*    cur        = base;    FT_Byte*    limit      = cur + size;    FT_UInt     n_keywords = (FT_UInt)( sizeof ( t42_keywords ) /                                        sizeof ( t42_keywords[0] ) );    FT_Byte     keyword_flags[T42_KEYWORD_COUNT];    {      FT_UInt  n;      for ( n = 0; n < T42_KEYWORD_COUNT; n++ )        keyword_flags[n] = 0;    }    parser->root.cursor = base;    parser->root.limit  = base + size;    parser->root.error  = 0;    for ( ; cur < limit; cur++ )    {      /* look for `FontDirectory', which causes problems on some fonts */      if ( *cur == 'F' && cur + 25 < limit                    &&           ft_strncmp( (char*)cur, "FontDirectory", 13 ) == 0 )      {        FT_Byte*  cur2;        /* skip the `FontDirectory' keyword */        cur += 13;        cur2 = cur;        /* lookup the `known' keyword */        while ( cur < limit && *cur != 'k'           &&                ft_strncmp( (char*)cur, "known", 5 ) )          cur++;        if ( cur < limit )        {          T1_TokenRec  token;          /* skip the `known' keyword and the token following it */          cur += 5;          loader->parser.root.cursor = cur;          T1_ToToken( &loader->parser, &token );          /* if the last token was an array, skip it! */          if ( token.type == T1_TOKEN_TYPE_ARRAY )            cur2 = parser->root.cursor;        }        cur = cur2;      }      /* look for immediates */      else if ( *cur == '/' && cur + 2 < limit )      {        FT_Byte*  cur2;        FT_UInt    i, len;        cur++;        cur2 = cur;        while ( cur2 < limit && t42_is_alpha( *cur2 ) )          cur2++;        len  = (FT_UInt)( cur2 - cur );        if ( len > 0 && len < 22 ) /* XXX What shall it this 22? */        {          /* now, compare the immediate name to the keyword table */          /* Loop through all known keywords */          for ( i = 0; i < n_keywords; i++ )          {            T1_Field  keyword = (T1_Field)&t42_keywords[i];            FT_Byte   *name   = (FT_Byte*)keyword->ident;            if ( !name )              continue;            if ( ( len == ft_strlen( (const char *)name ) ) &&                 ( ft_memcmp( cur, name, len ) == 0 )       )            {              /* we found it -- run the parsing callback! */              parser->root.cursor = cur2;              T1_Skip_Spaces( parser );              /* only record the first instance of each field/keyword */              /* to deal with synthetic fonts correctly               */              if ( keyword_flags[i] == 0 )              {                parser->root.error = t42_load_keyword(face,                                                      loader,                                                      keyword );                if ( parser->root.error )                  return parser->root.error;              }              keyword_flags[i] = 1;              cur = parser->root.cursor;              break;            }          }        }      }    }    return parser->root.error;  }  FT_LOCAL_DEF( void )  t42_loader_init( T42_Loader  loader,                   T42_Face    face )  {    FT_UNUSED( face );    FT_MEM_ZERO( loader, sizeof ( *loader ) );    loader->num_glyphs = 0;    loader->num_chars  = 0;    /* initialize the tables -- simply set their `init' field to 0 */    loader->encoding_table.init = 0;    loader->charstrings.init    = 0;    loader->glyph_names.init    = 0;  }  FT_LOCAL_DEF( void )  t42_loader_done( T42_Loader  loader )  {    T42_Parser  parser = &loader->parser;    /* finalize tables */    T1_Release_Table( &loader->encoding_table );    T1_Release_Table( &loader->charstrings );    T1_Release_Table( &loader->glyph_names );    /* finalize parser */    t42_parser_done( parser );  }/* END */

⌨️ 快捷键说明

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