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

📄 ttload.c

📁 Qt/Embedded是一个多平台的C++图形用户界面应用程序框架
💻 C
📖 第 1 页 / 共 5 页
字号:
/***************************************************************************//*                                                                         *//*  ttload.c                                                               *//*                                                                         *//*    TrueType tables loader (body).                                       *//*                                                                         *//*  Copyright 1996-1999 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.                                        *//*                                                                         *//*                                                                         *//*  WARNING: This file should not be compiled directly; it is meant to be  *//*           included in the source of several font drivers (i.e., the TTF *//*           and OTF drivers).                                             *//*                                                                         *//***************************************************************************/#include <ftdebug.h>#include <ftconfig.h>#include <ttload.h>#include <tttags.h>#include <ttcmap.h>#include <tterrors.h>/* required by the tracing mode */#undef  FT_COMPONENT#define FT_COMPONENT      trace_ttload#define READ_FIELDS  /*************************************************************************/  /*                                                                       */  /* <Function>                                                            */  /*    TT_LookUp_Table                                                    */  /*                                                                       */  /* <Description>                                                         */  /*    Looks for a TrueType table by name.                                */  /*                                                                       */  /* <Input>                                                               */  /*    face :: A face object handle.                                      */  /*    tag  :: The  searched tag.                                         */  /*                                                                       */  /* <Return>                                                              */  /*    pointer to table directory entry. 0 if not found..                 */  /*                                                                       */  EXPORT_FUNC  TT_Table*  TT_LookUp_Table( TT_Face   face,                              TT_ULong  tag  )  {    TT_Table*  entry;    TT_Table*  limit;        FT_TRACE4(( "TT_LookUp_Table( %08lx, %c%c%c%c )\n",                  (TT_Long)face,                  (TT_Char)(tag >> 24),                  (TT_Char)(tag >> 16),                  (TT_Char)(tag >> 8),                  (TT_Char)(tag) ));    entry = face->dir_tables;    limit = entry + face->num_tables;    for ( ; entry < limit; entry++ )    {      if ( entry->Tag == tag )        return entry;    }        FT_TRACE4(( "    Could not find table!\n" ));    return 0;  }  /*************************************************************************/  /*                                                                       */  /* <Function>                                                            */  /*    TT_Goto_Table                                                      */  /*                                                                       */  /* <Description>                                                         */  /*    Looks for a TrueType table by name, then seek a stream to it.      */  /*                                                                       */  /* <Input>                                                               */  /*    face   :: a face object handle.                                    */  /*    tag    :: the  searched tag.                                       */  /*    stream :: the stream to seek when the table is found               */  /*                                                                       */  /* <Return>                                                              */  /*    pointer to table directory entry. 0 if not found..                 */  /*                                                                       */  EXPORT_FUNC  TT_Error   TT_Goto_Table( TT_Face    face,                            TT_ULong   tag,                            FT_Stream  stream,                            TT_ULong  *length )  {    TT_Table*  table;    TT_Error   error;        table = TT_LookUp_Table( face, tag );    if (table)    {      if (length)        *length = table->Length;              (void)FILE_Seek( table->Offset );    }    else      error = TT_Err_Table_Missing;          return error;  }  /*************************************************************************/  /*                                                                       */  /* <FuncType>                                                            */  /*    TT_Load_Format_Tag                                                 */  /*                                                                       */  /* <Description>                                                         */  /*    Loads the first 4 bytes of the font file. This is a tag that       */  /*    identifies the font format used.                                   */  /*                                                                       */  /* <Input>                                                               */  /*    face      :: A handle to the target face object.                   */  /*    stream    :: The input stream.                                     */  /*    faceIndex :: The index of the TrueType font, if we're opening a    */  /*                 collection.                                           */  /* <Output>                                                              */  /*    format_tag :: a 4-byte font format tag                             */  /*                                                                       */  /* <Return>                                                              */  /*    TrueType error code.  0 means success.                             */  /*                                                                       */  /* <Note>                                                                */  /*    The stream cursor must be at the font file's origin                */  /*    This function recognizes fonts embedded in a "TrueType collection" */  /*                                                                       */  LOCAL_FUNC  TT_Error  TT_Load_Format_Tag( TT_Face    face,                                FT_Stream  stream,                                TT_Long    faceIndex,                                TT_ULong  *format_tag )  {    TT_Error   error;    FT_Memory  memory = stream->memory;    #ifdef READ_FIELDS    const FT_Frame_Field  ttc_header_fields[] = {           { ft_frame_start, 0, 8 },   /* frame of 8 bytes */             FT_FRAME_LONG( TTC_Header, version  ),             FT_FRAME_LONG( TTC_Header, DirCount ),           { ft_frame_end, 0, 0 } };#endif    FT_TRACE2(( "TT_Load_Format_Tag(%08lx, %ld )\n",              (TT_Long)face, faceIndex ));    face->ttc_header.Tag      = 0;    face->ttc_header.version  = 0;    face->ttc_header.DirCount = 0;    face->num_tables = 0;    /* first of all, read the  first 4 bytes. If it's `ttcf', then the */    /* file is a TrueType collection, otherwise it can be any other    */    /* kind of font..                                                  */    if ( READ_ULong(*format_tag) ) goto Exit;    if ( *format_tag == TTAG_ttcf )    {      TT_Int  n;          FT_TRACE4(( "TT_Load_Format_Tag: file is a collection\n" ));            /* it's a TrueType collection, i.e. a file containing several */      /* font files. Read the font directory now                    */      /*                                                            */    #ifdef READ_FIELDS      if ( READ_Fields( ttc_header_fields, &face->ttc_header ) )        goto Exit;    #else      if ( ACCESS_Frame( 8 ) ) goto Exit;         face->ttc_header.version  = GET_Long();      face->ttc_header.DirCount = GET_Long();      FORGET_Frame();    #endif      /* now read the offsets of each font in the file         */      /*                                                       */      if ( ALLOC_ARRAY( face->ttc_header.TableDirectory,                        face->ttc_header.DirCount,                        TT_ULong )                        ||           ACCESS_Frame( face->ttc_header.DirCount * 4L ) )        goto Exit;      for ( n = 0; n < face->ttc_header.DirCount; n++ )        face->ttc_header.TableDirectory[n] = GET_ULong();      FORGET_Frame();      /* check face index */      if (faceIndex >= face->ttc_header.DirCount)      {        error = TT_Err_Bad_Argument;        goto Exit;      }                  /* if we're checking the font format, exit immediately */      if (faceIndex < 0)        goto Exit;              /* seek to the appropriate TrueType file, then read tag */      if ( FILE_Skip( face->ttc_header.TableDirectory[faceIndex] - 12 ) ||           READ_Long( *format_tag )                                     )        goto Exit;    }  Exit:    return error;  }  /*************************************************************************/  /*                                                                       */  /* <Function>                                                            */  /*    TT_Load_Directory                                                  */  /*                                                                       */  /* <Description>                                                         */  /*    Loads the table directory into a face object.                      */  /*                                                                       */  /* <Input>                                                               */  /*    face      :: A handle to the target face object.                   */  /*    stream    :: The input stream.                                     */  /*    faceIndex :: The index of the TrueType font, if we're opening a    */  /*                 collection.                                           */  /*                                                                       */  /* <Return>                                                              */  /*    TrueType error code.  0 means success.                             */  /*                                                                       */  /* <Note>                                                                */  /*    The stream cursor must be at the font file's origin                */  /*                                                                       */  LOCAL_FUNC  TT_Error  TT_Load_Directory( TT_Face    face,                               FT_Stream  stream,                               TT_Long    faceIndex )  {    TT_Error   error;    FT_Memory  memory = stream->memory;#ifdef READ_FIELDS    const FT_Frame_Field table_dir_fields[] = {           { ft_frame_start, 0, 8 },             FT_FRAME_USHORT( TT_TableDir, numTables ),             FT_FRAME_USHORT( TT_TableDir, searchRange ),             FT_FRAME_USHORT( TT_TableDir, entrySelector ),             FT_FRAME_USHORT( TT_TableDir, rangeShift ),           { ft_frame_end, 0 , 0 } };#endif    TT_TableDir  tableDir;    TT_Table *entry, *limit;    FT_TRACE2(( "TT_Load_Directory( %08lx, %ld )\n",              (TT_Long)face, faceIndex ));#ifdef READ_FIELDS    if ( READ_Fields( table_dir_fields, &tableDir ) )      goto Exit;#else    if ( ACCESS_Frame( 8L ) ) goto Exit;    tableDir.numTables     = GET_UShort();    tableDir.searchRange   = GET_UShort();    tableDir.entrySelector = GET_UShort();    tableDir.rangeShift    = GET_UShort();    FORGET_Frame();#endif    FT_TRACE2(( "-- Tables count   : %12u\n",  tableDir.numTables ));    FT_TRACE2(( "-- Format version : %08lx\n", tableDir.version ));    face->num_tables = tableDir.numTables;    if ( ALLOC_ARRAY( face->dir_tables,                      face->num_tables,                      TT_Table ) )      goto Exit;    if ( ACCESS_Frame( face->num_tables * 16L ) )      goto Exit;    entry = face->dir_tables;    limit = entry + face->num_tables;    for ( ; entry < limit; entry++ )    {                    /* loop through the tables and get all entries */      entry->Tag      = GET_Tag4();      entry->CheckSum = GET_ULong();      entry->Offset   = GET_Long();      entry->Length   = GET_Long();      FT_TRACE2(( "  %c%c%c%c  -  %08lx  -  %08lx\n",                (TT_Char)(entry->Tag >> 24),                (TT_Char)(entry->Tag >> 16),                (TT_Char)(entry->Tag >> 8 ),                (TT_Char)(entry->Tag),                entry->Offset,                entry->Length ));    }    FORGET_Frame();    FT_TRACE2(( "Directory loaded\n\n" ));  Exit:    return error;  }  /*************************************************************************/  /*                                                                       */  /* <Function>                                                            */  /*    TT_Load_Any                                                        */  /*                                                                       */  /* <Description>                                                         */

⌨️ 快捷键说明

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