1 /* Copyright (C) 1990, 1995, 1996, 1997, 1999 artofcode LLC.  All rights reserved.
2 
3   This program is free software; you can redistribute it and/or modify it
4   under the terms of the GNU General Public License as published by the
5   Free Software Foundation; either version 2 of the License, or (at your
6   option) any later version.
7 
8   This program is distributed in the hope that it will be useful, but
9   WITHOUT ANY WARRANTY; without even the implied warranty of
10   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11   General Public License for more details.
12 
13   You should have received a copy of the GNU General Public License along
14   with this program; if not, write to the Free Software Foundation, Inc.,
15   59 Temple Place, Suite 330, Boston, MA, 02111-1307.
16 
17 */
18 
19 /*$Id: gstype1.h,v 1.2.6.1.2.1 2003/01/17 00:49:03 giles Exp $ */
20 /* Client interface to Adobe Type 1 font routines */
21 
22 #ifndef gstype1_INCLUDED
23 #  define gstype1_INCLUDED
24 
25 /* ------ Normal client interface ------ */
26 
27 #define crypt_charstring_seed 4330
28 typedef struct gs_type1_state_s gs_type1_state;
29 
30 #ifndef gx_path_DEFINED
31 #  define gx_path_DEFINED
32 typedef struct gx_path_s gx_path;
33 #endif
34 #ifndef gs_font_type1_DEFINED
35 #  define gs_font_type1_DEFINED
36 typedef struct gs_font_type1_s gs_font_type1;
37 #endif
38 #ifndef gs_type1_data_s_DEFINED
39 struct gs_type1_data_s;
40 #endif
41 int gs_type1_interp_init(P7(gs_type1_state * pcis, gs_imager_state * pis,
42 			gx_path * ppath, const gs_log2_scale_point * pscale,
43 			    bool charpath_flag, int paint_type,
44 			    gs_font_type1 * pfont));
45 void gs_type1_set_callback_data(P2(gs_type1_state *pcis, void *callback_data));
46 void gs_type1_set_lsb(P2(gs_type1_state * pcis, const gs_point * psbpt));
47 void gs_type1_set_width(P2(gs_type1_state * pcis, const gs_point * pwpt));
48 
49 /* Backward compatibility */
50 #define gs_type1_init(pcis, penum, psbpt, charpath_flag, paint_type, pfont)\
51   (gs_type1_interp_init(pcis, (gs_imager_state *)((penum)->pgs),\
52 			(penum)->pgs->path, &(penum)->log2_current_scale,\
53 			charpath_flag, paint_type, pfont) |\
54    ((psbpt) == 0 ? 0 : (gs_type1_set_lsb(pcis, psbpt), 0)))
55 /*
56  * Continue interpreting a (Type 1) CharString.  If str != 0, it is taken as
57  * the byte string to interpret.  Return 0 on successful completion, <0 on
58  * error, or >0 when client intervention is required (or allowed).  The int*
59  * argument is where the othersubr # is stored for callothersubr.
60  */
61 #define type1_result_sbw 1	/* allow intervention after [h]sbw */
62 #define type1_result_callothersubr 2
63 
64 /* Define the generic procedure type for a CharString interpreter. */
65 #define charstring_interpret_proc(proc)\
66   int proc(P3(gs_type1_state *, const gs_const_string *, int *))
67 typedef charstring_interpret_proc((*charstring_interpret_proc_t));
68 
69 /* Define the Type 1 interpreter. */
70 charstring_interpret_proc(gs_type1_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