1 /* Copyright (C) 2001-2006 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, modified 8 or distributed except as expressly authorized under the terms of that 9 license. Refer to licensing information at http://www.artifex.com/ 10 or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134, 11 San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information. 12 */ 13 14 /* $Id: gsgdata.h 8022 2007-06-05 22:23:38Z giles $ */ 15 /* Interface for glyph data access */ 16 17 #ifndef gsgdata_INCLUDED 18 # define gsgdata_INCLUDED 19 20 #include "gsstype.h" /* for extern_st */ 21 22 /* 23 * Define the structure used to return the data for a glyph upon 24 * request. "Data" currently means the bytes of a Type 1, TrueType, or 25 * similar scalable outline, or the bits of a bitmap (not currently used). 26 */ 27 28 /* ------ Information for clients ------ */ 29 30 /* 31 * Clients that get glyph data (for example, using the get_outline procedure 32 * of a Type 42 or a CIDFontType 2 font) do so as follows: 33 34 gs_glyph_data_t gdata; 35 int code; 36 ... 37 code = ...get_outline(...&gdata...); 38 39 * 40 * If code >= 0 (no error), gdata.bits.{data,size} point to the outline data. 41 * 42 * Since the data may have been allocated in response to the request, 43 * when the client is finished with the data, it should call: 44 45 gs_glyph_data_free(&gdata, "client name"); 46 47 * This is a no-op if the data are stored in the font, but an actual freeing 48 * procedure if they were allocated by get_outline. 49 */ 50 51 /* ------ Structure declaration ------ */ 52 53 typedef struct gs_glyph_data_procs_s gs_glyph_data_procs_t; 54 #ifndef gs_glyph_data_DEFINED 55 # define gs_glyph_data_DEFINED 56 typedef struct gs_glyph_data_s gs_glyph_data_t; 57 #endif 58 struct gs_glyph_data_s { 59 gs_const_bytestring bits; /* pointer to actual data returned here */ 60 const gs_glyph_data_procs_t *procs; 61 void *proc_data; 62 gs_memory_t *memory; /* allocator to use (may be different than font) */ 63 }; 64 extern_st(st_glyph_data); 65 #define ST_GLYPH_DATA_NUM_PTRS 2 66 67 /* 68 * NOTE: Clients must not call these procedures directly. Use the 69 * gs_glyph_data_{substring,free} procedures declared below. 70 */ 71 struct gs_glyph_data_procs_s { 72 #define GS_PROC_GLYPH_DATA_FREE(proc)\ 73 void proc(gs_glyph_data_t *pgd, client_name_t cname) 74 GS_PROC_GLYPH_DATA_FREE((*free)); 75 #define GS_PROC_GLYPH_DATA_SUBSTRING(proc)\ 76 int proc(gs_glyph_data_t *pgd, uint offset, uint size) 77 GS_PROC_GLYPH_DATA_SUBSTRING((*substring)); 78 }; 79 80 /* 81 * Replace glyph data by a substring. If the data were allocated by 82 * get_outline et al, this frees the part of the data outside the substring. 83 */ 84 int gs_glyph_data_substring(gs_glyph_data_t *pgd, uint offset, uint size); 85 86 /* 87 * Free the data for a glyph if they were allocated by get_outline et al. 88 * This also does the equivalent of a from_null (see below) so that 89 * multiple calls of this procedure are harmless. 90 */ 91 void gs_glyph_data_free(gs_glyph_data_t *pgd, client_name_t cname); 92 93 /* ------ Information for implementors of get_outline et al ------ */ 94 95 /* 96 * The implementor of get_outline or similar procedures should set the 97 * client's glyph_data_t structure as follows: 98 99 ...get_outline...(...gs_font *pfont...gs_glyph_data_t *pgd...) 100 { 101 ... 102 gs_glyph_data_from_string(pgd, odata, osize, NULL); 103 (or) gs_glyph_data_from_string(pgd, odata, osize, pfont); 104 } 105 106 * If the data are in an object rather then a string, use 107 108 gs_glyph_data_from_bytes(pgd, obase, ooffset, osize, <NULL|pfont>); 109 110 * The last argument of gs_glyph_data_from_{string|bytes} should be pfont 111 * iff odata/osize were allocated by this call and will not be retained 112 * by the implementor (i.e., should be freed when the client calls 113 * gs_glyph_data_free), NULL otherwise. 114 */ 115 116 /* 117 * Initialize glyph data from a string or from bytes. 118 */ 119 #ifndef gs_font_DEFINED 120 # define gs_font_DEFINED 121 typedef struct gs_font_s gs_font; 122 #endif 123 void gs_glyph_data_from_string(gs_glyph_data_t *pgd, const byte *data, 124 uint size, gs_font *font); 125 void gs_glyph_data_from_bytes(gs_glyph_data_t *pgd, const byte *bytes, 126 uint offset, uint size, gs_font *font); 127 /* from_null(pgd) is a shortcut for from_string(pgd, NULL, 0, NULL). */ 128 void gs_glyph_data_from_null(gs_glyph_data_t *pgd); 129 130 #endif /* gsgdata_INCLUDED */ 131