Fixed floating point rounding problem
[pspp-builds.git] / src / output.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3    Written by Ben Pfaff <blp@gnu.org>.
4
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program; if not, write to the Free Software
17    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18    02111-1307, USA. */
19
20 #if !output_h
21 #define output_h 1
22
23 #include "str.h"
24
25 /* A rectangle. */
26 struct rect
27   {
28     int x1, y1;                 /* Upper left. */
29     int x2, y2;                 /* Lower right, not part of the rectangle. */
30   };
31
32 #if 0
33 #if __GNUC__ > 1 && defined(__OPTIMIZE__)
34 extern inline int width (rect r) __attribute__ ((const));
35 extern inline int height (rect r) __attribute__ ((const));
36
37 extern inline int
38 width (rect r)
39 {
40   return r.x2 - r.x1 + 1;
41 }
42
43 extern inline int 
44 height (rect r)
45 {
46   return r.y2 - r.y1 + 1;
47 }
48 #else /* !__GNUC__ */
49 /* Be carefull of these ... they use the argument more than once. */
50 #define width(R)                                \
51         ((R).x2 - (R).x1 + 1)
52 #define height(R)                               \
53         ((R).y2 - (R).y1 + 1)
54 #endif /* !__GNUC__ */
55 #endif
56
57 /* Color descriptor. */
58 struct color
59   {
60     int flags;                  /* 0=normal, 1=transparent (ignore r,g,b). */
61     int r;                      /* Red component, 0-65535. */
62     int g;                      /* Green component, 0-65535. */
63     int b;                      /* Blue component, 0-65535. */
64   };
65
66 /* Mount positions for the four basic fonts.  Do not change the values. */
67 enum
68   {
69     OUTP_F_R,                   /* Roman font. */
70     OUTP_F_I,                   /* Italic font. */
71     OUTP_F_B,                   /* Bold font. */
72     OUTP_F_BI                   /* Bold-italic font. */
73   };
74
75 /* Line styles.  These must match:
76    som.h:SLIN_*
77    ascii.c:ascii_line_*() 
78    postscript.c:ps_line_*() */
79 enum
80   {
81     OUTP_L_NONE = 0,            /* No line. */
82     OUTP_L_SINGLE = 1,          /* Single line. */
83     OUTP_L_DOUBLE = 2,          /* Double line. */
84     OUTP_L_SPECIAL = 3,         /* Special line of driver-defined style. */
85
86     OUTP_L_COUNT                /* Number of line styles. */
87   };
88
89 /* Contains a line style for each part of an intersection. */
90 struct outp_styles
91   {
92     int l;                      /* left */
93     int t;                      /* top */
94     int r;                      /* right */
95     int b;                      /* bottom */
96   };
97
98 /* Text display options. */
99 enum
100   {
101     OUTP_T_NONE = 0,
102
103     /* Must match tab.h:TAB_*. */
104     OUTP_T_JUST_MASK = 00003,   /* Justification mask. */
105     OUTP_T_JUST_RIGHT = 00000,  /* Right justification. */
106     OUTP_T_JUST_LEFT = 00001,   /* Left justification. */
107     OUTP_T_JUST_CENTER = 00002, /* Center justification. */
108
109     OUTP_T_HORZ = 00010,        /* Horizontal size is specified. */
110     OUTP_T_VERT = 00020,        /* (Max) vertical size is specified. */
111
112     OUTP_T_0 = 00140,           /* Normal orientation. */
113     OUTP_T_CC90 = 00040,        /* 90 degrees counterclockwise. */
114     OUTP_T_CC180 = 00100,       /* 180 degrees counterclockwise. */
115     OUTP_T_CC270 = 00140,       /* 270 degrees counterclockwise. */
116     OUTP_T_C90 = 00140,         /* 90 degrees clockwise. */
117     OUTP_T_C180 = 00100,        /* 180 degrees clockwise. */
118     OUTP_T_C270 = 00040,        /* 270 degrees clockwise. */
119
120     /* Internal use by drivers only. */
121     OUTP_T_INTERNAL_DRAW = 01000        /* 1=Draw the text, 0=Metrics only. */
122   };
123
124 /* Describes text output. */
125 struct outp_text
126   {
127     /* Public. */
128     int options;                /* What is specified. */
129     struct len_string s;        /* String. */
130     int h, v;                   /* Horizontal, vertical size. */
131     int x, y;                   /* Position. */
132
133     /* Internal use only. */
134     int w, l;                   /* Width, length. */
135   };
136
137 struct som_table;
138 struct outp_driver;
139
140 /* Defines a class of output driver. */
141 struct outp_class
142   {
143     /* Basic class information. */
144     const char *name;           /* Name of this driver class. */
145     int magic;                  /* Driver-specific constant. */
146     int special;                /* Boolean value. */
147
148     /* Static member functions. */
149     int (*open_global) (struct outp_class *);
150     int (*close_global) (struct outp_class *);
151     int *(*font_sizes) (struct outp_class *, int *n_valid_sizes);
152
153     /* Virtual member functions. */
154     int (*preopen_driver) (struct outp_driver *);
155     void (*option) (struct outp_driver *, const char *key,
156                     const struct string *value);
157     int (*postopen_driver) (struct outp_driver *);
158     int (*close_driver) (struct outp_driver *);
159
160     int (*open_page) (struct outp_driver *);
161     int (*close_page) (struct outp_driver *);
162
163     /* special != 0: Used to submit tables for output. */
164     void (*submit) (struct outp_driver *, struct som_table *);
165     
166     /* special != 0: Methods below need not be defined. */
167     
168     /* Line methods. */
169     void (*line_horz) (struct outp_driver *, const struct rect *,
170                        const struct color *, int style);
171     void (*line_vert) (struct outp_driver *, const struct rect *,
172                        const struct color *, int style);
173     void (*line_intersection) (struct outp_driver *, const struct rect *,
174                                const struct color *,
175                                const struct outp_styles *style);
176
177     /* Drawing methods. */
178     void (*box) (struct outp_driver *, const struct rect *,
179                  const struct color *bord, const struct color *fill);
180     void (*polyline_begin) (struct outp_driver *, const struct color *);
181     void (*polyline_point) (struct outp_driver *, int, int);
182     void (*polyline_end) (struct outp_driver *);
183
184     /* Text methods. */
185     void (*text_set_font_by_name) (struct outp_driver *, const char *s);
186     void (*text_set_font_by_position) (struct outp_driver *, int);
187     void (*text_set_font_family) (struct outp_driver *, const char *s);
188     const char *(*text_get_font_name) (struct outp_driver *);
189     const char *(*text_get_font_family) (struct outp_driver *);
190     int (*text_set_size) (struct outp_driver *, int);
191     int (*text_get_size) (struct outp_driver *, int *em_width);
192     void (*text_metrics) (struct outp_driver *, struct outp_text *);
193     void (*text_draw) (struct outp_driver *, struct outp_text *);
194   };
195
196 /* Device types. */
197 enum
198   {
199     OUTP_DEV_NONE = 0,          /* None of the below. */
200     OUTP_DEV_LISTING = 001,     /* Listing device. */
201     OUTP_DEV_SCREEN = 002,      /* Screen device. */
202     OUTP_DEV_PRINTER = 004,     /* Printer device. */
203     OUTP_DEV_DISABLED = 010     /* Broken device. */
204   };
205
206 /* Defines the configuration of an output driver. */
207 struct outp_driver
208   {
209     struct outp_class *class;           /* Driver class. */
210     char *name;                 /* Name of this driver. */
211     int driver_open;            /* 1=driver is open, 0=driver is closed. */
212     int page_open;              /* 1=page is open, 0=page is closed. */
213
214     struct outp_driver *next, *prev;    /* Next, previous output driver in list. */
215
216     int device;                 /* Zero or more of OUTP_DEV_*. */
217     int res, horiz, vert;       /* Device resolution. */
218     int width, length;          /* Page size. */
219
220     int cp_x, cp_y;             /* Current position. */
221     int font_height;            /* Default font character height. */
222     int prop_em_width;          /* Proportional font em width. */
223     int fixed_width;            /* Fixed-pitch font character width. */
224     int horiz_line_width[OUTP_L_COUNT]; /* Width of horizontal lines. */
225     int vert_line_width[OUTP_L_COUNT];  /* Width of vertical lines. */
226     int horiz_line_spacing[1 << OUTP_L_COUNT];
227     int vert_line_spacing[1 << OUTP_L_COUNT];
228
229     void *ext;                  /* Private extension record. */
230     void *prc;                  /* Per-procedure extension record. */
231   };
232
233 /* Option structure for the keyword recognizer. */
234 struct outp_option
235   {
236     const char *keyword;        /* Keyword name. */
237     int cat;                    /* Category. */
238     int subcat;                 /* Subcategory. */
239   };
240
241 /* Information structure for the keyword recognizer. */
242 struct outp_option_info
243   {
244     char *initial;                      /* Initial characters. */
245     struct outp_option **options;       /* Search starting points. */
246   };
247
248 /* A list of driver classes. */
249 struct outp_driver_class_list
250   {
251     int ref_count;
252     struct outp_class *class;
253     struct outp_driver_class_list *next;
254   };
255
256 /* List of known output driver classes. */
257 extern struct outp_driver_class_list *outp_class_list;
258
259 /* List of configured output drivers. */
260 extern struct outp_driver *outp_driver_list;
261
262 /* Title, subtitle. */
263 extern char *outp_title;
264 extern char *outp_subtitle;
265
266 int outp_init (void);
267 int outp_read_devices (void);
268 int outp_done (void);
269
270 void outp_configure_clear (void);
271 void outp_configure_add (char *);
272 void outp_configure_macro (char *);
273
274 void outp_list_classes (void);
275
276 void outp_enable_device (int enable, int device);
277 struct outp_driver *outp_drivers (struct outp_driver *);
278
279 int outp_match_keyword (const char *, struct outp_option *,
280                         struct outp_option_info *, int *);
281
282 int outp_evaluate_dimension (char *, char **);
283 int outp_get_paper_size (char *, int *h, int *v);
284
285 int outp_eject_page (struct outp_driver *);
286
287 int outp_string_width (struct outp_driver *, const char *);
288
289 /* Imported from som-frnt.c. */
290 void som_destroy_driver (struct outp_driver *);
291
292 #endif /* output.h */