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

📄 t2parse.c

📁 qt-embedded-2.3.8.tar.gz源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************//*                                                                         *//*  t2parse.c                                                              *//*                                                                         *//*    OpenType parser (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.                                        *//*                                                                         *//***************************************************************************/#ifdef FT_FLAT_COMPILE#include "t2parse.h"#else#include <cff/t2parse.h>#endif#include <freetype/internal/t2errors.h>#include <freetype/internal/ftstream.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_t2parse#define T2_Err_Stack_Underflow   FT_Err_Invalid_Argument#define T2_Err_Syntax_Error      FT_Err_Invalid_Argument  enum  {    t2_kind_none = 0,    t2_kind_num,    t2_kind_fixed,    t2_kind_string,    t2_kind_bool,    t2_kind_delta,    t2_kind_callback,    t2_kind_max  /* do not remove */  };  /* now generate handlers for the most simple fields */  typedef FT_Error  (*T2_Field_Reader)( T2_Parser*  parser );  typedef struct  T2_Field_Handler_  {    int              kind;    int              code;    FT_UInt          offset;    FT_Byte          size;    T2_Field_Reader  reader;    FT_UInt          array_max;    FT_UInt          count_offset;  } T2_Field_Handler;  FT_LOCAL_DEF  void  T2_Parser_Init( T2_Parser*  parser,                        FT_UInt     code,                        void*       object )  {    MEM_Set( parser, 0, sizeof ( *parser ) );    parser->top         = parser->stack;    parser->object_code = code;    parser->object      = object;  }  /* reads an integer */  static  FT_Long  parse_t2_integer( FT_Byte*  start,                             FT_Byte*  limit )  {    FT_Byte*  p   = start;    FT_Int    v   = *p++;    FT_Long   val = 0;    if ( v == 28 )    {      if ( p + 2 > limit )        goto Bad;      val = (FT_Short)( ( (FT_Int)p[0] << 8 ) | p[1] );      p  += 2;    }    else if ( v == 29 )    {      if ( p + 4 > limit )        goto Bad;      val = ( (FT_Long)p[0] << 24 ) |            ( (FT_Long)p[1] << 16 ) |            ( (FT_Long)p[2] <<  8 ) |                       p[3];      p += 4;    }    else if ( v < 247 )    {      val = v - 139;    }    else if ( v < 251 )    {      if ( p + 1 > limit )        goto Bad;      val = ( v - 247 ) * 256 + p[0] + 108;      p++;    }    else    {      if ( p + 1 > limit )        goto Bad;      val = -( v - 251 ) * 256 - p[0] - 108;      p++;    }  Exit:    return val;  Bad:    val = 0;    goto Exit;  }  /* read a real */  static  FT_Fixed  parse_t2_real( FT_Byte*  start,                           FT_Byte*  limit,                           FT_Int    power_ten )  {    FT_Byte*  p    = start;    FT_Long   num, divider, result, exp;    FT_Int    sign = 0, exp_sign = 0;    FT_Byte   nib;    FT_Byte   phase;    result  = 0;    num     = 0;    divider = 1;    /* first of all, read the integer part */    phase = 4;    for (;;)    {      /* If we entered this iteration with phase == 4, we need to */      /* read a new byte.  This also skips past the intial 0x1E.  */      if ( phase )        p++;      /* Make sure we don't read past the end. */      if ( p >= limit )        goto Bad;      /* Get the nibble. */      nib   = ( p[0] >> phase ) & 0xF;      phase = 4 - phase;      if ( nib == 0xE )        sign = 1;      else if ( nib > 9 )        break;      else        result = result * 10 + nib;    }    /* read decimal part, if any */    if ( nib == 0xa )      for (;;)      {        /* If we entered this iteration with phase == 4, we need */        /* to read a new byte.                                   */        if ( phase )          p++;        /* Make sure we don't read past the end. */        if ( p >= limit )          goto Bad;        /* Get the nibble. */        nib   = ( p[0] >> phase ) & 0xF;        phase = 4 - phase;        if ( nib >= 10 )          break;        if (divider < 10000000L)        {          num      = num * 10 + nib;          divider *= 10;        }      }    /* read exponent, if any */    if ( nib == 12 )    {      exp_sign = 1;      nib      = 11;    }    if ( nib == 11 )    {      exp = 0;      for (;;)      {        /* If we entered this iteration with phase == 4, we need */        /* to read a new byte.                                   */        if ( phase )          p++;        /* Make sure we don't read past the end. */        if ( p >= limit )          goto Bad;        /* Get the nibble. */        nib   = ( p[0] >> phase ) & 0xF;        phase = 4 - phase;        if ( nib >= 10 )          break;        exp = exp * 10 + nib;      }      if ( exp_sign )        exp = -exp;      power_ten += exp;    }    /* raise to power of ten if needed */    while ( power_ten > 0 )    {      result = result * 10;      num    = num * 10;      power_ten--;    }    while ( power_ten < 0 )    {      result  = result / 10;      divider = divider * 10;      power_ten++;    }    if ( num )      result += FT_DivFix( num, divider );    if ( sign )      result = -result;  Exit:    return result;  Bad:    result = 0;    goto Exit;  }  /* read a number, either integer or real */  static  FT_Long  t2_parse_num( FT_Byte**  d )  {    return ( **d == 30 ? ( parse_t2_real( d[0], d[1], 0 ) >> 16 )                       : parse_t2_integer( d[0], d[1] ) );  }  /* reads a floating point number, either integer or real */  static  FT_Fixed  t2_parse_fixed( FT_Byte**  d )  {    return ( **d == 30 ? parse_t2_real( d[0], d[1], 0 )                       : parse_t2_integer( d[0], d[1] ) << 16 );  }  static  FT_Error  parse_font_matrix( T2_Parser*  parser )  {    CFF_Font_Dict*  dict   = (CFF_Font_Dict*)parser->object;    FT_Matrix*      matrix = &dict->font_matrix;    FT_Byte**       data   = parser->stack;    FT_Error        error;    error = T2_Err_Stack_Underflow;    if ( parser->top >= parser->stack + 4 )    {      matrix->xx = t2_parse_fixed( data++ );      matrix->yx = t2_parse_fixed( data++ );      matrix->xy = t2_parse_fixed( data++ );      matrix->yy = t2_parse_fixed( data   );      error = T2_Err_Ok;    }    return error;

⌨️ 快捷键说明

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