Rewrite expression code.
[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 #include "config.h"
25
26 #include "chart.h"
27
28 /* A rectangle. */
29 struct rect
30   {
31     int x1, y1;                 /* Upper left. */
32     int x2, y2;                 /* Lower right, not part of the rectangle. */
33   };
34
35 /* Color descriptor. */
36 struct color
37   {
38     int flags;                  /* 0=normal, 1=transparent (ignore r,g,b). */
39     int r;                      /* Red component, 0-65535. */
40     int g;                      /* Green component, 0-65535. */
41     int b;                      /* Blue component, 0-65535. */
42   };
43
44 /* Mount positions for the four basic fonts.  Do not change the values. */
45 enum
46   {
47     OUTP_F_R,                   /* Roman font. */
48     OUTP_F_I,                   /* Italic font. */
49     OUTP_F_B,                   /* Bold font. */
50     OUTP_F_BI                   /* Bold-italic font. */
51   };
52
53 /* Line styles.  These must match:
54    som.h:SLIN_*
55    ascii.c:ascii_line_*() 
56    postscript.c:ps_line_*() */
57 enum
58   {
59     OUTP_L_NONE = 0,            /* No line. */
60     OUTP_L_SINGLE = 1,          /* Single line. */
61     OUTP_L_DOUBLE = 2,          /* Double line. */
62     OUTP_L_SPECIAL = 3,         /* Special line of driver-defined style. */
63
64     OUTP_L_COUNT                /* Number of line styles. */
65   };
66
67 /* Contains a line style for each part of an intersection. */
68 struct outp_styles
69   {
70     int l;                      /* left */
71     int t;                      /* top */
72     int r;                      /* right */
73     int b;                      /* bottom */
74   };
75
76 /* Text display options. */
77 enum
78   {
79     OUTP_T_NONE = 0,
80
81     /* Must match tab.h:TAB_*. */
82     OUTP_T_JUST_MASK = 00003,   /* Justification mask. */
83     OUTP_T_JUST_RIGHT = 00000,  /* Right justification. */
84     OUTP_T_JUST_LEFT = 00001,   /* Left justification. */
85     OUTP_T_JUST_CENTER = 00002, /* Center justification. */
86
87     OUTP_T_HORZ = 00010,        /* Horizontal size is specified. */
88     OUTP_T_VERT = 00020,        /* (Max) vertical size is specified. */
89
90     OUTP_T_0 = 00140,           /* Normal orientation. */
91     OUTP_T_CC90 = 00040,        /* 90 degrees counterclockwise. */
92     OUTP_T_CC180 = 00100,       /* 180 degrees counterclockwise. */
93     OUTP_T_CC270 = 00140,       /* 270 degrees counterclockwise. */
94     OUTP_T_C90 = 00140,         /* 90 degrees clockwise. */
95     OUTP_T_C180 = 00100,        /* 180 degrees clockwise. */
96     OUTP_T_C270 = 00040,        /* 270 degrees clockwise. */
97
98     /* Internal use by drivers only. */
99     OUTP_T_INTERNAL_DRAW = 01000        /* 1=Draw the text, 0=Metrics only. */
100   };
101
102 /* Describes text output. */
103 struct outp_text
104   {
105     /* Public. */
106     int options;                /* What is specified. */
107     struct fixed_string s;      /* String. */
108     int h, v;                   /* Horizontal, vertical size. */
109     int x, y;                   /* Position. */
110
111     /* Internal use only. */
112     int w, l;                   /* Width, length. */
113   };
114
115 struct som_entity;
116 struct outp_driver;
117
118 /* Defines a class of output driver. */
119 struct outp_class
120   {
121     /* Basic class information. */
122     const char *name;           /* Name of this driver class. */
123     int magic;                  /* Driver-specific constant. */
124     int special;                /* Boolean value. */
125
126     /* Static member functions. */
127     int (*open_global) (struct outp_class *);
128     int (*close_global) (struct outp_class *);
129     int *(*font_sizes) (struct outp_class *, int *n_valid_sizes);
130
131     /* Virtual member functions. */
132     int (*preopen_driver) (struct outp_driver *);
133     void (*option) (struct outp_driver *, const char *key,
134                     const struct string *value);
135     int (*postopen_driver) (struct outp_driver *);
136     int (*close_driver) (struct outp_driver *);
137
138     int (*open_page) (struct outp_driver *);
139     int (*close_page) (struct outp_driver *);
140
141     /* special != 0: Used to submit entities for output. */
142     void (*submit) (struct outp_driver *, struct som_entity *);
143     
144     /* special != 0: Methods below need not be defined. */
145     
146     /* Line methods. */
147     void (*line_horz) (struct outp_driver *, const struct rect *,
148                        const struct color *, int style);
149     void (*line_vert) (struct outp_driver *, const struct rect *,
150                        const struct color *, int style);
151     void (*line_intersection) (struct outp_driver *, const struct rect *,
152                                const struct color *,
153                                const struct outp_styles *style);
154
155     /* Drawing methods. */
156     void (*box) (struct outp_driver *, const struct rect *,
157                  const struct color *bord, const struct color *fill);
158     void (*polyline_begin) (struct outp_driver *, const struct color *);
159     void (*polyline_point) (struct outp_driver *, int, int);
160     void (*polyline_end) (struct outp_driver *);
161
162     /* Text methods. */
163     void (*text_set_font_by_name) (struct outp_driver *, const char *s);
164     void (*text_set_font_by_position) (struct outp_driver *, int);
165     void (*text_set_font_family) (struct outp_driver *, const char *s);
166     const char *(*text_get_font_name) (struct outp_driver *);
167     const char *(*text_get_font_family) (struct outp_driver *);
168     int (*text_set_size) (struct outp_driver *, int);
169     int (*text_get_size) (struct outp_driver *, int *em_width);
170     void (*text_metrics) (struct outp_driver *, struct outp_text *);
171     void (*text_draw) (struct outp_driver *, struct outp_text *);
172
173     void (*initialise_chart)(struct outp_class *, struct chart *);
174     void (*finialise_chart)(struct outp_class *, struct chart *);
175
176   };
177
178 /* Device types. */
179 enum
180   {
181     OUTP_DEV_NONE = 0,          /* None of the below. */
182     OUTP_DEV_LISTING = 001,     /* Listing device. */
183     OUTP_DEV_SCREEN = 002,      /* Screen device. */
184     OUTP_DEV_PRINTER = 004,     /* Printer device. */
185     OUTP_DEV_DISABLED = 010     /* Broken device. */
186   };
187
188 /* Defines the configuration of an output driver. */
189 struct outp_driver
190   {
191     struct outp_class *class;           /* Driver class. */
192     char *name;                 /* Name of this driver. */
193     int driver_open;            /* 1=driver is open, 0=driver is closed. */
194     int page_open;              /* 1=page is open, 0=page is closed. */
195
196     struct outp_driver *next, *prev;    /* Next, previous output driver in list. */
197
198     int device;                 /* Zero or more of OUTP_DEV_*. */
199     int res, horiz, vert;       /* Device resolution. */
200     int width, length;          /* Page size. */
201
202     int cp_x, cp_y;             /* Current position. */
203     int font_height;            /* Default font character height. */
204     int prop_em_width;          /* Proportional font em width. */
205     int fixed_width;            /* Fixed-pitch font character width. */
206     int horiz_line_width[OUTP_L_COUNT]; /* Width of horizontal lines. */
207     int vert_line_width[OUTP_L_COUNT];  /* Width of vertical lines. */
208     int horiz_line_spacing[1 << OUTP_L_COUNT];
209     int vert_line_spacing[1 << OUTP_L_COUNT];
210
211     void *ext;                  /* Private extension record. */
212     void *prc;                  /* Per-procedure extension record. */
213   };
214
215 /* Option structure for the keyword recognizer. */
216 struct outp_option
217   {
218     const char *keyword;        /* Keyword name. */
219     int cat;                    /* Category. */
220     int subcat;                 /* Subcategory. */
221   };
222
223 /* Information structure for the keyword recognizer. */
224 struct outp_option_info
225   {
226     char *initial;                      /* Initial characters. */
227     struct outp_option **options;       /* Search starting points. */
228   };
229
230 /* A list of driver classes. */
231 struct outp_driver_class_list
232   {
233     int ref_count;
234     struct outp_class *class;
235     struct outp_driver_class_list *next;
236   };
237
238 /* List of configured output drivers. */
239 extern struct outp_driver *outp_driver_list;
240
241 /* Title, subtitle. */
242 extern char *outp_title;
243 extern char *outp_subtitle;
244
245 int outp_init (void);
246 int outp_read_devices (void);
247 int outp_done (void);
248
249 void outp_configure_clear (void);
250 void outp_configure_add (char *);
251 void outp_configure_macro (char *);
252
253 void outp_list_classes (void);
254
255 void outp_enable_device (int enable, int device);
256 struct outp_driver *outp_drivers (struct outp_driver *);
257
258 int outp_match_keyword (const char *, struct outp_option *,
259                         struct outp_option_info *, int *);
260
261 int outp_evaluate_dimension (char *, char **);
262 int outp_get_paper_size (char *, int *h, int *v);
263
264 int outp_eject_page (struct outp_driver *);
265
266 int outp_string_width (struct outp_driver *, const char *);
267
268 /* Imported from som-frnt.c. */
269 void som_destroy_driver (struct outp_driver *);
270
271 #endif /* output.h */