cffgload.h revision f463818dd9146e11105c0572fb119e757eb47768
1/***************************************************************************/
2/*                                                                         */
3/*  cffgload.h                                                             */
4/*                                                                         */
5/*    OpenType Glyph Loader (specification).                               */
6/*                                                                         */
7/*  Copyright 1996-2001, 2002, 2003, 2004, 2006, 2007 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
28FT_BEGIN_HEADER
29
30
31#define CFF_MAX_OPERANDS     48
32#define CFF_MAX_SUBRS_CALLS  32
33
34
35  /*************************************************************************/
36  /*                                                                       */
37  /* <Structure>                                                           */
38  /*    CFF_Builder                                                        */
39  /*                                                                       */
40  /* <Description>                                                         */
41  /*     A structure used during glyph loading to store its outline.       */
42  /*                                                                       */
43  /* <Fields>                                                              */
44  /*    memory        :: The current memory object.                        */
45  /*                                                                       */
46  /*    face          :: The current face object.                          */
47  /*                                                                       */
48  /*    glyph         :: The current glyph slot.                           */
49  /*                                                                       */
50  /*    loader        :: The current glyph loader.                         */
51  /*                                                                       */
52  /*    base          :: The base glyph outline.                           */
53  /*                                                                       */
54  /*    current       :: The current glyph outline.                        */
55  /*                                                                       */
56  /*    last          :: The last point position.                          */
57  /*                                                                       */
58  /*    scale_x       :: The horizontal scale (FUnits to sub-pixels).      */
59  /*                                                                       */
60  /*    scale_y       :: The vertical scale (FUnits to sub-pixels).        */
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_Vector       last;
96
97    FT_Fixed        scale_x;
98    FT_Fixed        scale_y;
99
100    FT_Pos          pos_x;
101    FT_Pos          pos_y;
102
103    FT_Vector       left_bearing;
104    FT_Vector       advance;
105
106    FT_BBox         bbox;          /* bounding box */
107    FT_Bool         path_begun;
108    FT_Bool         load_points;
109    FT_Bool         no_recurse;
110
111    FT_Bool         metrics_only;
112
113    void*           hints_funcs;    /* hinter-specific */
114    void*           hints_globals;  /* hinter-specific */
115
116  } CFF_Builder;
117
118
119  /* execution context charstring zone */
120
121  typedef struct  CFF_Decoder_Zone_
122  {
123    FT_Byte*  base;
124    FT_Byte*  limit;
125    FT_Byte*  cursor;
126
127  } CFF_Decoder_Zone;
128
129
130  typedef struct  CFF_Decoder_
131  {
132    CFF_Builder        builder;
133    CFF_Font           cff;
134
135    FT_Fixed           stack[CFF_MAX_OPERANDS + 1];
136    FT_Fixed*          top;
137
138    CFF_Decoder_Zone   zones[CFF_MAX_SUBRS_CALLS + 1];
139    CFF_Decoder_Zone*  zone;
140
141    FT_Int             flex_state;
142    FT_Int             num_flex_vectors;
143    FT_Vector          flex_vectors[7];
144
145    FT_Pos             glyph_width;
146    FT_Pos             nominal_width;
147
148    FT_Bool            read_width;
149    FT_Int             num_hints;
150    FT_Fixed*          buildchar;
151    FT_Int             len_buildchar;
152
153    FT_UInt            num_locals;
154    FT_UInt            num_globals;
155
156    FT_Int             locals_bias;
157    FT_Int             globals_bias;
158
159    FT_Byte**          locals;
160    FT_Byte**          globals;
161
162    FT_Byte**          glyph_names;   /* for pure CFF fonts only  */
163    FT_UInt            num_glyphs;    /* number of glyphs in font */
164
165    FT_Render_Mode     hint_mode;
166
167  } CFF_Decoder;
168
169
170  FT_LOCAL( void )
171  cff_decoder_init( CFF_Decoder*    decoder,
172                    TT_Face         face,
173                    CFF_Size        size,
174                    CFF_GlyphSlot   slot,
175                    FT_Bool         hinting,
176                    FT_Render_Mode  hint_mode );
177
178  FT_LOCAL( FT_Error )
179  cff_decoder_prepare( CFF_Decoder*  decoder,
180                       FT_UInt       glyph_index );
181
182#if 0  /* unused until we support pure CFF fonts */
183
184  /* Compute the maximum advance width of a font through quick parsing */
185  FT_LOCAL( FT_Error )
186  cff_compute_max_advance( TT_Face  face,
187                           FT_Int*  max_advance );
188
189#endif /* 0 */
190
191  FT_LOCAL( FT_Error )
192  cff_decoder_parse_charstrings( CFF_Decoder*  decoder,
193                                 FT_Byte*      charstring_base,
194                                 FT_ULong      charstring_len );
195
196  FT_LOCAL( FT_Error )
197  cff_slot_load( CFF_GlyphSlot  glyph,
198                 CFF_Size       size,
199                 FT_UInt        glyph_index,
200                 FT_Int32       load_flags );
201
202
203FT_END_HEADER
204
205#endif /* __CFFGLOAD_H__ */
206
207
208/* END */
209