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