1 /****************************************************************************
5 * Basic OpenType/CFF type definitions and interface (specification
8 * Copyright (C) 1996-2023 by
9 * David Turner, Robert Wilhelm, and Werner Lemberg.
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.
24 #include <freetype/freetype.h>
25 #include <freetype/t1tables.h>
26 #include <freetype/internal/ftserv.h>
27 #include <freetype/internal/services/svpscmap.h>
28 #include <freetype/internal/pshints.h>
29 #include <freetype/internal/t1types.h>
35 /**************************************************************************
41 * A structure used to model a CFF Index table.
45 * The source input stream.
48 * The position of the first index byte in the input stream.
51 * The number of elements in the index.
54 * The size in bytes of object offsets in index.
57 * The position of first data byte in the index's bytes.
60 * The size of the data table in this index.
63 * A table of element offsets in the index. Must be loaded explicitly.
66 * If the index is loaded in memory, its bytes.
68 typedef struct CFF_IndexRec_
81 } CFF_IndexRec, *CFF_Index;
84 typedef struct CFF_EncodingRec_
90 FT_UShort sids [256]; /* avoid dynamic allocations */
93 } CFF_EncodingRec, *CFF_Encoding;
96 typedef struct CFF_CharsetRec_
103 FT_UShort* cids; /* the inverse mapping of `sids'; only needed */
104 /* for CID-keyed fonts */
108 } CFF_CharsetRec, *CFF_Charset;
111 /* cf. similar fields in file `ttgxvar.h' from the `truetype' module */
113 typedef struct CFF_VarData_
116 FT_UInt itemCount; /* not used; always zero */
117 FT_UInt shortDeltaCount; /* not used; always zero */
120 FT_UInt regionIdxCount; /* number of region indexes */
121 FT_UInt* regionIndices; /* array of `regionIdxCount' indices; */
122 /* these index `varRegionList' */
126 /* contribution of one axis to a region */
127 typedef struct CFF_AxisCoords_
130 FT_Fixed peakCoord; /* zero peak means no effect (factor = 1) */
136 typedef struct CFF_VarRegion_
138 CFF_AxisCoords* axisList; /* array of axisCount records */
143 typedef struct CFF_VStoreRec_
146 CFF_VarData* varData; /* array of dataCount records */
147 /* vsindex indexes this array */
149 FT_UInt regionCount; /* total number of regions defined */
150 CFF_VarRegion* varRegionList;
152 } CFF_VStoreRec, *CFF_VStore;
155 /* forward reference */
156 typedef struct CFF_FontRec_* CFF_Font;
159 /* This object manages one cached blend vector. */
161 /* There is a BlendRec for Private DICT parsing in each subfont */
162 /* and a BlendRec for charstrings in CF2_Font instance data. */
163 /* A cached BV may be used across DICTs or Charstrings if inputs */
164 /* have not changed. */
166 /* `usedBV' is reset at the start of each parse or charstring. */
167 /* vsindex cannot be changed after a BV is used. */
169 /* Note: NDV is long (32/64 bit), while BV is 16.16 (FT_Int32). */
170 typedef struct CFF_BlendRec_
172 FT_Bool builtBV; /* blendV has been built */
173 FT_Bool usedBV; /* blendV has been used */
174 CFF_Font font; /* top level font struct */
175 FT_UInt lastVsindex; /* last vsindex used */
176 FT_UInt lenNDV; /* normDV length (aka numAxes) */
177 FT_Fixed* lastNDV; /* last NDV used */
178 FT_UInt lenBV; /* BlendV length (aka numMasters) */
179 FT_Int32* BV; /* current blendV (per DICT/glyph) */
181 } CFF_BlendRec, *CFF_Blend;
184 typedef struct CFF_FontRecDictRec_
192 FT_Bool is_fixed_pitch;
193 FT_Fixed italic_angle;
194 FT_Fixed underline_position;
195 FT_Fixed underline_thickness;
197 FT_Int charstring_type;
198 FT_Matrix font_matrix;
199 FT_Bool has_font_matrix;
200 FT_ULong units_per_em; /* temporarily used as scaling value also */
201 FT_Vector font_offset;
205 FT_ULong charset_offset;
206 FT_ULong encoding_offset;
207 FT_ULong charstrings_offset;
208 FT_ULong private_offset;
209 FT_ULong private_size;
210 FT_Long synthetic_base;
211 FT_UInt embedded_postscript;
213 /* these should only be used for the top-level font dictionary */
214 FT_UInt cid_registry;
215 FT_UInt cid_ordering;
216 FT_Long cid_supplement;
218 FT_Long cid_font_version;
219 FT_Long cid_font_revision;
220 FT_Long cid_font_type;
222 FT_ULong cid_uid_base;
223 FT_ULong cid_fd_array_offset;
224 FT_ULong cid_fd_select_offset;
225 FT_UInt cid_font_name;
227 /* the next fields come from the data of the deprecated */
228 /* `MultipleMaster' operator; they are needed to parse the (also */
229 /* deprecated) `blend' operator in Type 2 charstrings */
230 FT_UShort num_designs;
233 /* fields for CFF2 */
234 FT_ULong vstore_offset;
237 } CFF_FontRecDictRec, *CFF_FontRecDict;
240 /* forward reference */
241 typedef struct CFF_SubFontRec_* CFF_SubFont;
244 typedef struct CFF_PrivateRec_
246 FT_Byte num_blue_values;
247 FT_Byte num_other_blues;
248 FT_Byte num_family_blues;
249 FT_Byte num_family_other_blues;
251 FT_Pos blue_values[14];
252 FT_Pos other_blues[10];
253 FT_Pos family_blues[14];
254 FT_Pos family_other_blues[10];
259 FT_Pos standard_width;
260 FT_Pos standard_height;
262 FT_Byte num_snap_widths;
263 FT_Byte num_snap_heights;
264 FT_Pos snap_widths[13];
265 FT_Pos snap_heights[13];
267 FT_Fixed force_bold_threshold;
269 FT_Int language_group;
270 FT_Fixed expansion_factor;
271 FT_Long initial_random_seed;
272 FT_ULong local_subrs_offset;
273 FT_Pos default_width;
274 FT_Pos nominal_width;
276 /* fields for CFF2 */
280 } CFF_PrivateRec, *CFF_Private;
283 typedef struct CFF_FDSelectRec_
288 /* that's the table, taken from the file `as is' */
292 /* small cache for format 3 only */
297 } CFF_FDSelectRec, *CFF_FDSelect;
300 /* A SubFont packs a font dict and a private dict together. They are */
301 /* needed to support CID-keyed CFF fonts. */
302 typedef struct CFF_SubFontRec_
304 CFF_FontRecDictRec font_dict;
305 CFF_PrivateRec private_dict;
307 /* fields for CFF2 */
308 CFF_BlendRec blend; /* current blend vector */
309 FT_UInt lenNDV; /* current length NDV or zero */
310 FT_Fixed* NDV; /* ptr to current NDV or NULL */
312 /* `blend_stack' is a writable buffer to hold blend results. */
313 /* This buffer is to the side of the normal cff parser stack; */
314 /* `cff_parse_blend' and `cff_blend_doBlend' push blend results here. */
315 /* The normal stack then points to these values instead of the DICT */
316 /* because all other operators in Private DICT clear the stack. */
317 /* `blend_stack' could be cleared at each operator other than blend. */
318 /* Blended values are stored as 5-byte fixed-point values. */
320 FT_Byte* blend_stack; /* base of stack allocation */
321 FT_Byte* blend_top; /* first empty slot */
322 FT_UInt blend_used; /* number of bytes in use */
323 FT_UInt blend_alloc; /* number of bytes allocated */
325 CFF_IndexRec local_subrs_index;
326 FT_Byte** local_subrs; /* array of pointers */
327 /* into Local Subrs INDEX data */
334 #define CFF_MAX_CID_FONTS 256
337 typedef struct CFF_FontRec_
341 FT_Memory memory; /* TODO: take this from stream->memory? */
342 FT_ULong base_offset; /* offset to start of CFF */
346 FT_Byte version_major;
347 FT_Byte version_minor;
350 FT_UInt top_dict_length; /* cff2 only */
354 CFF_IndexRec name_index;
355 CFF_IndexRec top_dict_index;
356 CFF_IndexRec global_subrs_index;
358 CFF_EncodingRec encoding;
359 CFF_CharsetRec charset;
361 CFF_IndexRec charstrings_index;
362 CFF_IndexRec font_dict_index;
363 CFF_IndexRec private_index;
364 CFF_IndexRec local_subrs_index;
366 FT_String* font_name;
368 /* array of pointers into Global Subrs INDEX data */
369 FT_Byte** global_subrs;
371 /* array of pointers into String INDEX data stored at string_pool */
374 FT_Byte* string_pool;
375 FT_ULong string_pool_size;
377 CFF_SubFontRec top_font;
378 FT_UInt num_subfonts;
379 CFF_SubFont subfonts[CFF_MAX_CID_FONTS];
381 CFF_FDSelectRec fd_select;
383 /* interface to PostScript hinter */
384 PSHinter_Service pshinter;
386 /* interface to Postscript Names service */
387 FT_Service_PsCMaps psnames;
389 /* interface to CFFLoad service */
392 /* since version 2.3.0 */
393 PS_FontInfoRec* font_info; /* font info dictionary */
395 /* since version 2.3.6 */
399 /* since version 2.4.12 */
400 FT_Generic cf2_instance;
402 /* since version 2.7.1 */
403 CFF_VStoreRec vstore; /* parsed vstore structure */
405 /* since version 2.9 */
406 PS_FontExtraRec* font_extra;
413 #endif /* CFFTYPES_H_ */