1 /* Copyright (C) 2001-2012 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., 7 Mt. Lassen Drive - Suite A-134, San Rafael, 13 CA 94903, U.S.A., +1(415)492-9861, for further information. 14 */ 15 16 17 /* Font API interface */ 18 19 #ifndef ifapi_INCLUDED 20 # define ifapi_INCLUDED 21 22 #include "iplugin.h" 23 #include "gstypes.h" 24 #include "gsmatrix.h" 25 #include "memory_.h" 26 #include "gp.h" 27 28 typedef int FracInt; /* A fractional integer with statically unknown number of fraction bits. 29 The number of bits depends on plugin and is being specified in 30 FAPI_server::frac_shift. 31 */ 32 typedef int FAPI_retcode; 33 34 typedef enum { 35 FAPI_FONT_FEATURE_FontMatrix, 36 FAPI_FONT_FEATURE_UniqueID, 37 FAPI_FONT_FEATURE_BlueScale, 38 FAPI_FONT_FEATURE_Weight, 39 FAPI_FONT_FEATURE_ItalicAngle, 40 FAPI_FONT_FEATURE_IsFixedPitch, 41 FAPI_FONT_FEATURE_UnderLinePosition, 42 FAPI_FONT_FEATURE_UnderlineThickness, 43 FAPI_FONT_FEATURE_FontType, 44 FAPI_FONT_FEATURE_FontBBox, 45 FAPI_FONT_FEATURE_BlueValues_count, 46 FAPI_FONT_FEATURE_BlueValues, 47 FAPI_FONT_FEATURE_OtherBlues_count, 48 FAPI_FONT_FEATURE_OtherBlues, 49 FAPI_FONT_FEATURE_FamilyBlues_count, 50 FAPI_FONT_FEATURE_FamilyBlues, 51 FAPI_FONT_FEATURE_FamilyOtherBlues_count, 52 FAPI_FONT_FEATURE_FamilyOtherBlues, 53 FAPI_FONT_FEATURE_BlueShift, 54 FAPI_FONT_FEATURE_BlueFuzz, 55 FAPI_FONT_FEATURE_StdHW, 56 FAPI_FONT_FEATURE_StdVW, 57 FAPI_FONT_FEATURE_StemSnapH_count, 58 FAPI_FONT_FEATURE_StemSnapH, 59 FAPI_FONT_FEATURE_StemSnapV_count, 60 FAPI_FONT_FEATURE_StemSnapV, 61 FAPI_FONT_FEATURE_ForceBold, 62 FAPI_FONT_FEATURE_LanguageGroup, 63 FAPI_FONT_FEATURE_lenIV, 64 FAPI_FONT_FEATURE_GlobalSubrs_count, 65 FAPI_FONT_FEATURE_Subrs_count, 66 FAPI_FONT_FEATURE_Subrs_total_size, 67 FAPI_FONT_FEATURE_TT_size, 68 /* Multiple Master specifics */ 69 FAPI_FONT_FEATURE_DollarBlend, 70 FAPI_FONT_FEATURE_DollarBlend_length, 71 FAPI_FONT_FEATURE_BlendAxisTypes_count, 72 FAPI_FONT_FEATURE_BlendAxisTypes, 73 FAPI_FONT_FEATURE_BlendPrivate_count, 74 FAPI_FONT_FEATURE_BlendFontInfo_count, 75 FAPI_FONT_FEATURE_WeightVector_count, 76 FAPI_FONT_FEATURE_WeightVector, 77 FAPI_FONT_FEATURE_BlendDesignPositionsArrays_count, 78 FAPI_FONT_FEATURE_BlendDesignPositionsArrayValue, 79 FAPI_FONT_FEATURE_BlendDesignMapArrays_count, 80 FAPI_FONT_FEATURE_BlendDesignMapSubArrays_count, 81 FAPI_FONT_FEATURE_BlendDesignMapArrayValue, 82 /* End MM specifics */ 83 /* CharString emission */ 84 FAPI_FONT_FEATURE_CharStrings_count, 85 /* End CharString emission */ 86 } fapi_font_feature; 87 88 typedef enum { 89 FAPI_METRICS_NOTDEF, 90 FAPI_METRICS_ADD, /* Add to native glyph width. */ 91 FAPI_METRICS_REPLACE_WIDTH, /* Replace the native glyph width. */ 92 FAPI_METRICS_REPLACE /* Replace the native glyph width and lsb. */ 93 } FAPI_metrics_type; 94 95 typedef struct { 96 int char_code; /* Backwards compatibility. Depricated. */ 97 int client_char_code; /* Debug purpose. */ 98 int char_codes[4]; 99 int char_codes_count; 100 bool is_glyph_index; /* true if char_code contains glyph index */ 101 const unsigned char *char_name; /* to be used exclusively with char_code. */ 102 unsigned int char_name_length; 103 FAPI_metrics_type metrics_type; 104 FracInt sb_x, sb_y, aw_x, aw_y; /* replaced PS metrics. */ 105 int metrics_scale; /* Scale for replaced PS metrics. 106 Zero means "em box size". */ 107 } FAPI_char_ref; 108 109 typedef struct FAPI_font_s FAPI_font; 110 struct FAPI_font_s { 111 /* server's data : */ 112 void *server_font_data; 113 bool need_decrypt; 114 /* client's data : */ 115 const gs_memory_t *memory; 116 const char *font_file_path; 117 int subfont; 118 bool is_type1; /* Only for non-disk fonts; dirty for disk fonts. */ 119 bool is_cid; 120 bool is_outline_font; 121 bool is_mtx_skipped; /* Ugly. Only UFST needs. */ 122 bool is_vertical; 123 void *client_ctx_p; 124 void *client_font_data; 125 void *client_font_data2; 126 const void *char_data; 127 int char_data_len; 128 unsigned short (*get_word )(FAPI_font *ff, fapi_font_feature var_id, int index); 129 unsigned long (*get_long )(FAPI_font *ff, fapi_font_feature var_id, int index); 130 float (*get_float)(FAPI_font *ff, fapi_font_feature var_id, int index); 131 int (*get_name) (FAPI_font *ff, fapi_font_feature var_id, int index, char *buffer, int len); 132 int (*get_proc) (FAPI_font *ff, fapi_font_feature var_id, int index, char *Buffer); 133 unsigned short (*get_gsubr)(FAPI_font *ff, int index, byte *buf, ushort buf_length); 134 unsigned short (*get_subr) (FAPI_font *ff, int index, byte *buf, ushort buf_length); 135 unsigned short (*get_raw_subr) (FAPI_font *ff, int index, byte *buf, ushort buf_length); 136 int (*get_glyph)(FAPI_font *ff, int char_code, byte *buf, ushort buf_length); 137 unsigned short (*serialize_tt_font)(FAPI_font *ff, void *buf, int buf_size); 138 unsigned short (*get_charstring) (FAPI_font *ff, int index, byte *buf, ushort buf_length); 139 unsigned short (*get_charstring_name) (FAPI_font *ff, int index, byte *buf, ushort buf_length); 140 }; 141 142 typedef struct FAPI_face_s FAPI_face; 143 struct FAPI_face_s { 144 gs_id font_id; 145 gs_matrix ctm; 146 gs_log2_scale_point log2_scale; 147 bool align_to_pixels; 148 float HWResolution[2]; 149 }; 150 151 typedef struct FAPI_path_s FAPI_path; 152 struct FAPI_path_s { 153 void *olh; /* Client's data. */ 154 int shift; 155 int gs_error; 156 int (*moveto )(FAPI_path *, int64_t, int64_t); 157 int (*lineto )(FAPI_path *, int64_t, int64_t); 158 int (*curveto )(FAPI_path *, int64_t, int64_t, int64_t, int64_t, int64_t, int64_t); 159 int (*closepath)(FAPI_path *); 160 }; 161 162 typedef struct FAPI_font_scale_s { 163 FracInt matrix[6]; 164 FracInt HWResolution[2]; 165 int subpixels[2]; 166 bool align_to_pixels; 167 } FAPI_font_scale; 168 169 typedef struct FAPI_metrics_s { 170 int bbox_x0, bbox_y0, bbox_x1, bbox_y1; /* design units */ 171 int escapement; /* design units */ 172 int v_escapement; /* design units */ 173 int em_x, em_y; /* design units */ 174 } FAPI_metrics; 175 176 typedef struct { /* 1bit/pixel only, rows are byte-aligned. */ 177 void *p; 178 int width, height, line_step; 179 int orig_x, orig_y; /* origin, 1/16s pixel */ 180 int left_indent, top_indent; 181 int black_width, black_height; 182 } FAPI_raster; 183 184 #ifndef FAPI_server_DEFINED 185 #define FAPI_server_DEFINED 186 typedef struct FAPI_server_s FAPI_server; 187 #endif 188 189 typedef enum FAPI_descendant_code_s { /* Possible values are descendant font indices and 4 ones defined below. */ 190 FAPI_DESCENDANT_PREPARED = -1, /* See FAPI_prepare_font in zfapi.c . */ 191 FAPI_TOPLEVEL_PREPARED = -2, 192 FAPI_TOPLEVEL_BEGIN = -3, 193 FAPI_TOPLEVEL_COMPLETE = -4 194 } FAPI_descendant_code; 195 196 struct FAPI_server_s { 197 i_plugin_instance ig; 198 int frac_shift; /* The number of fractional bits in coordinates. */ 199 FAPI_face face; 200 FAPI_font ff; 201 int max_bitmap; 202 bool use_outline; 203 gs_matrix initial_FontMatrix; /* Font Matrix at the time the font is defined */ 204 /* Used to use the stored 'OrigFont' entry but */ 205 /* this did not change f a font was defined */ 206 /* using an existing base font */ 207 FAPI_retcode (*ensure_open)(FAPI_server *server, const byte * param, int param_size); 208 FAPI_retcode (*get_scaled_font)(FAPI_server *server, FAPI_font *ff, const FAPI_font_scale *scale, const char *xlatmap, FAPI_descendant_code dc); 209 FAPI_retcode (*get_decodingID)(FAPI_server *server, FAPI_font *ff, const char **decodingID); 210 FAPI_retcode (*get_font_bbox)(FAPI_server *server, FAPI_font *ff, int BBox[4]); 211 FAPI_retcode (*get_font_proportional_feature)(FAPI_server *server, FAPI_font *ff, bool *bProportional); 212 FAPI_retcode (*can_retrieve_char_by_name)(FAPI_server *server, FAPI_font *ff, FAPI_char_ref *c, int *result); 213 FAPI_retcode (*can_replace_metrics)(FAPI_server *server, FAPI_font *ff, FAPI_char_ref *c, int *result); 214 FAPI_retcode (*get_fontmatrix)(FAPI_server *server, gs_matrix *m); 215 FAPI_retcode (*get_char_width)(FAPI_server *server, FAPI_font *ff, FAPI_char_ref *c, FAPI_metrics *metrics); 216 FAPI_retcode (*get_char_raster_metrics)(FAPI_server *server, FAPI_font *ff, FAPI_char_ref *c, FAPI_metrics *metrics); 217 FAPI_retcode (*get_char_raster)(FAPI_server *server, FAPI_raster *r); 218 FAPI_retcode (*get_char_outline_metrics)(FAPI_server *server, FAPI_font *ff, FAPI_char_ref *c, FAPI_metrics *metrics); 219 FAPI_retcode (*get_char_outline)(FAPI_server *server, FAPI_path *p); 220 FAPI_retcode (*release_char_data)(FAPI_server *server); 221 FAPI_retcode (*release_typeface)(FAPI_server *server, void *server_font_data); 222 FAPI_retcode (*check_cmap_for_GID)(FAPI_server *server, uint *index); 223 /* Some people get confused with terms "font cache" and "character cache". 224 "font cache" means a cache for scaled font objects, which mainly 225 keep the font header information and rules for adjusting it to specific raster. 226 "character cahce" is a cache for specific character outlines and/or character rasters. 227 */ 228 /* get_scaled_font opens a typeface with a server and scales it according to CTM and HWResolution. 229 This creates a server's scaled font object. 230 Since UFST doesn't provide a handle to this object, 231 we need to build the data for it and call this function whenever scaled font data may change. 232 The server must cache scaled fonts internally. 233 Note that FreeType doesn't provide internal font cache, 234 so the bridge must do. 235 */ 236 /* GS cannot provide information when a scaled font to be closed. 237 Therefore we don't provide close_scaled_font function in this interface. 238 The server must cache scaled fonts, and close ones which were 239 not in use during a long time. 240 */ 241 /* Due to the interpreter fallback with CDevProc, 242 get_char_raster_metrics leaves some data kept by the server, 243 so taht get_char_raster uses them and release_char_data releases them. 244 Therefore calls from GS to these functions must not 245 interfer with different characters. 246 */ 247 }; 248 249 #endif /* ifapi_INCLUDED */ 250