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

📄 ftstream.c

📁 qt-embedded-2.3.8.tar.gz源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************//*                                                                         *//*  ftstream.c                                                             *//*                                                                         *//*    I/O stream support (body).                                           *//*                                                                         *//*  Copyright 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/ftstream.h>#include <freetype/internal/ftdebug.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_stream  FT_BASE_DEF( void )  FT_New_Memory_Stream( FT_Library  library,                                             FT_Byte*    base,                                             FT_ULong    size,                                             FT_Stream   stream )  {    stream->memory = library->memory;    stream->base   = base;    stream->size   = size;    stream->pos    = 0;    stream->cursor = 0;    stream->read   = 0;    stream->close  = 0;  }  FT_BASE_DEF( FT_Error )  FT_Seek_Stream( FT_Stream  stream,                                           FT_ULong   pos )  {    FT_Error  error;    stream->pos = pos;    if ( stream->read )    {      if ( stream->read( stream, pos, 0, 0 ) )      {        FT_ERROR(( "FT_Seek_Stream:" ));        FT_ERROR(( " invalid i/o; pos = 0x%lx, size = 0x%lx\n",                   pos, stream->size ));        error = FT_Err_Invalid_Stream_Operation;      }      else        error = FT_Err_Ok;    }    /* note that seeking to the first position after the file is valid */    else if ( pos > stream->size )    {      FT_ERROR(( "FT_Seek_Stream:" ));      FT_ERROR(( " invalid i/o; pos = 0x%lx, size = 0x%lx\n",                 pos, stream->size ));      error = FT_Err_Invalid_Stream_Operation;    }    else      error = FT_Err_Ok;    return error;  }  FT_BASE_DEF( FT_Error )  FT_Skip_Stream( FT_Stream  stream,                                           FT_Long    distance )  {    return FT_Seek_Stream( stream, (FT_ULong)( stream->pos + distance ) );  }  FT_BASE_DEF( FT_Long )  FT_Stream_Pos( FT_Stream  stream )  {    return stream->pos;  }  FT_BASE_DEF( FT_Error )  FT_Read_Stream( FT_Stream  stream,                                           FT_Byte*   buffer,                                           FT_ULong   count )  {    return FT_Read_Stream_At( stream, stream->pos, buffer, count );  }  FT_BASE_DEF( FT_Error )  FT_Read_Stream_At( FT_Stream  stream,                                              FT_ULong   pos,                                              FT_Byte*   buffer,                                              FT_ULong   count )  {    FT_Error  error = FT_Err_Ok;    FT_ULong  read_bytes;    if ( pos >= stream->size )    {      FT_ERROR(( "FT_Read_Stream_At:" ));      FT_ERROR(( " invalid i/o; pos = 0x%lx, size = 0x%lx\n",                 pos, stream->size ));      return FT_Err_Invalid_Stream_Operation;    }    if ( stream->read )      read_bytes = stream->read( stream, pos, buffer, count );    else    {      read_bytes = stream->size - pos;      if ( read_bytes > count )        read_bytes = count;      MEM_Copy( buffer, stream->base + pos, read_bytes );    }    stream->pos = pos + read_bytes;    if ( read_bytes < count )    {      FT_ERROR(( "FT_Read_Stream_At:" ));      FT_ERROR(( " invalid read; expected %lu bytes, got %lu\n",                 count, read_bytes ));      error = FT_Err_Invalid_Stream_Operation;    }    return error;  }  FT_BASE_DEF( FT_Error )  FT_Extract_Frame( FT_Stream  stream,                                             FT_ULong   count,                                             FT_Byte**  pbytes )  {    FT_Error  error;    error = FT_Access_Frame( stream, count );    if ( !error )    {      *pbytes = (FT_Byte*)stream->cursor;      /* equivalent to FT_Forget_Frame(), with no memory block release */      stream->cursor = 0;      stream->limit  = 0;    }    return error;  }  FT_BASE_DEF( void )  FT_Release_Frame( FT_Stream  stream,                                         FT_Byte**  pbytes )  {    if ( stream->read )    {      FT_Memory  memory = stream->memory;      FREE( *pbytes );    }    *pbytes = 0;  }  FT_BASE_DEF( FT_Error )  FT_Access_Frame( FT_Stream  stream,                                            FT_ULong   count )  {    FT_Error  error = FT_Err_Ok;    FT_ULong  read_bytes;    /* check for nested frame access */    FT_Assert( stream && stream->cursor == 0 );    if ( stream->read )    {      /* allocate the frame in memory */      FT_Memory  memory = stream->memory;      if ( ALLOC( stream->base, count ) )        goto Exit;      /* read it */      read_bytes = stream->read( stream, stream->pos,                                 stream->base, count );      if ( read_bytes < count )      {        FT_ERROR(( "FT_Access_Frame:" ));        FT_ERROR(( " invalid read; expected %lu bytes, got %lu\n",                   count, read_bytes ));        FREE( stream->base );        error = FT_Err_Invalid_Stream_Operation;      }      stream->cursor = stream->base;      stream->limit  = stream->cursor + count;      stream->pos   += read_bytes;    }    else    {      /* check current and new position */      if ( stream->pos >= stream->size        ||           stream->pos + count > stream->size )      {        FT_ERROR(( "FT_Access_Frame:" ));        FT_ERROR(( " invalid i/o; pos = 0x%lx, count = %lu, size = 0x%lx\n",                   stream->pos, count, stream->size ));        error = FT_Err_Invalid_Stream_Operation;        goto Exit;      }      /* set cursor */      stream->cursor = stream->base + stream->pos;      stream->limit  = stream->cursor + count;      stream->pos   += count;    }  Exit:    return error;  }  FT_BASE_DEF( void )  FT_Forget_Frame( FT_Stream  stream )  {    /* IMPORTANT: The assertion stream->cursor != 0 was removed, given    */    /*            that it is possible to access a frame of length 0 in    */    /*            some weird fonts (usually, when accessing an array of   */    /*            0 records, like in some strange kern tables).           */    /*                                                                    */    /*  In this case, the loader code handles the 0-length table          */    /*  gracefully; however, stream.cursor is really set to 0 by the      */    /*  FT_Access_Frame() call, and this is not an error.                 */    /*                                                                    */    FT_Assert( stream );    if ( stream->read )    {      FT_Memory  memory = stream->memory;      FREE( stream->base );    }    stream->cursor = 0;    stream->limit  = 0;  }  FT_BASE_DEF( FT_Char )  FT_Get_Char( FT_Stream  stream )  {    FT_Char  result;    FT_Assert( stream && stream->cursor );    result = 0;    if ( stream->cursor < stream->limit )      result = *stream->cursor++;    return result;  }  FT_BASE_DEF( FT_Short )  FT_Get_Short( FT_Stream  stream )  {    FT_Byte*  p;    FT_Short  result;    FT_Assert( stream && stream->cursor );    result         = 0;    p              = stream->cursor;    if ( p + 1 < stream->limit )      result       = NEXT_Short( p );    stream->cursor = p;    return result;  }  FT_BASE_DEF( FT_Short )  FT_Get_ShortLE( FT_Stream  stream )  {    FT_Byte*  p;    FT_Short  result;    FT_Assert( stream && stream->cursor );    result         = 0;    p              = stream->cursor;    if ( p + 1 < stream->limit )      result       = NEXT_ShortLE( p );    stream->cursor = p;    return result;  }  FT_BASE_DEF( FT_Long )  FT_Get_Offset( FT_Stream  stream )  {    FT_Byte*  p;    FT_Long   result;    FT_Assert( stream && stream->cursor );    result         = 0;    p              = stream->cursor;    if ( p + 2 < stream->limit )      result       = NEXT_Offset( p );    stream->cursor = p;    return result;  }  FT_BASE_DEF( FT_Long )  FT_Get_Long( FT_Stream  stream )  {    FT_Byte*  p;    FT_Long   result;    FT_Assert( stream && stream->cursor );    result         = 0;    p              = stream->cursor;    if ( p + 3 < stream->limit )      result       = NEXT_Long( p );    stream->cursor = p;    return result;  }  FT_BASE_DEF( FT_Long )  FT_Get_LongLE( FT_Stream  stream )  {    FT_Byte*  p;    FT_Long   result;    FT_Assert( stream && stream->cursor );    result         = 0;    p              = stream->cursor;    if ( p + 3 < stream->limit )      result       = NEXT_LongLE( p );    stream->cursor = p;    return result;  }  FT_BASE_DEF( FT_Char )  FT_Read_Char( FT_Stream  stream,                                        FT_Error*  error )  {    FT_Byte  result = 0;    FT_Assert( stream );    *error = FT_Err_Ok;    if ( stream->read )    {      if ( stream->read( stream, stream->pos, &result, 1L ) != 1L )        goto Fail;    }    else    {      if ( stream->pos < stream->size )        result = stream->base[stream->pos];

⌨️ 快捷键说明

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