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