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

📄 psobjs.c

📁 qt-embedded-2.3.8.tar.gz源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/***************************************************************************//*                                                                         *//*  psobjs.c                                                               *//*                                                                         *//*    Auxiliary functions for PostScript fonts (body).                     *//*                                                                         *//*  Copyright 1996-2000 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 <freetype/internal/psaux.h>#include <freetype/fterrors.h>#include <freetype/internal/ftdebug.h>#ifdef FT_FLAT_COMPILE#include "psobjs.h"#else#include <psaux/psobjs.h>#endif  /*************************************************************************/  /*************************************************************************/  /*****                                                               *****/  /*****                             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 ( ALLOC_ARRAY( table->elements, count, FT_Byte*  ) ||         ALLOC_ARRAY( table->lengths, count, FT_Byte* )   )      goto Exit;    table->max_elems = count;    table->init      = 0xDEADBEEFUL;    table->num_elems = 0;    table->block     = 0;    table->capacity  = 0;    table->cursor    = 0;    table->funcs     = ps_table_funcs;  Exit:    if ( error )      FREE( table->elements );    return error;  }  static  void  shift_elements( PS_Table*  table,                        FT_Byte*   old_base )  {    FT_Long    delta  = table->block - old_base;    FT_Byte**  offset = table->elements;    FT_Byte**  limit  = offset + table->max_elems;    if ( delta )      for ( ; offset < limit; offset++ )      {        if ( offset[0] )          offset[0] += delta;      }  }  static  FT_Error  reallocate_t1_table( PS_Table*  table,                                 FT_Int     new_size )  {    FT_Memory  memory   = table->memory;    FT_Byte*   old_base = table->block;    FT_Error   error;    /* reallocate the base block */    if ( REALLOC( table->block, table->capacity, new_size ) )      return error;    table->capacity = new_size;    /* shift all offsets if necessary */    if ( old_base )      shift_elements( table, old_base );    return FT_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>                                                               */  /*    index  :: 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     index,                          void*      object,                          FT_Int     length )  {    if ( index < 0 || index > table->max_elems )    {      FT_ERROR(( "PS_Table_Add: invalid index\n" ));      return FT_Err_Invalid_Argument;    }    /* grow the base block if needed */    if ( table->cursor + length > table->capacity )    {      FT_Error  error;      FT_Int    new_size = table->capacity;      while ( new_size < table->cursor + length )        new_size += 1024;      error = reallocate_t1_table( table, new_size );      if ( error )        return error;    }    /* add the object to the base block and adjust offset */    table->elements[index] = table->block + table->cursor;    table->lengths [index] = length;    MEM_Copy( table->block + table->cursor, object, length );    table->cursor += length;    return FT_Err_Ok;  }  /*************************************************************************/  /*                                                                       */  /* <Function>                                                            */  /*    PS_Table_Done                                                      */  /*                                                                       */  /* <Description>                                                         */  /*    Finalizes a PS_Table (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;    /* should never fail, because rec.cursor <= rec.size */    old_base = table->block;    if ( !old_base )      return;    if ( REALLOC( table->block, table->capacity, table->cursor ) )      return;    table->capacity = table->cursor;    if ( old_base != table->block )      shift_elements( table, old_base );  }  FT_LOCAL_DEF  void  PS_Table_Release( PS_Table*  table )  {    FT_Memory  memory = table->memory;    if ( (FT_ULong)table->init == 0xDEADBEEFUL )    {      FREE( table->block );      FREE( table->elements );      FREE( table->lengths );      table->init = 0;    }  }  /*************************************************************************/  /*************************************************************************/  /*****                                                               *****/  /*****                            T1 PARSER                          *****/  /*****                                                               *****/  /*************************************************************************/  /*************************************************************************/#define IS_T1_WHITESPACE( c )  ( (c) == ' '  || (c) == '\t' )#define IS_T1_LINESPACE( c )   ( (c) == '\r' || (c) == '\n' )#define IS_T1_SPACE( c )  ( IS_T1_WHITESPACE( c ) || IS_T1_LINESPACE( c ) )  FT_LOCAL_DEF  void  T1_Skip_Spaces( T1_Parser*  parser )  {    FT_Byte* cur   = parser->cursor;    FT_Byte* limit = parser->limit;    while ( cur < limit )    {      FT_Byte  c = *cur;      if ( !IS_T1_SPACE( c ) )        break;      cur++;    }    parser->cursor = cur;  }  FT_LOCAL_DEF  void  T1_Skip_Alpha( T1_Parser*  parser )  {    FT_Byte* cur   = parser->cursor;    FT_Byte* limit = parser->limit;    while ( cur < limit )    {      FT_Byte  c = *cur;      if ( IS_T1_SPACE( c ) )        break;      cur++;    }    parser->cursor = cur;  }  FT_LOCAL_DEF  void  T1_ToToken( T1_Parser*  parser,                    T1_Token*   token )  {    FT_Byte*  cur;    FT_Byte*  limit;    FT_Byte   starter, ender;    FT_Int    embed;    token->type  = t1_token_none;    token->start = 0;    token->limit = 0;    /* first of all, skip space */    T1_Skip_Spaces( parser );    cur   = parser->cursor;    limit = parser->limit;    if ( cur < limit )    {      switch ( *cur )      {        /************* check for strings ***********************/      case '(':        token->type = t1_token_string;        ender = ')';        goto Lookup_Ender;        /************* check for programs/array ****************/      case '{':        token->type = t1_token_array;        ender = '}';        goto Lookup_Ender;        /************* check for table/array ******************/      case '[':        token->type = t1_token_array;        ender = ']';      Lookup_Ender:        embed   = 1;        starter = *cur++;        token->start = cur;        while ( cur < limit )        {          if ( *cur == starter )            embed++;          else if ( *cur == ender )          {            embed--;            if ( embed <= 0 )            {              token->limit = cur++;              break;            }          }          cur++;        }        break;        /* **************** otherwise, it's any token **********/      default:        token->start = cur++;        token->type  = t1_token_any;        while ( cur < limit && !IS_T1_SPACE( *cur ) )          cur++;        token->limit = cur;      }      if ( !token->limit )      {        token->start = 0;        token->type  = t1_token_none;      }      parser->cursor = cur;    }  }  FT_LOCAL_DEF  void  T1_ToTokenArray( T1_Parser*  parser,                         T1_Token*   tokens,                         FT_UInt     max_tokens,                         FT_Int*     pnum_tokens )  {    T1_Token  master;    *pnum_tokens = -1;    T1_ToToken( parser, &master );    if ( master.type == t1_token_array )    {      FT_Byte*   old_cursor = parser->cursor;      FT_Byte*   old_limit  = parser->limit;      T1_Token*  cur        = tokens;      T1_Token*  limit      = cur + max_tokens;      parser->cursor = master.start;      parser->limit  = master.limit;      while ( parser->cursor < parser->limit )      {        T1_Token  token;        T1_ToToken( parser, &token );        if ( !token.type )          break;        if ( cur < limit )          *cur = token;        cur++;      }      *pnum_tokens = cur - tokens;      parser->cursor = old_cursor;      parser->limit  = old_limit;    }  }  static  FT_Long  t1_toint( FT_Byte**  cursor,                     FT_Byte*   limit )  {    FT_Long   result = 0;    FT_Byte*  cur    = *cursor;

⌨️ 快捷键说明

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