Edit

kc3-lang/freetype/src/cff/cffparse.h

Branch :

  • Show log

    Commit

  • Author : Dave Arnold
    Date : 2016-12-15 21:56:44
    Hash : edf40148
    Message : [cff] Implement CFF2 support (2/2). The font variation code. All parts dependent on the GX code in the `truetype' module are guarded with TT_CONFIG_OPTION_GX_VAR_SUPPORT. In other words, you can still compile the `cff' module without defining TT_CONFIG_OPTION_GX_VAR_SUPPORT (which brings you CFF2 support without font variation). * src/cff/cf2font.c (cf2_font_setup): Add support for font variation. * src/cff/cf2font.h (CF2_Font): Add fields for variation data. * src/cff/cf2ft.c (cf2_free_instance): Free blend data. (cf2_getVStore, cf2_getNormalizedVector): New functions. * src/cff/cf2ft.h: Updated. * src/cff/cf2intrp.c: Include `cffload.h'. (cf2_cmdRESERVED_15, cf2_cmdRESERVED_16): Replace with... (cf2_cmdVSINDEX, cf2_cmdBLEND): ... this new enum values. (cf2_doBlend): New function. (cf2_interpT2CharString): Handle `vsindex' and `blend' opcodes. * src/cff/cffload.c (FT_fdot14ToFixed): New macro. (cff_vstore_done, cff_vstore_load): New functions. (cff_blend_clear, cff_blend_doBlend, cff_blend_build_vector, cff_blend_check_vector): New functions. (cff_load_private_dict): Add arguments for blend vector. Handle blend data. (cff_subfont_load, cff_subfont_done): Updated. (cff_font_load): Handle CFF2 variation store data. (cff_font_done): Updated. * src/cff/cffload.h: Include `cffparse.h'. Updated. * src/cff/cffobjs.c (cff_face_done): Updated. * src/cff/cffparse.c: Include `cffload.h'. (cff_parse_num): Handle internal value 255. (cff_parse_vsindex, cff_parse_blend): New functions. (CFF_FIELD_BLEND): New macro. (cff_parser_run): Updated. * src/cff/cffparse.h (cff_kind_blend): New enum value. * src/cff/cfftoken.h: Handle `vstore', `vsindex', and `blend' dictionary values. * src/cff/cfftypes.h (CFF_VarData, CFF_AxisCoords, CFF_VarRegion, CFF_VStore, CFF_Blend): New structures. (CFF_FontRecDict): Add `vstore_offset' field. (CFF_Private): Add `vsindex' field. (CFF_SubFont): Add fields for blend data. (CFF_Font): Add `vstore' field. * src/truetype/ttgxvar.c (TT_Get_MM_Var): `CFF2' is equal to `gvar', since glyph variation data is directly embedded. (TT_Set_MM_Blend): Don't load `gvar' table for CFF2 fonts.

  • src/cff/cffparse.h
  • /***************************************************************************/
    /*                                                                         */
    /*  cffparse.h                                                             */
    /*                                                                         */
    /*    CFF token stream parser (specification)                              */
    /*                                                                         */
    /*  Copyright 1996-2016 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 CFFPARSE_H_
    #define CFFPARSE_H_
    
    
    #include <ft2build.h>
    #include "cfftypes.h"
    #include FT_INTERNAL_OBJECTS_H
    
    
    FT_BEGIN_HEADER
    
    
      /* CFF uses constant parser stack size; */
      /* CFF2 can increase from default 193   */
    #define CFF_MAX_STACK_DEPTH  96
    #define CFF2_MAX_STACK      513
    #define CFF2_DEFAULT_STACK  193
    
    #define CFF_CODE_TOPDICT    0x1000
    #define CFF_CODE_PRIVATE    0x2000
    #define CFF2_CODE_TOPDICT   0x3000
    #define CFF2_CODE_FONTDICT  0x4000
    #define CFF2_CODE_PRIVATE   0x5000
    
    
      typedef struct  CFF_ParserRec_
      {
        FT_Library  library;
        FT_Byte*    start;
        FT_Byte*    limit;
        FT_Byte*    cursor;
    
        FT_Byte**   stack;
        FT_Byte**   top;
        FT_UInt     stackSize;  /* allocated size */
    
        FT_UInt     object_code;
        void*       object;
    
        FT_UShort   num_designs; /* a copy of `CFF_FontRecDict->num_designs' */
        FT_UShort   num_axes;    /* a copy of `CFF_FontRecDict->num_axes'    */
    
      } CFF_ParserRec, *CFF_Parser;
    
    
      FT_LOCAL( FT_Long )
      cff_parse_num( CFF_Parser  parser,
                     FT_Byte**   d );
    
      FT_LOCAL( FT_Error )
      cff_parser_init( CFF_Parser  parser,
                       FT_UInt     code,
                       void*       object,
                       FT_Library  library,
                       FT_UInt     stackSize,
                       FT_UShort   num_designs,
                       FT_UShort   num_axes );
    
      FT_LOCAL( void )
      cff_parser_done( CFF_Parser  parser );
    
      FT_LOCAL( FT_Error )
      cff_parser_run( CFF_Parser  parser,
                      FT_Byte*    start,
                      FT_Byte*    limit );
    
    
      enum
      {
        cff_kind_none = 0,
        cff_kind_num,
        cff_kind_fixed,
        cff_kind_fixed_thousand,
        cff_kind_string,
        cff_kind_bool,
        cff_kind_delta,
        cff_kind_callback,
        cff_kind_blend,
    
        cff_kind_max  /* do not remove */
      };
    
    
      /* now generate handlers for the most simple fields */
      typedef FT_Error  (*CFF_Field_Reader)( CFF_Parser  parser );
    
      typedef struct  CFF_Field_Handler_
      {
        int               kind;
        int               code;
        FT_UInt           offset;
        FT_Byte           size;
        CFF_Field_Reader  reader;
        FT_UInt           array_max;
        FT_UInt           count_offset;
    
    #ifdef FT_DEBUG_LEVEL_TRACE
        const char*       id;
    #endif
    
      } CFF_Field_Handler;
    
    
    FT_END_HEADER
    
    
    #endif /* CFFPARSE_H_ */
    
    
    /* END */