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