groff before CVS: release 1.06
[s-roff.git] / troff / node.h
blob562ce255ec22850adb5bd8310467b52476c8777c
1 // -*- C++ -*-
2 /* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
3 Written by James Clark (jjc@jclark.com)
5 This file is part of groff.
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 2, or (at your option) any later
10 version.
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.
17 You should have received a copy of the GNU General Public License along
18 with groff; see the file COPYING. If not, write to the Free Software
19 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
22 struct hyphen_list {
23 unsigned char hyphen;
24 unsigned char breakable;
25 unsigned char hyphenation_code;
26 hyphen_list *next;
27 hyphen_list(unsigned char code, hyphen_list *p = 0);
30 void hyphenate(hyphen_list *, unsigned);
32 enum hyphenation_type { HYPHEN_MIDDLE, HYPHEN_BOUNDARY, HYPHEN_INHIBIT };
34 class ascii_output_file;
36 struct breakpoint;
37 struct vertical_size;
38 struct charinfo;
40 class macro;
42 class troff_output_file;
43 class tfont;
44 class environment;
46 class glyph_node;
47 class diverted_space_node;
48 class token_node;
50 struct node {
51 node *next;
52 node();
53 node(node *n);
54 node *add_char(charinfo *c, environment *, hunits *widthp);
56 virtual ~node();
57 virtual node *copy() = 0;
58 virtual hunits width();
59 virtual hunits subscript_correction();
60 virtual hunits italic_correction();
61 virtual hunits left_italic_correction();
62 virtual hunits skew();
63 virtual int nspaces();
64 virtual int merge_space(hunits);
65 virtual vunits vertical_width();
66 virtual node *last_char_node();
67 virtual void vertical_extent(vunits *min, vunits *max);
68 virtual int character_type();
69 virtual void set_vertical_size(vertical_size *);
70 virtual int ends_sentence();
71 virtual node *merge_self(node *);
72 virtual node *add_discretionary_hyphen();
73 virtual node *add_self(node *, hyphen_list **);
74 virtual hyphen_list *get_hyphen_list(hyphen_list *s = 0);
75 virtual void ascii_print(ascii_output_file *);
76 virtual void asciify(macro *);
77 virtual int discardable();
78 virtual void spread_space(int *, hunits *);
79 virtual void freeze_space();
80 virtual breakpoint *get_breakpoints(hunits width, int nspaces,
81 breakpoint *rest = 0,
82 int is_inner = 0);
83 virtual int nbreaks();
84 virtual void split(int, node **, node **);
85 virtual hyphenation_type get_hyphenation_type();
86 virtual int reread(int *);
87 virtual token_node *get_token_node();
88 virtual int overlaps_vertically();
89 virtual int overlaps_horizontally();
90 virtual units size();
91 virtual int interpret(macro *);
93 virtual node *merge_glyph_node(glyph_node *);
94 virtual tfont *get_tfont();
95 virtual void tprint(troff_output_file *);
96 virtual void zero_width_tprint(troff_output_file *);
98 node *add_italic_correction(hunits *);
100 virtual int same(node *) = 0;
101 virtual const char *type() = 0;
104 inline node::node() : next(0)
108 inline node::node(node *n) : next(n)
112 inline node::~node()
116 // 0 means it doesn't, 1 means it does, 2 means it's transparent
118 int node_list_ends_sentence(node *);
120 struct breakpoint {
121 breakpoint *next;
122 hunits width;
123 int nspaces;
124 node *nd;
125 int index;
126 char hyphenated;
129 class line_start_node : public node {
130 public:
131 line_start_node() {}
132 node *copy() { return new line_start_node; }
133 int same(node *);
134 const char *type();
135 void asciify(macro *);
138 class space_node : public node {
139 private:
140 #if 0
141 enum { BLOCK = 1024 };
142 static space_node *free_list;
143 void operator delete(void *);
144 #endif
145 protected:
146 hunits n;
147 char set;
148 space_node(hunits, int, node * = 0);
149 public:
150 space_node(hunits d, node *p = 0);
151 #if 0
152 ~space_node();
153 void *operator new(size_t);
154 #endif
155 node *copy();
156 int nspaces();
157 hunits width();
158 int discardable();
159 int merge_space(hunits);
160 void freeze_space();
161 void spread_space(int*, hunits*);
162 void tprint(troff_output_file *);
163 breakpoint *get_breakpoints(hunits width, int nspaces, breakpoint *rest = 0,
164 int is_inner = 0);
165 int nbreaks();
166 void split(int, node **, node **);
167 void ascii_print(ascii_output_file *);
168 int same(node *);
169 const char *type();
172 class word_space_node : public space_node {
173 protected:
174 word_space_node(hunits, int, node * = 0);
175 public:
176 word_space_node(hunits, node * = 0);
177 node *copy();
178 void tprint(troff_output_file *);
179 int same(node *);
180 const char *type();
183 class unbreakable_space_node : public word_space_node {
184 unbreakable_space_node(hunits, int, node * = 0);
185 public:
186 unbreakable_space_node(hunits, node * = 0);
187 node *copy();
188 int same(node *);
189 const char *type();
190 breakpoint *get_breakpoints(hunits width, int nspaces, breakpoint *rest = 0,
191 int is_inner = 0);
192 int nbreaks();
193 void split(int, node **, node **);
194 int merge_space(hunits);
197 class diverted_space_node : public node {
198 public:
199 vunits n;
200 diverted_space_node(vunits d, node *p = 0);
201 node *copy();
202 int reread(int *);
203 int same(node *);
204 const char *type();
207 class diverted_copy_file_node : public node {
208 symbol filename;
209 public:
210 vunits n;
211 diverted_copy_file_node(symbol s, node *p = 0);
212 node *copy();
213 int reread(int *);
214 int same(node *);
215 const char *type();
218 class extra_size_node : public node {
219 vunits n;
220 public:
221 extra_size_node(vunits i) : n(i) {}
222 void set_vertical_size(vertical_size *);
223 node *copy();
224 int same(node *);
225 const char *type();
228 class vertical_size_node : public node {
229 vunits n;
230 public:
231 vertical_size_node(vunits i) : n(i) {}
232 void set_vertical_size(vertical_size *);
233 void asciify(macro *);
234 node *copy();
235 int same(node *);
236 const char *type();
239 class hmotion_node : public node {
240 protected:
241 hunits n;
242 public:
243 hmotion_node(hunits i, node *next = 0) : node(next), n(i) {}
244 node *copy();
245 void tprint(troff_output_file *);
246 hunits width();
247 void ascii_print(ascii_output_file *);
248 int same(node *);
249 const char *type();
252 class space_char_hmotion_node : public hmotion_node {
253 public:
254 space_char_hmotion_node(hunits i, node *next = 0);
255 node *copy();
256 void ascii_print(ascii_output_file *);
257 void asciify(macro *);
258 int same(node *);
259 const char *type();
262 class vmotion_node : public node {
263 vunits n;
264 public:
265 vmotion_node(vunits i) : n(i) {}
266 void tprint(troff_output_file *);
267 node *copy();
268 vunits vertical_width();
269 int same(node *);
270 const char *type();
274 class hline_node : public node {
275 hunits x;
276 node *n;
277 public:
278 hline_node(hunits i, node *c, node *next = 0) : node(next), x(i), n(c) {}
279 ~hline_node();
280 node *copy();
281 hunits width();
282 void tprint(troff_output_file *);
283 int same(node *);
284 const char *type();
287 class vline_node : public node {
288 vunits x;
289 node *n;
290 public:
291 vline_node(vunits i, node *c, node *next= 0) : node(next), x(i), n(c) {}
292 ~vline_node();
293 node *copy();
294 void tprint(troff_output_file *);
295 hunits width();
296 vunits vertical_width();
297 void vertical_extent(vunits *, vunits *);
298 int same(node *);
299 const char *type();
303 class dummy_node : public node {
304 public:
305 dummy_node(node *nd = 0) : node(nd) {}
306 node *copy();
307 int same(node *);
308 const char *type();
309 hyphenation_type get_hyphenation_type();
312 class transparent_dummy_node : public node {
313 public:
314 transparent_dummy_node() {}
315 node *copy();
316 int same(node *);
317 const char *type();
318 int ends_sentence();
319 hyphenation_type get_hyphenation_type();
322 class zero_width_node : public node {
323 node *n;
324 public:
325 zero_width_node(node *gn);
326 ~zero_width_node();
327 node *copy();
328 void tprint(troff_output_file *);
329 int same(node *);
330 const char *type();
331 void append(node *);
332 int character_type();
333 void vertical_extent(vunits *min, vunits *max);
336 class left_italic_corrected_node : public node {
337 node *n;
338 hunits x;
339 public:
340 left_italic_corrected_node(node * = 0);
341 ~left_italic_corrected_node();
342 void tprint(troff_output_file *);
343 void ascii_print(ascii_output_file *);
344 void asciify(macro *);
345 node *copy();
346 int same(node *);
347 const char *type();
348 hunits width();
349 node *last_char_node();
350 void vertical_extent(vunits *, vunits *);
351 int ends_sentence();
352 int overlaps_horizontally();
353 int overlaps_vertically();
354 hyphenation_type get_hyphenation_type();
355 tfont *get_tfont();
356 int character_type();
357 hunits skew();
358 hunits italic_correction();
359 hunits subscript_correction();
360 hyphen_list *get_hyphen_list(hyphen_list *ss = 0);
361 node *add_self(node *, hyphen_list **);
362 node *merge_glyph_node(glyph_node *);
365 class overstrike_node : public node {
366 node *list;
367 hunits max_width;
368 public:
369 overstrike_node();
370 ~overstrike_node();
371 node *copy();
372 void tprint(troff_output_file *);
373 void overstrike(node *); // add another node to be overstruck
374 hunits width();
375 int same(node *);
376 const char *type();
379 class bracket_node : public node {
380 node *list;
381 hunits max_width;
382 public:
383 bracket_node();
384 ~bracket_node();
385 node *copy();
386 void tprint(troff_output_file *);
387 void bracket(node *); // add another node to be overstruck
388 hunits width();
389 int same(node *);
390 const char *type();
393 class special_node : public node {
394 macro mac;
395 void tprint_start(troff_output_file *);
396 void tprint_char(troff_output_file *, unsigned char);
397 void tprint_end(troff_output_file *);
398 public:
399 special_node(const macro &);
400 node *copy();
401 void tprint(troff_output_file *);
402 int same(node *);
403 const char *type();
407 struct hvpair {
408 hunits h;
409 vunits v;
411 hvpair();
414 class draw_node : public node {
415 int npoints;
416 font_size sz;
417 char code;
418 hvpair *point;
419 public:
420 draw_node(char, hvpair *, int, font_size);
421 ~draw_node();
422 hunits width();
423 vunits vertical_width();
424 node *copy();
425 void tprint(troff_output_file *);
426 int same(node *);
427 const char *type();
430 class charinfo;
431 node *make_node(charinfo *ci, environment *);
432 int character_exists(charinfo *, environment *);
434 int same_node_list(node *n1, node *n2);
435 node *reverse_node_list(node *n);
436 void delete_node_list(node *);
437 node *copy_node_list(node *);
439 int get_bold_fontno(int f);
441 inline hyphen_list::hyphen_list(unsigned char code, hyphen_list *p)
442 : hyphenation_code(code), next(p), hyphen(0), breakable(0)
446 extern void read_desc();
447 extern int mount_font(int n, symbol, symbol = NULL_SYMBOL);
448 extern void mount_style(int n, symbol);
449 extern int is_good_fontno(int n);
450 extern int symbol_fontno(symbol);
451 extern int next_available_font_position();
452 extern void init_size_table(int *);
453 extern int get_underline_fontno();
455 class output_file {
456 char make_g_plus_plus_shut_up;
457 public:
458 output_file();
459 virtual ~output_file();
460 virtual void flush() = 0;
461 virtual void transparent_char(unsigned char) = 0;
462 virtual void print_line(hunits x, vunits y, node *n,
463 vunits before, vunits after) = 0;
464 virtual void begin_page(int pageno, vunits page_length) = 0;
465 virtual void copy_file(hunits x, vunits y, const char *filename) = 0;
466 virtual int is_printing() = 0;
467 #ifdef COLUMN
468 virtual void vjustify(vunits, symbol);
469 #endif /* COLUMN */
472 extern char *pipe_command;
474 extern output_file *the_output;
475 extern void init_output();
476 int in_output_page_list(int n);
478 static void invalidate_fontno(int);
480 class font_family {
481 int *map;
482 int map_size;
483 public:
484 const symbol nm;
486 font_family(symbol);
487 ~font_family();
488 make_definite(int);
489 friend void invalidate_fontno(int);
492 font_family *lookup_family(symbol);