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