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

📄 psobjs.c

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 C
📖 第 1 页 / 共 4 页
字号:
/***************************************************************************//*                                                                         *//*  psobjs.c                                                               *//*                                                                         *//*    Auxiliary functions for PostScript fonts (body).                     *//*                                                                         *//*  Copyright 1996-2001, 2002, 2003, 2004, 2005 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 FT_INTERNAL_POSTSCRIPT_AUX_H#include FT_INTERNAL_DEBUG_H#include "psobjs.h"#include "psauxerr.h"  /*************************************************************************/  /*************************************************************************/  /*****                                                               *****/  /*****                             PS_TABLE                          *****/  /*****                                                               *****/  /*************************************************************************/  /*************************************************************************/  /*************************************************************************/  /*                                                                       */  /* <Function>                                                            */  /*    ps_table_new                                                       */  /*                                                                       */  /* <Description>                                                         */  /*    Initializes a PS_Table.                                            */  /*                                                                       */  /* <InOut>                                                               */  /*    table  :: The address of the target table.                         */  /*                                                                       */  /* <Input>                                                               */  /*    count  :: The table size = the maximum number of elements.         */  /*                                                                       */  /*    memory :: The memory object to use for all subsequent              */  /*              reallocations.                                           */  /*                                                                       */  /* <Return>                                                              */  /*    FreeType error code.  0 means success.                             */  /*                                                                       */  FT_LOCAL_DEF( FT_Error )  ps_table_new( PS_Table   table,                FT_Int     count,                FT_Memory  memory )  {    FT_Error  error;    table->memory = memory;    if ( FT_NEW_ARRAY( table->elements, count ) ||         FT_NEW_ARRAY( table->lengths,  count ) )      goto Exit;    table->max_elems = count;    table->init      = 0xDEADBEEFUL;    table->num_elems = 0;    table->block     = 0;    table->capacity  = 0;    table->cursor    = 0;    *(PS_Table_FuncsRec*)&table->funcs = ps_table_funcs;  Exit:    if ( error )      FT_FREE( table->elements );    return error;  }  static void  shift_elements( PS_Table  table,                  FT_Byte*  old_base )  {    FT_Long    delta  = (FT_Long)( table->block - old_base );    FT_Byte**  offset = table->elements;    FT_Byte**  limit  = offset + table->max_elems;    for ( ; offset < limit; offset++ )    {      if ( offset[0] )        offset[0] += delta;    }  }  static FT_Error  reallocate_t1_table( PS_Table  table,                       FT_Long   new_size )  {    FT_Memory  memory   = table->memory;    FT_Byte*   old_base = table->block;    FT_Error   error;    /* allocate new base block */    if ( FT_ALLOC( table->block, new_size ) )    {      table->block = old_base;      return error;    }    /* copy elements and shift offsets */    if (old_base )    {      FT_MEM_COPY( table->block, old_base, table->capacity );      shift_elements( table, old_base );      FT_FREE( old_base );    }    table->capacity = new_size;    return PSaux_Err_Ok;  }  /*************************************************************************/  /*                                                                       */  /* <Function>                                                            */  /*    ps_table_add                                                       */  /*                                                                       */  /* <Description>                                                         */  /*    Adds an object to a PS_Table, possibly growing its memory block.   */  /*                                                                       */  /* <InOut>                                                               */  /*    table  :: The target table.                                        */  /*                                                                       */  /* <Input>                                                               */  /*    idx    :: The index of the object in the table.                    */  /*                                                                       */  /*    object :: The address of the object to copy in memory.             */  /*                                                                       */  /*    length :: The length in bytes of the source object.                */  /*                                                                       */  /* <Return>                                                              */  /*    FreeType error code.  0 means success.  An error is returned if a  */  /*    reallocation fails.                                                */  /*                                                                       */  FT_LOCAL_DEF( FT_Error )  ps_table_add( PS_Table    table,                FT_Int      idx,                void*       object,                FT_PtrDist  length )  {    if ( idx < 0 || idx > table->max_elems )    {      FT_ERROR(( "ps_table_add: invalid index\n" ));      return PSaux_Err_Invalid_Argument;    }    /* grow the base block if needed */    if ( table->cursor + length > table->capacity )    {      FT_Error   error;      FT_Offset  new_size  = table->capacity;      FT_Long    in_offset;      in_offset = (FT_Long)((FT_Byte*)object - table->block);      if ( (FT_ULong)in_offset >= table->capacity )        in_offset = -1;      while ( new_size < table->cursor + length )      {        /* increase size by 25% and round up to the nearest multiple           of 1024 */        new_size += ( new_size >> 2 ) + 1;        new_size  = FT_PAD_CEIL( new_size, 1024 );      }      error = reallocate_t1_table( table, new_size );      if ( error )        return error;      if ( in_offset >= 0 )        object = table->block + in_offset;    }    /* add the object to the base block and adjust offset */    table->elements[idx] = table->block + table->cursor;    table->lengths [idx] = length;    FT_MEM_COPY( table->block + table->cursor, object, length );    table->cursor += length;    return PSaux_Err_Ok;  }  /*************************************************************************/  /*                                                                       */  /* <Function>                                                            */  /*    ps_table_done                                                      */  /*                                                                       */  /* <Description>                                                         */  /*    Finalizes a PS_TableRec (i.e., reallocate it to its current        */  /*    cursor).                                                           */  /*                                                                       */  /* <InOut>                                                               */  /*    table :: The target table.                                         */  /*                                                                       */  /* <Note>                                                                */  /*    This function does NOT release the heap's memory block.  It is up  */  /*    to the caller to clean it, or reference it in its own structures.  */  /*                                                                       */  FT_LOCAL_DEF( void )  ps_table_done( PS_Table  table )  {    FT_Memory  memory = table->memory;    FT_Error   error;    FT_Byte*   old_base = table->block;    /* should never fail, because rec.cursor <= rec.size */    if ( !old_base )      return;    if ( FT_ALLOC( table->block, table->cursor ) )      return;    FT_MEM_COPY( table->block, old_base, table->cursor );    shift_elements( table, old_base );    table->capacity = table->cursor;    FT_FREE( old_base );    FT_UNUSED( error );  }  FT_LOCAL_DEF( void )  ps_table_release( PS_Table  table )  {    FT_Memory  memory = table->memory;    if ( (FT_ULong)table->init == 0xDEADBEEFUL )    {      FT_FREE( table->block );      FT_FREE( table->elements );      FT_FREE( table->lengths );      table->init = 0;    }  }  /*************************************************************************/  /*************************************************************************/  /*****                                                               *****/  /*****                            T1 PARSER                          *****/  /*****                                                               *****/  /*************************************************************************/  /*************************************************************************/  /* In the PostScript Language Reference Manual (PLRM) the following */  /* characters are called `whitespace characters'.                   */#define IS_T1_WHITESPACE( c )  ( (c) == ' '  || (c) == '\t' )#define IS_T1_LINESPACE( c )   ( (c) == '\r' || (c) == '\n' || (c) == '\f' )#define IS_T1_NULLSPACE( c )   ( (c) == '\0' )  /* According to the PLRM all whitespace characters are equivalent, */  /* except in comments and strings.                                 */#define IS_T1_SPACE( c )  ( IS_T1_WHITESPACE( c ) || \                            IS_T1_LINESPACE( c )  || \                            IS_T1_NULLSPACE( c )  )  /* The following array is used by various functions to quickly convert */  /* digits (both decimal and non-decimal) into numbers.                 */#if 'A' == 65  /* ASCII */  static const char  ft_char_table[128] =  {    /* 0x00 */    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,     0,  1,  2,  3,  4,  5,  6,  7,  8,  9, -1, -1, -1, -1, -1, -1,    -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,    25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1,    -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,    25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1,  };  /* no character >= 0x80 can represent a valid number */#define OP  >=#endif /* 'A' == 65 */#if 'A' == 193  /* EBCDIC */  static const char  ft_char_table[128] =  {    /* 0x80 */    -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, -1, -1, -1, -1, -1, -1,    -1, 19, 20, 21, 22, 23, 24, 25, 26, 27, -1, -1, -1, -1, -1, -1,    -1, -1, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, -1,    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,    -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, -1, -1, -1, -1, -1, -1,    -1, 19, 20, 21, 22, 23, 24, 25, 26, 27, -1, -1, -1, -1, -1, -1,    -1, -1, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, -1,     0,  1,  2,  3,  4,  5,  6,  7,  8,  9, -1, -1, -1, -1, -1, -1,  }  /* no character < 0x80 can represent a valid number */#define OP  <#endif /* 'A' == 193 */  /* first character must be already part of the comment */  static void  skip_comment( FT_Byte*  *acur,                FT_Byte*   limit )  {    FT_Byte*  cur = *acur;    while ( cur < limit )    {      if ( IS_T1_LINESPACE( *cur ) )        break;      cur++;    }    *acur = cur;  }  static void  skip_spaces( FT_Byte*  *acur,               FT_Byte*   limit )  {    FT_Byte*  cur = *acur;    while ( cur < limit )    {      if ( !IS_T1_SPACE( *cur ) )      {        if ( *cur == '%' )          /* According to the PLRM, a comment is equal to a space. */          skip_comment( &cur, limit );        else          break;      }      cur++;    }    *acur = cur;  }  /* first character must be `(' */  static void  skip_literal_string( FT_Byte*  *acur,                       FT_Byte*   limit )  {    FT_Byte*  cur   = *acur;    FT_Int    embed = 0;    while ( cur < limit )    {      if ( *cur == '\\' )        cur++;      else if ( *cur == '(' )        embed++;      else if ( *cur == ')' )      {        embed--;        if ( embed == 0 )        {          cur++;          break;        }      }      cur++;    }    *acur = cur;  }  /* first character must be `<' */  static void  skip_string( PS_Parser  parser )  {    FT_Byte*  cur   = parser->cursor;    FT_Byte*  limit = parser->limit;    while ( ++cur < limit )    {      int  d;      /* All whitespace characters are ignored. */      skip_spaces( &cur, limit );      if ( cur >= limit )        break;      if ( *cur OP 0x80 )        break;      d = ft_char_table[*cur & 0x7F];      if ( d < 0 || d >= 16 )        break;    }    if ( cur < limit && *cur != '>' )    {      FT_ERROR(( "skip_string: missing closing delimiter `>'\n" ));      parser->error = PSaux_Err_Invalid_File_Format;    }    else      cur++;    parser->cursor = cur;  }  /***********************************************************************/  /*                                                                     */  /* All exported parsing routines handle leading whitespace and stop at */  /* the first character which isn't part of the just handled token.     */  /*                                                                     */  /***********************************************************************/

⌨️ 快捷键说明

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