xref: /plan9/sys/src/cmd/gs/src/gstypes.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1989, 1995, 1998, 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: gstypes.h,v 1.7 2005/09/05 13:58:55 leonardo Exp $ */
18 /* Miscellaneous common types for Ghostscript library */
19 
20 #ifndef gstypes_INCLUDED
21 #  define gstypes_INCLUDED
22 
23 /*
24  * Define a type used internally for unique IDs of various kinds
25  * (primarily, but not exclusively, character and halftone bitmaps).
26  * These IDs bear no relation to any other ID space; we generate them all
27  * ourselves.
28  */
29 typedef ulong gs_id;
30 
31 #define gs_no_id 0L
32 
33 /*
34  * Define a sensible representation of a string, as opposed to
35  * the C char * type (which can't store arbitrary data, represent
36  * substrings, or perform concatenation without destroying aliases).
37  *
38  * If a byte * pointer P is the result of allocating a string of size N,
39  * then any substring of [P .. P+N) is a valid gs_string, i.e., any
40  * gs_string S is valid (until the string is deallocated) if it has P <=
41  * S.data and S.data + S.size <= P + N.
42  */
43 #define GS_STRING_COMMON\
44     byte *data;\
45     uint size
46 typedef struct gs_string_s {
47     GS_STRING_COMMON;
48 } gs_string;
49 #define GS_CONST_STRING_COMMON\
50     const byte *data;\
51     uint size
52 typedef struct gs_const_string_s {
53     GS_CONST_STRING_COMMON;
54 } gs_const_string;
55 typedef struct gs_param_string_s {
56     GS_CONST_STRING_COMMON;
57     bool persistent;
58 } gs_param_string;
59 
60 /*
61  * Since strings are allocated differently from ordinary objects, define a
62  * structure that can reference either a string or a byte object.  If bytes
63  * == 0, data and size are the same as for a gs_string.  If bytes != 0, data
64  * and size point within the object addressed by bytes (i.e., the bytes
65  * member plays the role of P in the consistency condition given for
66  * gs_string above).  Thus in either case, code can process the string using
67  * only data and size: bytes is only relevant for garbage collection.
68  *
69  * Note: for garbage collection purposes, the string_common members must
70  * come first.
71  */
72 typedef struct gs_bytestring_s {
73     GS_STRING_COMMON;
74     byte *bytes;		/* see above */
75 } gs_bytestring;
76 typedef struct gs_const_bytestring_s {
77     GS_CONST_STRING_COMMON;
78     const byte *bytes;		/* see above */
79 } gs_const_bytestring;
80 
81 #define gs_bytestring_from_string(pbs, dat, siz)\
82   ((pbs)->data = (dat), (pbs)->size = (siz), (pbs)->bytes = 0)
83 #define gs_bytestring_from_bytes(pbs, byts, offset, siz)\
84   ((pbs)->data = ((pbs)->bytes = (byts)) + (offset), (pbs)->size = (siz))
85 
86 /*
87  * Define types for Cartesian points.
88  */
89 typedef struct gs_point_s {
90     double x, y;
91 } gs_point;
92 typedef struct gs_int_point_s {
93     int x, y;
94 } gs_int_point;
95 
96 /*
97  * Define a scale for oversampling.  Clients don't actually use this,
98  * but this seemed like the handiest place for it.
99  */
100 typedef struct gs_log2_scale_point_s {
101     int x, y;
102 } gs_log2_scale_point;
103 
104 /*
105  * Define types for rectangles in the Cartesian plane.
106  * Note that rectangles are half-open, i.e.: their width is
107  * q.x-p.x and their height is q.y-p.y; they include the points
108  * (x,y) such that p.x<=x<q.x and p.y<=y<q.y.
109  */
110 typedef struct gs_rect_s {
111     gs_point p, q;		/* origin point, corner point */
112 } gs_rect;
113 typedef struct gs_int_rect_s {
114     gs_int_point p, q;
115 } gs_int_rect;
116 
117 /*
118  * Define a type for a floating-point parameter range.  Note that unlike
119  * the intervals for gs_rect and gs_int_rect, these intervals are closed
120  * (i.e., they represent rmin <= x <= rmax, not rmin <= x < rmax).
121  */
122 typedef struct gs_range_s {
123     float rmin, rmax;
124 } gs_range_t;
125 
126 #endif /* gstypes_INCLUDED */
127