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