Home | History | Annotate | Download | only in internal
      1 /***************************************************************************/
      2 /*                                                                         */
      3 /*  cfftypes.h                                                             */
      4 /*                                                                         */
      5 /*    Basic OpenType/CFF type definitions and interface (specification     */
      6 /*    only).                                                               */
      7 /*                                                                         */
      8 /*  Copyright 1996-2018 by                                                 */
      9 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
     10 /*                                                                         */
     11 /*  This file is part of the FreeType project, and may only be used,       */
     12 /*  modified, and distributed under the terms of the FreeType project      */
     13 /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
     14 /*  this file you indicate that you have read the license and              */
     15 /*  understand and accept it fully.                                        */
     16 /*                                                                         */
     17 /***************************************************************************/
     18 
     19 
     20 #ifndef CFFTYPES_H_
     21 #define CFFTYPES_H_
     22 
     23 
     24 #include <ft2build.h>
     25 #include FT_FREETYPE_H
     26 #include FT_TYPE1_TABLES_H
     27 #include FT_INTERNAL_SERVICE_H
     28 #include FT_SERVICE_POSTSCRIPT_CMAPS_H
     29 #include FT_INTERNAL_POSTSCRIPT_HINTS_H
     30 #include FT_INTERNAL_TYPE1_TYPES_H
     31 
     32 
     33 FT_BEGIN_HEADER
     34 
     35 
     36   /*************************************************************************/
     37   /*                                                                       */
     38   /* <Struct>                                                              */
     39   /*    CFF_IndexRec                                                       */
     40   /*                                                                       */
     41   /* <Description>                                                         */
     42   /*    A structure used to model a CFF Index table.                       */
     43   /*                                                                       */
     44   /* <Fields>                                                              */
     45   /*    stream      :: The source input stream.                            */
     46   /*                                                                       */
     47   /*    start       :: The position of the first index byte in the         */
     48   /*                   input stream.                                       */
     49   /*                                                                       */
     50   /*    count       :: The number of elements in the index.                */
     51   /*                                                                       */
     52   /*    off_size    :: The size in bytes of object offsets in index.       */
     53   /*                                                                       */
     54   /*    data_offset :: The position of first data byte in the index's      */
     55   /*                   bytes.                                              */
     56   /*                                                                       */
     57   /*    data_size   :: The size of the data table in this index.           */
     58   /*                                                                       */
     59   /*    offsets     :: A table of element offsets in the index.  Must be   */
     60   /*                   loaded explicitly.                                  */
     61   /*                                                                       */
     62   /*    bytes       :: If the index is loaded in memory, its bytes.        */
     63   /*                                                                       */
     64   typedef struct  CFF_IndexRec_
     65   {
     66     FT_Stream  stream;
     67     FT_ULong   start;
     68     FT_UInt    hdr_size;
     69     FT_UInt    count;
     70     FT_Byte    off_size;
     71     FT_ULong   data_offset;
     72     FT_ULong   data_size;
     73 
     74     FT_ULong*  offsets;
     75     FT_Byte*   bytes;
     76 
     77   } CFF_IndexRec, *CFF_Index;
     78 
     79 
     80   typedef struct  CFF_EncodingRec_
     81   {
     82     FT_UInt     format;
     83     FT_ULong    offset;
     84 
     85     FT_UInt     count;
     86     FT_UShort   sids [256];  /* avoid dynamic allocations */
     87     FT_UShort   codes[256];
     88 
     89   } CFF_EncodingRec, *CFF_Encoding;
     90 
     91 
     92   typedef struct  CFF_CharsetRec_
     93   {
     94 
     95     FT_UInt     format;
     96     FT_ULong    offset;
     97 
     98     FT_UShort*  sids;
     99     FT_UShort*  cids;       /* the inverse mapping of `sids'; only needed */
    100                             /* for CID-keyed fonts                        */
    101     FT_UInt     max_cid;
    102     FT_UInt     num_glyphs;
    103 
    104   } CFF_CharsetRec, *CFF_Charset;
    105 
    106 
    107   /* cf. similar fields in file `ttgxvar.h' from the `truetype' module */
    108 
    109   typedef struct  CFF_VarData_
    110   {
    111 #if 0
    112     FT_UInt  itemCount;       /* not used; always zero */
    113     FT_UInt  shortDeltaCount; /* not used; always zero */
    114 #endif
    115 
    116     FT_UInt   regionIdxCount; /* number of region indexes           */
    117     FT_UInt*  regionIndices;  /* array of `regionIdxCount' indices; */
    118                               /* these index `varRegionList'        */
    119   } CFF_VarData;
    120 
    121 
    122   /* contribution of one axis to a region */
    123   typedef struct  CFF_AxisCoords_
    124   {
    125     FT_Fixed  startCoord;
    126     FT_Fixed  peakCoord;      /* zero peak means no effect (factor = 1) */
    127     FT_Fixed  endCoord;
    128 
    129   } CFF_AxisCoords;
    130 
    131 
    132   typedef struct  CFF_VarRegion_
    133   {
    134     CFF_AxisCoords*  axisList;      /* array of axisCount records */
    135 
    136   } CFF_VarRegion;
    137 
    138 
    139   typedef struct  CFF_VStoreRec_
    140   {
    141     FT_UInt         dataCount;
    142     CFF_VarData*    varData;        /* array of dataCount records      */
    143                                     /* vsindex indexes this array      */
    144     FT_UShort       axisCount;
    145     FT_UInt         regionCount;    /* total number of regions defined */
    146     CFF_VarRegion*  varRegionList;
    147 
    148   } CFF_VStoreRec, *CFF_VStore;
    149 
    150 
    151   /* forward reference */
    152   typedef struct CFF_FontRec_*  CFF_Font;
    153 
    154 
    155   /* This object manages one cached blend vector.                  */
    156   /*                                                               */
    157   /* There is a BlendRec for Private DICT parsing in each subfont  */
    158   /* and a BlendRec for charstrings in CF2_Font instance data.     */
    159   /* A cached BV may be used across DICTs or Charstrings if inputs */
    160   /* have not changed.                                             */
    161   /*                                                               */
    162   /* `usedBV' is reset at the start of each parse or charstring.   */
    163   /* vsindex cannot be changed after a BV is used.                 */
    164   /*                                                               */
    165   /* Note: NDV is long (32/64 bit), while BV is 16.16 (FT_Int32).  */
    166   typedef struct  CFF_BlendRec_
    167   {
    168     FT_Bool    builtBV;        /* blendV has been built           */
    169     FT_Bool    usedBV;         /* blendV has been used            */
    170     CFF_Font   font;           /* top level font struct           */
    171     FT_UInt    lastVsindex;    /* last vsindex used               */
    172     FT_UInt    lenNDV;         /* normDV length (aka numAxes)     */
    173     FT_Fixed*  lastNDV;        /* last NDV used                   */
    174     FT_UInt    lenBV;          /* BlendV length (aka numMasters)  */
    175     FT_Int32*  BV;             /* current blendV (per DICT/glyph) */
    176 
    177   } CFF_BlendRec, *CFF_Blend;
    178 
    179 
    180   typedef struct  CFF_FontRecDictRec_
    181   {
    182     FT_UInt    version;
    183     FT_UInt    notice;
    184     FT_UInt    copyright;
    185     FT_UInt    full_name;
    186     FT_UInt    family_name;
    187     FT_UInt    weight;
    188     FT_Bool    is_fixed_pitch;
    189     FT_Fixed   italic_angle;
    190     FT_Fixed   underline_position;
    191     FT_Fixed   underline_thickness;
    192     FT_Int     paint_type;
    193     FT_Int     charstring_type;
    194     FT_Matrix  font_matrix;
    195     FT_Bool    has_font_matrix;
    196     FT_ULong   units_per_em;  /* temporarily used as scaling value also */
    197     FT_Vector  font_offset;
    198     FT_ULong   unique_id;
    199     FT_BBox    font_bbox;
    200     FT_Pos     stroke_width;
    201     FT_ULong   charset_offset;
    202     FT_ULong   encoding_offset;
    203     FT_ULong   charstrings_offset;
    204     FT_ULong   private_offset;
    205     FT_ULong   private_size;
    206     FT_Long    synthetic_base;
    207     FT_UInt    embedded_postscript;
    208 
    209     /* these should only be used for the top-level font dictionary */
    210     FT_UInt    cid_registry;
    211     FT_UInt    cid_ordering;
    212     FT_Long    cid_supplement;
    213 
    214     FT_Long    cid_font_version;
    215     FT_Long    cid_font_revision;
    216     FT_Long    cid_font_type;
    217     FT_ULong   cid_count;
    218     FT_ULong   cid_uid_base;
    219     FT_ULong   cid_fd_array_offset;
    220     FT_ULong   cid_fd_select_offset;
    221     FT_UInt    cid_font_name;
    222 
    223     /* the next fields come from the data of the deprecated          */
    224     /* `MultipleMaster' operator; they are needed to parse the (also */
    225     /* deprecated) `blend' operator in Type 2 charstrings            */
    226     FT_UShort  num_designs;
    227     FT_UShort  num_axes;
    228 
    229     /* fields for CFF2 */
    230     FT_ULong   vstore_offset;
    231     FT_UInt    maxstack;
    232 
    233   } CFF_FontRecDictRec, *CFF_FontRecDict;
    234 
    235 
    236   /* forward reference */
    237   typedef struct CFF_SubFontRec_*  CFF_SubFont;
    238 
    239 
    240   typedef struct  CFF_PrivateRec_
    241   {
    242     FT_Byte   num_blue_values;
    243     FT_Byte   num_other_blues;
    244     FT_Byte   num_family_blues;
    245     FT_Byte   num_family_other_blues;
    246 
    247     FT_Pos    blue_values[14];
    248     FT_Pos    other_blues[10];
    249     FT_Pos    family_blues[14];
    250     FT_Pos    family_other_blues[10];
    251 
    252     FT_Fixed  blue_scale;
    253     FT_Pos    blue_shift;
    254     FT_Pos    blue_fuzz;
    255     FT_Pos    standard_width;
    256     FT_Pos    standard_height;
    257 
    258     FT_Byte   num_snap_widths;
    259     FT_Byte   num_snap_heights;
    260     FT_Pos    snap_widths[13];
    261     FT_Pos    snap_heights[13];
    262     FT_Bool   force_bold;
    263     FT_Fixed  force_bold_threshold;
    264     FT_Int    lenIV;
    265     FT_Int    language_group;
    266     FT_Fixed  expansion_factor;
    267     FT_Long   initial_random_seed;
    268     FT_ULong  local_subrs_offset;
    269     FT_Pos    default_width;
    270     FT_Pos    nominal_width;
    271 
    272     /* fields for CFF2 */
    273     FT_UInt      vsindex;
    274     CFF_SubFont  subfont;
    275 
    276   } CFF_PrivateRec, *CFF_Private;
    277 
    278 
    279   typedef struct  CFF_FDSelectRec_
    280   {
    281     FT_Byte   format;
    282     FT_UInt   range_count;
    283 
    284     /* that's the table, taken from the file `as is' */
    285     FT_Byte*  data;
    286     FT_UInt   data_size;
    287 
    288     /* small cache for format 3 only */
    289     FT_UInt   cache_first;
    290     FT_UInt   cache_count;
    291     FT_Byte   cache_fd;
    292 
    293   } CFF_FDSelectRec, *CFF_FDSelect;
    294 
    295 
    296   /* A SubFont packs a font dict and a private dict together.  They are */
    297   /* needed to support CID-keyed CFF fonts.                             */
    298   typedef struct  CFF_SubFontRec_
    299   {
    300     CFF_FontRecDictRec  font_dict;
    301     CFF_PrivateRec      private_dict;
    302 
    303     /* fields for CFF2 */
    304     CFF_BlendRec  blend;      /* current blend vector       */
    305     FT_UInt       lenNDV;     /* current length NDV or zero */
    306     FT_Fixed*     NDV;        /* ptr to current NDV or NULL */
    307 
    308     /* `blend_stack' is a writable buffer to hold blend results.          */
    309     /* This buffer is to the side of the normal cff parser stack;         */
    310     /* `cff_parse_blend' and `cff_blend_doBlend' push blend results here. */
    311     /* The normal stack then points to these values instead of the DICT   */
    312     /* because all other operators in Private DICT clear the stack.       */
    313     /* `blend_stack' could be cleared at each operator other than blend.  */
    314     /* Blended values are stored as 5-byte fixed point values.            */
    315 
    316     FT_Byte*  blend_stack;    /* base of stack allocation     */
    317     FT_Byte*  blend_top;      /* first empty slot             */
    318     FT_UInt   blend_used;     /* number of bytes in use       */
    319     FT_UInt   blend_alloc;    /* number of bytes allocated    */
    320 
    321     CFF_IndexRec  local_subrs_index;
    322     FT_Byte**     local_subrs; /* array of pointers           */
    323                                /* into Local Subrs INDEX data */
    324 
    325     FT_UInt32  random;
    326 
    327   } CFF_SubFontRec;
    328 
    329 
    330 #define CFF_MAX_CID_FONTS  256
    331 
    332 
    333   typedef struct  CFF_FontRec_
    334   {
    335     FT_Library       library;
    336     FT_Stream        stream;
    337     FT_Memory        memory;        /* TODO: take this from stream->memory? */
    338     FT_ULong         base_offset;   /* offset to start of CFF */
    339     FT_UInt          num_faces;
    340     FT_UInt          num_glyphs;
    341 
    342     FT_Byte          version_major;
    343     FT_Byte          version_minor;
    344     FT_Byte          header_size;
    345 
    346     FT_UInt          top_dict_length;   /* cff2 only */
    347 
    348     FT_Bool          cff2;
    349 
    350     CFF_IndexRec     name_index;
    351     CFF_IndexRec     top_dict_index;
    352     CFF_IndexRec     global_subrs_index;
    353 
    354     CFF_EncodingRec  encoding;
    355     CFF_CharsetRec   charset;
    356 
    357     CFF_IndexRec     charstrings_index;
    358     CFF_IndexRec     font_dict_index;
    359     CFF_IndexRec     private_index;
    360     CFF_IndexRec     local_subrs_index;
    361 
    362     FT_String*       font_name;
    363 
    364     /* array of pointers into Global Subrs INDEX data */
    365     FT_Byte**        global_subrs;
    366 
    367     /* array of pointers into String INDEX data stored at string_pool */
    368     FT_UInt          num_strings;
    369     FT_Byte**        strings;
    370     FT_Byte*         string_pool;
    371     FT_ULong         string_pool_size;
    372 
    373     CFF_SubFontRec   top_font;
    374     FT_UInt          num_subfonts;
    375     CFF_SubFont      subfonts[CFF_MAX_CID_FONTS];
    376 
    377     CFF_FDSelectRec  fd_select;
    378 
    379     /* interface to PostScript hinter */
    380     PSHinter_Service  pshinter;
    381 
    382     /* interface to Postscript Names service */
    383     FT_Service_PsCMaps  psnames;
    384 
    385     /* interface to CFFLoad service */
    386     const void*  cffload;
    387 
    388     /* since version 2.3.0 */
    389     PS_FontInfoRec*  font_info;   /* font info dictionary */
    390 
    391     /* since version 2.3.6 */
    392     FT_String*       registry;
    393     FT_String*       ordering;
    394 
    395     /* since version 2.4.12 */
    396     FT_Generic       cf2_instance;
    397 
    398     /* since version 2.7.1 */
    399     CFF_VStoreRec    vstore;        /* parsed vstore structure */
    400 
    401     /* since version 2.9 */
    402     PS_FontExtraRec*  font_extra;
    403 
    404   } CFF_FontRec;
    405 
    406 
    407 FT_END_HEADER
    408 
    409 #endif /* CFFTYPES_H_ */
    410 
    411 
    412 /* END */
    413