1 /* Copyright (C) 2001-2019 Artifex Software, Inc.
2    All Rights Reserved.
3 
4    This software is provided AS-IS with no warranty, either express or
5    implied.
6 
7    This software is distributed under license and may not be copied,
8    modified or distributed except as expressly authorized under the terms
9    of the license contained in the file LICENSE in this distribution.
10 
11    Refer to licensing information at http://www.artifex.com or contact
12    Artifex Software, Inc.,  1305 Grant Avenue - Suite 200, Novato,
13    CA 94945, U.S.A., +1(415)492-9861, for further information.
14 */
15 
16 
17 /* Interpreter internal font representation */
18 
19 #ifndef ifont_INCLUDED
20 #  define ifont_INCLUDED
21 
22 #include "gxfont.h"
23 #include "iref.h"
24 #include "gsfont.h"
25 
26 /* The external definition of fonts is given in the PostScript manual, */
27 /* pp. 91-93. */
28 
29 /* The structure given below is 'client data' from the viewpoint */
30 /* of the library.  font-type objects (t_struct/st_font, "t_fontID") */
31 /* point directly to a gs_font.  */
32 /* Note: From the GC point of view, it is handled as an array of refs, followed by */
33 /*       non-relocatable data starting with u.type42.mru_sfnts_index; this also    */
34 /*       means all members of union _fs must start with the same number of refs    */
35 
36 typedef struct font_data_s {
37     ref dict;			/* font dictionary object */
38     ref BuildChar;
39     ref BuildGlyph;
40     ref Encoding;
41     ref CharStrings;
42     ref GlyphNames2Unicode;
43     union _fs {
44         struct _f1 {
45             ref OtherSubrs;	/* from Private dictionary */
46             ref Subrs;		/* from Private dictionary */
47             ref GlobalSubrs;	/* from Private dictionary, */
48             /* for Type 2 charstrings */
49         } type1;
50         struct _f42 {
51             ref sfnts;
52             ref CIDMap;		/* for CIDFontType 2 fonts */
53             ref GlyphDirectory;
54             /* the following are used to optimize lookups into sfnts */
55             uint mru_sfnts_index;   /* index of most recently used sfnts string */
56             ulong mru_sfnts_pos;    /* data bytes before sfnts string at index mru_sfnts_index */
57         } type42;
58         struct _fc0 {
59             ref GlyphDirectory;
60             ref GlyphData;	/* (if preloaded) string or array of strings */
61             ref DataSource;	/* (if not preloaded) reusable stream */
62         } cid0;
63     } u;
64 } font_data;
65 
66 /*
67  * Even though the interpreter's part of the font data actually
68  * consists of refs, allocating it as refs tends to create sandbars;
69  * since it is always allocated and freed as a unit, we can treat it
70  * as an ordinary structure.
71  */
72 /* st_font_data is exported for zdefault_make_font in zfont.c. */
73 extern_st(st_font_data);
74 #define public_st_font_data()	/* in zbfont.c */\
75   static struct_proc_clear_marks(font_data_clear_marks);\
76   static struct_proc_enum_ptrs(font_data_enum_ptrs);\
77   static struct_proc_reloc_ptrs(font_data_reloc_ptrs);\
78   gs_public_st_complex_only(st_font_data, font_data, "font_data",\
79     font_data_clear_marks, font_data_enum_ptrs, font_data_reloc_ptrs, 0)
80 #define pfont_data(pfont) ((font_data *)((pfont)->client_data))
81 #define pfont_dict(pfont) (&pfont_data(pfont)->dict)
82 
83 /* ================Internal procedures shared across files ================ */
84 
85 /* ---------------- Exported by zchar.c ---------------- */
86 
87 /*
88  * Get the FontBBox from a font dictionary, if any; if none, or if invalid,
89  * return 4 zeros.
90  */
91 int font_bbox_param(const gs_memory_t *mem, const ref *pfdict, double bbox[4]);
92 
93 /* ---------------- Exported by zfont.c ---------------- */
94 
95 /*
96  * Check a parameter that should be a valid font dictionary, and return
97  * the gs_font stored in its FID entry.
98  */
99 int font_param(const ref * pfdict, gs_font ** ppfont);
100 
101 /*
102  * Mark a glyph as a PostScript name (if it isn't a CID) for the garbage
103  * collector.  Return true if a mark was just added.  This procedure is
104  * intended to be used as the mark_glyph procedure in the character cache.
105  */
106 bool zfont_mark_glyph_name(const gs_memory_t *mem, gs_glyph glyph, void *ignore_data);
107 
108 /*
109  * Return information about a font, including information from the FontInfo
110  * dictionary.  This procedure is intended to be used as the font_info
111  * procedure in all PostScript fonts.
112  */
113 font_proc_font_info(zfont_info);
114 
115 #endif /* ifont_INCLUDED */
116