Sync-to-go: update copyright for 2015
[s-roff.git] / src / troff / node.h
bloba1e2d6544f0f8124b09edec6f1c5d940c9e16b8c
1 /*@
2 * Copyright (c) 2014 - 2015 Steffen (Daode) Nurpmeso <sdaoden@users.sf.net>.
4 * Copyright (C) 1989 - 1992, 2000 - 2004, 2006
5 * Free Software Foundation, Inc.
6 * Written by James Clark (jjc@jclark.com)
8 * This 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 * This 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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA.
22 #ifndef _NODE_H
23 #define _NODE_H
25 #include "config.h"
26 #include "troff-config.h"
28 class hyphen_list
30 public:
31 unsigned char hyphen;
32 unsigned char breakable;
33 unsigned char hyphenation_code;
34 hyphen_list *next;
36 hyphen_list(unsigned char code, hyphen_list *p = 0);
39 void hyphenate(hyphen_list *, unsigned);
41 enum hyphenation_type { HYPHEN_MIDDLE, HYPHEN_BOUNDARY, HYPHEN_INHIBIT };
43 class ascii_output_file;
45 struct breakpoint;
46 struct vertical_size;
47 class charinfo;
49 class macro;
51 class troff_output_file;
52 class tfont;
53 class environment;
55 class glyph_node;
56 class diverted_space_node;
57 class token_node;
59 class node
61 public:
62 node *next;
63 node *last;
64 statem *state;
65 statem *push_state;
66 int div_nest_level;
67 int is_special;
69 node();
70 node(node *);
71 node(node *, statem *, int);
72 node *add_char(charinfo *, environment *, hunits *, int *, node ** = 0);
74 virtual ~node();
75 virtual node *copy() = 0;
76 virtual int set_unformat_flag();
77 virtual int force_tprint() = 0;
78 virtual int is_tag() = 0;
79 virtual hunits width();
80 virtual hunits subscript_correction();
81 virtual hunits italic_correction();
82 virtual hunits left_italic_correction();
83 virtual hunits skew();
84 virtual int nspaces();
85 virtual int merge_space(hunits, hunits, hunits);
86 virtual vunits vertical_width();
87 virtual node *last_char_node();
88 virtual void vertical_extent(vunits *, vunits *);
89 virtual int character_type();
90 virtual void set_vertical_size(vertical_size *);
91 virtual int ends_sentence();
92 virtual node *merge_self(node *);
93 virtual node *add_discretionary_hyphen();
94 virtual node *add_self(node *, hyphen_list **);
95 virtual hyphen_list *get_hyphen_list(hyphen_list *, int *);
96 virtual void ascii_print(ascii_output_file *);
97 virtual void asciify(macro *);
98 virtual int discardable();
99 virtual void spread_space(int *, hunits *);
100 virtual void freeze_space();
101 virtual void is_escape_colon();
102 virtual breakpoint *get_breakpoints(hunits, int, breakpoint * = 0, int = 0);
103 virtual int nbreaks();
104 virtual void split(int, node **, node **);
105 virtual hyphenation_type get_hyphenation_type();
106 virtual int reread(int *);
107 virtual token_node *get_token_node();
108 virtual int overlaps_vertically();
109 virtual int overlaps_horizontally();
110 virtual units size();
111 virtual int interpret(macro *);
113 virtual node *merge_glyph_node(glyph_node *);
114 virtual tfont *get_tfont();
115 virtual color *get_glyph_color();
116 virtual color *get_fill_color();
117 virtual void tprint(troff_output_file *);
118 virtual void zero_width_tprint(troff_output_file *);
120 node *add_italic_correction(hunits *);
122 virtual int same(node *) = 0;
123 virtual const char *type() = 0;
124 virtual void debug_node();
125 virtual void debug_node_list();
128 inline node::node()
129 : next(0), last(0), state(0), push_state(0), div_nest_level(0), is_special(0)
133 inline node::node(node *n)
134 : next(n), last(0), state(0), push_state(0), div_nest_level(0), is_special(0)
138 inline node::node(node *n, statem *s, int divlevel)
139 : next(n), last(0), push_state(0), div_nest_level(divlevel), is_special(0)
141 if (s)
142 state = new statem(s);
143 else
144 state = 0;
147 inline node::~node()
151 // 0 means it doesn't, 1 means it does, 2 means it's transparent
153 int node_list_ends_sentence(node *);
155 struct breakpoint {
156 breakpoint *next;
157 hunits width;
158 int nspaces;
159 node *nd;
160 int index;
161 char hyphenated;
164 class line_start_node
165 : public node
167 public:
168 line_start_node() {}
169 node *copy() { return new line_start_node; }
170 int same(node *);
171 int force_tprint();
172 int is_tag();
173 const char *type();
174 void asciify(macro *);
177 class space_node
178 : public node
180 #if 0
181 enum { BLOCK = 1024 };
182 static space_node *free_list;
183 void operator delete(void *);
184 #endif
186 protected:
187 hunits n;
188 char set;
189 char was_escape_colon;
190 color *col; /* for grotty */
192 space_node(hunits, int, int, color *, statem *, int, node * = 0);
194 public:
195 space_node(hunits, color *, statem *, int, node * = 0);
196 space_node(hunits, color *, node * = 0);
197 #if 0
198 ~space_node();
199 void *operator new(size_t);
200 #endif
201 node *copy();
202 int nspaces();
203 hunits width();
204 int discardable();
205 int merge_space(hunits, hunits, hunits);
206 void freeze_space();
207 void is_escape_colon();
208 void spread_space(int *, hunits *);
209 void tprint(troff_output_file *);
210 breakpoint *get_breakpoints(hunits, int, breakpoint * = 0, int = 0);
211 int nbreaks();
212 void split(int, node **, node **);
213 void ascii_print(ascii_output_file *);
214 int same(node *);
215 void asciify(macro *);
216 const char *type();
217 int force_tprint();
218 int is_tag();
219 hyphenation_type get_hyphenation_type();
222 class width_list
224 public:
225 hunits width;
226 hunits sentence_width;
227 width_list *next;
229 width_list(hunits, hunits);
230 width_list(width_list *);
233 class word_space_node
234 : public space_node
236 protected:
237 width_list *orig_width;
238 unsigned char unformat;
240 word_space_node(hunits, int, color *, width_list *, int, statem *, int,
241 node * = 0);
243 public:
244 word_space_node(hunits, color *, width_list *, node * = 0);
245 ~word_space_node();
246 node *copy();
247 int reread(int *);
248 int set_unformat_flag();
249 void tprint(troff_output_file *);
250 int same(node *);
251 void asciify(macro *);
252 const char *type();
253 int merge_space(hunits, hunits, hunits);
254 int force_tprint();
255 int is_tag();
258 class unbreakable_space_node
259 : public word_space_node
261 unbreakable_space_node(hunits, int, color *, statem *, int, node * = 0);
263 public:
264 unbreakable_space_node(hunits, color *, node * = 0);
265 node *copy();
266 int reread(int *);
267 void tprint(troff_output_file *);
268 int same(node *);
269 void asciify(macro *);
270 const char *type();
271 int force_tprint();
272 int is_tag();
273 breakpoint *get_breakpoints(hunits, int, breakpoint * = 0, int = 0);
274 int nbreaks();
275 void split(int, node **, node **);
276 int merge_space(hunits, hunits, hunits);
277 node *add_self(node *, hyphen_list **);
278 hyphen_list *get_hyphen_list(hyphen_list *, int *);
279 hyphenation_type get_hyphenation_type();
282 class diverted_space_node
283 : public node
285 public:
286 vunits n;
288 diverted_space_node(vunits, node * = 0);
289 diverted_space_node(vunits, statem *, int, node * = 0);
290 node *copy();
291 int reread(int *);
292 int same(node *);
293 const char *type();
294 int force_tprint();
295 int is_tag();
298 class diverted_copy_file_node
299 : public node
301 symbol filename;
303 public:
304 vunits n;
306 diverted_copy_file_node(symbol, node * = 0);
307 diverted_copy_file_node(symbol, statem *, int, node * = 0);
308 node *copy();
309 int reread(int *);
310 int same(node *);
311 const char *type();
312 int force_tprint();
313 int is_tag();
316 class extra_size_node
317 : public node
319 vunits n;
321 public:
322 extra_size_node(vunits);
323 extra_size_node(vunits, statem *, int);
324 void set_vertical_size(vertical_size *);
325 node *copy();
326 int same(node *);
327 const char *type();
328 int force_tprint();
329 int is_tag();
332 class vertical_size_node
333 : public node
335 vunits n;
337 public:
338 vertical_size_node(vunits, statem *, int);
339 vertical_size_node(vunits);
340 void set_vertical_size(vertical_size *);
341 void asciify(macro *);
342 node *copy();
343 int set_unformat_flag();
344 int same(node *);
345 const char *type();
346 int force_tprint();
347 int is_tag();
350 class hmotion_node
351 : public node
353 protected:
354 hunits n;
355 unsigned char was_tab;
356 unsigned char unformat;
357 color *col; /* for grotty */
359 public:
360 hmotion_node(hunits i, color *c, node *nxt = 0)
361 : node(nxt), n(i), was_tab(0), unformat(0), col(c) {}
362 hmotion_node(hunits i, color *c, statem *s, int divlevel, node *nxt = 0)
363 : node(nxt, s, divlevel), n(i), was_tab(0), unformat(0), col(c) {}
364 hmotion_node(hunits i, int flag1, int flag2, color *c, statem *s,
365 int divlevel, node *nxt = 0)
366 : node(nxt, s, divlevel), n(i), was_tab(flag1), unformat(flag2),
367 col(c) {}
368 hmotion_node(hunits i, int flag1, int flag2, color *c, node *nxt = 0)
369 : node(nxt), n(i), was_tab(flag1), unformat(flag2), col(c) {}
370 node *copy();
371 int reread(int *);
372 int set_unformat_flag();
373 void asciify(macro *);
374 void tprint(troff_output_file *);
375 hunits width();
376 void ascii_print(ascii_output_file *);
377 int same(node *);
378 const char *type();
379 int force_tprint();
380 int is_tag();
381 node *add_self(node *, hyphen_list **);
382 hyphen_list *get_hyphen_list(hyphen_list *, int *);
383 hyphenation_type get_hyphenation_type();
386 class space_char_hmotion_node
387 : public hmotion_node
389 public:
390 space_char_hmotion_node(hunits, color *, node * = 0);
391 space_char_hmotion_node(hunits, color *, statem *, int, node * = 0);
392 node *copy();
393 void ascii_print(ascii_output_file *);
394 void asciify(macro *);
395 void tprint(troff_output_file *);
396 int same(node *);
397 const char *type();
398 int force_tprint();
399 int is_tag();
400 node *add_self(node *, hyphen_list **);
401 hyphen_list *get_hyphen_list(hyphen_list *, int *);
402 hyphenation_type get_hyphenation_type();
405 class vmotion_node
406 : public node
408 vunits n;
409 color *col; /* for grotty */
411 public:
412 vmotion_node(vunits, color *);
413 vmotion_node(vunits, color *, statem *, int);
414 void tprint(troff_output_file *);
415 node *copy();
416 vunits vertical_width();
417 int same(node *);
418 const char *type();
419 int force_tprint();
420 int is_tag();
423 class hline_node
424 : public node
426 hunits x;
427 node *n;
429 public:
430 hline_node(hunits, node *, node * = 0);
431 hline_node(hunits, node *, statem *, int, node * = 0);
432 ~hline_node();
433 node *copy();
434 hunits width();
435 void tprint(troff_output_file *);
436 int same(node *);
437 const char *type();
438 int force_tprint();
439 int is_tag();
442 class vline_node
443 : public node
445 vunits x;
446 node *n;
448 public:
449 vline_node(vunits, node *, node * = 0);
450 vline_node(vunits, node *, statem *, int, node * = 0);
451 ~vline_node();
452 node *copy();
453 void tprint(troff_output_file *);
454 hunits width();
455 vunits vertical_width();
456 void vertical_extent(vunits *, vunits *);
457 int same(node *);
458 const char *type();
459 int force_tprint();
460 int is_tag();
463 class dummy_node
464 : public node
466 public:
467 dummy_node(node *nd = 0) : node(nd) {}
468 node *copy();
469 int same(node *);
470 const char *type();
471 int force_tprint();
472 int is_tag();
473 hyphenation_type get_hyphenation_type();
476 class transparent_dummy_node
477 : public node
479 public:
480 transparent_dummy_node(node *nd = 0) : node(nd) {}
481 node *copy();
482 int same(node *);
483 const char *type();
484 int force_tprint();
485 int is_tag();
486 int ends_sentence();
487 hyphenation_type get_hyphenation_type();
490 class zero_width_node
491 : public node
493 node *n;
495 public:
496 zero_width_node(node *);
497 zero_width_node(node *, statem *, int);
498 ~zero_width_node();
499 node *copy();
500 void tprint(troff_output_file *);
501 int same(node *);
502 const char *type();
503 int force_tprint();
504 int is_tag();
505 void append(node *);
506 int character_type();
507 void vertical_extent(vunits *, vunits *);
510 class left_italic_corrected_node
511 : public node
513 node *n;
514 hunits x;
516 public:
517 left_italic_corrected_node(node * = 0);
518 left_italic_corrected_node(statem *, int, node * = 0);
519 ~left_italic_corrected_node();
520 void tprint(troff_output_file *);
521 void ascii_print(ascii_output_file *);
522 void asciify(macro *);
523 node *copy();
524 int same(node *);
525 const char *type();
526 int force_tprint();
527 int is_tag();
528 hunits width();
529 node *last_char_node();
530 void vertical_extent(vunits *, vunits *);
531 int ends_sentence();
532 int overlaps_horizontally();
533 int overlaps_vertically();
534 hyphenation_type get_hyphenation_type();
535 tfont *get_tfont();
536 int character_type();
537 hunits skew();
538 hunits italic_correction();
539 hunits subscript_correction();
540 hyphen_list *get_hyphen_list(hyphen_list *, int *);
541 node *add_self(node *, hyphen_list **);
542 node *merge_glyph_node(glyph_node *);
545 class overstrike_node
546 : public node
548 node *list;
549 hunits max_width;
551 public:
552 overstrike_node();
553 overstrike_node(statem *, int);
554 ~overstrike_node();
555 node *copy();
556 void tprint(troff_output_file *);
557 void overstrike(node *); // add another node to be overstruck
558 hunits width();
559 int same(node *);
560 const char *type();
561 int force_tprint();
562 int is_tag();
563 node *add_self(node *, hyphen_list **);
564 hyphen_list *get_hyphen_list(hyphen_list *, int *);
565 hyphenation_type get_hyphenation_type();
568 class bracket_node
569 : public node
571 node *list;
572 hunits max_width;
574 public:
575 bracket_node();
576 bracket_node(statem *, int);
577 ~bracket_node();
578 node *copy();
579 void tprint(troff_output_file *);
580 void bracket(node *); // add another node to be overstruck
581 hunits width();
582 int same(node *);
583 const char *type();
584 int force_tprint();
585 int is_tag();
588 class special_node
589 : public node
591 macro mac;
592 tfont *tf;
593 color *gcol;
594 color *fcol;
595 int no_init_string;
597 void tprint_start(troff_output_file *);
598 void tprint_char(troff_output_file *, unsigned char);
599 void tprint_end(troff_output_file *);
601 public:
602 special_node(const macro &, int = 0);
603 special_node(const macro &, tfont *, color *, color *, statem *, int,
604 int = 0);
605 node *copy();
606 void tprint(troff_output_file *);
607 int same(node *);
608 const char *type();
609 int force_tprint();
610 int is_tag();
611 int ends_sentence();
612 tfont *get_tfont();
615 class suppress_node
616 : public node
618 int is_on;
619 int emit_limits; // must we issue the extent of the area written out?
620 symbol filename;
621 char position;
622 int image_id;
624 void put(troff_output_file *, const char *);
626 public:
627 suppress_node(int, int);
628 suppress_node(symbol, char, int);
629 suppress_node(int, int, symbol, char, int, statem *, int);
630 suppress_node(int, int, symbol, char, int);
631 node *copy();
632 void tprint(troff_output_file *);
633 hunits width();
634 int same(node *);
635 const char *type();
636 int force_tprint();
637 int is_tag();
640 class tag_node
641 : public node
643 public:
644 string tag_string;
645 int delayed;
647 tag_node();
648 tag_node(string, int);
649 tag_node(string, statem *, int, int);
650 node *copy();
651 void tprint(troff_output_file *);
652 int same(node *);
653 const char *type();
654 int force_tprint();
655 int is_tag();
656 int ends_sentence();
659 class hvpair
661 public:
662 hunits h;
663 vunits v;
665 hvpair();
668 class draw_node
669 : public node
671 int npoints;
672 font_size sz;
673 color *gcol;
674 color *fcol;
675 char code;
676 hvpair *point;
678 public:
679 draw_node(char, hvpair *, int, font_size, color *, color *);
680 draw_node(char, hvpair *, int, font_size, color *, color *, statem *, int);
681 ~draw_node();
682 hunits width();
683 vunits vertical_width();
684 node *copy();
685 void tprint(troff_output_file *);
686 int same(node *);
687 const char *type();
688 int force_tprint();
689 int is_tag();
692 class charinfo;
693 node *make_node(charinfo *, environment *);
694 int character_exists(charinfo *, environment *);
696 int same_node_list(node *, node *);
697 node *reverse_node_list(node *);
698 void delete_node_list(node *);
699 node *copy_node_list(node *);
701 int get_bold_fontno(int);
703 inline hyphen_list::hyphen_list(unsigned char code, hyphen_list *p)
704 : hyphen(0), breakable(0), hyphenation_code(code), next(p)
708 extern void read_desc();
709 extern int mount_font(int, symbol, symbol = NULL_SYMBOL);
710 extern int check_font(symbol, symbol);
711 extern int check_style(symbol);
712 extern void mount_style(int, symbol);
713 extern int is_good_fontno(int);
714 extern int symbol_fontno(symbol);
715 extern int next_available_font_position();
716 extern void init_size_table(int *);
717 extern int get_underline_fontno();
719 class output_file
721 char make_g_plus_plus_shut_up;
723 public:
724 output_file();
725 virtual ~output_file();
726 virtual void trailer(vunits);
727 virtual void flush() = 0;
728 virtual void transparent_char(unsigned char) = 0;
729 virtual void print_line(hunits x, vunits y, node *n,
730 vunits before, vunits after, hunits width) = 0;
731 virtual void begin_page(int pageno, vunits page_length) = 0;
732 virtual void copy_file(hunits x, vunits y, const char *filename) = 0;
733 virtual int is_printing() = 0;
734 virtual void put_filename(const char *, int);
735 virtual void on();
736 virtual void off();
737 #ifdef COLUMN
738 virtual void vjustify(vunits, symbol);
739 #endif
740 mtsm state;
743 #ifndef POPEN_MISSING
744 extern char *pipe_command;
745 #endif
747 extern output_file *the_output;
748 extern void init_output();
749 int in_output_page_list(int);
751 class font_family
753 int *map;
754 int map_size;
756 public:
757 const symbol nm;
759 font_family(symbol);
760 ~font_family();
761 int make_definite(int);
762 static void invalidate_fontno(int);
765 font_family *lookup_family(symbol);
766 symbol get_font_name(int, environment *);
767 symbol get_style_name(int);
768 extern search_path include_search_path;
770 #endif // _NODE_H
771 // s-it2-mode