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

📄 psobjs.c

📁 奇趣公司比较新的qt/emd版本
💻 C
📖 第 1 页 / 共 4 页
字号:
/***************************************************************************//*                                                                         *//*  psobjs.c                                                               *//*                                                                         *//*    Auxiliary functions for PostScript fonts (body).                     *//*                                                                         *//*  Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007 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 "psconv.h"#include "psauxerr.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_psobjs  /*************************************************************************/  /*************************************************************************/  /*****                                                               *****/  /*****                             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_PtrDist  delta  = 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                          *****/  /*****                                                               *****/  /*************************************************************************/  /*************************************************************************/  /* 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_PS_NEWLINE( *cur ) )        break;      cur++;    }    *acur = cur;  }  static void  skip_spaces( FT_Byte*  *acur,               FT_Byte*   limit )  {    FT_Byte*  cur = *acur;    while ( cur < limit )    {      if ( !IS_PS_SPACE( *cur ) )      {        if ( *cur == '%' )          /* According to the PLRM, a comment is equal to a space. */          skip_comment( &cur, limit );        else          break;      }      cur++;    }    *acur = cur;  }#define IS_OCTAL_DIGIT( c ) ( '0' <= (c) && (c) <= '7' )  /* first character must be `(';                               */  /* *acur is positioned at the character after the closing `)' */  static FT_Error  skip_literal_string( FT_Byte*  *acur,                       FT_Byte*   limit )  {    FT_Byte*      cur   = *acur;    FT_Int        embed = 0;    FT_Error      error = PSaux_Err_Invalid_File_Format;    unsigned int  i;    while ( cur < limit )    {      FT_Byte  c = *cur;      ++cur;      if ( c == '\\' )      {        /* Red Book 3rd ed., section `Literal Text Strings', p. 29:     */        /* A backslash can introduce three different types              */        /* of escape sequences:                                         */        /*   - a special escaped char like \r, \n, etc.                 */        /*   - a one-, two-, or three-digit octal number                */        /*   - none of the above in which case the backslash is ignored */        if ( cur == limit )          /* error (or to be ignored?) */          break;        switch ( *cur )        {          /* skip `special' escape */        case 'n':        case 'r':        case 't':        case 'b':        case 'f':        case '\\':        case '(':        case ')':          ++cur;          break;        default:          /* skip octal escape or ignore backslash */          for ( i = 0; i < 3 && cur < limit; ++i )          {            if ( ! IS_OCTAL_DIGIT( *cur ) )              break;            ++cur;          }        }      }      else if ( c == '(' )        embed++;      else if ( c == ')' )      {        embed--;        if ( embed == 0 )        {          error = PSaux_Err_Ok;          break;        }      }    }    *acur = cur;    return error;  }  /* first character must be `<' */  static FT_Error  skip_string( FT_Byte*  *acur,               FT_Byte*   limit )  {    FT_Byte*  cur = *acur;    FT_Error  err =  PSaux_Err_Ok;    while ( ++cur < limit )    {      /* All whitespace characters are ignored. */      skip_spaces( &cur, limit );      if ( cur >= limit )

⌨️ 快捷键说明

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