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