PageRenderTime 144ms CodeModel.GetById 49ms app.highlight 83ms RepoModel.GetById 2ms app.codeStats 0ms

/src/freetype/src/cff/cffgload.c

https://bitbucket.org/cabalistic/ogredeps/
C | 2972 lines | 2012 code | 597 blank | 363 comment | 262 complexity | a4c78591e5a1d86038c4f0b2f8c8ad39 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1/***************************************************************************/
   2/*                                                                         */
   3/*  cffgload.c                                                             */
   4/*                                                                         */
   5/*    OpenType Glyph Loader (body).                                        */
   6/*                                                                         */
   7/*  Copyright 1996-2012 by                                                 */
   8/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
   9/*                                                                         */
  10/*  This file is part of the FreeType project, and may only be used,       */
  11/*  modified, and distributed under the terms of the FreeType project      */
  12/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
  13/*  this file you indicate that you have read the license and              */
  14/*  understand and accept it fully.                                        */
  15/*                                                                         */
  16/***************************************************************************/
  17
  18
  19#include <ft2build.h>
  20#include FT_INTERNAL_DEBUG_H
  21#include FT_INTERNAL_STREAM_H
  22#include FT_INTERNAL_SFNT_H
  23#include FT_OUTLINE_H
  24
  25#include "cffobjs.h"
  26#include "cffload.h"
  27#include "cffgload.h"
  28
  29#include "cfferrs.h"
  30
  31
  32  /*************************************************************************/
  33  /*                                                                       */
  34  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
  35  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
  36  /* messages during execution.                                            */
  37  /*                                                                       */
  38#undef  FT_COMPONENT
  39#define FT_COMPONENT  trace_cffgload
  40
  41
  42  typedef enum  CFF_Operator_
  43  {
  44    cff_op_unknown = 0,
  45
  46    cff_op_rmoveto,
  47    cff_op_hmoveto,
  48    cff_op_vmoveto,
  49
  50    cff_op_rlineto,
  51    cff_op_hlineto,
  52    cff_op_vlineto,
  53
  54    cff_op_rrcurveto,
  55    cff_op_hhcurveto,
  56    cff_op_hvcurveto,
  57    cff_op_rcurveline,
  58    cff_op_rlinecurve,
  59    cff_op_vhcurveto,
  60    cff_op_vvcurveto,
  61
  62    cff_op_flex,
  63    cff_op_hflex,
  64    cff_op_hflex1,
  65    cff_op_flex1,
  66
  67    cff_op_endchar,
  68
  69    cff_op_hstem,
  70    cff_op_vstem,
  71    cff_op_hstemhm,
  72    cff_op_vstemhm,
  73
  74    cff_op_hintmask,
  75    cff_op_cntrmask,
  76    cff_op_dotsection,  /* deprecated, acts as no-op */
  77
  78    cff_op_abs,
  79    cff_op_add,
  80    cff_op_sub,
  81    cff_op_div,
  82    cff_op_neg,
  83    cff_op_random,
  84    cff_op_mul,
  85    cff_op_sqrt,
  86
  87    cff_op_blend,
  88
  89    cff_op_drop,
  90    cff_op_exch,
  91    cff_op_index,
  92    cff_op_roll,
  93    cff_op_dup,
  94
  95    cff_op_put,
  96    cff_op_get,
  97    cff_op_store,
  98    cff_op_load,
  99
 100    cff_op_and,
 101    cff_op_or,
 102    cff_op_not,
 103    cff_op_eq,
 104    cff_op_ifelse,
 105
 106    cff_op_callsubr,
 107    cff_op_callgsubr,
 108    cff_op_return,
 109
 110    /* Type 1 opcodes: invalid but seen in real life */
 111    cff_op_hsbw,
 112    cff_op_closepath,
 113    cff_op_callothersubr,
 114    cff_op_pop,
 115    cff_op_seac,
 116    cff_op_sbw,
 117    cff_op_setcurrentpoint,
 118
 119    /* do not remove */
 120    cff_op_max
 121
 122  } CFF_Operator;
 123
 124
 125#define CFF_COUNT_CHECK_WIDTH  0x80
 126#define CFF_COUNT_EXACT        0x40
 127#define CFF_COUNT_CLEAR_STACK  0x20
 128
 129  /* count values which have the `CFF_COUNT_CHECK_WIDTH' flag set are  */
 130  /* used for checking the width and requested numbers of arguments    */
 131  /* only; they are set to zero afterwards                             */
 132
 133  /* the other two flags are informative only and unused currently     */
 134
 135  static const FT_Byte  cff_argument_counts[] =
 136  {
 137    0,  /* unknown */
 138
 139    2 | CFF_COUNT_CHECK_WIDTH | CFF_COUNT_EXACT, /* rmoveto */
 140    1 | CFF_COUNT_CHECK_WIDTH | CFF_COUNT_EXACT,
 141    1 | CFF_COUNT_CHECK_WIDTH | CFF_COUNT_EXACT,
 142
 143    0 | CFF_COUNT_CLEAR_STACK, /* rlineto */
 144    0 | CFF_COUNT_CLEAR_STACK,
 145    0 | CFF_COUNT_CLEAR_STACK,
 146
 147    0 | CFF_COUNT_CLEAR_STACK, /* rrcurveto */
 148    0 | CFF_COUNT_CLEAR_STACK,
 149    0 | CFF_COUNT_CLEAR_STACK,
 150    0 | CFF_COUNT_CLEAR_STACK,
 151    0 | CFF_COUNT_CLEAR_STACK,
 152    0 | CFF_COUNT_CLEAR_STACK,
 153    0 | CFF_COUNT_CLEAR_STACK,
 154
 155    13, /* flex */
 156    7,
 157    9,
 158    11,
 159
 160    0 | CFF_COUNT_CHECK_WIDTH, /* endchar */
 161
 162    2 | CFF_COUNT_CHECK_WIDTH, /* hstem */
 163    2 | CFF_COUNT_CHECK_WIDTH,
 164    2 | CFF_COUNT_CHECK_WIDTH,
 165    2 | CFF_COUNT_CHECK_WIDTH,
 166
 167    0 | CFF_COUNT_CHECK_WIDTH, /* hintmask */
 168    0 | CFF_COUNT_CHECK_WIDTH, /* cntrmask */
 169    0, /* dotsection */
 170
 171    1, /* abs */
 172    2,
 173    2,
 174    2,
 175    1,
 176    0,
 177    2,
 178    1,
 179
 180    1, /* blend */
 181
 182    1, /* drop */
 183    2,
 184    1,
 185    2,
 186    1,
 187
 188    2, /* put */
 189    1,
 190    4,
 191    3,
 192
 193    2, /* and */
 194    2,
 195    1,
 196    2,
 197    4,
 198
 199    1, /* callsubr */
 200    1,
 201    0,
 202
 203    2, /* hsbw */
 204    0,
 205    0,
 206    0,
 207    5, /* seac */
 208    4, /* sbw */
 209    2  /* setcurrentpoint */
 210  };
 211
 212
 213  /*************************************************************************/
 214  /*************************************************************************/
 215  /*************************************************************************/
 216  /**********                                                      *********/
 217  /**********                                                      *********/
 218  /**********             GENERIC CHARSTRING PARSING               *********/
 219  /**********                                                      *********/
 220  /**********                                                      *********/
 221  /*************************************************************************/
 222  /*************************************************************************/
 223  /*************************************************************************/
 224
 225
 226  /*************************************************************************/
 227  /*                                                                       */
 228  /* <Function>                                                            */
 229  /*    cff_builder_init                                                   */
 230  /*                                                                       */
 231  /* <Description>                                                         */
 232  /*    Initializes a given glyph builder.                                 */
 233  /*                                                                       */
 234  /* <InOut>                                                               */
 235  /*    builder :: A pointer to the glyph builder to initialize.           */
 236  /*                                                                       */
 237  /* <Input>                                                               */
 238  /*    face    :: The current face object.                                */
 239  /*                                                                       */
 240  /*    size    :: The current size object.                                */
 241  /*                                                                       */
 242  /*    glyph   :: The current glyph object.                               */
 243  /*                                                                       */
 244  /*    hinting :: Whether hinting is active.                              */
 245  /*                                                                       */
 246  static void
 247  cff_builder_init( CFF_Builder*   builder,
 248                    TT_Face        face,
 249                    CFF_Size       size,
 250                    CFF_GlyphSlot  glyph,
 251                    FT_Bool        hinting )
 252  {
 253    builder->path_begun  = 0;
 254    builder->load_points = 1;
 255
 256    builder->face   = face;
 257    builder->glyph  = glyph;
 258    builder->memory = face->root.memory;
 259
 260    if ( glyph )
 261    {
 262      FT_GlyphLoader  loader = glyph->root.internal->loader;
 263
 264
 265      builder->loader  = loader;
 266      builder->base    = &loader->base.outline;
 267      builder->current = &loader->current.outline;
 268      FT_GlyphLoader_Rewind( loader );
 269
 270      builder->hints_globals = 0;
 271      builder->hints_funcs   = 0;
 272
 273      if ( hinting && size )
 274      {
 275        CFF_Internal  internal = (CFF_Internal)size->root.internal;
 276
 277
 278        builder->hints_globals = (void *)internal->topfont;
 279        builder->hints_funcs   = glyph->root.internal->glyph_hints;
 280      }
 281    }
 282
 283    builder->pos_x = 0;
 284    builder->pos_y = 0;
 285
 286    builder->left_bearing.x = 0;
 287    builder->left_bearing.y = 0;
 288    builder->advance.x      = 0;
 289    builder->advance.y      = 0;
 290  }
 291
 292
 293  /*************************************************************************/
 294  /*                                                                       */
 295  /* <Function>                                                            */
 296  /*    cff_builder_done                                                   */
 297  /*                                                                       */
 298  /* <Description>                                                         */
 299  /*    Finalizes a given glyph builder.  Its contents can still be used   */
 300  /*    after the call, but the function saves important information       */
 301  /*    within the corresponding glyph slot.                               */
 302  /*                                                                       */
 303  /* <Input>                                                               */
 304  /*    builder :: A pointer to the glyph builder to finalize.             */
 305  /*                                                                       */
 306  static void
 307  cff_builder_done( CFF_Builder*  builder )
 308  {
 309    CFF_GlyphSlot  glyph = builder->glyph;
 310
 311
 312    if ( glyph )
 313      glyph->root.outline = *builder->base;
 314  }
 315
 316
 317  /*************************************************************************/
 318  /*                                                                       */
 319  /* <Function>                                                            */
 320  /*    cff_compute_bias                                                   */
 321  /*                                                                       */
 322  /* <Description>                                                         */
 323  /*    Computes the bias value in dependence of the number of glyph       */
 324  /*    subroutines.                                                       */
 325  /*                                                                       */
 326  /* <Input>                                                               */
 327  /*    in_charstring_type :: The `CharstringType' value of the top DICT   */
 328  /*                          dictionary.                                  */
 329  /*                                                                       */
 330  /*    num_subrs          :: The number of glyph subroutines.             */
 331  /*                                                                       */
 332  /* <Return>                                                              */
 333  /*    The bias value.                                                    */
 334  static FT_Int
 335  cff_compute_bias( FT_Int   in_charstring_type,
 336                    FT_UInt  num_subrs )
 337  {
 338    FT_Int  result;
 339
 340
 341    if ( in_charstring_type == 1 )
 342      result = 0;
 343    else if ( num_subrs < 1240 )
 344      result = 107;
 345    else if ( num_subrs < 33900U )
 346      result = 1131;
 347    else
 348      result = 32768U;
 349
 350    return result;
 351  }
 352
 353
 354  /*************************************************************************/
 355  /*                                                                       */
 356  /* <Function>                                                            */
 357  /*    cff_decoder_init                                                   */
 358  /*                                                                       */
 359  /* <Description>                                                         */
 360  /*    Initializes a given glyph decoder.                                 */
 361  /*                                                                       */
 362  /* <InOut>                                                               */
 363  /*    decoder :: A pointer to the glyph builder to initialize.           */
 364  /*                                                                       */
 365  /* <Input>                                                               */
 366  /*    face      :: The current face object.                              */
 367  /*                                                                       */
 368  /*    size      :: The current size object.                              */
 369  /*                                                                       */
 370  /*    slot      :: The current glyph object.                             */
 371  /*                                                                       */
 372  /*    hinting   :: Whether hinting is active.                            */
 373  /*                                                                       */
 374  /*    hint_mode :: The hinting mode.                                     */
 375  /*                                                                       */
 376  FT_LOCAL_DEF( void )
 377  cff_decoder_init( CFF_Decoder*    decoder,
 378                    TT_Face         face,
 379                    CFF_Size        size,
 380                    CFF_GlyphSlot   slot,
 381                    FT_Bool         hinting,
 382                    FT_Render_Mode  hint_mode )
 383  {
 384    CFF_Font  cff = (CFF_Font)face->extra.data;
 385
 386
 387    /* clear everything */
 388    FT_MEM_ZERO( decoder, sizeof ( *decoder ) );
 389
 390    /* initialize builder */
 391    cff_builder_init( &decoder->builder, face, size, slot, hinting );
 392
 393    /* initialize Type2 decoder */
 394    decoder->cff          = cff;
 395    decoder->num_globals  = cff->global_subrs_index.count;
 396    decoder->globals      = cff->global_subrs;
 397    decoder->globals_bias = cff_compute_bias(
 398                              cff->top_font.font_dict.charstring_type,
 399                              decoder->num_globals );
 400
 401    decoder->hint_mode    = hint_mode;
 402  }
 403
 404
 405  /* this function is used to select the subfont */
 406  /* and the locals subrs array                  */
 407  FT_LOCAL_DEF( FT_Error )
 408  cff_decoder_prepare( CFF_Decoder*  decoder,
 409                       CFF_Size      size,
 410                       FT_UInt       glyph_index )
 411  {
 412    CFF_Builder  *builder = &decoder->builder;
 413    CFF_Font      cff     = (CFF_Font)builder->face->extra.data;
 414    CFF_SubFont   sub     = &cff->top_font;
 415    FT_Error      error   = CFF_Err_Ok;
 416
 417
 418    /* manage CID fonts */
 419    if ( cff->num_subfonts )
 420    {
 421      FT_Byte  fd_index = cff_fd_select_get( &cff->fd_select, glyph_index );
 422
 423
 424      if ( fd_index >= cff->num_subfonts )
 425      {
 426        FT_TRACE4(( "cff_decoder_prepare: invalid CID subfont index\n" ));
 427        error = CFF_Err_Invalid_File_Format;
 428        goto Exit;
 429      }
 430
 431      FT_TRACE3(( "glyph index %d (subfont %d):\n", glyph_index, fd_index ));
 432
 433      sub = cff->subfonts[fd_index];
 434
 435      if ( builder->hints_funcs && size )
 436      {
 437        CFF_Internal  internal = (CFF_Internal)size->root.internal;
 438
 439
 440        /* for CFFs without subfonts, this value has already been set */
 441        builder->hints_globals = (void *)internal->subfonts[fd_index];
 442      }
 443    }
 444#ifdef FT_DEBUG_LEVEL_TRACE
 445    else
 446      FT_TRACE3(( "glyph index %d:\n", glyph_index ));
 447#endif
 448
 449    decoder->num_locals    = sub->local_subrs_index.count;
 450    decoder->locals        = sub->local_subrs;
 451    decoder->locals_bias   = cff_compute_bias(
 452                               decoder->cff->top_font.font_dict.charstring_type,
 453                               decoder->num_locals );
 454
 455    decoder->glyph_width   = sub->private_dict.default_width;
 456    decoder->nominal_width = sub->private_dict.nominal_width;
 457
 458  Exit:
 459    return error;
 460  }
 461
 462
 463  /* check that there is enough space for `count' more points */
 464  static FT_Error
 465  check_points( CFF_Builder*  builder,
 466                FT_Int        count )
 467  {
 468    return FT_GLYPHLOADER_CHECK_POINTS( builder->loader, count, 0 );
 469  }
 470
 471
 472  /* add a new point, do not check space */
 473  static void
 474  cff_builder_add_point( CFF_Builder*  builder,
 475                         FT_Pos        x,
 476                         FT_Pos        y,
 477                         FT_Byte       flag )
 478  {
 479    FT_Outline*  outline = builder->current;
 480
 481
 482    if ( builder->load_points )
 483    {
 484      FT_Vector*  point   = outline->points + outline->n_points;
 485      FT_Byte*    control = (FT_Byte*)outline->tags + outline->n_points;
 486
 487
 488      point->x = x >> 16;
 489      point->y = y >> 16;
 490      *control = (FT_Byte)( flag ? FT_CURVE_TAG_ON : FT_CURVE_TAG_CUBIC );
 491    }
 492
 493    outline->n_points++;
 494  }
 495
 496
 497  /* check space for a new on-curve point, then add it */
 498  static FT_Error
 499  cff_builder_add_point1( CFF_Builder*  builder,
 500                          FT_Pos        x,
 501                          FT_Pos        y )
 502  {
 503    FT_Error  error;
 504
 505
 506    error = check_points( builder, 1 );
 507    if ( !error )
 508      cff_builder_add_point( builder, x, y, 1 );
 509
 510    return error;
 511  }
 512
 513
 514  /* check space for a new contour, then add it */
 515  static FT_Error
 516  cff_builder_add_contour( CFF_Builder*  builder )
 517  {
 518    FT_Outline*  outline = builder->current;
 519    FT_Error     error;
 520
 521
 522    if ( !builder->load_points )
 523    {
 524      outline->n_contours++;
 525      return CFF_Err_Ok;
 526    }
 527
 528    error = FT_GLYPHLOADER_CHECK_POINTS( builder->loader, 0, 1 );
 529    if ( !error )
 530    {
 531      if ( outline->n_contours > 0 )
 532        outline->contours[outline->n_contours - 1] =
 533          (short)( outline->n_points - 1 );
 534
 535      outline->n_contours++;
 536    }
 537
 538    return error;
 539  }
 540
 541
 542  /* if a path was begun, add its first on-curve point */
 543  static FT_Error
 544  cff_builder_start_point( CFF_Builder*  builder,
 545                           FT_Pos        x,
 546                           FT_Pos        y )
 547  {
 548    FT_Error  error = CFF_Err_Ok;
 549
 550
 551    /* test whether we are building a new contour */
 552    if ( !builder->path_begun )
 553    {
 554      builder->path_begun = 1;
 555      error = cff_builder_add_contour( builder );
 556      if ( !error )
 557        error = cff_builder_add_point1( builder, x, y );
 558    }
 559
 560    return error;
 561  }
 562
 563
 564  /* close the current contour */
 565  static void
 566  cff_builder_close_contour( CFF_Builder*  builder )
 567  {
 568    FT_Outline*  outline = builder->current;
 569    FT_Int       first;
 570
 571
 572    if ( !outline )
 573      return;
 574
 575    first = outline->n_contours <= 1
 576            ? 0 : outline->contours[outline->n_contours - 2] + 1;
 577
 578    /* We must not include the last point in the path if it */
 579    /* is located on the first point.                       */
 580    if ( outline->n_points > 1 )
 581    {
 582      FT_Vector*  p1      = outline->points + first;
 583      FT_Vector*  p2      = outline->points + outline->n_points - 1;
 584      FT_Byte*    control = (FT_Byte*)outline->tags + outline->n_points - 1;
 585
 586
 587      /* `delete' last point only if it coincides with the first    */
 588      /* point and if it is not a control point (which can happen). */
 589      if ( p1->x == p2->x && p1->y == p2->y )
 590        if ( *control == FT_CURVE_TAG_ON )
 591          outline->n_points--;
 592    }
 593
 594    if ( outline->n_contours > 0 )
 595    {
 596      /* Don't add contours only consisting of one point, i.e., */
 597      /* check whether begin point and last point are the same. */
 598      if ( first == outline->n_points - 1 )
 599      {
 600        outline->n_contours--;
 601        outline->n_points--;
 602      }
 603      else
 604        outline->contours[outline->n_contours - 1] =
 605          (short)( outline->n_points - 1 );
 606    }
 607  }
 608
 609
 610  static FT_Int
 611  cff_lookup_glyph_by_stdcharcode( CFF_Font  cff,
 612                                   FT_Int    charcode )
 613  {
 614    FT_UInt    n;
 615    FT_UShort  glyph_sid;
 616
 617
 618    /* CID-keyed fonts don't have glyph names */
 619    if ( !cff->charset.sids )
 620      return -1;
 621
 622    /* check range of standard char code */
 623    if ( charcode < 0 || charcode > 255 )
 624      return -1;
 625
 626    /* Get code to SID mapping from `cff_standard_encoding'. */
 627    glyph_sid = cff_get_standard_encoding( (FT_UInt)charcode );
 628
 629    for ( n = 0; n < cff->num_glyphs; n++ )
 630    {
 631      if ( cff->charset.sids[n] == glyph_sid )
 632        return n;
 633    }
 634
 635    return -1;
 636  }
 637
 638
 639  static FT_Error
 640  cff_get_glyph_data( TT_Face    face,
 641                      FT_UInt    glyph_index,
 642                      FT_Byte**  pointer,
 643                      FT_ULong*  length )
 644  {
 645#ifdef FT_CONFIG_OPTION_INCREMENTAL
 646    /* For incremental fonts get the character data using the */
 647    /* callback function.                                     */
 648    if ( face->root.internal->incremental_interface )
 649    {
 650      FT_Data   data;
 651      FT_Error  error =
 652                  face->root.internal->incremental_interface->funcs->get_glyph_data(
 653                    face->root.internal->incremental_interface->object,
 654                    glyph_index, &data );
 655
 656
 657      *pointer = (FT_Byte*)data.pointer;
 658      *length = data.length;
 659
 660      return error;
 661    }
 662    else
 663#endif /* FT_CONFIG_OPTION_INCREMENTAL */
 664
 665    {
 666      CFF_Font  cff  = (CFF_Font)(face->extra.data);
 667
 668
 669      return cff_index_access_element( &cff->charstrings_index, glyph_index,
 670                                       pointer, length );
 671    }
 672  }
 673
 674
 675  static void
 676  cff_free_glyph_data( TT_Face    face,
 677                       FT_Byte**  pointer,
 678                       FT_ULong   length )
 679  {
 680#ifndef FT_CONFIG_OPTION_INCREMENTAL
 681    FT_UNUSED( length );
 682#endif
 683
 684#ifdef FT_CONFIG_OPTION_INCREMENTAL
 685    /* For incremental fonts get the character data using the */
 686    /* callback function.                                     */
 687    if ( face->root.internal->incremental_interface )
 688    {
 689      FT_Data data;
 690
 691
 692      data.pointer = *pointer;
 693      data.length  = length;
 694
 695      face->root.internal->incremental_interface->funcs->free_glyph_data(
 696        face->root.internal->incremental_interface->object, &data );
 697    }
 698    else
 699#endif /* FT_CONFIG_OPTION_INCREMENTAL */
 700
 701    {
 702      CFF_Font  cff = (CFF_Font)(face->extra.data);
 703
 704
 705      cff_index_forget_element( &cff->charstrings_index, pointer );
 706    }
 707  }
 708
 709
 710  static FT_Error
 711  cff_operator_seac( CFF_Decoder*  decoder,
 712                     FT_Pos        asb,
 713                     FT_Pos        adx,
 714                     FT_Pos        ady,
 715                     FT_Int        bchar,
 716                     FT_Int        achar )
 717  {
 718    FT_Error      error;
 719    CFF_Builder*  builder = &decoder->builder;
 720    FT_Int        bchar_index, achar_index;
 721    TT_Face       face = decoder->builder.face;
 722    FT_Vector     left_bearing, advance;
 723    FT_Byte*      charstring;
 724    FT_ULong      charstring_len;
 725    FT_Pos        glyph_width;
 726
 727
 728    if ( decoder->seac )
 729    {
 730      FT_ERROR(( "cff_operator_seac: invalid nested seac\n" ));
 731      return CFF_Err_Syntax_Error;
 732    }
 733
 734    adx += decoder->builder.left_bearing.x;
 735    ady += decoder->builder.left_bearing.y;
 736
 737#ifdef FT_CONFIG_OPTION_INCREMENTAL
 738    /* Incremental fonts don't necessarily have valid charsets.        */
 739    /* They use the character code, not the glyph index, in this case. */
 740    if ( face->root.internal->incremental_interface )
 741    {
 742      bchar_index = bchar;
 743      achar_index = achar;
 744    }
 745    else
 746#endif /* FT_CONFIG_OPTION_INCREMENTAL */
 747    {
 748      CFF_Font cff = (CFF_Font)(face->extra.data);
 749
 750
 751      bchar_index = cff_lookup_glyph_by_stdcharcode( cff, bchar );
 752      achar_index = cff_lookup_glyph_by_stdcharcode( cff, achar );
 753    }
 754
 755    if ( bchar_index < 0 || achar_index < 0 )
 756    {
 757      FT_ERROR(( "cff_operator_seac:"
 758                 " invalid seac character code arguments\n" ));
 759      return CFF_Err_Syntax_Error;
 760    }
 761
 762    /* If we are trying to load a composite glyph, do not load the */
 763    /* accent character and return the array of subglyphs.         */
 764    if ( builder->no_recurse )
 765    {
 766      FT_GlyphSlot    glyph  = (FT_GlyphSlot)builder->glyph;
 767      FT_GlyphLoader  loader = glyph->internal->loader;
 768      FT_SubGlyph     subg;
 769
 770
 771      /* reallocate subglyph array if necessary */
 772      error = FT_GlyphLoader_CheckSubGlyphs( loader, 2 );
 773      if ( error )
 774        goto Exit;
 775
 776      subg = loader->current.subglyphs;
 777
 778      /* subglyph 0 = base character */
 779      subg->index = bchar_index;
 780      subg->flags = FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES |
 781                    FT_SUBGLYPH_FLAG_USE_MY_METRICS;
 782      subg->arg1  = 0;
 783      subg->arg2  = 0;
 784      subg++;
 785
 786      /* subglyph 1 = accent character */
 787      subg->index = achar_index;
 788      subg->flags = FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES;
 789      subg->arg1  = (FT_Int)( adx >> 16 );
 790      subg->arg2  = (FT_Int)( ady >> 16 );
 791
 792      /* set up remaining glyph fields */
 793      glyph->num_subglyphs = 2;
 794      glyph->subglyphs     = loader->base.subglyphs;
 795      glyph->format        = FT_GLYPH_FORMAT_COMPOSITE;
 796
 797      loader->current.num_subglyphs = 2;
 798    }
 799
 800    FT_GlyphLoader_Prepare( builder->loader );
 801
 802    /* First load `bchar' in builder */
 803    error = cff_get_glyph_data( face, bchar_index,
 804                                &charstring, &charstring_len );
 805    if ( !error )
 806    {
 807      /* the seac operator must not be nested */
 808      decoder->seac = TRUE;
 809      error = cff_decoder_parse_charstrings( decoder, charstring,
 810                                             charstring_len );
 811      decoder->seac = FALSE;
 812
 813      cff_free_glyph_data( face, &charstring, charstring_len );
 814
 815      if ( error )
 816        goto Exit;
 817    }
 818
 819    /* Save the left bearing, advance and glyph width of the base */
 820    /* character as they will be erased by the next load.         */
 821
 822    left_bearing = builder->left_bearing;
 823    advance      = builder->advance;
 824    glyph_width  = decoder->glyph_width;
 825
 826    builder->left_bearing.x = 0;
 827    builder->left_bearing.y = 0;
 828
 829    builder->pos_x = adx - asb;
 830    builder->pos_y = ady;
 831
 832    /* Now load `achar' on top of the base outline. */
 833    error = cff_get_glyph_data( face, achar_index,
 834                                &charstring, &charstring_len );
 835    if ( !error )
 836    {
 837      /* the seac operator must not be nested */
 838      decoder->seac = TRUE;
 839      error = cff_decoder_parse_charstrings( decoder, charstring,
 840                                             charstring_len );
 841      decoder->seac = FALSE;
 842
 843      cff_free_glyph_data( face, &charstring, charstring_len );
 844
 845      if ( error )
 846        goto Exit;
 847    }
 848
 849    /* Restore the left side bearing, advance and glyph width */
 850    /* of the base character.                                 */
 851    builder->left_bearing = left_bearing;
 852    builder->advance      = advance;
 853    decoder->glyph_width  = glyph_width;
 854
 855    builder->pos_x = 0;
 856    builder->pos_y = 0;
 857
 858  Exit:
 859    return error;
 860  }
 861
 862
 863  /*************************************************************************/
 864  /*                                                                       */
 865  /* <Function>                                                            */
 866  /*    cff_decoder_parse_charstrings                                      */
 867  /*                                                                       */
 868  /* <Description>                                                         */
 869  /*    Parses a given Type 2 charstrings program.                         */
 870  /*                                                                       */
 871  /* <InOut>                                                               */
 872  /*    decoder         :: The current Type 1 decoder.                     */
 873  /*                                                                       */
 874  /* <Input>                                                               */
 875  /*    charstring_base :: The base of the charstring stream.              */
 876  /*                                                                       */
 877  /*    charstring_len  :: The length in bytes of the charstring stream.   */
 878  /*                                                                       */
 879  /* <Return>                                                              */
 880  /*    FreeType error code.  0 means success.                             */
 881  /*                                                                       */
 882  FT_LOCAL_DEF( FT_Error )
 883  cff_decoder_parse_charstrings( CFF_Decoder*  decoder,
 884                                 FT_Byte*      charstring_base,
 885                                 FT_ULong      charstring_len )
 886  {
 887    FT_Error           error;
 888    CFF_Decoder_Zone*  zone;
 889    FT_Byte*           ip;
 890    FT_Byte*           limit;
 891    CFF_Builder*       builder = &decoder->builder;
 892    FT_Pos             x, y;
 893    FT_Fixed           seed;
 894    FT_Fixed*          stack;
 895    FT_Int             charstring_type =
 896                         decoder->cff->top_font.font_dict.charstring_type;
 897
 898    T2_Hints_Funcs     hinter;
 899
 900
 901    /* set default width */
 902    decoder->num_hints  = 0;
 903    decoder->read_width = 1;
 904
 905    /* compute random seed from stack address of parameter */
 906    seed = (FT_Fixed)( ( (FT_PtrDist)(char*)&seed              ^
 907                         (FT_PtrDist)(char*)&decoder           ^
 908                         (FT_PtrDist)(char*)&charstring_base ) &
 909                         FT_ULONG_MAX ) ;
 910    seed = ( seed ^ ( seed >> 10 ) ^ ( seed >> 20 ) ) & 0xFFFFL;
 911    if ( seed == 0 )
 912      seed = 0x7384;
 913
 914    /* initialize the decoder */
 915    decoder->top  = decoder->stack;
 916    decoder->zone = decoder->zones;
 917    zone          = decoder->zones;
 918    stack         = decoder->top;
 919
 920    hinter = (T2_Hints_Funcs)builder->hints_funcs;
 921
 922    builder->path_begun = 0;
 923
 924    zone->base           = charstring_base;
 925    limit = zone->limit  = charstring_base + charstring_len;
 926    ip    = zone->cursor = zone->base;
 927
 928    error = CFF_Err_Ok;
 929
 930    x = builder->pos_x;
 931    y = builder->pos_y;
 932
 933    /* begin hints recording session, if any */
 934    if ( hinter )
 935      hinter->open( hinter->hints );
 936
 937    /* now execute loop */
 938    while ( ip < limit )
 939    {
 940      CFF_Operator  op;
 941      FT_Byte       v;
 942
 943
 944      /********************************************************************/
 945      /*                                                                  */
 946      /* Decode operator or operand                                       */
 947      /*                                                                  */
 948      v = *ip++;
 949      if ( v >= 32 || v == 28 )
 950      {
 951        FT_Int    shift = 16;
 952        FT_Int32  val;
 953
 954
 955        /* this is an operand, push it on the stack */
 956        if ( v == 28 )
 957        {
 958          if ( ip + 1 >= limit )
 959            goto Syntax_Error;
 960          val = (FT_Short)( ( (FT_Short)ip[0] << 8 ) | ip[1] );
 961          ip += 2;
 962        }
 963        else if ( v < 247 )
 964          val = (FT_Int32)v - 139;
 965        else if ( v < 251 )
 966        {
 967          if ( ip >= limit )
 968            goto Syntax_Error;
 969          val = ( (FT_Int32)v - 247 ) * 256 + *ip++ + 108;
 970        }
 971        else if ( v < 255 )
 972        {
 973          if ( ip >= limit )
 974            goto Syntax_Error;
 975          val = -( (FT_Int32)v - 251 ) * 256 - *ip++ - 108;
 976        }
 977        else
 978        {
 979          if ( ip + 3 >= limit )
 980            goto Syntax_Error;
 981          val = ( (FT_Int32)ip[0] << 24 ) |
 982                ( (FT_Int32)ip[1] << 16 ) |
 983                ( (FT_Int32)ip[2] <<  8 ) |
 984                            ip[3];
 985          ip    += 4;
 986          if ( charstring_type == 2 )
 987            shift = 0;
 988        }
 989        if ( decoder->top - stack >= CFF_MAX_OPERANDS )
 990          goto Stack_Overflow;
 991
 992        val           <<= shift;
 993        *decoder->top++ = val;
 994
 995#ifdef FT_DEBUG_LEVEL_TRACE
 996        if ( !( val & 0xFFFFL ) )
 997          FT_TRACE4(( " %ld", (FT_Int32)( val >> 16 ) ));
 998        else
 999          FT_TRACE4(( " %.2f", val / 65536.0 ));
1000#endif
1001
1002      }
1003      else
1004      {
1005        /* The specification says that normally arguments are to be taken */
1006        /* from the bottom of the stack.  However, this seems not to be   */
1007        /* correct, at least for Acroread 7.0.8 on GNU/Linux: It pops the */
1008        /* arguments similar to a PS interpreter.                         */
1009
1010        FT_Fixed*  args     = decoder->top;
1011        FT_Int     num_args = (FT_Int)( args - decoder->stack );
1012        FT_Int     req_args;
1013
1014
1015        /* find operator */
1016        op = cff_op_unknown;
1017
1018        switch ( v )
1019        {
1020        case 1:
1021          op = cff_op_hstem;
1022          break;
1023        case 3:
1024          op = cff_op_vstem;
1025          break;
1026        case 4:
1027          op = cff_op_vmoveto;
1028          break;
1029        case 5:
1030          op = cff_op_rlineto;
1031          break;
1032        case 6:
1033          op = cff_op_hlineto;
1034          break;
1035        case 7:
1036          op = cff_op_vlineto;
1037          break;
1038        case 8:
1039          op = cff_op_rrcurveto;
1040          break;
1041        case 9:
1042          op = cff_op_closepath;
1043          break;
1044        case 10:
1045          op = cff_op_callsubr;
1046          break;
1047        case 11:
1048          op = cff_op_return;
1049          break;
1050        case 12:
1051          {
1052            if ( ip >= limit )
1053              goto Syntax_Error;
1054            v = *ip++;
1055
1056            switch ( v )
1057            {
1058            case 0:
1059              op = cff_op_dotsection;
1060              break;
1061            case 1: /* this is actually the Type1 vstem3 operator */
1062              op = cff_op_vstem;
1063              break;
1064            case 2: /* this is actually the Type1 hstem3 operator */
1065              op = cff_op_hstem;
1066              break;
1067            case 3:
1068              op = cff_op_and;
1069              break;
1070            case 4:
1071              op = cff_op_or;
1072              break;
1073            case 5:
1074              op = cff_op_not;
1075              break;
1076            case 6:
1077              op = cff_op_seac;
1078              break;
1079            case 7:
1080              op = cff_op_sbw;
1081              break;
1082            case 8:
1083              op = cff_op_store;
1084              break;
1085            case 9:
1086              op = cff_op_abs;
1087              break;
1088            case 10:
1089              op = cff_op_add;
1090              break;
1091            case 11:
1092              op = cff_op_sub;
1093              break;
1094            case 12:
1095              op = cff_op_div;
1096              break;
1097            case 13:
1098              op = cff_op_load;
1099              break;
1100            case 14:
1101              op = cff_op_neg;
1102              break;
1103            case 15:
1104              op = cff_op_eq;
1105              break;
1106            case 16:
1107              op = cff_op_callothersubr;
1108              break;
1109            case 17:
1110              op = cff_op_pop;
1111              break;
1112            case 18:
1113              op = cff_op_drop;
1114              break;
1115            case 20:
1116              op = cff_op_put;
1117              break;
1118            case 21:
1119              op = cff_op_get;
1120              break;
1121            case 22:
1122              op = cff_op_ifelse;
1123              break;
1124            case 23:
1125              op = cff_op_random;
1126              break;
1127            case 24:
1128              op = cff_op_mul;
1129              break;
1130            case 26:
1131              op = cff_op_sqrt;
1132              break;
1133            case 27:
1134              op = cff_op_dup;
1135              break;
1136            case 28:
1137              op = cff_op_exch;
1138              break;
1139            case 29:
1140              op = cff_op_index;
1141              break;
1142            case 30:
1143              op = cff_op_roll;
1144              break;
1145            case 33:
1146              op = cff_op_setcurrentpoint;
1147              break;
1148            case 34:
1149              op = cff_op_hflex;
1150              break;
1151            case 35:
1152              op = cff_op_flex;
1153              break;
1154            case 36:
1155              op = cff_op_hflex1;
1156              break;
1157            case 37:
1158              op = cff_op_flex1;
1159              break;
1160            default:
1161              FT_TRACE4(( " unknown op (12, %d)\n", v ));
1162              break;
1163            }
1164          }
1165          break;
1166        case 13:
1167          op = cff_op_hsbw;
1168          break;
1169        case 14:
1170          op = cff_op_endchar;
1171          break;
1172        case 16:
1173          op = cff_op_blend;
1174          break;
1175        case 18:
1176          op = cff_op_hstemhm;
1177          break;
1178        case 19:
1179          op = cff_op_hintmask;
1180          break;
1181        case 20:
1182          op = cff_op_cntrmask;
1183          break;
1184        case 21:
1185          op = cff_op_rmoveto;
1186          break;
1187        case 22:
1188          op = cff_op_hmoveto;
1189          break;
1190        case 23:
1191          op = cff_op_vstemhm;
1192          break;
1193        case 24:
1194          op = cff_op_rcurveline;
1195          break;
1196        case 25:
1197          op = cff_op_rlinecurve;
1198          break;
1199        case 26:
1200          op = cff_op_vvcurveto;
1201          break;
1202        case 27:
1203          op = cff_op_hhcurveto;
1204          break;
1205        case 29:
1206          op = cff_op_callgsubr;
1207          break;
1208        case 30:
1209          op = cff_op_vhcurveto;
1210          break;
1211        case 31:
1212          op = cff_op_hvcurveto;
1213          break;
1214        default:
1215          FT_TRACE4(( " unknown op (%d)\n", v ));
1216          break;
1217        }
1218
1219        if ( op == cff_op_unknown )
1220          continue;
1221
1222        /* check arguments */
1223        req_args = cff_argument_counts[op];
1224        if ( req_args & CFF_COUNT_CHECK_WIDTH )
1225        {
1226          if ( num_args > 0 && decoder->read_width )
1227          {
1228            /* If `nominal_width' is non-zero, the number is really a      */
1229            /* difference against `nominal_width'.  Else, the number here  */
1230            /* is truly a width, not a difference against `nominal_width'. */
1231            /* If the font does not set `nominal_width', then              */
1232            /* `nominal_width' defaults to zero, and so we can set         */
1233            /* `glyph_width' to `nominal_width' plus number on the stack   */
1234            /* -- for either case.                                         */
1235
1236            FT_Int  set_width_ok;
1237
1238
1239            switch ( op )
1240            {
1241            case cff_op_hmoveto:
1242            case cff_op_vmoveto:
1243              set_width_ok = num_args & 2;
1244              break;
1245
1246            case cff_op_hstem:
1247            case cff_op_vstem:
1248            case cff_op_hstemhm:
1249            case cff_op_vstemhm:
1250            case cff_op_rmoveto:
1251            case cff_op_hintmask:
1252            case cff_op_cntrmask:
1253              set_width_ok = num_args & 1;
1254              break;
1255
1256            case cff_op_endchar:
1257              /* If there is a width specified for endchar, we either have */
1258              /* 1 argument or 5 arguments.  We like to argue.             */
1259              set_width_ok = ( num_args == 5 ) || ( num_args == 1 );
1260              break;
1261
1262            default:
1263              set_width_ok = 0;
1264              break;
1265            }
1266
1267            if ( set_width_ok )
1268            {
1269              decoder->glyph_width = decoder->nominal_width +
1270                                       ( stack[0] >> 16 );
1271
1272              if ( decoder->width_only )
1273              {
1274                /* we only want the advance width; stop here */
1275                break;
1276              }
1277
1278              /* Consumed an argument. */
1279              num_args--;
1280            }
1281          }
1282
1283          decoder->read_width = 0;
1284          req_args            = 0;
1285        }
1286
1287        req_args &= 0x000F;
1288        if ( num_args < req_args )
1289          goto Stack_Underflow;
1290        args     -= req_args;
1291        num_args -= req_args;
1292
1293        /* At this point, `args' points to the first argument of the  */
1294        /* operand in case `req_args' isn't zero.  Otherwise, we have */
1295        /* to adjust `args' manually.                                 */
1296
1297        /* Note that we only pop arguments from the stack which we    */
1298        /* really need and can digest so that we can continue in case */
1299        /* of superfluous stack elements.                             */
1300
1301        switch ( op )
1302        {
1303        case cff_op_hstem:
1304        case cff_op_vstem:
1305        case cff_op_hstemhm:
1306        case cff_op_vstemhm:
1307          /* the number of arguments is always even here */
1308          FT_TRACE4((
1309              op == cff_op_hstem   ? " hstem\n"   :
1310            ( op == cff_op_vstem   ? " vstem\n"   :
1311            ( op == cff_op_hstemhm ? " hstemhm\n" : " vstemhm\n" ) ) ));
1312
1313          if ( hinter )
1314            hinter->stems( hinter->hints,
1315                           ( op == cff_op_hstem || op == cff_op_hstemhm ),
1316                           num_args / 2,
1317                           args - ( num_args & ~1 ) );
1318
1319          decoder->num_hints += num_args / 2;
1320          args = stack;
1321          break;
1322
1323        case cff_op_hintmask:
1324        case cff_op_cntrmask:
1325          FT_TRACE4(( op == cff_op_hintmask ? " hintmask" : " cntrmask" ));
1326
1327          /* implement vstem when needed --                        */
1328          /* the specification doesn't say it, but this also works */
1329          /* with the 'cntrmask' operator                          */
1330          /*                                                       */
1331          if ( num_args > 0 )
1332          {
1333            if ( hinter )
1334              hinter->stems( hinter->hints,
1335                             0,
1336                             num_args / 2,
1337                             args - ( num_args & ~1 ) );
1338
1339            decoder->num_hints += num_args / 2;
1340          }
1341
1342          /* In a valid charstring there must be at least one byte */
1343          /* after `hintmask' or `cntrmask' (e.g., for a `return'  */
1344          /* instruction).  Additionally, there must be space for  */
1345          /* `num_hints' bits.                                     */
1346
1347          if ( ( ip + ( ( decoder->num_hints + 7 ) >> 3 ) ) >= limit )
1348            goto Syntax_Error;
1349
1350          if ( hinter )
1351          {
1352            if ( op == cff_op_hintmask )
1353              hinter->hintmask( hinter->hints,
1354                                builder->current->n_points,
1355                                decoder->num_hints,
1356                                ip );
1357            else
1358              hinter->counter( hinter->hints,
1359                               decoder->num_hints,
1360                               ip );
1361          }
1362
1363#ifdef FT_DEBUG_LEVEL_TRACE
1364          {
1365            FT_UInt maskbyte;
1366
1367
1368            FT_TRACE4(( " (maskbytes:" ));
1369
1370            for ( maskbyte = 0;
1371                  maskbyte < (FT_UInt)( ( decoder->num_hints + 7 ) >> 3 );
1372                  maskbyte++, ip++ )
1373              FT_TRACE4(( " 0x%02X", *ip ));
1374
1375            FT_TRACE4(( ")\n" ));
1376          }
1377#else
1378          ip += ( decoder->num_hints + 7 ) >> 3;
1379#endif
1380          args = stack;
1381          break;
1382
1383        case cff_op_rmoveto:
1384          FT_TRACE4(( " rmoveto\n" ));
1385
1386          cff_builder_close_contour( builder );
1387          builder->path_begun = 0;
1388          x   += args[-2];
1389          y   += args[-1];
1390          args = stack;
1391          break;
1392
1393        case cff_op_vmoveto:
1394          FT_TRACE4(( " vmoveto\n" ));
1395
1396          cff_builder_close_contour( builder );
1397          builder->path_begun = 0;
1398          y   += args[-1];
1399          args = stack;
1400          break;
1401
1402        case cff_op_hmoveto:
1403          FT_TRACE4(( " hmoveto\n" ));
1404
1405          cff_builder_close_contour( builder );
1406          builder->path_begun = 0;
1407          x   += args[-1];
1408          args = stack;
1409          break;
1410
1411        case cff_op_rlineto:
1412          FT_TRACE4(( " rlineto\n" ));
1413
1414          if ( cff_builder_start_point ( builder, x, y ) ||
1415               check_points( builder, num_args / 2 )     )
1416            goto Fail;
1417
1418          if ( num_args < 2 )
1419            goto Stack_Underflow;
1420
1421          args -= num_args & ~1;
1422          while ( args < decoder->top )
1423          {
1424            x += args[0];
1425            y += args[1];
1426            cff_builder_add_point( builder, x, y, 1 );
1427            args += 2;
1428          }
1429          args = stack;
1430          break;
1431
1432        case cff_op_hlineto:
1433        case cff_op_vlineto:
1434          {
1435            FT_Int  phase = ( op == cff_op_hlineto );
1436
1437
1438            FT_TRACE4(( op == cff_op_hlineto ? " hlineto\n"
1439                                             : " vlineto\n" ));
1440
1441            if ( num_args < 0 )
1442              goto Stack_Underflow;
1443
1444            /* there exist subsetted fonts (found in PDFs) */
1445            /* which call `hlineto' without arguments      */
1446            if ( num_args == 0 )
1447              break;
1448
1449            if ( cff_builder_start_point ( builder, x, y ) ||
1450                 check_points( builder, num_args )         )
1451              goto Fail;
1452
1453            args = stack;
1454            while ( args < decoder->top )
1455            {
1456              if ( phase )
1457                x += args[0];
1458              else
1459                y += args[0];
1460
1461              if ( cff_builder_add_point1( builder, x, y ) )
1462                goto Fail;
1463
1464              args++;
1465              phase ^= 1;
1466            }
1467            args = stack;
1468          }
1469          break;
1470
1471        case cff_op_rrcurveto:
1472          {
1473            FT_Int  nargs;
1474
1475
1476            FT_TRACE4(( " rrcurveto\n" ));
1477
1478            if ( num_args < 6 )
1479              goto Stack_Underflow;
1480
1481            nargs = num_args - num_args % 6;
1482
1483            if ( cff_builder_start_point ( builder, x, y ) ||
1484                 check_points( builder, nargs / 2 )     )
1485              goto Fail;
1486
1487            args -= nargs;
1488            while ( args < decoder->top )
1489            {
1490              x += args[0];
1491              y += args[1];
1492              cff_builder_add_point( builder, x, y, 0 );
1493              x += args[2];
1494              y += args[3];
1495              cff_builder_add_point( builder, x, y, 0 );
1496              x += args[4];
1497              y += args[5];
1498              cff_builder_add_point( builder, x, y, 1 );
1499              args += 6;
1500            }
1501            args = stack;
1502          }
1503          break;
1504
1505        case cff_op_vvcurveto:
1506          {
1507            FT_Int  nargs;
1508
1509
1510            FT_TRACE4(( " vvcurveto\n" ));
1511
1512            if ( num_args < 4 )
1513              goto Stack_Underflow;
1514
1515            /* if num_args isn't of the form 4n or 4n+1, */
1516            /* we enforce it by clearing the second bit  */
1517
1518            nargs = num_args & ~2;
1519
1520            if ( cff_builder_start_point( builder, x, y ) )
1521              goto Fail;
1522
1523            args -= nargs;
1524
1525            if ( nargs & 1 )
1526            {
1527              x += args[0];
1528              args++;
1529              nargs--;
1530            }
1531
1532            if ( check_points( builder, 3 * ( nargs / 4 ) ) )
1533              goto Fail;
1534
1535            while ( args < decoder->top )
1536            {
1537              y += args[0];
1538              cff_builder_add_point( builder, x, y, 0 );
1539              x += args[1];
1540              y += args[2];
1541              cff_builder_add_point( builder, x, y, 0 );
1542              y += args[3];
1543              cff_builder_add_point( builder, x, y, 1 );
1544              args += 4;
1545            }
1546            args = stack;
1547          }
1548          break;
1549
1550        case cff_op_hhcurveto:
1551          {
1552            FT_Int  nargs;
1553
1554
1555            FT_TRACE4(( " hhcurveto\n" ));
1556
1557            if ( num_args < 4 )
1558              goto Stack_Underflow;
1559
1560            /* if num_args isn't of the form 4n or 4n+1, */
1561            /* we enforce it by clearing the second bit  */
1562
1563            nargs = num_args & ~2;
1564
1565            if ( cff_builder_start_point( builder, x, y ) )
1566              goto Fail;
1567
1568            args -= nargs;
1569            if ( nargs & 1 )
1570            {
1571              y += args[0];
1572              args++;
1573              nargs--;
1574            }
1575
1576            if ( check_points( builder, 3 * ( nargs / 4 ) ) )
1577              goto Fail;
1578
1579            while ( args < decoder->top )
1580            {
1581              x += args[0];
1582              cff_builder_add_point( builder, x, y, 0 );
1583              x += args[1];
1584              y += args[2];
1585              cff_builder_add_point( builder, x, y, 0 );
1586              x += args[3];
1587              cff_builder_add_point( builder, x, y, 1 );
1588              args += 4;
1589            }
1590            args = stack;
1591          }
1592          break;
1593
1594        case cff_op_vhcurveto:
1595        case cff_op_hvcurveto:
1596          {
1597            FT_Int  phase;
1598            FT_Int  nargs;
1599
1600
1601            FT_TRACE4(( op == cff_op_vhcurveto ? " vhcurveto\n"
1602                                               : " hvcurveto\n" ));
1603
1604            if ( cff_builder_start_point( builder, x, y ) )
1605              goto Fail;
1606
1607            if ( num_args < 4 )
1608              goto Stack_Underflow;
1609
1610            /* if num_args isn't of the form 8n, 8n+1, 8n+4, or 8n+5, */
1611            /* we enforce it by clearing the second bit               */
1612
1613            nargs = num_args & ~2;
1614
1615            args -= nargs;
1616            if ( check_points( builder, ( nargs / 4 ) * 3 ) )
1617              goto Stack_Underflow;
1618
1619            phase = ( op == cff_op_hvcurveto );
1620
1621            while ( nargs >= 4 )
1622            {
1623              nargs -= 4;
1624              if ( phase )
1625              {
1626                x += args[0];
1627                cff_builder_add_point( builder, x, y, 0 );
1628                x += args[1];
1629                y += args[2];
1630                cff_builder_add_point( builder, x, y, 0 );
1631                y += args[3];
1632                if ( nargs == 1 )
1633                  x += args[4];
1634                cff_builder_add_point( builder, x, y, 1 );
1635              }
1636              else
1637              {
1638                y += args[0];
1639                cff_builder_add_point( builder, x, y, 0 );
1640                x += args[1];
1641                y += args[2];
1642                cff_builder_add_point( builder, x, y, 0 );
1643                x += args[3];
1644                if ( nargs == 1 )
1645                  y += args[4];
1646                cff_builder_add_point( builder, x, y, 1 );
1647              }
1648              args  += 4;
1649              phase ^= 1;
1650            }
1651            args = stack;
1652          }
1653          break;
1654
1655        case cff_op_rlinecurve:
1656          {
1657            FT_Int  num_lines;
1658            FT_Int  nargs;
1659
1660
1661            FT_TRACE4(( " rlinecurve\n" ));
1662
1663            if ( num_args < 8 )
1664              goto Stack_Underflow;
1665
1666            nargs     = num_args & ~1;
1667            num_lines = ( nargs - 6 ) / 2;
1668
1669           

Large files files are truncated, but you can click here to view the full file