groff: update vendor branch to v1.20.1
[dragonfly.git] / contrib / groff / src / roff / troff / env.h
1 // -*- C++ -*-
2 /* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2004, 2005,
3                  2006, 2009
4    Free Software Foundation, Inc.
5      Written by James Clark (jjc@jclark.com)
6
7 This file is part of groff.
8
9 groff is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 groff is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
17 for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
22 class statem;
23
24 struct size_range {
25   int min;
26   int max;
27 };
28
29 class font_size {
30   static size_range *size_table;
31   static int nranges;
32   int p;
33 public:
34   font_size();
35   font_size(int points);
36   int to_points();
37   int to_scaled_points();
38   int to_units();
39   int operator==(font_size);
40   int operator!=(font_size);
41   static void init_size_table(int *sizes);
42 };
43
44 inline font_size::font_size() : p(0)
45 {
46 }
47
48 inline int font_size::operator==(font_size fs)
49 {
50   return p == fs.p;
51 }
52
53 inline int font_size::operator!=(font_size fs)
54 {
55   return p != fs.p;
56 }
57
58 inline int font_size::to_scaled_points()
59 {
60   return p;
61 }
62
63 inline int font_size::to_points()
64 {
65   return p/sizescale;
66 }
67
68 class environment;
69
70 hunits env_digit_width(environment *);
71 hunits env_space_width(environment *);
72 hunits env_sentence_space_width(environment *);
73 hunits env_narrow_space_width(environment *);
74 hunits env_half_narrow_space_width(environment *);
75 int env_get_zoom(environment *);
76
77 struct tab;
78
79 enum tab_type { TAB_NONE, TAB_LEFT, TAB_CENTER, TAB_RIGHT };
80
81 class tab_stops {
82   tab *initial_list;
83   tab *repeated_list;
84 public:
85   tab_stops();
86   tab_stops(hunits distance, tab_type type);
87   tab_stops(const tab_stops &);
88   ~tab_stops();
89   void operator=(const tab_stops &);
90   tab_type distance_to_next_tab(hunits pos, hunits *distance);
91   tab_type distance_to_next_tab(hunits curpos, hunits *distance, hunits *leftpos);
92   void clear();
93   void add_tab(hunits pos, tab_type type, int repeated);
94   const char *to_string();
95 };
96
97 const unsigned MARGIN_CHARACTER_ON = 1;
98 const unsigned MARGIN_CHARACTER_NEXT = 2;
99
100 class charinfo;
101 struct node;
102 struct breakpoint;
103 class font_family;
104 class pending_output_line;
105
106 // declarations to avoid friend name injection problems
107 void title_length();
108 void space_size();
109 void fill();
110 void no_fill();
111 void adjust();
112 void no_adjust();
113 void center();
114 void right_justify();
115 void vertical_spacing();
116 void post_vertical_spacing();
117 void line_spacing();
118 void line_length();
119 void indent();
120 void temporary_indent();
121 void do_underline(int);
122 void do_input_trap(int);
123 void set_tabs();
124 void margin_character();
125 void no_number();
126 void number_lines();
127 void leader_character();
128 void tab_character();
129 void hyphenate_request();
130 void no_hyphenate();
131 void hyphen_line_max_request();
132 void hyphenation_space_request();
133 void hyphenation_margin_request();
134 void line_width();
135 #if 0
136 void tabs_save();
137 void tabs_restore();
138 #endif
139 void line_tabs_request();
140 void title();
141 #ifdef WIDOW_CONTROL
142 void widow_control_request();
143 #endif /* WIDOW_CONTROL */
144
145 void do_divert(int append, int boxing);
146
147 class environment {
148   int dummy;                    // dummy environment used for \w
149   hunits prev_line_length;
150   hunits line_length;
151   hunits prev_title_length;
152   hunits title_length;
153   font_size prev_size;
154   font_size size;
155   int requested_size;
156   int prev_requested_size;
157   int char_height;
158   int char_slant;
159   int prev_fontno;
160   int fontno;
161   font_family *prev_family;
162   font_family *family;
163   int space_size;               // in 36ths of an em
164   int sentence_space_size;      // same but for spaces at the end of sentences
165   int adjust_mode;
166   int fill;
167   int interrupted;
168   int prev_line_interrupted;
169   int center_lines;
170   int right_justify_lines;
171   vunits prev_vertical_spacing;
172   vunits vertical_spacing;
173   vunits prev_post_vertical_spacing;
174   vunits post_vertical_spacing;
175   int prev_line_spacing;
176   int line_spacing;
177   hunits prev_indent;
178   hunits indent;
179   hunits temporary_indent;
180   int have_temporary_indent;
181   hunits saved_indent;
182   hunits target_text_length;
183   int pre_underline_fontno;
184   int underline_lines;
185   int underline_spaces;
186   symbol input_trap;
187   int input_trap_count;
188   int continued_input_trap;
189   node *line;                   // in reverse order
190   hunits prev_text_length;
191   hunits width_total;
192   int space_total;
193   hunits input_line_start;
194   node *tab_contents;
195   hunits tab_width;
196   hunits tab_distance;
197   int line_tabs;
198   tab_type current_tab;
199   node *leader_node;
200   charinfo *tab_char;
201   charinfo *leader_char;
202   int current_field;            // is there a current field?
203   hunits field_distance;
204   hunits pre_field_width;
205   int field_spaces;
206   int tab_field_spaces;
207   int tab_precedes_field;
208   int discarding;
209   int spread_flag;              // set by \p
210   unsigned margin_character_flags;
211   node *margin_character_node;
212   hunits margin_character_distance;
213   node *numbering_nodes;
214   hunits line_number_digit_width;
215   int number_text_separation;   // in digit spaces
216   int line_number_indent;       // in digit spaces
217   int line_number_multiple;
218   int no_number_count;
219   unsigned hyphenation_flags;
220   int hyphen_line_count;
221   int hyphen_line_max;
222   hunits hyphenation_space;
223   hunits hyphenation_margin;
224   int composite;                // used for construction of composite char?
225   pending_output_line *pending_lines;
226 #ifdef WIDOW_CONTROL
227   int widow_control;
228 #endif /* WIDOW_CONTROL */
229   color *glyph_color;
230   color *prev_glyph_color;
231   color *fill_color;
232   color *prev_fill_color;
233
234   tab_type distance_to_next_tab(hunits *);
235   tab_type distance_to_next_tab(hunits *distance, hunits *leftpos);
236   void start_line();
237   void output_line(node *, hunits, int);
238   void output(node *nd, int retain_size, vunits vs, vunits post_vs,
239               hunits width, int was_centered);
240   void output_title(node *nd, int retain_size, vunits vs, vunits post_vs,
241                     hunits width);
242 #ifdef WIDOW_CONTROL
243   void mark_last_line();
244 #endif /* WIDOW_CONTROL */
245   breakpoint *choose_breakpoint();
246   void hyphenate_line(int start_here = 0);
247   void start_field();
248   void wrap_up_field();
249   void add_padding();
250   node *make_tab_node(hunits d, node *next = 0);
251   node *get_prev_char();
252 public:
253   int seen_space;
254   int seen_eol;
255   int suppress_next_eol;
256   int seen_break;
257   tab_stops tabs;
258   const symbol name;
259   unsigned char control_char;
260   unsigned char no_break_control_char;
261   charinfo *hyphen_indicator_char;
262   
263   environment(symbol);
264   environment(const environment *);     // for temporary environment
265   ~environment();
266   statem *construct_state(int only_eol);
267   void print_env();
268   void copy(const environment *);
269   int is_dummy() { return dummy; }
270   int is_empty();
271   int is_composite() { return composite; }
272   void set_composite() { composite = 1; }
273   vunits get_vertical_spacing();        // .v
274   vunits get_post_vertical_spacing();   // .pvs
275   int get_line_spacing();               // .L
276   vunits total_post_vertical_spacing();
277   int get_point_size() { return size.to_scaled_points(); }
278   font_size get_font_size() { return size; }
279   int get_size() { return size.to_units(); }
280   int get_requested_point_size() { return requested_size; }
281   int get_char_height() { return char_height; }
282   int get_char_slant() { return char_slant; }
283   hunits get_digit_width();
284   int get_font() { return fontno; };    // .f
285   int get_zoom();                       // .zoom
286   font_family *get_family() { return family; }
287   int get_bold();                       // .b
288   int get_adjust_mode();                // .j
289   int get_fill();                       // .u
290   hunits get_indent();                  // .i
291   hunits get_temporary_indent();
292   hunits get_line_length();             // .l
293   hunits get_saved_line_length();       // .ll
294   hunits get_saved_indent();            // .in
295   hunits get_title_length();
296   hunits get_prev_char_width();         // .w
297   hunits get_prev_char_skew();
298   vunits get_prev_char_height();
299   vunits get_prev_char_depth();
300   hunits get_text_length();             // .k 
301   hunits get_prev_text_length();        // .n
302   hunits get_space_width() { return env_space_width(this); }
303   int get_space_size() { return space_size; }   // in ems/36
304   int get_sentence_space_size() { return sentence_space_size; }
305   hunits get_narrow_space_width() { return env_narrow_space_width(this); }
306   hunits get_half_narrow_space_width()
307     { return env_half_narrow_space_width(this); }
308   hunits get_input_line_position();
309   const char *get_tabs();
310   int get_line_tabs();
311   int get_hyphenation_flags();
312   int get_hyphen_line_max();
313   int get_hyphen_line_count();
314   hunits get_hyphenation_space();
315   hunits get_hyphenation_margin();
316   int get_center_lines();
317   int get_right_justify_lines();
318   int get_prev_line_interrupted() { return prev_line_interrupted; }
319   color *get_fill_color();
320   color *get_glyph_color();
321   color *get_prev_glyph_color();
322   color *get_prev_fill_color();
323   void set_glyph_color(color *c);
324   void set_fill_color(color *c);
325   node *make_char_node(charinfo *);
326   node *extract_output_line();
327   void width_registers();
328   void wrap_up_tab();
329   void set_font(int);
330   void set_font(symbol);
331   void set_family(symbol);
332   void set_size(int);
333   void set_char_height(int);
334   void set_char_slant(int);
335   void set_input_line_position(hunits); // used by \n(hp
336   void interrupt();
337   void spread() { spread_flag = 1; }
338   void possibly_break_line(int start_here = 0, int forced = 0);
339   void do_break(int spread = 0);        // .br
340   void final_break();
341   node *make_tag(const char *name, int i);
342   void newline();
343   void handle_tab(int is_leader = 0);   // do a tab or leader
344   void add_node(node *);
345   void add_char(charinfo *);
346   void add_hyphen_indicator();
347   void add_italic_correction();
348   void space();
349   void space(hunits, hunits);
350   void space_newline();
351   const char *get_glyph_color_string();
352   const char *get_fill_color_string();
353   const char *get_font_family_string();
354   const char *get_font_name_string();
355   const char *get_style_name_string();
356   const char *get_name_string();
357   const char *get_point_size_string();
358   const char *get_requested_point_size_string();
359   void output_pending_lines();
360   void construct_format_state(node *n, int was_centered, int fill);
361   void construct_new_line_state(node *n);
362   void dump_troff_state();
363   
364   friend void title_length();
365   friend void space_size();
366   friend void fill();
367   friend void no_fill();
368   friend void adjust();
369   friend void no_adjust();
370   friend void center();
371   friend void right_justify();
372   friend void vertical_spacing();
373   friend void post_vertical_spacing();
374   friend void line_spacing();
375   friend void line_length();
376   friend void indent();
377   friend void temporary_indent();
378   friend void do_underline(int);
379   friend void do_input_trap(int);
380   friend void set_tabs();
381   friend void margin_character();
382   friend void no_number();
383   friend void number_lines();
384   friend void leader_character();
385   friend void tab_character();
386   friend void hyphenate_request();
387   friend void no_hyphenate();
388   friend void hyphen_line_max_request();
389   friend void hyphenation_space_request();
390   friend void hyphenation_margin_request();
391   friend void line_width();
392 #if 0
393   friend void tabs_save();
394   friend void tabs_restore();
395 #endif
396   friend void line_tabs_request();
397   friend void title();
398 #ifdef WIDOW_CONTROL
399   friend void widow_control_request();
400 #endif /* WIDOW_CONTROL */
401
402   friend void do_divert(int append, int boxing);
403 };
404
405 extern environment *curenv;
406 extern void pop_env();
407 extern void push_env(int);
408
409 void init_environments();
410 void read_hyphen_file(const char *name);
411
412 extern double spread_limit;
413
414 extern int break_flag;
415 extern symbol default_family;
416 extern int translate_space_to_dummy;
417
418 extern unsigned char hpf_code_table[];