xref: /plan9/sys/src/cmd/gs/src/gstype1.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1990, 1995, 1996, 1997, 1999, 2001 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: gstype1.h,v 1.9 2003/10/21 01:43:28 igor Exp $ */
18 /* Client interface to Adobe Type 1 font routines */
19 
20 #ifndef gstype1_INCLUDED
21 #  define gstype1_INCLUDED
22 
23 /* ------ Normal client interface ------ */
24 
25 #define crypt_charstring_seed 4330
26 typedef struct gs_type1_state_s gs_type1_state;
27 
28 #ifndef gx_path_DEFINED
29 #  define gx_path_DEFINED
30 typedef struct gx_path_s gx_path;
31 #endif
32 #ifndef gs_font_type1_DEFINED
33 #  define gs_font_type1_DEFINED
34 typedef struct gs_font_type1_s gs_font_type1;
35 #endif
36 #ifndef gs_type1_data_s_DEFINED
37 struct gs_type1_data_s;
38 #endif
39 int gs_type1_interp_init(gs_type1_state * pcis, gs_imager_state * pis,
40 			 gx_path * ppath, const gs_log2_scale_point * pscale,
41 			 const gs_log2_scale_point * psubpixels, bool no_grid_fitting,
42 			 int paint_type, gs_font_type1 * pfont);
43 void gs_type1_set_callback_data(gs_type1_state *pcis, void *callback_data);
44 void gs_type1_set_lsb(gs_type1_state * pcis, const gs_point * psbpt);
45 void gs_type1_set_width(gs_type1_state * pcis, const gs_point * pwpt);
46 
47 /* Backward compatibility */
48 #define gs_type1_init(pcis, penum, psbpt, charpath_flag, paint_type, pfont)\
49   (gs_type1_interp_init(pcis, (gs_imager_state *)((penum)->pgs),\
50 			(penum)->pgs->path, &(penum)->log2_current_scale,\
51 			charpath_flag, paint_type, pfont) |\
52    ((psbpt) == 0 ? 0 : (gs_type1_set_lsb(pcis, psbpt), 0)))
53 /*
54  * Continue interpreting a (Type 1) CharString.  If str != 0, it is taken as
55  * the byte string to interpret.  Return 0 on successful completion, <0 on
56  * error, or >0 when client intervention is required (or allowed).  The int*
57  * argument is where the othersubr # is stored for callothersubr.
58  */
59 #define type1_result_sbw 1	/* allow intervention after [h]sbw */
60 #define type1_result_callothersubr 2
61 
62 /* Define the generic procedure type for a CharString interpreter. */
63 #define charstring_interpret_proc(proc)\
64   int proc(gs_type1_state *, const gs_glyph_data_t *, int *)
65 typedef charstring_interpret_proc((*charstring_interpret_proc_t));
66 
67 /* Define the Type 1 interpreter. */
68 charstring_interpret_proc(gs_type1_interpret);
69 /* Define the Type 2 interpreter. */
70 charstring_interpret_proc(gs_type2_interpret);
71 
72 /* ------ CharString number representation ------ */
73 
74 /* Define the representation of integers used by both Type 1 and Type 2. */
75 typedef enum {
76 
77     /* Values from 32 to 246 represent small integers. */
78     c_num1 = 32,
79 #define c_value_num1(ch) ((int)(byte)(ch) - 139)
80 
81     /* The next 4 values represent 2-byte positive integers. */
82     c_pos2_0 = 247,
83     c_pos2_1 = 248,
84     c_pos2_2 = 249,
85     c_pos2_3 = 250,
86 #define c_value_pos2(c1,c2)\
87   (((int)(byte)((c1) - (int)c_pos2_0) << 8) + (int)(byte)(c2) + 108)
88 
89     /* The next 4 values represent 2-byte negative integers. */
90     c_neg2_0 = 251,
91     c_neg2_1 = 252,
92     c_neg2_2 = 253,
93     c_neg2_3 = 254
94 #define c_value_neg2(c1,c2)\
95   -(((int)(byte)((c1) - (int)c_neg2_0) << 8) + (int)(byte)(c2) + 108)
96 
97 } char_num_command;
98 
99 /* ------ Type 1 & Type 2 CharString representation ------ */
100 
101 /*
102  * We define both the Type 1 and Type 2 operators here, because they
103  * overlap so much.
104  */
105 typedef enum {
106 
107     /* Commands with identical functions in Type 1 and Type 2 */
108     /* charstrings. */
109 
110     c_undef0 = 0,
111     c_undef2 = 2,
112     c_callsubr = 10,
113     c_return = 11,
114     c_undoc15 = 15,		/* An obsolete and undocumented */
115     /* command used in some very old */
116     /* Adobe fonts. */
117     c_undef17 = 17,
118 
119     /* Commands with similar but not identical functions */
120     /* in Type 1 and Type 2 charstrings. */
121 
122     cx_hstem = 1,
123     cx_vstem = 3,
124     cx_vmoveto = 4,
125     cx_rlineto = 5,
126     cx_hlineto = 6,
127     cx_vlineto = 7,
128     cx_rrcurveto = 8,
129     cx_escape = 12,		/* extends the command set */
130     cx_endchar = 14,
131     cx_rmoveto = 21,
132     cx_hmoveto = 22,
133     cx_vhcurveto = 30,
134     cx_hvcurveto = 31,
135 
136     cx_num4 = 255,		/* 4-byte numbers */
137 
138     /* Commands recognized only in Type 1 charstrings. */
139 
140     c1_closepath = 9,
141     c1_hsbw = 13,
142 
143     /* Commands not recognized in Type 1 charstrings. */
144 
145 #define case_c1_undefs\
146 	case 16: case 18: case 19:\
147 	case 20: case 23: case 24:\
148 	case 25: case 26: case 27: case 28: case 29
149 
150     /* Commands only recognized in Type 2 charstrings. */
151 
152     c2_blend = 16,
153     c2_hstemhm = 18,
154     c2_hintmask = 19,
155     c2_cntrmask = 20,
156     c2_vstemhm = 23,
157     c2_rcurveline = 24,
158     c2_rlinecurve = 25,
159     c2_vvcurveto = 26,
160     c2_hhcurveto = 27,
161     c2_shortint = 28,
162     c2_callgsubr = 29
163 
164     /* Commands not recognized in Type 2 charstrings. */
165 
166 #define case_c2_undefs\
167 	case 9: case 13
168 
169 } char_command;
170 
171 #define char1_command_names\
172   0, "hstem", 0, "vstem", "vmoveto",\
173   "rlineto", "hlineto", "vlineto", "rrcurveto", "closepath",\
174   "callsubr", "return", "(escape)", "hsbw", "endchar",\
175   "undoc15", 0, 0, 0, 0,\
176   0, "rmoveto", "hmoveto", 0, 0,\
177   0, 0, 0, 0, 0,\
178   "vhcurveto", "hvcurveto"
179 #define char2_command_names\
180   0, "hstem", 0, "vstem", "vmoveto",\
181   "rlineto", "hlineto", "vlineto", "rrcurveto", 0,\
182   "callsubr", "return", "(escape)", 0, "endchar",\
183   "undoc15", "blend", 0, "hstemhm", "hintmask",\
184   "cntrmask", "rmoveto", "hmoveto", "vstemhm", "rcurveline",\
185   "rlinecurve", "vvcurveto", "hhcurveto", "shortint", "callgsubr",\
186   "vhcurveto", "hvcurveto"
187 
188 /*
189  * Extended (escape) commands in Type 1 charstrings.
190  */
191 typedef enum {
192     ce1_dotsection = 0,
193     ce1_vstem3 = 1,
194     ce1_hstem3 = 2,
195     ce1_seac = 6,
196     ce1_sbw = 7,
197     ce1_div = 12,
198     ce1_undoc15 = 15,		/* An obsolete and undocumented */
199     /* command used in some very old */
200     /* Adobe fonts. */
201     ce1_callothersubr = 16,
202     ce1_pop = 17,
203     ce1_setcurrentpoint = 33
204 } char1_extended_command;
205 
206 #define char1_extended_command_count 34
207 #define char1_extended_command_names\
208   "dotsection", "vstem3", "hstem3", 0, 0,\
209   0, "seac", "sbw", 0, 0,\
210   0, 0, "div", 0, 0,\
211   "undoc15", "callothersubr", "pop", 0, 0,\
212   0, 0, 0, 0, 0,\
213   0, 0, 0, 0, 0,\
214   0, 0, 0, "setcurrentpoint"
215 
216 /*
217  * Extended (escape) commands in Type 2 charstrings.
218  */
219 typedef enum {
220     ce2_and = 3,
221     ce2_or = 4,
222     ce2_not = 5,
223     ce2_store = 8,
224     ce2_abs = 9,
225     ce2_add = 10,
226     ce2_sub = 11,
227     ce2_div = 12,		/* same as ce1_div */
228     ce2_load = 13,
229     ce2_neg = 14,
230     ce2_eq = 15,
231     ce2_drop = 18,
232     ce2_put = 20,
233     ce2_get = 21,
234     ce2_ifelse = 22,
235     ce2_random = 23,
236     ce2_mul = 24,
237     ce2_sqrt = 26,
238     ce2_dup = 27,
239     ce2_exch = 28,
240     ce2_index = 29,
241     ce2_roll = 30,
242     ce2_hflex = 34,
243     ce2_flex = 35,
244     ce2_hflex1 = 36,
245     ce2_flex1 = 37
246 } char2_extended_command;
247 
248 #define char2_extended_command_count 38
249 #define char2_extended_command_names\
250   0, 0, 0, "and", "or",\
251   "not", 0, 0, "store", "abs",\
252   "add", "sub", "div", "load", "neg",\
253   "eq", 0, 0, "drop", 0,\
254   "put", "get", "ifelse", "random", "mul",\
255   0, "sqrt", "dup", "exch", "index",\
256   "roll", 0, 0, 0, "hflex",\
257   "flex", "hflex1", "flex1"
258 
259 #endif /* gstype1_INCLUDED */
260