Imported Upstream version 1.22.4
[platform/upstream/groff.git] / src / preproc / eqn / box.h
1 // -*- C++ -*-
2 /* Copyright (C) 1989-2018 Free Software Foundation, Inc.
3      Written by James Clark (jjc@jclark.com)
4
5 This file is part of groff.
6
7 groff is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 groff is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
19
20 class list_box;
21
22 class box {
23 private:
24   static int next_uid;
25 public:
26   int spacing_type;
27   const int uid;
28   box();
29   virtual void debug_print() = 0;
30   virtual ~box();
31   void top_level();
32   virtual int compute_metrics(int);
33   virtual void compute_subscript_kern();
34   virtual void compute_skew();
35   virtual void output();
36   void extra_space();
37   virtual list_box *to_list_box();
38   virtual int is_simple();
39   virtual int is_char();
40   virtual int left_is_italic();
41   virtual int right_is_italic();
42   virtual void handle_char_type(int, int);
43   enum { FOUND_NOTHING = 0, FOUND_MARK = 1, FOUND_LINEUP = 2 };
44   void set_spacing_type(char *type);
45   virtual void hint(unsigned);
46   virtual void check_tabs(int);
47 };
48
49 class box_list {
50 private:
51   int maxlen;
52 public:
53   box **p;
54   int len;
55
56   box_list(box *);
57   ~box_list();
58   void append(box *);
59   void list_check_tabs(int);
60   void list_debug_print(const char *sep);
61   friend class list_box;
62 };
63
64 // declarations to avoid friend name injection problems
65 box *make_script_box(box *, box *, box *);
66 box *make_mark_box(box *);
67 box *make_lineup_box(box *);
68
69 class list_box : public box {
70   int is_script;
71   box_list list;
72   int sty;
73 public:
74   list_box(box *);
75   void debug_print();
76   int compute_metrics(int);
77   void compute_subscript_kern();
78   void output();
79   void check_tabs(int);
80   void append(box *);
81   list_box *to_list_box();
82   void handle_char_type(int, int);
83   void compute_sublist_width(int n);
84   friend box *make_script_box(box *, box *, box *);
85   friend box *make_mark_box(box *);
86   friend box *make_lineup_box(box *);
87 };
88
89 enum alignment { LEFT_ALIGN, RIGHT_ALIGN, CENTER_ALIGN };
90
91 class column : public box_list {
92   alignment align;
93   int space;
94 public:
95   column(box *);
96   void set_alignment(alignment);
97   void set_space(int);
98   void debug_print(const char *);
99
100   friend class matrix_box;
101   friend class pile_box;
102 };
103
104 class pile_box : public box {
105   column col;
106 public:
107   pile_box(box *);
108   int compute_metrics(int);
109   void output();
110   void debug_print();
111   void check_tabs(int);
112   void set_alignment(alignment a) { col.set_alignment(a); }
113   void set_space(int n) { col.set_space(n); }
114   void append(box *p) { col.append(p); }
115 };
116
117 class matrix_box : public box {
118 private:
119   int len;
120   int maxlen;
121   column **p;
122 public:
123   matrix_box(column *);
124   ~matrix_box();
125   void append(column *);
126   int compute_metrics(int);
127   void output();
128   void check_tabs(int);
129   void debug_print();
130 };
131
132 class pointer_box : public box {
133 protected:
134   box *p;
135 public:
136   pointer_box(box *);
137   ~pointer_box();
138   int compute_metrics(int);
139   void compute_subscript_kern();
140   void compute_skew();
141   void debug_print() = 0;
142   void check_tabs(int);
143 };
144
145 class vcenter_box : public pointer_box {
146 public:
147   vcenter_box(box *);
148   int compute_metrics(int);
149   void output();
150   void debug_print();
151 };
152
153 class simple_box : public box {
154 public:
155   int compute_metrics(int);
156   void compute_subscript_kern();
157   void compute_skew();
158   void output() = 0;
159   void debug_print() = 0;
160   int is_simple();
161 };
162
163 class quoted_text_box : public simple_box {
164   char *text;
165 public:
166   quoted_text_box(char *);
167   ~quoted_text_box();
168   void debug_print();
169   void output();
170 };
171
172 class half_space_box : public simple_box {
173 public:
174   half_space_box();
175   void output();
176   void debug_print();
177 };
178
179 class space_box : public simple_box {
180 public:
181   space_box();
182   void output();
183   void debug_print();
184 };
185
186 class tab_box : public box {
187   int disabled;
188 public:
189   tab_box();
190   void output();
191   void debug_print();
192   void check_tabs(int);
193 };
194
195 class size_box : public pointer_box {
196 private:
197   char *size;
198 public:
199   size_box(char *, box *);
200   ~size_box();
201   int compute_metrics(int);
202   void output();
203   void debug_print();
204 };
205
206 class font_box : public pointer_box {
207 private:
208   char *f;
209 public:
210   font_box(char *, box *);
211   ~font_box();
212   int compute_metrics(int);
213   void output();
214   void debug_print();
215 };
216
217 class fat_box : public pointer_box {
218 public:
219   fat_box(box *);
220   int compute_metrics(int);
221   void output();
222   void debug_print();
223 };
224
225 class vmotion_box : public pointer_box {
226 private:
227   int n;                        // up is >= 0
228 public:
229   vmotion_box(int, box *);
230   int compute_metrics(int);
231   void output();
232   void debug_print();
233 };
234
235 class hmotion_box : public pointer_box {
236   int n;
237 public:
238   hmotion_box(int, box *);
239   int compute_metrics(int);
240   void output();
241   void debug_print();
242 };
243
244 box *split_text(char *);
245 box *make_delim_box(char *, box *, char *);
246 box *make_sqrt_box(box *);
247 box *make_prime_box(box *);
248 box *make_over_box(box *, box *);
249 box *make_small_over_box(box *, box *);
250 box *make_limit_box(box *, box *, box *);
251 box *make_accent_box(box *, box *);
252 box *make_uaccent_box(box *, box *);
253 box *make_overline_box(box *);
254 box *make_underline_box(box *);
255 box *make_special_box(char *, box *);
256
257 void set_space(int);
258 int set_gsize(const char *);
259 void set_gfont(const char *);
260 void set_grfont(const char *);
261 void set_gbfont(const char *);
262 const char *get_gfont();
263 const char *get_grfont();
264 const char *get_gbfont();
265 void start_string();
266 void output_string();
267 void do_text(const char *);
268 void restore_compatibility();
269 void set_script_reduction(int n);
270 void set_minimum_size(int n);
271 void set_param(const char *name, int value);
272
273 void set_char_type(const char *type, char *ch);
274
275 void init_char_table();
276 void init_extensible();
277 void define_extensible(const char *name, const char *ext, const char *top = 0,
278                        const char *mid = 0, const char *bot = 0);