Clean up output subsystem.
[pspp-builds.git] / src / output / 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., 51 Franklin Street, Fifth Floor, Boston, MA
18    02110-1301, USA. */
19
20 #if !output_h
21 #define output_h 1
22
23 #include <config.h>
24
25 #include <libpspp/str.h>
26
27
28 /* Line styles.  */
29 enum outp_line_style
30   {
31     OUTP_L_NONE,                /* No line. */
32     OUTP_L_SINGLE,              /* Single line. */
33     OUTP_L_DOUBLE,              /* Double line. */
34     OUTP_L_COUNT
35   };
36
37 /* Text justification. */
38 enum outp_justification
39   {
40     OUTP_RIGHT,                 /* Right justification. */
41     OUTP_LEFT,                  /* Left justification. */
42     OUTP_CENTER,                /* Center justification. */
43   };
44
45 enum outp_font 
46   {
47     OUTP_FIXED,                 /* Fixed-width font. */
48     OUTP_PROPORTIONAL,          /* Proportional font. */
49     OUTP_EMPHASIS,              /* Proportional font used for emphasis. */
50     OUTP_FONT_CNT               /* Number of fonts. */
51   };
52
53 /* Describes text output. */
54 struct outp_text
55   {
56     enum outp_font font;
57     enum outp_justification justification;
58     struct fixed_string string;
59     int h, v;                   /* Horizontal, vertical size. */
60     int x, y;                   /* Position. */
61   };
62
63 struct som_entity;
64 struct outp_driver;
65 struct chart;
66
67 /* Defines a class of output driver. */
68 struct outp_class
69   {
70     const char *name;           /* Name of this driver class. */
71     int special;                /* Boolean value. */
72
73     bool (*open_driver) (struct outp_driver *, const char *options);
74     bool (*close_driver) (struct outp_driver *);
75
76     void (*open_page) (struct outp_driver *);
77     void (*close_page) (struct outp_driver *);
78
79     /* special != 0 only. */
80     void (*submit) (struct outp_driver *, struct som_entity *);
81     
82     /* special == 0 only.  */
83     void (*line) (struct outp_driver *, int x0, int y0, int x1, int y1,
84                   enum outp_line_style top, enum outp_line_style left,
85                   enum outp_line_style bottom, enum outp_line_style right);
86     void (*text_metrics) (struct outp_driver *, const struct outp_text *,
87                           int *width, int *height);
88     void (*text_draw) (struct outp_driver *, const struct outp_text *);
89     void (*initialise_chart)(struct outp_driver *, struct chart *);
90     void (*finalise_chart)(struct outp_driver *, struct chart *);
91   };
92
93 /* Device types. */
94 enum
95   {
96     OUTP_DEV_NONE = 0,          /* None of the below. */
97     OUTP_DEV_LISTING = 001,     /* Listing device. */
98     OUTP_DEV_SCREEN = 002,      /* Screen device. */
99     OUTP_DEV_PRINTER = 004,     /* Printer device. */
100   };
101
102 /* Defines the configuration of an output driver. */
103 struct outp_driver
104   {
105     struct outp_driver *next, *prev; /* List of drivers. */
106     struct outp_class *class;   /* Driver class. */
107     char *name;                 /* Name of this driver. */
108     bool page_open;             /* 1=page is open, 0=page is closed. */
109     int device;                 /* Zero or more of OUTP_DEV_*. */
110     int cp_x, cp_y;             /* Current position. */
111
112     int width, length;          /* Page size. */
113     int font_height;            /* Default font character height. */
114     int prop_em_width;          /* Proportional font em width. */
115     int fixed_width;            /* Fixed-pitch font character width. */
116     int horiz_line_width[OUTP_L_COUNT]; /* Width of horizontal lines. */
117     int vert_line_width[OUTP_L_COUNT];  /* Width of vertical lines. */
118
119     void *ext;                  /* Private extension record. */
120     void *prc;                  /* Per-procedure extension record. */
121   };
122
123 /* Option structure for the keyword recognizer. */
124 struct outp_option
125   {
126     const char *keyword;        /* Keyword name. */
127     int cat;                    /* Category. */
128     int subcat;                 /* Subcategory. */
129   };
130
131 /* List of configured output drivers. */
132 extern struct outp_driver *outp_driver_list;
133
134 /* Title, subtitle. */
135 extern char *outp_title;
136 extern char *outp_subtitle;
137
138 void outp_init (void);
139 void outp_read_devices (void);
140 void outp_done (void);
141
142 void outp_configure_clear (void);
143 void outp_configure_add (char *);
144 void outp_configure_macro (char *);
145
146 void outp_list_classes (void);
147
148 void outp_enable_device (int enable, int device);
149 struct outp_driver *outp_drivers (struct outp_driver *);
150
151 bool outp_parse_options (const char *options,
152                          bool (*) (struct outp_driver *, const char *key,
153                                    const struct string *value),
154                          struct outp_driver *);
155 int outp_match_keyword (const char *, struct outp_option *, int *);
156
157 int outp_evaluate_dimension (char *, char **);
158 int outp_get_paper_size (char *, int *h, int *v);
159
160 void outp_open_page (struct outp_driver *);
161 void outp_close_page (struct outp_driver *);
162 void outp_eject_page (struct outp_driver *);
163
164 int outp_string_width (struct outp_driver *, const char *, enum outp_font);
165
166 /* Imported from som-frnt.c. */
167 void som_destroy_driver (struct outp_driver *);
168
169 #endif /* output.h */