Home | History | Annotate | Download | only in cff
      1 /***************************************************************************/
      2 /*                                                                         */
      3 /*  cffgload.h                                                             */
      4 /*                                                                         */
      5 /*    OpenType Glyph Loader (specification).                               */
      6 /*                                                                         */
      7 /*  Copyright 1996-2017 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 #ifndef CFFGLOAD_H_
     20 #define CFFGLOAD_H_
     21 
     22 
     23 #include <ft2build.h>
     24 #include FT_FREETYPE_H
     25 #include "cffobjs.h"
     26 
     27 
     28 FT_BEGIN_HEADER
     29 
     30 
     31 #define CFF_MAX_OPERANDS        48
     32 #define CFF_MAX_SUBRS_CALLS     16  /* maximum subroutine nesting;         */
     33                                     /* only 10 are allowed but there exist */
     34                                     /* fonts like `HiraKakuProN-W3.ttf'    */
     35                                     /* (Hiragino Kaku Gothic ProN W3;      */
     36                                     /* 8.2d6e1; 2014-12-19) that exceed    */
     37                                     /* this limit                          */
     38 #define CFF_MAX_TRANS_ELEMENTS  32
     39 
     40 
     41   /*************************************************************************/
     42   /*                                                                       */
     43   /* <Structure>                                                           */
     44   /*    CFF_Builder                                                        */
     45   /*                                                                       */
     46   /* <Description>                                                         */
     47   /*     A structure used during glyph loading to store its outline.       */
     48   /*                                                                       */
     49   /* <Fields>                                                              */
     50   /*    memory        :: The current memory object.                        */
     51   /*                                                                       */
     52   /*    face          :: The current face object.                          */
     53   /*                                                                       */
     54   /*    glyph         :: The current glyph slot.                           */
     55   /*                                                                       */
     56   /*    loader        :: The current glyph loader.                         */
     57   /*                                                                       */
     58   /*    base          :: The base glyph outline.                           */
     59   /*                                                                       */
     60   /*    current       :: The current glyph outline.                        */
     61   /*                                                                       */
     62   /*    pos_x         :: The horizontal translation (if composite glyph).  */
     63   /*                                                                       */
     64   /*    pos_y         :: The vertical translation (if composite glyph).    */
     65   /*                                                                       */
     66   /*    left_bearing  :: The left side bearing point.                      */
     67   /*                                                                       */
     68   /*    advance       :: The horizontal advance vector.                    */
     69   /*                                                                       */
     70   /*    bbox          :: Unused.                                           */
     71   /*                                                                       */
     72   /*    path_begun    :: A flag which indicates that a new path has begun. */
     73   /*                                                                       */
     74   /*    load_points   :: If this flag is not set, no points are loaded.    */
     75   /*                                                                       */
     76   /*    no_recurse    :: Set but not used.                                 */
     77   /*                                                                       */
     78   /*    metrics_only  :: A boolean indicating that we only want to compute */
     79   /*                     the metrics of a given glyph, not load all of its */
     80   /*                     points.                                           */
     81   /*                                                                       */
     82   /*    hints_funcs   :: Auxiliary pointer for hinting.                    */
     83   /*                                                                       */
     84   /*    hints_globals :: Auxiliary pointer for hinting.                    */
     85   /*                                                                       */
     86   typedef struct  CFF_Builder_
     87   {
     88     FT_Memory       memory;
     89     TT_Face         face;
     90     CFF_GlyphSlot   glyph;
     91     FT_GlyphLoader  loader;
     92     FT_Outline*     base;
     93     FT_Outline*     current;
     94 
     95     FT_Pos          pos_x;
     96     FT_Pos          pos_y;
     97 
     98     FT_Vector       left_bearing;
     99     FT_Vector       advance;
    100 
    101     FT_BBox         bbox;          /* bounding box */
    102     FT_Bool         path_begun;
    103     FT_Bool         load_points;
    104     FT_Bool         no_recurse;
    105 
    106     FT_Bool         metrics_only;
    107 
    108     void*           hints_funcs;    /* hinter-specific */
    109     void*           hints_globals;  /* hinter-specific */
    110 
    111   } CFF_Builder;
    112 
    113 
    114   FT_LOCAL( FT_Error )
    115   cff_check_points( CFF_Builder*  builder,
    116                     FT_Int        count );
    117 
    118   FT_LOCAL( void )
    119   cff_builder_add_point( CFF_Builder*  builder,
    120                          FT_Pos        x,
    121                          FT_Pos        y,
    122                          FT_Byte       flag );
    123   FT_LOCAL( FT_Error )
    124   cff_builder_add_point1( CFF_Builder*  builder,
    125                           FT_Pos        x,
    126                           FT_Pos        y );
    127   FT_LOCAL( FT_Error )
    128   cff_builder_start_point( CFF_Builder*  builder,
    129                            FT_Pos        x,
    130                            FT_Pos        y );
    131   FT_LOCAL( void )
    132   cff_builder_close_contour( CFF_Builder*  builder );
    133 
    134 
    135   FT_LOCAL( FT_Int )
    136   cff_lookup_glyph_by_stdcharcode( CFF_Font  cff,
    137                                    FT_Int    charcode );
    138   FT_LOCAL( FT_Error )
    139   cff_get_glyph_data( TT_Face    face,
    140                       FT_UInt    glyph_index,
    141                       FT_Byte**  pointer,
    142                       FT_ULong*  length );
    143   FT_LOCAL( void )
    144   cff_free_glyph_data( TT_Face    face,
    145                        FT_Byte**  pointer,
    146                        FT_ULong   length );
    147 
    148 
    149   /* execution context charstring zone */
    150 
    151   typedef struct  CFF_Decoder_Zone_
    152   {
    153     FT_Byte*  base;
    154     FT_Byte*  limit;
    155     FT_Byte*  cursor;
    156 
    157   } CFF_Decoder_Zone;
    158 
    159 
    160   typedef struct  CFF_Decoder_
    161   {
    162     CFF_Builder        builder;
    163     CFF_Font           cff;
    164 
    165     FT_Fixed           stack[CFF_MAX_OPERANDS + 1];
    166     FT_Fixed*          top;
    167 
    168     CFF_Decoder_Zone   zones[CFF_MAX_SUBRS_CALLS + 1];
    169     CFF_Decoder_Zone*  zone;
    170 
    171     FT_Int             flex_state;
    172     FT_Int             num_flex_vectors;
    173     FT_Vector          flex_vectors[7];
    174 
    175     FT_Pos             glyph_width;
    176     FT_Pos             nominal_width;
    177 
    178     FT_Bool            read_width;
    179     FT_Bool            width_only;
    180     FT_Int             num_hints;
    181     FT_Fixed           buildchar[CFF_MAX_TRANS_ELEMENTS];
    182 
    183     FT_UInt            num_locals;
    184     FT_UInt            num_globals;
    185 
    186     FT_Int             locals_bias;
    187     FT_Int             globals_bias;
    188 
    189     FT_Byte**          locals;
    190     FT_Byte**          globals;
    191 
    192     FT_Byte**          glyph_names;   /* for pure CFF fonts only  */
    193     FT_UInt            num_glyphs;    /* number of glyphs in font */
    194 
    195     FT_Render_Mode     hint_mode;
    196 
    197     FT_Bool            seac;
    198 
    199     CFF_SubFont        current_subfont; /* for current glyph_index */
    200 
    201   } CFF_Decoder;
    202 
    203 
    204   FT_LOCAL( void )
    205   cff_decoder_init( CFF_Decoder*    decoder,
    206                     TT_Face         face,
    207                     CFF_Size        size,
    208                     CFF_GlyphSlot   slot,
    209                     FT_Bool         hinting,
    210                     FT_Render_Mode  hint_mode );
    211 
    212   FT_LOCAL( FT_Error )
    213   cff_decoder_prepare( CFF_Decoder*  decoder,
    214                        CFF_Size      size,
    215                        FT_UInt       glyph_index );
    216 
    217 #if 0  /* unused until we support pure CFF fonts */
    218 
    219   /* Compute the maximum advance width of a font through quick parsing */
    220   FT_LOCAL( FT_Error )
    221   cff_compute_max_advance( TT_Face  face,
    222                            FT_Int*  max_advance );
    223 
    224 #endif /* 0 */
    225 
    226 #ifdef CFF_CONFIG_OPTION_OLD_ENGINE
    227   FT_LOCAL( FT_Error )
    228   cff_decoder_parse_charstrings( CFF_Decoder*  decoder,
    229                                  FT_Byte*      charstring_base,
    230                                  FT_ULong      charstring_len,
    231                                  FT_Bool       in_dict );
    232 #endif
    233 
    234   FT_LOCAL( FT_Error )
    235   cff_slot_load( CFF_GlyphSlot  glyph,
    236                  CFF_Size       size,
    237                  FT_UInt        glyph_index,
    238                  FT_Int32       load_flags );
    239 
    240 
    241 FT_END_HEADER
    242 
    243 #endif /* CFFGLOAD_H_ */
    244 
    245 
    246 /* END */
    247