xref: /plan9/sys/src/cmd/gs/src/gsccode.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1993, 2000, 2002 Aladdin Enterprises.  All rights reserved.
2 
3   This software is provided AS-IS with no warranty, either express or
4   implied.
5 
6   This software is distributed under license and may not be copied,
7   modified or distributed except as expressly authorized under the terms
8   of the license contained in the file LICENSE in this distribution.
9 
10   For more information about licensing, please refer to
11   http://www.ghostscript.com/licensing/. For information on
12   commercial licensing, go to http://www.artifex.com/licensing/ or
13   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15 */
16 
17 /* $Id: gsccode.h,v 1.14 2004/08/19 19:33:09 stefan Exp $ */
18 /* Types for character codes */
19 
20 #ifndef gsccode_INCLUDED
21 #  define gsccode_INCLUDED
22 
23 /*
24  * Define a character code.  Normally this is just a single byte from a
25  * string, but because of composite fonts, character codes must be
26  * at least 32 bits.
27  */
28 typedef ulong gs_char;
29 
30 #define GS_NO_CHAR ((gs_char)~0L)
31 /* Backward compatibility */
32 #define gs_no_char GS_NO_CHAR
33 
34 /*
35  * Define a character glyph code, a.k.a. character name.  The space of
36  * glyph codes is divided into five sections:
37  *
38  *	- Codes >= GS_MIN_GLYPH_INDEX represent (non-negative)
39  *	  integers biased by GS_MIN_CID_GLYPH.  They represent glyph indices
40  *	  of a specific font.
41  *
42  *	- Codes within [GS_MIN_CID_GLYPH, GS_MIN_GLYPH_INDEX) represent (non-negative)
43  *	  integers biased by GS_MIN_CID_GLYPH.  They represent PostScript CIDs
44  *        of a specific Ordering.
45  *
46  *	- Codes < GS_MIN_CID_GLYPH represent named glyphs.  There are
47  *	  three sub-sections:
48  *
49  *	  - GS_NO_GLYPH, which means "no known glyph value".  Note that
50  *	    it is not the same as /.notdef or CID 0 or GID 0: it means
51  *	    that the identity of the glyph is unknown, as opposed to a
52  *	    known glyph that is used for rendering an unknown character
53  *	    code.
54  *
55  *	  - Codes < gs_c_min_std_encoding_glyph represent names in some
56  *	    global space that the graphics library doesn't attempt to
57  *	    interpret.  (When the client is the PostScript interpreter,
58  *	    these codes are PostScript name indices, but the graphics
59  *	    library doesn't know or rely on this.)  The graphics library
60  *	    *does* assume that such codes denote the same names across
61  *	    all fonts, and that they can be converted to a string name
62  *	    by the font's glyph_name virtual procedure.
63  *
64  *	  - Codes >= gs_c_min_std_encoding_glyph (and < GS_MIN_CID_GLYPH)
65  *	    represent names in a special space used for the 11 built-in
66  *	    Encodings.  The API is defined in gscencs.h.  The only
67  *	    procedures that generate or recognize such codes are the ones
68  *	    declared in that file: clients must be careful not to mix
69  *	    such codes with codes in the global space.
70  *
71  * Client code may assume that GS_NO_GLYPH < GS_MIN_CID_GLYPH (i.e., it is a
72  * "name", not an integer), but should not make assumptions about whether
73  * GS_NO_GLYPH is less than or greater than gs_c_min_std_encoding_glyph.
74  */
75 typedef ulong gs_glyph;
76 
77 #define GS_NO_GLYPH ((gs_glyph)0x7fffffff)
78 #if arch_sizeof_long > 4
79 #  define GS_MIN_CID_GLYPH ((gs_glyph)0x80000000L)
80 #else
81 /* Avoid compiler warnings about signed/unsigned constants. */
82 #  define GS_MIN_CID_GLYPH ((gs_glyph)~0x7fffffff)
83 #endif
84 #define GS_MIN_GLYPH_INDEX (GS_MIN_CID_GLYPH | (GS_MIN_CID_GLYPH >> 1))
85 #define GS_GLYPH_TAG (gs_glyph)(GS_MIN_CID_GLYPH | GS_MIN_GLYPH_INDEX)
86 #define GS_MAX_GLYPH max_ulong
87 /* Backward compatibility */
88 #define gs_no_glyph GS_NO_GLYPH
89 #define gs_min_cid_glyph GS_MIN_CID_GLYPH
90 #define gs_max_glyph GS_MAX_GLYPH
91 
92 /* Define a procedure for marking a gs_glyph during garbage collection. */
93 typedef bool (*gs_glyph_mark_proc_t)(const gs_memory_t *mem, gs_glyph glyph, void *proc_data);
94 
95 /* Define the indices for known encodings. */
96 typedef enum {
97     ENCODING_INDEX_UNKNOWN = -1,
98 	/* Real encodings.  These must come first. */
99     ENCODING_INDEX_STANDARD = 0,
100     ENCODING_INDEX_ISOLATIN1,
101     ENCODING_INDEX_SYMBOL,
102     ENCODING_INDEX_DINGBATS,
103     ENCODING_INDEX_WINANSI,
104     ENCODING_INDEX_MACROMAN,
105     ENCODING_INDEX_MACEXPERT,
106 #define NUM_KNOWN_REAL_ENCODINGS 7
107 	/* Pseudo-encodings (glyph sets). */
108     ENCODING_INDEX_MACGLYPH,	/* Mac glyphs */
109     ENCODING_INDEX_ALOGLYPH,	/* Adobe Latin glyph set */
110     ENCODING_INDEX_ALXGLYPH,	/* Adobe Latin Extended glyph set */
111     ENCODING_INDEX_CFFSTRINGS	/* CFF StandardStrings */
112 #define NUM_KNOWN_ENCODINGS 11
113 } gs_encoding_index_t;
114 #define KNOWN_REAL_ENCODING_NAMES\
115   "StandardEncoding", "ISOLatin1Encoding", "SymbolEncoding",\
116   "DingbatsEncoding", "WinAnsiEncoding", "MacRomanEncoding",\
117   "MacExpertEncoding"
118 
119 /*
120  * For fonts that use more than one method to identify glyphs, define the
121  * glyph space for the values returned by procedures that return glyphs.
122  * Note that if a font uses only one method (such as Type 1 fonts, which
123  * only use names, or TrueType fonts, which only use indexes), the
124  * glyph_space argument is ignored.
125  */
126 typedef enum gs_glyph_space_s {
127     GLYPH_SPACE_NAME,		/* names (if available) */
128     GLYPH_SPACE_INDEX,		/* indexes (if available) */
129     GLYPH_SPACE_NOGEN		/* don't generate new names (Type 3 only) */
130 } gs_glyph_space_t;
131 
132 /*
133  * Define a procedure for mapping a glyph to its (string) name.  This is
134  * currently used only for CMaps: it is *not* the same as the glyph_name
135  * procedure in fonts.
136  */
137 typedef int (*gs_glyph_name_proc_t)(const gs_memory_t *mem,
138 				    gs_glyph glyph, gs_const_string *pstr,
139 				    void *proc_data);
140 
141 #endif /* gsccode_INCLUDED */
142