shithub: freetype+ttf2subf

ref: 3d99f79669fb9a8a489339985975bdb55d1a7a73
dir: /src/cff/t2gload.h/

View raw version
/***************************************************************************/
/*                                                                         */
/*  t2gload.h                                                              */
/*                                                                         */
/*    OpenType Glyph Loader (specification).                               */
/*                                                                         */
/*  Copyright 1996-1999 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.                                        */
/*                                                                         */
/***************************************************************************/


#ifndef T2GLOAD_H
#define T2GLOAD_H

#include <t2objs.h>

#ifdef __cplusplus
  extern "C" {
#endif

  #define T2_MAX_OPERANDS     48
  #define T2_MAX_SUBRS_CALLS  32

/*************************************************************************/
/*                                                                       */
/* <Structure> T2_Builder                                                */
/*                                                                       */
/* <Description>                                                         */
/*     a structure used during glyph loading to store its outline.       */
/*                                                                       */
/* <Fields>                                                              */
/*    system :: current system object                                    */
/*    face   :: current face object                                      */
/*    glyph  :: current glyph slot                                       */
/*                                                                       */
/*    current :: current glyph outline                                   */
/*    base    :: base glyph outline                                      */
/*                                                                       */
/*    max_points   :: maximum points in builder outline                  */
/*    max_contours :: maximum contours in builder outline                */
/*                                                                       */
/*    last     :: last point position                                    */
/*                                                                       */
/*    scale_x  :: horizontal scale ( FUnits to sub-pixels )              */
/*    scale_y  :: vertical scale   ( FUnits to sub-pixels )              */
/*    pos_x    :: horizontal translation (composite glyphs)              */
/*    pos_y    :: vertical translation   (composite glyph)               */
/*                                                                       */
/*    left_bearing  :: left side bearing point                           */
/*    advance       :: horizontal advance vector                         */
/*                                                                       */
/*    path_begun    :: flag, indicates that a new path has begun         */
/*    load_points   :: flag, if not set, no points are loaded            */
/*                                                                       */
/*    error         :: an error code that is only used to report         */
/*                     memory allocation problems..                      */
/*                                                                       */
/*    metrics_only  :: a boolean indicating that we only want to         */
/*                     compute the metrics of a given glyph, not load    */
/*                     all of its points..                               */
/*                                                                       */

  typedef struct T2_Builder_
  {
    FT_Memory     memory;
    TT_Face       face;
    T2_GlyphSlot  glyph;

    FT_Outline    current;       /* the current glyph outline   */
    FT_Outline    base;          /* the composite glyph outline */

    FT_Int        max_points;    /* capacity of base outline in points   */
    FT_Int        max_contours;  /* capacity of base outline in contours */

    FT_Vector     last;

    FT_Fixed      scale_x;
    FT_Fixed      scale_y;

    FT_Pos        pos_x;
    FT_Pos        pos_y;

    FT_Vector     left_bearing;
    FT_Vector     advance;

    FT_BBox       bbox;          /* bounding box */
    FT_Bool       path_begun;
    FT_Bool       load_points;
    FT_Bool       no_recurse;

    FT_Error      error;         /* only used for memory errors */
    FT_Bool       metrics_only;

  } T2_Builder;


  /* execution context charstring zone */
  typedef struct T2_Decoder_Zone_
  {
    FT_Byte*  base;
    FT_Byte*  limit;
    FT_Byte*  cursor;

  } T2_Decoder_Zone;


  typedef struct T2_Decoder_
  {
    T2_Builder         builder;
    CFF_Font*          cff;

    FT_Fixed           stack[ T2_MAX_OPERANDS+1 ];
    FT_Fixed*          top;

    T2_Decoder_Zone    zones[ T2_MAX_SUBRS_CALLS+1 ];
    T2_Decoder_Zone*   zone;

    FT_Int             flex_state;
    FT_Int             num_flex_vectors;
    FT_Vector          flex_vectors[7];

    FT_Pos             glyph_width;
    FT_Pos             nominal_width;
    
    FT_Bool            read_width;
    FT_Int             num_hints;
    FT_Fixed*          buildchar;
    FT_Int             len_buildchar;

    FT_UInt            num_locals;
    FT_UInt            num_globals;
    
    FT_Int             locals_bias;
    FT_Int             globals_bias;
    
    FT_Byte**          locals;
    FT_Byte**          globals;


  } T2_Decoder;



  LOCAL_DEF
  void  T2_Init_Decoder( T2_Decoder*  decoder,
                         TT_Face      face,
                         T2_Size      size,
                         T2_GlyphSlot slot );


#if 0  /* unused until we support pure CFF fonts */
  /* Compute the maximum advance width of a font through quick parsing */
  LOCAL_DEF
  FT_Error  T2_Compute_Max_Advance( TT_Face  face,
                                    FT_Int  *max_advance );
#endif

  /* This function is exported, because it is used by the T1Dump utility */
  LOCAL_DEF
  FT_Error   T2_Parse_CharStrings( T2_Decoder*  decoder,
                                   FT_Byte*     charstring_base,
                                   FT_Int       charstring_len );



  LOCAL_DEF
  FT_Error  T2_Load_Glyph( T2_GlyphSlot  glyph,
                           T2_Size       size,
                           FT_Int        glyph_index,
                           FT_Int        load_flags );




#ifdef __cplusplus
  }
#endif


#endif /* T2GLOAD_H */


/* END */