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

📄 sfobjs.c

📁 一个Xpdf应用的例子
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************//*                                                                         *//*  sfobjs.c                                                               *//*                                                                         *//*    SFNT object management (base).                                       *//*                                                                         *//*  Copyright 1996-2001 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.                                        *//*                                                                         *//***************************************************************************/#include <ft2build.h>#include "sfobjs.h"#include "ttload.h"#include FT_INTERNAL_SFNT_H#include FT_INTERNAL_POSTSCRIPT_NAMES_H#include FT_TRUETYPE_IDS_H#include FT_TRUETYPE_TAGS_H#include "sferrors.h"  /*************************************************************************/  /*                                                                       */  /* 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_sfobjs  /*************************************************************************/  /*                                                                       */  /* <Function>                                                            */  /*    Get_Name                                                           */  /*                                                                       */  /* <Description>                                                         */  /*    Returns a given ENGLISH name record in ASCII.                      */  /*                                                                       */  /* <Input>                                                               */  /*    face   :: A handle to the source face object.                      */  /*                                                                       */  /*    nameid :: The name id of the name record to return.                */  /*                                                                       */  /* <Return>                                                              */  /*    Character string.  NULL if no name is present.                     */  /*                                                                       */  static FT_String*  Get_Name( TT_Face    face,            FT_UShort  nameid )  {    FT_Memory    memory = face->root.memory;    FT_UShort    n;    TT_NameRec*  rec;    FT_Bool      wide_chars    = 1;    FT_Int       found_apple   = -1;    FT_Int       found_win     = -1;    FT_Int       found_unicode = -1;    FT_Int       found;    rec = face->name_table.names;    for ( n = 0; n < face->name_table.numNameRecords; n++, rec++ )    {      if ( rec->nameID == nameid && rec->string )      {        switch ( rec->platformID )        {          case TT_PLATFORM_APPLE_UNICODE:            {              found_unicode = n;              break;            }                      case TT_PLATFORM_MACINTOSH:            {              if ( rec->languageID == TT_MAC_ID_ROMAN )                found_apple = n;                            break;            }                      case TT_PLATFORM_MICROSOFT:            {              if (  rec->encodingID <= TT_MS_ID_UNICODE_CS &&                   (rec->languageID & 0x3FF) == 0x009      )              {                found_win = n;              }              break;            }                    default:            ;        }      }    }    /* some fonts contain invalid Unicode or Macintosh formatted entries */    /* we will thus favor name encoded in Windows formats when they're   */    /* available..                                                       */    /*                                                                   */    found = found_win;    if ( found < 0 )    {      found = found_apple;      if ( found_apple < 0 )        found = found_unicode;      else        wide_chars = 0;    }    /* found a Unicode name */    if ( found >= 0 )    {      FT_String*  string;      FT_UInt     len;      rec = face->name_table.names + found;      if ( wide_chars )      {        FT_UInt   m;        len = (FT_UInt)rec->stringLength / 2;        if ( MEM_Alloc( string, len + 1 ) )          return NULL;        for ( m = 0; m < len; m ++ )          string[m] = rec->string[2 * m + 1];      }      else      {        len = rec->stringLength;        if ( MEM_Alloc( string, len + 1 ) )          return NULL;        MEM_Copy( string, rec->string, len );      }      string[len] = '\0';      return string;    }    return NULL;  }  static FT_Encoding  find_encoding( int  platform_id,                 int  encoding_id )  {    typedef struct  TEncoding    {      int          platform_id;      int          encoding_id;      FT_Encoding  encoding;    } TEncoding;    static    const TEncoding  tt_encodings[] =    {      { TT_PLATFORM_ISO,           -1,                  ft_encoding_unicode },      { TT_PLATFORM_APPLE_UNICODE, -1,                  ft_encoding_unicode },      { TT_PLATFORM_MACINTOSH,     TT_MAC_ID_ROMAN,     ft_encoding_apple_roman },      { TT_PLATFORM_MICROSOFT,     TT_MS_ID_SYMBOL_CS,  ft_encoding_symbol },      { TT_PLATFORM_MICROSOFT,     TT_MS_ID_UCS_4,      ft_encoding_unicode },      { TT_PLATFORM_MICROSOFT,     TT_MS_ID_UNICODE_CS, ft_encoding_unicode },      { TT_PLATFORM_MICROSOFT,     TT_MS_ID_SJIS,       ft_encoding_sjis },      { TT_PLATFORM_MICROSOFT,     TT_MS_ID_GB2312,     ft_encoding_gb2312 },      { TT_PLATFORM_MICROSOFT,     TT_MS_ID_BIG_5,      ft_encoding_big5 },      { TT_PLATFORM_MICROSOFT,     TT_MS_ID_WANSUNG,    ft_encoding_wansung },      { TT_PLATFORM_MICROSOFT,     TT_MS_ID_JOHAB,      ft_encoding_johab }    };    const TEncoding  *cur, *limit;    cur   = tt_encodings;    limit = cur + sizeof ( tt_encodings ) / sizeof ( tt_encodings[0] );    for ( ; cur < limit; cur++ )    {      if ( cur->platform_id == platform_id )      {        if ( cur->encoding_id == encoding_id ||             cur->encoding_id == -1          )          return cur->encoding;      }    }    return ft_encoding_none;  }  FT_LOCAL_DEF FT_Error  SFNT_Init_Face( FT_Stream      stream,                  TT_Face        face,                  FT_Int         face_index,                  FT_Int         num_params,                  FT_Parameter*  params )  {    FT_Error            error;    FT_Library          library = face->root.driver->root.library;    SFNT_Interface*     sfnt;    SFNT_Header         sfnt_header;    /* for now, parameters are unused */    FT_UNUSED( num_params );    FT_UNUSED( params );    sfnt = (SFNT_Interface*)face->sfnt;    if ( !sfnt )    {      sfnt = (SFNT_Interface*)FT_Get_Module_Interface( library, "sfnt" );      if ( !sfnt )      {        error = SFNT_Err_Invalid_File_Format;        goto Exit;      }      face->sfnt       = sfnt;      face->goto_table = sfnt->goto_table;    }    if ( !face->psnames )    {      face->psnames = (PSNames_Interface*)                       FT_Get_Module_Interface( library, "psnames" );    }    /* check that we have a valid TrueType file */    error = sfnt->load_sfnt_header( face, stream, face_index, &sfnt_header );    if ( error )      goto Exit;    face->format_tag = sfnt_header.format_tag;    face->num_tables = sfnt_header.num_tables;    /* Load font directory */    error = sfnt->load_directory( face, stream, &sfnt_header );    if ( error )      goto Exit;    face->root.num_faces = face->ttc_header.count;    if ( face->root.num_faces < 1 )      face->root.num_faces = 1;  Exit:    return error;  }#undef  LOAD_#define LOAD_( x )  ( ( error = sfnt->load_##x( face, stream ) ) \                      != SFNT_Err_Ok )  FT_LOCAL_DEF FT_Error  SFNT_Load_Face( FT_Stream      stream,                  TT_Face        face,                  FT_Int         face_index,                  FT_Int         num_params,                  FT_Parameter*  params )  {    FT_Error         error;    FT_Bool          has_outline;    FT_Bool          is_apple_sbit;    SFNT_Interface*  sfnt = (SFNT_Interface*)face->sfnt;    FT_UNUSED( face_index );    FT_UNUSED( num_params );    FT_UNUSED( params );    /* Load tables */    /* We now support two SFNT-based bitmapped font formats.  They */    /* are recognized easily as they do not include a `glyf'       */    /* table.                                                      */    /*                                                             */    /* The first format comes from Apple, and uses a table named   */    /* `bhed' instead of `head' to store the font header (using    */    /* the same format).  It also doesn't include horizontal and   */    /* vertical metrics tables (i.e. `hhea' and `vhea' tables are  */    /* missing).                                                   */    /*                                                             */    /* The other format comes from Microsoft, and is used with     */    /* WinCE/PocketPC.  It looks like a standard TTF, except that  */    /* it doesn't contain outlines.                                */    /*                                                             */    /* do we have outlines in there? */    has_outline   = FT_BOOL( ( TT_LookUp_Table( face, TTAG_glyf ) != 0 ) ||                             ( TT_LookUp_Table( face, TTAG_CFF  ) != 0 ) );    is_apple_sbit = 0;#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS    /* if this font doesn't contain outlines, we try to load */    /* a `bhed' table                                        */    if ( !has_outline )      is_apple_sbit = FT_BOOL( !LOAD_( bitmap_header ) );#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */    /* load the font header (`head' table) if this isn't an Apple */    /* sbit font file                                             */    if ( !is_apple_sbit && LOAD_( header ) )      goto Exit;    /* the following tables are often not present in embedded TrueType */    /* fonts within PDF documents, so don't check for them.            */    (void)LOAD_( max_profile );    (void)LOAD_( charmaps );          /* the following tables are optional in PCL fonts -- */    /* don't check for errors                            */    (void)LOAD_( names );    (void)LOAD_( psnames );    /* do not load the metrics headers and tables if this is an Apple */    /* sbit font file                                                 */    if ( !is_apple_sbit )    {      /* load the `hhea' and `hmtx' tables at once */      error = sfnt->load_metrics( face, stream, 0 );      if ( error )        goto Exit;      /* try to load the `vhea' and `vmtx' tables at once */      error = sfnt->load_metrics( face, stream, 1 );      if ( error )        goto Exit;      if ( LOAD_( os2 ) )        goto Exit;    }

⌨️ 快捷键说明

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