groff: update vendor branch to v1.20.1
[dragonfly.git] / contrib / groff / src / roff / troff / env.h
CommitLineData
92d0a6a6 1// -*- C++ -*-
4d3e9548
JL
2/* Copyright (C) 1989, 1990, 1991, 1992, 2000, 2001, 2002, 2004, 2005,
3 2006, 2009
92d0a6a6
JR
4 Free Software Foundation, Inc.
5 Written by James Clark (jjc@jclark.com)
6
7This file is part of groff.
8
9groff is free software; you can redistribute it and/or modify it under
10the terms of the GNU General Public License as published by the Free
4d3e9548
JL
11Software Foundation, either version 3 of the License, or
12(at your option) any later version.
92d0a6a6
JR
13
14groff is distributed in the hope that it will be useful, but WITHOUT ANY
15WARRANTY; without even the implied warranty of MERCHANTABILITY or
16FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17for more details.
18
4d3e9548
JL
19You should have received a copy of the GNU General Public License
20along with this program. If not, see <http://www.gnu.org/licenses/>. */
465b256c
JR
21
22class statem;
92d0a6a6
JR
23
24struct size_range {
25 int min;
26 int max;
27};
28
29class font_size {
30 static size_range *size_table;
31 static int nranges;
32 int p;
33public:
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
44inline font_size::font_size() : p(0)
45{
46}
47
48inline int font_size::operator==(font_size fs)
49{
50 return p == fs.p;
51}
52
53inline int font_size::operator!=(font_size fs)
54{
55 return p != fs.p;
56}
57
58inline int font_size::to_scaled_points()
59{
60 return p;
61}
62
63inline int font_size::to_points()
64{
65 return p/sizescale;
66}
67
68class environment;
69
70hunits env_digit_width(environment *);
71hunits env_space_width(environment *);
72hunits env_sentence_space_width(environment *);
73hunits env_narrow_space_width(environment *);
74hunits env_half_narrow_space_width(environment *);
4d3e9548 75int env_get_zoom(environment *);
92d0a6a6
JR
76
77struct tab;
78
79enum tab_type { TAB_NONE, TAB_LEFT, TAB_CENTER, TAB_RIGHT };
80
81class tab_stops {
82 tab *initial_list;
83 tab *repeated_list;
84public:
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
97const unsigned MARGIN_CHARACTER_ON = 1;
98const unsigned MARGIN_CHARACTER_NEXT = 2;
99
100class charinfo;
101struct node;
102struct breakpoint;
103class font_family;
104class pending_output_line;
105
465b256c
JR
106// declarations to avoid friend name injection problems
107void title_length();
108void space_size();
109void fill();
110void no_fill();
111void adjust();
112void no_adjust();
113void center();
114void right_justify();
115void vertical_spacing();
116void post_vertical_spacing();
117void line_spacing();
118void line_length();
119void indent();
120void temporary_indent();
121void do_underline(int);
122void do_input_trap(int);
123void set_tabs();
124void margin_character();
125void no_number();
126void number_lines();
127void leader_character();
128void tab_character();
129void hyphenate_request();
130void no_hyphenate();
131void hyphen_line_max_request();
132void hyphenation_space_request();
133void hyphenation_margin_request();
134void line_width();
135#if 0
136void tabs_save();
137void tabs_restore();
138#endif
139void line_tabs_request();
140void title();
141#ifdef WIDOW_CONTROL
142void widow_control_request();
143#endif /* WIDOW_CONTROL */
144
145void do_divert(int append, int boxing);
146
92d0a6a6
JR
147class 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;
92d0a6a6
JR
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 */
92d0a6a6
JR
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();
465b256c 237 void output_line(node *, hunits, int);
92d0a6a6 238 void output(node *nd, int retain_size, vunits vs, vunits post_vs,
465b256c 239 hunits width, int was_centered);
92d0a6a6
JR
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();
252public:
465b256c
JR
253 int seen_space;
254 int seen_eol;
255 int suppress_next_eol;
256 int seen_break;
257 tab_stops tabs;
92d0a6a6
JR
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();
465b256c 266 statem *construct_state(int only_eol);
4d3e9548 267 void print_env();
92d0a6a6
JR
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; }
465b256c
JR
273 vunits get_vertical_spacing(); // .v
274 vunits get_post_vertical_spacing(); // .pvs
275 int get_line_spacing(); // .L
92d0a6a6
JR
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();
465b256c 284 int get_font() { return fontno; }; // .f
4d3e9548 285 int get_zoom(); // .zoom
92d0a6a6 286 font_family *get_family() { return family; }
465b256c
JR
287 int get_bold(); // .b
288 int get_adjust_mode(); // .j
289 int get_fill(); // .u
290 hunits get_indent(); // .i
92d0a6a6 291 hunits get_temporary_indent();
465b256c
JR
292 hunits get_line_length(); // .l
293 hunits get_saved_line_length(); // .ll
294 hunits get_saved_indent(); // .in
92d0a6a6 295 hunits get_title_length();
465b256c 296 hunits get_prev_char_width(); // .w
92d0a6a6
JR
297 hunits get_prev_char_skew();
298 vunits get_prev_char_height();
299 vunits get_prev_char_depth();
465b256c
JR
300 hunits get_text_length(); // .k
301 hunits get_prev_text_length(); // .n
92d0a6a6
JR
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();
465b256c 341 node *make_tag(const char *name, int i);
92d0a6a6 342 void newline();
465b256c 343 void handle_tab(int is_leader = 0); // do a tab or leader
92d0a6a6
JR
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();
465b256c 355 const char *get_style_name_string();
92d0a6a6
JR
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();
465b256c
JR
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();
92d0a6a6
JR
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};
4d3e9548 404
92d0a6a6
JR
405extern environment *curenv;
406extern void pop_env();
407extern void push_env(int);
408
409void init_environments();
410void read_hyphen_file(const char *name);
411
412extern double spread_limit;
413
414extern int break_flag;
415extern symbol default_family;
416extern int translate_space_to_dummy;
417
418extern unsigned char hpf_code_table[];