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