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

📄 ttgload.c

📁 下载来的一个看图软件的源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
      if ( loader->exec )        loader->exec->glyphSize = 0;#endif      error = TT_Err_Ok;      goto Exit;    }    loader->byte_len = (FT_Int)count;    offset = loader->glyf_offset + offset;    /* access glyph frame */    error = face->access_glyph_frame( loader, glyph_index, offset, count );    if ( error )      goto Exit;    opened_frame = 1;    /* read first glyph header */    error = face->read_glyph_header( loader );    if ( error )      goto Fail;    contours_count = loader->n_contours;    count -= 10;    loader->pp1.x = loader->bbox.xMin - loader->left_bearing;    loader->pp1.y = 0;    loader->pp2.x = loader->pp1.x + loader->advance;    loader->pp2.y = 0;    if ( ( loader->load_flags & FT_LOAD_NO_SCALE ) == 0 )    {      loader->pp1.x = FT_MulFix( loader->pp1.x, x_scale );      loader->pp2.x = FT_MulFix( loader->pp2.x, x_scale );    }    /***********************************************************************/    /***********************************************************************/    /***********************************************************************/    /* if it is a simple glyph, load it */    if ( contours_count >= 0 )    {      /* check that we can add the contours to the glyph */      error = FT_GlyphLoader_CheckPoints( gloader, 0, contours_count );      if ( error )        goto Fail;      error = face->read_simple_glyph( loader );      if ( error )        goto Fail;#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER      {        TT_Size  size = (TT_Size)loader->size;        error = TT_Process_Simple_Glyph( loader,                                         (FT_Bool)( size && size->debug ) );      }#else      error = TT_Process_Simple_Glyph( loader, 0 );#endif      if ( error )        goto Fail;      FT_GlyphLoader_Add( gloader );      /* Note: We could have put the simple loader source there */      /*       but the code is fat enough already :-)           */    }    /***********************************************************************/    /***********************************************************************/    /***********************************************************************/    /* otherwise, load a composite! */    else if ( contours_count == -1 )    {      TT_GlyphSlot  glyph = (TT_GlyphSlot)loader->glyph;      FT_UInt       start_point;#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER      FT_UInt       start_contour;      FT_ULong      ins_pos;  /* position of composite instructions, if any */#endif      /* for each subglyph, read composite header */      start_point   = gloader->base.outline.n_points;#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER      start_contour = gloader->base.outline.n_contours;#endif      error = face->read_composite_glyph( loader );      if ( error )        goto Fail;#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER      ins_pos = loader->ins_pos;#endif      face->forget_glyph_frame( loader );      opened_frame = 0;      /* if the flag FT_LOAD_NO_RECURSE is set, we return the subglyph */      /* `as is' in the glyph slot (the client application will be     */      /* responsible for interpreting these data)...                   */      /*                                                               */      if ( loader->load_flags & FT_LOAD_NO_RECURSE )      {        /* set up remaining glyph fields */        FT_GlyphLoader_Add( gloader );        glyph->num_subglyphs = gloader->base.num_subglyphs;        glyph->format        = FT_GLYPH_FORMAT_COMPOSITE;        glyph->subglyphs     = gloader->base.subglyphs;        goto Exit;      }      /*********************************************************************/      /*********************************************************************/      /*********************************************************************/      /* Now, read each subglyph independently. */      {        FT_Int       n, num_base_points, num_new_points;        FT_SubGlyph  subglyph       = 0;        FT_UInt      num_subglyphs  = gloader->current.num_subglyphs;        FT_UInt      num_base_subgs = gloader->base.num_subglyphs;        FT_GlyphLoader_Add( gloader );        for ( n = 0; n < (FT_Int)num_subglyphs; n++ )        {          FT_Vector  pp1, pp2;          FT_Pos     x, y;          /* Each time we call load_truetype_glyph in this loop, the   */          /* value of `gloader.base.subglyphs' can change due to table */          /* reallocations.  We thus need to recompute the subglyph    */          /* pointer on each iteration.                                */          subglyph = gloader->base.subglyphs + num_base_subgs + n;          pp1 = loader->pp1;          pp2 = loader->pp2;          num_base_points = gloader->base.outline.n_points;          error = load_truetype_glyph( loader, subglyph->index,                                       recurse_count + 1 );          if ( error )            goto Fail;          /* restore subglyph pointer */          subglyph = gloader->base.subglyphs + num_base_subgs + n;          if ( subglyph->flags & USE_MY_METRICS )          {            pp1 = loader->pp1;            pp2 = loader->pp2;          }          else          {            loader->pp1 = pp1;            loader->pp2 = pp2;          }          num_points = gloader->base.outline.n_points;          num_new_points = num_points - num_base_points;          /* now perform the transform required for this subglyph */          if ( subglyph->flags & ( WE_HAVE_A_SCALE     |                                   WE_HAVE_AN_XY_SCALE |                                   WE_HAVE_A_2X2       ) )          {            FT_Vector*  cur   = gloader->base.outline.points +                                  num_base_points;            FT_Vector*  org   = gloader->base.extra_points +                                  num_base_points;            FT_Vector*  limit = cur + num_new_points;            for ( ; cur < limit; cur++, org++ )            {              FT_Vector_Transform( cur, &subglyph->transform );              FT_Vector_Transform( org, &subglyph->transform );            }          }          /* apply offset */          if ( !( subglyph->flags & ARGS_ARE_XY_VALUES ) )          {            FT_UInt     k = subglyph->arg1;            FT_UInt     l = subglyph->arg2;            FT_Vector*  p1;            FT_Vector*  p2;            if ( start_point + k >= (FT_UInt)num_base_points ||                               l >= (FT_UInt)num_new_points  )            {              error = TT_Err_Invalid_Composite;              goto Fail;            }            l += num_base_points;            p1 = gloader->base.outline.points + start_point + k;            p2 = gloader->base.outline.points + start_point + l;            x = p1->x - p2->x;            y = p1->y - p2->y;          }          else          {            x = subglyph->arg1;            y = subglyph->arg2;  /* Use a default value dependent on                                     */  /* TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED.  This is useful for old TT */  /* fonts which don't set the xxx_COMPONENT_OFFSET bit.                  */#ifdef TT_CONFIG_OPTION_COMPONENT_OFFSET_SCALED            if ( !( subglyph->flags & UNSCALED_COMPONENT_OFFSET ) &&#else            if (  ( subglyph->flags & SCALED_COMPONENT_OFFSET ) &&#endif                  ( subglyph->flags & ( WE_HAVE_A_SCALE     |                                        WE_HAVE_AN_XY_SCALE |                                        WE_HAVE_A_2X2       )) )            {#if 0  /*************************************************************************/  /*                                                                       */  /* This algorithm is what Apple documents.  But it doesn't work.         */  /*                                                                       */              int  a = subglyph->transform.xx > 0 ?  subglyph->transform.xx                                                  : -subglyph->transform.xx;              int  b = subglyph->transform.yx > 0 ?  subglyph->transform.yx                                                  : -subglyph->transform.yx;              int  c = subglyph->transform.xy > 0 ?  subglyph->transform.xy                                                  : -subglyph->transform.xy;              int  d = subglyph->transform.yy > 0 ? subglyph->transform.yy                                                  : -subglyph->transform.yy;              int  m = a > b ? a : b;              int  n = c > d ? c : d;              if ( a - b <= 33 && a - b >= -33 )                m *= 2;              if ( c - d <= 33 && c - d >= -33 )                n *= 2;              x = FT_MulFix( x, m );              y = FT_MulFix( y, n );#else /* 0 */  /*************************************************************************/  /*                                                                       */  /* This algorithm is a guess and works much better than the above.       */  /*                                                                       */              FT_Fixed  mac_xscale = FT_SqrtFixed(                                       FT_MulFix( subglyph->transform.xx,                                                  subglyph->transform.xx ) +                                       FT_MulFix( subglyph->transform.xy,                                                  subglyph->transform.xy) );              FT_Fixed  mac_yscale = FT_SqrtFixed(                                       FT_MulFix( subglyph->transform.yy,                                                  subglyph->transform.yy ) +                                       FT_MulFix( subglyph->transform.yx,                                                  subglyph->transform.yx ) );              x = FT_MulFix( x, mac_xscale );              y = FT_MulFix( y, mac_yscale );#endif /* 0 */            }            if ( !( loader->load_flags & FT_LOAD_NO_SCALE ) )            {              x = FT_MulFix( x, x_scale );              y = FT_MulFix( y, y_scale );              if ( subglyph->flags & ROUND_XY_TO_GRID )              {                x = ( x + 32 ) & -64;                y = ( y + 32 ) & -64;              }            }          }          if ( x || y )          {            translate_array( num_new_points,                             gloader->base.outline.points + num_base_points,                             x, y );            translate_array( num_new_points,                             gloader->base.extra_points + num_base_points,                             x, y );          }        }        /*******************************************************************/        /*******************************************************************/        /*******************************************************************/        /* we have finished loading all sub-glyphs; now, look for */        /* instructions for this composite!                       */#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER        if ( num_subglyphs > 0               &&             loader->exec                    &&             ins_pos > 0                     &&             subglyph->flags & WE_HAVE_INSTR )        {          FT_UShort       n_ins;          TT_ExecContext  exec = loader->exec;          TT_GlyphZone    pts;          FT_Vector*      pp1;          /* read size of instructions */          if ( FT_STREAM_SEEK( ins_pos ) ||               FT_READ_USHORT( n_ins ) )            goto Fail;          FT_TRACE5(( "  Instructions size = %d\n", n_ins ));          /* in some fonts? */          if ( n_ins == 0xFFFFU )            n_ins = 0;          /* check it */          if ( n_ins > face->max_profile.maxSizeOfInstructions )          {            FT_TRACE0(( "Too many instructions (%d) in composite glyph %ld\n",                        n_ins, subglyph->index ));            error = TT_Err_Too_Many_Hints;            goto Fail;          }          /* read the instructions */          if ( FT_STREAM_READ( exec->glyphIns, n_ins ) )            goto Fail;          glyph->control_data = exec->glyphIns;          glyph->control_len  = n_ins;          error = TT_Set_CodeRange( exec,                                    tt_coderange_glyph,                                    exec->glyphIns,                                    n_ins );          if ( error )            goto Fail;          error = FT_GlyphLoader_CheckPoints( gloader, num_points + 2, 0 );          if ( error )            goto Fail;          /* prepare the execution context */          tt_prepare_zone( &exec->pts, &gloader->base,                           start_point, start_contour );          pts = &exec->pts;          pts->n_points   = (short)(num_points + 2);          pts->n_contours = gloader->base.outline.n_contours;          /* add phantom points */          pp1    = pts->cur + num_points;          pp1[0] = loader->pp1;          pp1[1] = loader->pp2;          pts->tags[num_points    ] = 0;          pts->tags[num_points + 1] = 0;          /* if hinting, round the phantom points */          if ( IS_HINTED( loader->load_flags ) )          {            pp1[0].x = ( ( loader->pp1.x + 32 ) & -64 );            pp1[1].x = ( ( loader->pp2.x + 32 ) & -64 );          }          {            FT_UInt  k;            for ( k = 0; k < num_points; k++ )              pts->tags[k] &= FT_CURVE_TAG_ON;          }          cur_to_org( num_points + 2, pts );          /* now consider hinting */          if ( IS_HINTED( loader->load_flags ) && n_ins > 0 )          {            exec->is_composite     = TRUE;            exec->pedantic_hinting =              (FT_Bool)( loader->load_flags & FT_LOAD_PEDANTIC );            error = TT_Run_Context( exec, ((TT_Size)loader->size)->debug );            if ( error && exec->pedantic_hinting )              goto Fail;          }          /* save glyph origin and advance points */          loader->pp1 = pp1[0];          loader->pp2 = pp1[1];        }#endif /* TT_CONFIG_OPTION_BYTECODE_INTERPRETER */      }      /* end of composite loading */    }    else    {      /* invalid composite count ( negative but not -1 ) */      error = TT_Err_Invalid_Outline;      goto Fail;    }    /***********************************************************************/    /***********************************************************************/    /***********************************************************************/  Fail:    if ( opened_frame )      face->forget_glyph_frame( loader );  Exit:

⌨️ 快捷键说明

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