* src/roff/troff/env.cpp (hyphen_trie::read_patterns_file): Fix loop
[s-roff.git] / src / roff / troff / node.h
blob86382b7f3b6397253900dcad38fff464083e46c3
1 // -*- C++ -*-
2 /* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
4 Written by James Clark (jjc@jclark.com)
6 This file is part of groff.
8 groff is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2, or (at your option) any later
11 version.
13 groff is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 You should have received a copy of the GNU General Public License along
19 with groff; see the file COPYING. If not, write to the Free Software
20 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 *last;
53 node();
54 node(node *n);
55 node *add_char(charinfo *c, environment *, hunits *widthp, int *spacep);
57 virtual ~node();
58 virtual node *copy() = 0;
59 virtual int set_unformat_flag();
60 virtual int force_tprint() = 0;
61 virtual hunits width();
62 virtual hunits subscript_correction();
63 virtual hunits italic_correction();
64 virtual hunits left_italic_correction();
65 virtual hunits skew();
66 virtual int nspaces();
67 virtual int merge_space(hunits, hunits, hunits);
68 virtual vunits vertical_width();
69 virtual node *last_char_node();
70 virtual void vertical_extent(vunits *min, vunits *max);
71 virtual int character_type();
72 virtual void set_vertical_size(vertical_size *);
73 virtual int ends_sentence();
74 virtual node *merge_self(node *);
75 virtual node *add_discretionary_hyphen();
76 virtual node *add_self(node *, hyphen_list **);
77 virtual hyphen_list *get_hyphen_list(hyphen_list *, int *);
78 virtual void ascii_print(ascii_output_file *);
79 virtual void asciify(macro *);
80 virtual int discardable();
81 virtual void spread_space(int *, hunits *);
82 virtual void freeze_space();
83 virtual void is_escape_colon();
84 virtual breakpoint *get_breakpoints(hunits width, int nspaces,
85 breakpoint *rest = 0,
86 int is_inner = 0);
87 virtual int nbreaks();
88 virtual void split(int, node **, node **);
89 virtual hyphenation_type get_hyphenation_type();
90 virtual int reread(int *);
91 virtual token_node *get_token_node();
92 virtual int overlaps_vertically();
93 virtual int overlaps_horizontally();
94 virtual units size();
95 virtual int interpret(macro *);
97 virtual node *merge_glyph_node(glyph_node *);
98 virtual tfont *get_tfont();
99 virtual color *get_glyph_color();
100 virtual color *get_fill_color();
101 virtual void tprint(troff_output_file *);
102 virtual void zero_width_tprint(troff_output_file *);
104 node *add_italic_correction(hunits *);
106 virtual int same(node *) = 0;
107 virtual const char *type() = 0;
110 inline node::node()
111 : next(0), last(0)
115 inline node::node(node *n)
116 : next(n), last(0)
120 inline node::~node()
124 // 0 means it doesn't, 1 means it does, 2 means it's transparent
126 int node_list_ends_sentence(node *);
128 struct breakpoint {
129 breakpoint *next;
130 hunits width;
131 int nspaces;
132 node *nd;
133 int index;
134 char hyphenated;
137 class line_start_node : public node {
138 public:
139 line_start_node() {}
140 node *copy() { return new line_start_node; }
141 int same(node *);
142 int force_tprint();
143 const char *type();
144 void asciify(macro *);
147 class space_node : public node {
148 private:
149 #if 0
150 enum { BLOCK = 1024 };
151 static space_node *free_list;
152 void operator delete(void *);
153 #endif
154 protected:
155 hunits n;
156 char set;
157 char was_escape_colon;
158 color *col; /* for grotty */
159 space_node(hunits, int, int, color *, node * = 0);
160 public:
161 space_node(hunits, color *, node * = 0);
162 #if 0
163 ~space_node();
164 void *operator new(size_t);
165 #endif
166 node *copy();
167 int nspaces();
168 hunits width();
169 int discardable();
170 int merge_space(hunits, hunits, hunits);
171 void freeze_space();
172 void is_escape_colon();
173 void spread_space(int *, hunits *);
174 void tprint(troff_output_file *);
175 breakpoint *get_breakpoints(hunits width, int nspaces, breakpoint *rest = 0,
176 int is_inner = 0);
177 int nbreaks();
178 void split(int, node **, node **);
179 void ascii_print(ascii_output_file *);
180 int same(node *);
181 void asciify(macro *);
182 const char *type();
183 int force_tprint();
184 hyphenation_type get_hyphenation_type();
187 struct width_list {
188 hunits width;
189 hunits sentence_width;
190 width_list *next;
191 width_list(hunits, hunits);
192 width_list(width_list *);
195 class word_space_node : public space_node {
196 protected:
197 width_list *orig_width;
198 unsigned char unformat;
199 word_space_node(hunits, int, color *, width_list *, int, node * = 0);
200 public:
201 word_space_node(hunits, color *, width_list *, node * = 0);
202 ~word_space_node();
203 node *copy();
204 int reread(int *);
205 int set_unformat_flag();
206 void tprint(troff_output_file *);
207 int same(node *);
208 void asciify(macro *);
209 const char *type();
210 int merge_space(hunits, hunits, hunits);
211 int force_tprint();
214 class unbreakable_space_node : public word_space_node {
215 unbreakable_space_node(hunits, int, color *, node * = 0);
216 public:
217 unbreakable_space_node(hunits, color *, node * = 0);
218 node *copy();
219 int reread(int *);
220 void tprint(troff_output_file *);
221 int same(node *);
222 void asciify(macro *);
223 const char *type();
224 int force_tprint();
225 breakpoint *get_breakpoints(hunits width, int nspaces, breakpoint *rest = 0,
226 int is_inner = 0);
227 int nbreaks();
228 void split(int, node **, node **);
229 int merge_space(hunits, hunits, hunits);
230 node *add_self(node *, hyphen_list **);
231 hyphen_list *get_hyphen_list(hyphen_list *, int *);
232 hyphenation_type get_hyphenation_type();
235 class diverted_space_node : public node {
236 public:
237 vunits n;
238 diverted_space_node(vunits d, node *p = 0);
239 node *copy();
240 int reread(int *);
241 int same(node *);
242 const char *type();
243 int force_tprint();
246 class diverted_copy_file_node : public node {
247 symbol filename;
248 public:
249 vunits n;
250 diverted_copy_file_node(symbol s, node *p = 0);
251 node *copy();
252 int reread(int *);
253 int same(node *);
254 const char *type();
255 int force_tprint();
258 class extra_size_node : public node {
259 vunits n;
260 public:
261 extra_size_node(vunits i) : n(i) {}
262 void set_vertical_size(vertical_size *);
263 node *copy();
264 int same(node *);
265 const char *type();
266 int force_tprint();
269 class vertical_size_node : public node {
270 vunits n;
271 public:
272 vertical_size_node(vunits i) : n(i) {}
273 void set_vertical_size(vertical_size *);
274 void asciify(macro *);
275 node *copy();
276 int set_unformat_flag();
277 int same(node *);
278 const char *type();
279 int force_tprint();
282 class hmotion_node : public node {
283 protected:
284 hunits n;
285 unsigned char was_tab;
286 unsigned char unformat;
287 color *col; /* for grotty */
288 public:
289 hmotion_node(hunits i, color *c, node *next = 0)
290 : node(next), n(i), was_tab(0), unformat(0), col(c) {}
291 hmotion_node(hunits i, int flag1, int flag2, color *c, node *next = 0)
292 : node(next), n(i), was_tab(flag1), unformat(flag2), col(c) {}
293 node *copy();
294 int reread(int *);
295 int set_unformat_flag();
296 void asciify(macro *);
297 void tprint(troff_output_file *);
298 hunits width();
299 void ascii_print(ascii_output_file *);
300 int same(node *);
301 const char *type();
302 int force_tprint();
303 node *add_self(node *, hyphen_list **);
304 hyphen_list *get_hyphen_list(hyphen_list *, int *);
305 hyphenation_type get_hyphenation_type();
308 class space_char_hmotion_node : public hmotion_node {
309 public:
310 space_char_hmotion_node(hunits, color *, node * = 0);
311 node *copy();
312 void ascii_print(ascii_output_file *);
313 void asciify(macro *);
314 void tprint(troff_output_file *);
315 int same(node *);
316 const char *type();
317 int force_tprint();
318 node *add_self(node *, hyphen_list **);
319 hyphen_list *get_hyphen_list(hyphen_list *, int *);
320 hyphenation_type get_hyphenation_type();
323 class vmotion_node : public node {
324 vunits n;
325 color *col; /* for grotty */
326 public:
327 vmotion_node(vunits i, color *c) : n(i), col(c) {}
328 void tprint(troff_output_file *);
329 node *copy();
330 vunits vertical_width();
331 int same(node *);
332 const char *type();
333 int force_tprint();
336 class hline_node : public node {
337 hunits x;
338 node *n;
339 public:
340 hline_node(hunits i, node *c, node *next = 0) : node(next), x(i), n(c) {}
341 ~hline_node();
342 node *copy();
343 hunits width();
344 void tprint(troff_output_file *);
345 int same(node *);
346 const char *type();
347 int force_tprint();
350 class vline_node : public node {
351 vunits x;
352 node *n;
353 public:
354 vline_node(vunits i, node *c, node *next= 0) : node(next), x(i), n(c) {}
355 ~vline_node();
356 node *copy();
357 void tprint(troff_output_file *);
358 hunits width();
359 vunits vertical_width();
360 void vertical_extent(vunits *, vunits *);
361 int same(node *);
362 const char *type();
363 int force_tprint();
367 class dummy_node : public node {
368 public:
369 dummy_node(node *nd = 0) : node(nd) {}
370 node *copy();
371 int same(node *);
372 const char *type();
373 int force_tprint();
374 hyphenation_type get_hyphenation_type();
377 class transparent_dummy_node : public node {
378 public:
379 transparent_dummy_node(node *nd = 0) : node(nd) {}
380 node *copy();
381 int same(node *);
382 const char *type();
383 int force_tprint();
384 int ends_sentence();
385 hyphenation_type get_hyphenation_type();
388 class zero_width_node : public node {
389 node *n;
390 public:
391 zero_width_node(node *gn);
392 ~zero_width_node();
393 node *copy();
394 void tprint(troff_output_file *);
395 int same(node *);
396 const char *type();
397 int force_tprint();
398 void append(node *);
399 int character_type();
400 void vertical_extent(vunits *min, vunits *max);
403 class left_italic_corrected_node : public node {
404 node *n;
405 hunits x;
406 public:
407 left_italic_corrected_node(node * = 0);
408 ~left_italic_corrected_node();
409 void tprint(troff_output_file *);
410 void ascii_print(ascii_output_file *);
411 void asciify(macro *);
412 node *copy();
413 int same(node *);
414 const char *type();
415 int force_tprint();
416 hunits width();
417 node *last_char_node();
418 void vertical_extent(vunits *, vunits *);
419 int ends_sentence();
420 int overlaps_horizontally();
421 int overlaps_vertically();
422 hyphenation_type get_hyphenation_type();
423 tfont *get_tfont();
424 int character_type();
425 hunits skew();
426 hunits italic_correction();
427 hunits subscript_correction();
428 hyphen_list *get_hyphen_list(hyphen_list *, int *);
429 node *add_self(node *, hyphen_list **);
430 node *merge_glyph_node(glyph_node *);
433 class overstrike_node : public node {
434 node *list;
435 hunits max_width;
436 public:
437 overstrike_node();
438 ~overstrike_node();
439 node *copy();
440 void tprint(troff_output_file *);
441 void overstrike(node *); // add another node to be overstruck
442 hunits width();
443 int same(node *);
444 const char *type();
445 int force_tprint();
446 node *add_self(node *, hyphen_list **);
447 hyphen_list *get_hyphen_list(hyphen_list *, int *);
448 hyphenation_type get_hyphenation_type();
451 class bracket_node : public node {
452 node *list;
453 hunits max_width;
454 public:
455 bracket_node();
456 ~bracket_node();
457 node *copy();
458 void tprint(troff_output_file *);
459 void bracket(node *); // add another node to be overstruck
460 hunits width();
461 int same(node *);
462 const char *type();
463 int force_tprint();
466 class special_node : public node {
467 macro mac;
468 tfont *tf;
469 color *gcol;
470 color *fcol;
471 int no_init_string;
472 void tprint_start(troff_output_file *);
473 void tprint_char(troff_output_file *, unsigned char);
474 void tprint_end(troff_output_file *);
475 public:
476 special_node(const macro &, int = 0);
477 special_node(const macro &, tfont *, color *, color *, int = 0);
478 node *copy();
479 void tprint(troff_output_file *);
480 int same(node *);
481 const char *type();
482 int force_tprint();
483 int ends_sentence();
484 tfont *get_tfont();
487 class suppress_node : public node {
488 int is_on;
489 int emit_limits; // must we issue the extent of the area written out?
490 symbol filename;
491 char position;
492 int image_id;
493 public:
494 suppress_node(int, int);
495 suppress_node(symbol f, char p, int id);
496 suppress_node(int, int, symbol f, char p, int id);
497 node *copy();
498 void tprint(troff_output_file *);
499 hunits width();
500 int same(node *);
501 const char *type();
502 int force_tprint();
503 private:
504 void put(troff_output_file *out, const char *s);
507 struct hvpair {
508 hunits h;
509 vunits v;
510 hvpair();
513 class draw_node : public node {
514 int npoints;
515 font_size sz;
516 color *gcol;
517 color *fcol;
518 char code;
519 hvpair *point;
520 public:
521 draw_node(char, hvpair *, int, font_size, color *, color *);
522 ~draw_node();
523 hunits width();
524 vunits vertical_width();
525 node *copy();
526 void tprint(troff_output_file *);
527 int same(node *);
528 const char *type();
529 int force_tprint();
532 class charinfo;
533 node *make_node(charinfo *ci, environment *);
534 int character_exists(charinfo *, environment *);
536 int same_node_list(node *n1, node *n2);
537 node *reverse_node_list(node *n);
538 void delete_node_list(node *);
539 node *copy_node_list(node *);
541 int get_bold_fontno(int f);
543 inline hyphen_list::hyphen_list(unsigned char code, hyphen_list *p)
544 : hyphen(0), breakable(0), hyphenation_code(code), next(p)
548 extern void read_desc();
549 extern int mount_font(int n, symbol, symbol = NULL_SYMBOL);
550 extern void mount_style(int n, symbol);
551 extern int is_good_fontno(int n);
552 extern int symbol_fontno(symbol);
553 extern int next_available_font_position();
554 extern void init_size_table(int *);
555 extern int get_underline_fontno();
557 class output_file {
558 char make_g_plus_plus_shut_up;
559 public:
560 output_file();
561 virtual ~output_file();
562 virtual void trailer(vunits page_length);
563 virtual void flush() = 0;
564 virtual void transparent_char(unsigned char) = 0;
565 virtual void print_line(hunits x, vunits y, node *n,
566 vunits before, vunits after, hunits width) = 0;
567 virtual void begin_page(int pageno, vunits page_length) = 0;
568 virtual void copy_file(hunits x, vunits y, const char *filename) = 0;
569 virtual int is_printing() = 0;
570 virtual void put_filename(const char *filename);
571 virtual void on();
572 virtual void off();
573 #ifdef COLUMN
574 virtual void vjustify(vunits, symbol);
575 #endif /* COLUMN */
578 #ifndef POPEN_MISSING
579 extern char *pipe_command;
580 #endif
582 extern output_file *the_output;
583 extern void init_output();
584 int in_output_page_list(int n);
586 class font_family {
587 int *map;
588 int map_size;
589 public:
590 const symbol nm;
591 font_family(symbol);
592 ~font_family();
593 int make_definite(int);
594 static void invalidate_fontno(int);
597 font_family *lookup_family(symbol);
598 symbol get_font_name(int, environment *);
599 extern search_path include_search_path;