1 /* Copyright (C) 1989, 1995, 1996, 1997, 1999, 2000 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: gxfont.h,v 1.3.4.1.2.1 2003/01/17 00:49:03 giles Exp $ */ 20 /* Font object structure */ 21 /* Requires gsmatrix.h, gxdevice.h */ 22 23 #ifndef gxfont_INCLUDED 24 # define gxfont_INCLUDED 25 26 #include "gsccode.h" 27 #include "gsfont.h" 28 #include "gsnotify.h" 29 #include "gsuid.h" 30 #include "gsstype.h" /* for extern_st */ 31 #include "gxftype.h" 32 33 /* A font object as seen by clients. */ 34 /* See the PostScript Language Reference Manual for details. */ 35 36 #ifndef gs_text_enum_DEFINED 37 # define gs_text_enum_DEFINED 38 typedef struct gs_text_enum_s gs_text_enum_t; 39 #endif 40 41 #ifndef gx_path_DEFINED 42 # define gx_path_DEFINED 43 typedef struct gx_path_s gx_path; 44 #endif 45 46 /* 47 * Define flags for font properties (Flags* members in the structure below.) 48 * Currently these must match the ones defined for PDF. 49 */ 50 #define FONT_IS_FIXED_WIDTH (1<<0) 51 /* 52 * Define the structure used to return information about the font as a 53 * whole. Currently this structure almost exactly parallels the PDF 54 * FontDescriptor. 55 * 56 * Unless otherwise specified, values are in the font's native character 57 * space, scaled as requested by the call to the font_info procedure. 58 * Note that Type 1 fonts typically have 1000 units per em, while 59 * TrueType fonts typically have 1 unit per em. 60 */ 61 typedef struct gs_font_info_s { 62 int members; 63 64 /* The following members exactly parallel the PDF FontDescriptor flags. */ 65 66 #define FONT_INFO_ASCENT 0x0001 67 int Ascent; 68 #define FONT_INFO_AVG_WIDTH 0x0002 69 int AvgWidth; 70 #define FONT_INFO_BBOX 0x0004 71 gs_int_rect BBox; /* computed from outlines, not FontBBox */ 72 #define FONT_INFO_CAP_HEIGHT 0x0008 73 int CapHeight; 74 #define FONT_INFO_DESCENT 0x0010 75 int Descent; 76 #define FONT_INFO_FLAGS 0x0020 77 uint Flags; /* a mask of FONT_IS_ bits */ 78 uint Flags_requested; /* client must set this if FLAGS requested */ 79 uint Flags_returned; 80 #define FONT_INFO_ITALIC_ANGLE 0x0100 81 float ItalicAngle; /* degrees CCW from vertical */ 82 #define FONT_INFO_LEADING 0x0200 83 int Leading; 84 #define FONT_INFO_MAX_WIDTH 0x0400 85 int MaxWidth; 86 #define FONT_INFO_MISSING_WIDTH 0x0800 87 int MissingWidth; 88 #define FONT_INFO_STEM_H 0x00010000 89 int StemH; 90 #define FONT_INFO_STEM_V 0x00020000 91 int StemV; 92 #define FONT_INFO_UNDERLINE_POSITION 0x00040000 93 int UnderlinePosition; 94 #define FONT_INFO_UNDERLINE_THICKNESS 0x00080000 95 int UnderlineThickness; 96 #define FONT_INFO_X_HEIGHT 0x00100000 97 int XHeight; 98 99 /* The following members do NOT appear in the PDF FontDescriptor. */ 100 101 #define FONT_INFO_COPYRIGHT 0x0040 102 gs_const_string Copyright; 103 #define FONT_INFO_NOTICE 0x0080 104 gs_const_string Notice; 105 #define FONT_INFO_FAMILY_NAME 0x1000 106 gs_const_string FamilyName; 107 #define FONT_INFO_FULL_NAME 0x2000 108 gs_const_string FullName; 109 110 } gs_font_info_t; 111 112 /* 113 * Define the structure used to return information about a glyph. 114 */ 115 typedef struct gs_glyph_info_s { 116 int members; /* mask of which members are valid */ 117 #define GLYPH_INFO_WIDTH0 1 118 #define GLYPH_INFO_WIDTH GLYPH_INFO_WIDTH0 119 #define GLYPH_INFO_WIDTH1 2 /* must be WIDTH0 << 1 */ 120 #define GLYPH_INFO_WIDTHS (GLYPH_INFO_WIDTH0 | GLYPH_INFO_WIDTH1) 121 gs_point width[2]; /* width for WMode 0/1 */ 122 #define GLYPH_INFO_BBOX 4 123 gs_rect bbox; 124 #define GLYPH_INFO_NUM_PIECES 8 125 int num_pieces; /* # of pieces if composite, 0 if not */ 126 #define GLYPH_INFO_PIECES 16 127 gs_glyph *pieces; /* pieces are stored here: the caller must */ 128 /* preset pieces if INFO_PIECES is set. */ 129 } gs_glyph_info_t; 130 131 /* Define the "object" procedures of fonts. */ 132 133 typedef struct gs_font_procs_s { 134 135 /* ------ Font-level procedures ------ */ 136 137 /* 138 * Define any special handling of gs_definefont. 139 * We break this out so it can be different for composite fonts. 140 */ 141 142 #define font_proc_define_font(proc)\ 143 int proc(P2(gs_font_dir *, gs_font *)) 144 font_proc_define_font((*define_font)); 145 146 /* 147 * Define any special handling of gs_makefont. 148 * We break this out so it can be different for composite fonts. 149 */ 150 151 #define font_proc_make_font(proc)\ 152 int proc(P4(gs_font_dir *, const gs_font *, const gs_matrix *, gs_font **)) 153 font_proc_make_font((*make_font)); 154 155 /* 156 * Get information about the font, as specified by the members mask. 157 * Disregard the FontMatrix: scale the font as indicated by *pscale 158 * (pscale=NULL means no scaling). Set info->members to the members 159 * that are actually returned. Note that some member options require 160 * the caller to preset some of the elements of info. Note also that 161 * this procedure may return more information than was requested. 162 */ 163 164 #define font_proc_font_info(proc)\ 165 int proc(P4(gs_font *font, const gs_point *pscale, int members,\ 166 gs_font_info_t *info)) 167 font_proc_font_info((*font_info)); 168 169 /* 170 * Determine whether this font is the "same as" another font in the ways 171 * specified by the mask. The returned value is a subset of the mask. 172 * This procedure is allowed to be conservative (return false in cases 173 * of uncertainty). Note that this procedure does not test the UniqueID 174 * or FontMatrix. 175 */ 176 177 #define FONT_SAME_OUTLINES 1 178 #define FONT_SAME_METRICS 2 179 #define FONT_SAME_ENCODING 4 180 181 #define font_proc_same_font(proc)\ 182 int proc(P3(const gs_font *font, const gs_font *ofont, int mask)) 183 font_proc_same_font((*same_font)); 184 185 /* ------ Glyph-level procedures ------ */ 186 187 /* Map a character code to a glyph. Some PostScript fonts use both 188 * names and indices to identify glyphs: for example, in PostScript Type 189 * 42 fonts, the Encoding array maps character codes to glyph names, and 190 * the CharStrings dictionary maps glyph names to glyph indices. In 191 * such fonts, the glyph_space argument determines which type of glyph 192 * is returned. 193 */ 194 195 #define font_proc_encode_char(proc)\ 196 gs_glyph proc(P3(gs_font *, gs_char, gs_glyph_space_t)) 197 font_proc_encode_char((*encode_char)); 198 199 /* 200 * Get the next glyph in an enumeration of all glyphs defined by the 201 * font. index = 0 means return the first one; a returned index of 0 202 * means the enumeration is finished. The glyphs are enumerated in 203 * an unpredictable order. 204 */ 205 206 #define font_proc_enumerate_glyph(proc)\ 207 int proc(P4(gs_font *font, int *pindex, gs_glyph_space_t glyph_space,\ 208 gs_glyph *pglyph)) 209 font_proc_enumerate_glyph((*enumerate_glyph)); 210 211 /* 212 * Get information about a glyph, as specified by the members mask. 213 * pmat = NULL means get the scalable values; non-NULL pmat means get 214 * the scaled values. Set info->members to the members that are 215 * actually returned. Return gs_error_undefined if the glyph doesn't 216 * exist in the font; calling glyph_info with members = 0 is an 217 * efficient way to find out whether a given glyph exists. Note that 218 * some member options require the caller to preset some of the elements 219 * of info. Note also that this procedure may return more information 220 * than was requested. 221 */ 222 223 #define font_proc_glyph_info(proc)\ 224 int proc(P5(gs_font *font, gs_glyph glyph, const gs_matrix *pmat,\ 225 int members, gs_glyph_info_t *info)) 226 font_proc_glyph_info((*glyph_info)); 227 228 /* 229 * Append the outline for a glyph to a path, with the glyph origin 230 * at the current point. pmat is as for glyph_width. The outline 231 * does include a final moveto for the advance width. 232 */ 233 234 #define font_proc_glyph_outline(proc)\ 235 int proc(P4(gs_font *font, gs_glyph glyph, const gs_matrix *pmat,\ 236 gx_path *ppath)) 237 font_proc_glyph_outline((*glyph_outline)); 238 239 /* ------ Glyph rendering procedures ------ */ 240 241 /* 242 * Define any needed procedure for initializing the composite 243 * font stack in a show enumerator. This is a no-op for 244 * all but composite fonts. 245 */ 246 247 #define font_proc_init_fstack(proc)\ 248 int proc(P2(gs_text_enum_t *, gs_font *)) 249 font_proc_init_fstack((*init_fstack)); 250 251 /* 252 * Define the font's algorithm for getting the next character or glyph 253 * from a string being shown. This is trivial, except for composite 254 * fonts. Returns 0 if the current (base) font didn't change, 1 if it 255 * did change, 2 if there are no more characters, or an error code. 256 * 257 * This procedure may set either *pchar to gs_no_char or *pglyph to 258 * gs_no_glyph, but not both. 259 */ 260 261 #define font_proc_next_char_glyph(proc)\ 262 int proc(P3(gs_text_enum_t *pte, gs_char *pchar, gs_glyph *pglyph)) 263 font_proc_next_char_glyph((*next_char_glyph)); 264 265 /* 266 * Define a client-supplied BuildChar/BuildGlyph procedure. 267 * The gs_char may be gs_no_char (for BuildGlyph), or the gs_glyph 268 * may be gs_no_glyph (for BuildChar), but not both. Return 0 for 269 * success, 1 if the procedure was unable to render the character 270 * (but no error occurred), <0 for error. 271 */ 272 273 #define font_proc_build_char(proc)\ 274 int proc(P5(gs_text_enum_t *, gs_state *, gs_font *, gs_char, gs_glyph)) 275 font_proc_build_char((*build_char)); 276 277 /* Callback procedures for external font rasterizers */ 278 /* (see gsccode.h for details.) */ 279 280 gx_xfont_callbacks callbacks; 281 282 } gs_font_procs; 283 284 /* Default font-level font procedures in gsfont.c */ 285 font_proc_define_font(gs_no_define_font); 286 font_proc_make_font(gs_no_make_font); 287 font_proc_make_font(gs_base_make_font); 288 font_proc_font_info(gs_default_font_info); 289 font_proc_same_font(gs_default_same_font); 290 font_proc_same_font(gs_base_same_font); 291 /* Default glyph-level font procedures in gsfont.c */ 292 font_proc_encode_char(gs_no_encode_char); 293 font_proc_enumerate_glyph(gs_no_enumerate_glyph); 294 font_proc_glyph_info(gs_default_glyph_info); 295 font_proc_glyph_outline(gs_no_glyph_outline); 296 /* Default glyph rendering procedures in gstext.c */ 297 font_proc_init_fstack(gs_default_init_fstack); 298 font_proc_next_char_glyph(gs_default_next_char_glyph); 299 font_proc_build_char(gs_no_build_char); 300 /* Default procedure vector in gsfont.c */ 301 extern const gs_font_procs gs_font_procs_default; 302 303 /* The font names are only needed for xfont lookup and high-level output. */ 304 typedef struct gs_font_name_s { 305 #define gs_font_name_max 47 /* must be >= 40 */ 306 /* The +1 is so we can null-terminate for debugging printout. */ 307 byte chars[gs_font_name_max + 1]; 308 uint size; 309 } gs_font_name; 310 311 /* 312 * Define a generic font. We include PaintType and StrokeWidth here because 313 * they affect rendering algorithms outside the Type 1 font machinery. 314 * 315 * ****** NOTE: If you define any subclasses of gs_font, you *must* define 316 * ****** the finalization procedure as gs_font_finalize. Finalization 317 * ****** procedures are not automatically inherited. 318 */ 319 #define gs_font_common\ 320 gs_font *next, *prev; /* chain for original font list or */\ 321 /* scaled font cache */\ 322 gs_memory_t *memory; /* allocator for this font */\ 323 gs_font_dir *dir; /* directory where registered */\ 324 bool is_resource;\ 325 gs_notify_list_t notify_list; /* clients to notify when freeing */\ 326 gs_id id; /* internal ID (no relation to UID) */\ 327 gs_font *base; /* original (unscaled) base font */\ 328 void *client_data; /* additional client data */\ 329 gs_matrix FontMatrix;\ 330 font_type FontType;\ 331 bool BitmapWidths;\ 332 fbit_type ExactSize, InBetweenSize, TransformedChar;\ 333 int WMode; /* 0 or 1 */\ 334 int PaintType; /* PaintType for Type 1/4/42 fonts, */\ 335 /* 0 for others */\ 336 float StrokeWidth; /* StrokeWidth for Type 1/4/42 */\ 337 /* fonts (if present), 0 for others */\ 338 gs_font_procs procs;\ 339 /* We store both the FontDirectory key (key_name) and, */\ 340 /* if present, the FontName (font_name). */\ 341 gs_font_name key_name, font_name 342 /*typedef struct gs_font_s gs_font; *//* in gsfont.h and other places */ 343 struct gs_font_s { 344 gs_font_common; 345 }; 346 347 extern_st(st_gs_font); /* (abstract) */ 348 struct_proc_finalize(gs_font_finalize); /* public for concrete subclasses */ 349 #define public_st_gs_font() /* in gsfont.c */\ 350 gs_public_st_complex_only(st_gs_font, gs_font, "gs_font",\ 351 0, font_enum_ptrs, font_reloc_ptrs, gs_font_finalize) 352 #define st_gs_font_max_ptrs (st_gs_notify_list_max_ptrs + 5) 353 354 #define private_st_gs_font_ptr() /* in gsfont.c */\ 355 gs_private_st_ptr(st_gs_font_ptr, gs_font *, "gs_font *",\ 356 font_ptr_enum_ptrs, font_ptr_reloc_ptrs) 357 #define st_gs_font_ptr_max_ptrs 1 358 359 extern_st(st_gs_font_ptr_element); 360 #define public_st_gs_font_ptr_element() /* in gsfont.c */\ 361 gs_public_st_element(st_gs_font_ptr_element, gs_font *, "gs_font *[]",\ 362 font_ptr_element_enum_ptrs, font_ptr_element_reloc_ptrs, st_gs_font_ptr) 363 364 /* Allocate and minimally initialize a font. */ 365 /* Does not set: FontMatrix, FontType, key_name, font_name. */ 366 gs_font * 367 gs_font_alloc(P5(gs_memory_t *mem, gs_memory_type_ptr_t pstype, 368 const gs_font_procs *procs, gs_font_dir *dir, 369 client_name_t cname)); 370 371 /* 372 * Register/unregister a client for notification by a font. Currently 373 * the clients are only notified when a font is freed. Note that any 374 * such client must unregister itself when *it* is freed. 375 */ 376 int gs_font_notify_register(P3(gs_font *font, gs_notify_proc_t proc, 377 void *proc_data)); 378 int gs_font_notify_unregister(P3(gs_font *font, gs_notify_proc_t proc, 379 void *proc_data)); 380 381 /* Define a base (not composite) font. */ 382 #define gs_font_base_common\ 383 gs_font_common;\ 384 gs_rect FontBBox;\ 385 gs_uid UID;\ 386 gs_encoding_index_t encoding_index;\ 387 gs_encoding_index_t nearest_encoding_index /* (may be >= 0 even if */\ 388 /* encoding_index = -1) */ 389 #ifndef gs_font_base_DEFINED 390 # define gs_font_base_DEFINED 391 typedef struct gs_font_base_s gs_font_base; 392 #endif 393 struct gs_font_base_s { 394 gs_font_base_common; 395 }; 396 397 extern_st(st_gs_font_base); 398 #define public_st_gs_font_base() /* in gsfont.c */\ 399 gs_public_st_suffix_add1_final(st_gs_font_base, gs_font_base,\ 400 "gs_font_base", font_base_enum_ptrs, font_base_reloc_ptrs,\ 401 gs_font_finalize, st_gs_font, UID.xvalues) 402 #define st_gs_font_base_max_ptrs (st_gs_font_max_ptrs + 1) 403 404 /* Allocate and minimally initialize a base font. */ 405 /* Does not set: same elements as gs_alloc_font. */ 406 gs_font_base * 407 gs_font_base_alloc(P5(gs_memory_t *mem, gs_memory_type_ptr_t pstype, 408 const gs_font_procs *procs, gs_font_dir *dir, 409 client_name_t cname)); 410 411 /* 412 * Test whether a glyph is the notdef glyph for a base font. 413 * The test is somewhat adhoc: perhaps this should be a virtual procedure. 414 */ 415 bool gs_font_glyph_is_notdef(P2(gs_font_base *bfont, gs_glyph glyph)); 416 417 #endif /* gxfont_INCLUDED */ 418