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