Adding a new option -P and new environment variable GROPS_PROLOGUE
[s-roff.git] / src / roff / troff / env.h
blobd2a1fb34578f5dc9d7f1addb897521e1b0ce337f
1 // -*- C++ -*-
2 /* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
3 Written by James Clark (jjc@jclark.com)
5 This file is part of groff.
7 groff is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 groff is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License along
18 with groff; see the file COPYING. If not, write to the Free Software
19 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 struct size_range {
22 int min;
23 int max;
26 class font_size {
27 static size_range *size_table;
28 static int nranges;
29 int p;
30 public:
31 font_size();
32 font_size(int points);
33 int to_points();
34 int to_scaled_points();
35 int to_units();
36 int operator==(font_size);
37 int operator!=(font_size);
38 static void init_size_table(int *sizes);
41 inline font_size::font_size() : p(0)
45 inline int font_size::operator==(font_size fs)
47 return p == fs.p;
50 inline int font_size::operator!=(font_size fs)
52 return p != fs.p;
55 inline int font_size::to_scaled_points()
57 return p;
60 inline int font_size::to_points()
62 return p/sizescale;
65 struct environment;
67 hunits env_digit_width(environment *);
68 hunits env_space_width(environment *);
69 hunits env_sentence_space_width(environment *);
70 hunits env_narrow_space_width(environment *);
71 hunits env_half_narrow_space_width(environment *);
73 struct tab;
75 enum tab_type { TAB_NONE, TAB_LEFT, TAB_CENTER, TAB_RIGHT };
77 class tab_stops {
78 tab *initial_list;
79 tab *repeated_list;
80 public:
81 tab_stops();
82 tab_stops(hunits distance, tab_type type);
83 tab_stops(const tab_stops &);
84 ~tab_stops();
85 void operator=(const tab_stops &);
86 tab_type distance_to_next_tab(hunits pos, hunits *distance);
87 void clear();
88 void add_tab(hunits pos, tab_type type, int repeated);
89 const char *to_string();
92 const unsigned MARGIN_CHARACTER_ON = 1;
93 const unsigned MARGIN_CHARACTER_NEXT = 2;
95 struct charinfo;
96 struct node;
97 struct breakpoint;
98 struct font_family;
99 struct pending_output_line;
101 class environment {
102 int dummy; // dummy environment used for \w
103 hunits prev_line_length;
104 hunits line_length;
105 hunits prev_title_length;
106 hunits title_length;
107 font_size prev_size;
108 font_size size;
109 int requested_size;
110 int prev_requested_size;
111 int char_height;
112 int char_slant;
113 int prev_fontno;
114 int fontno;
115 font_family *prev_family;
116 font_family *family;
117 int space_size; // in 36ths of an em
118 int sentence_space_size; // same but for spaces at the end of sentences
119 int adjust_mode;
120 int fill;
121 int interrupted;
122 int prev_line_interrupted;
123 int center_lines;
124 int right_justify_lines;
125 vunits prev_vertical_spacing;
126 vunits vertical_spacing;
127 vunits prev_post_vertical_spacing;
128 vunits post_vertical_spacing;
129 int prev_line_spacing;
130 int line_spacing;
131 hunits prev_indent;
132 hunits indent;
133 hunits temporary_indent;
134 int have_temporary_indent;
135 hunits saved_indent;
136 hunits target_text_length;
137 int pre_underline_fontno;
138 int underline_lines;
139 symbol input_trap;
140 int input_trap_count;
141 node *line; // in reverse order
142 hunits prev_text_length;
143 hunits width_total;
144 int space_total;
145 hunits input_line_start;
146 tab_stops tabs;
147 node *tab_contents;
148 hunits tab_width;
149 hunits tab_distance;
150 tab_type current_tab;
151 node *leader_node;
152 charinfo *tab_char;
153 charinfo *leader_char;
154 int current_field; // is there a current field?
155 hunits field_distance;
156 hunits pre_field_width;
157 int field_spaces;
158 int tab_field_spaces;
159 int tab_precedes_field;
160 int discarding;
161 int spread_flag; // set by \p
162 unsigned margin_character_flags;
163 node *margin_character_node;
164 hunits margin_character_distance;
165 node *numbering_nodes;
166 hunits line_number_digit_width;
167 int number_text_separation; // in digit spaces
168 int line_number_indent; // in digit spaces
169 int line_number_multiple;
170 int no_number_count;
171 unsigned hyphenation_flags;
172 int hyphen_line_count;
173 int hyphen_line_max;
174 hunits hyphenation_space;
175 hunits hyphenation_margin;
176 int composite; // used for construction of composite char?
177 pending_output_line *pending_lines;
178 #ifdef WIDOW_CONTROL
179 int widow_control;
180 #endif /* WIDOW_CONTROL */
182 tab_type distance_to_next_tab(hunits *);
183 void start_line();
184 void output_line(node *, hunits);
185 void output(node *nd, int retain_size, vunits vs, vunits post_vs,
186 hunits width);
187 void output_title(node *nd, int retain_size, vunits vs, vunits post_vs,
188 hunits width);
189 #ifdef WIDOW_CONTROL
190 void mark_last_line();
191 #endif /* WIDOW_CONTROL */
192 void possibly_break_line(int forced = 0);
193 breakpoint *choose_breakpoint();
194 void hyphenate_line();
195 void start_field();
196 void wrap_up_field();
197 void add_padding();
198 node *make_tab_node(hunits d, node *next = 0);
199 node *get_prev_char();
200 public:
201 const symbol name;
202 unsigned char control_char;
203 unsigned char no_break_control_char;
204 charinfo *hyphen_indicator_char;
206 environment(symbol);
207 environment(const environment *); // for temporary environment
208 ~environment();
209 void copy(const environment *);
210 int is_dummy() { return dummy; }
211 int is_empty();
212 int is_composite() { return composite; }
213 void set_composite() { composite = 1; }
214 vunits get_vertical_spacing(); // .v
215 vunits get_post_vertical_spacing(); // .pvs
216 int get_line_spacing(); // .L
217 vunits total_post_vertical_spacing();
218 int get_point_size() { return size.to_scaled_points(); }
219 font_size get_font_size() { return size; }
220 int get_size() { return size.to_units(); }
221 int get_requested_point_size() { return requested_size; }
222 int get_char_height() { return char_height; }
223 int get_char_slant() { return char_slant; }
224 hunits get_digit_width();
225 int get_font() { return fontno; }; // .f
226 font_family *get_family() { return family; }
227 int get_bold(); // .b
228 int get_adjust_mode(); // .j
229 int get_fill(); // .u
230 hunits get_indent(); // .i
231 hunits get_temporary_indent();
232 hunits get_line_length(); // .l
233 hunits get_saved_line_length(); // .ll
234 hunits get_saved_indent(); // .in
235 hunits get_title_length();
236 hunits get_prev_char_width(); // .w
237 hunits get_prev_char_skew();
238 vunits get_prev_char_height();
239 vunits get_prev_char_depth();
240 hunits get_text_length(); // .k
241 hunits get_prev_text_length(); // .n
242 hunits get_space_width() { return env_space_width(this); }
243 int get_space_size() { return space_size; } // in ems/36
244 int get_sentence_space_size() { return sentence_space_size; }
245 hunits get_narrow_space_width() { return env_narrow_space_width(this); }
246 hunits get_half_narrow_space_width()
247 { return env_half_narrow_space_width(this); }
248 hunits get_input_line_position();
249 const char *get_tabs();
250 int get_hyphenation_flags();
251 int get_hyphen_line_max();
252 int get_hyphen_line_count();
253 hunits get_hyphenation_space();
254 hunits get_hyphenation_margin();
255 int get_center_lines();
256 int get_right_justify_lines();
257 int get_prev_line_interrupted() { return prev_line_interrupted; }
258 node *make_char_node(charinfo *);
259 node *extract_output_line();
260 void width_registers();
261 void wrap_up_tab();
262 void set_font(int);
263 void set_font(symbol);
264 void set_family(symbol);
265 void set_size(int);
266 void set_char_height(int);
267 void set_char_slant(int);
268 void set_input_line_position(hunits); // used by \n(hp
269 void interrupt();
270 void spread() { spread_flag = 1; }
271 void do_break(); // .br
272 void final_break();
273 void add_html_tag (const char *name);
274 void newline();
275 void handle_tab(int is_leader = 0); // do a tab or leader
276 void add_node(node *);
277 void add_char(charinfo *);
278 void add_hyphen_indicator();
279 void add_italic_correction();
280 void space();
281 void space_newline();
282 const char *get_font_family_string();
283 const char *get_name_string();
284 const char *get_point_size_string();
285 const char *get_requested_point_size_string();
286 void output_pending_lines();
288 friend void title_length();
289 friend void space_size();
290 friend void fill();
291 friend void no_fill();
292 friend void adjust();
293 friend void no_adjust();
294 friend void center();
295 friend void right_justify();
296 friend void vertical_spacing();
297 friend void post_vertical_spacing();
298 friend void line_spacing();
299 friend void line_length();
300 friend void indent();
301 friend void temporary_indent();
302 friend void underline();
303 friend void input_trap();
304 friend void set_tabs();
305 friend void margin_character();
306 friend void no_number();
307 friend void number_lines();
308 friend void leader_character();
309 friend void tab_character();
310 friend void hyphenate_request();
311 friend void no_hyphenate();
312 friend void hyphen_line_max_request();
313 friend void hyphenation_space_request();
314 friend void hyphenation_margin_request();
315 friend void line_width();
316 #if 0
317 friend void tabs_save();
318 friend void tabs_restore();
319 #endif
320 friend void title();
321 #ifdef WIDOW_CONTROL
322 friend void widow_control_request();
323 #endif /* WIDOW_CONTROL */
326 extern environment *curenv;
327 extern void pop_env();
328 extern void push_env(int);
330 void init_environments();
331 void read_hyphen_file(const char *name);
333 extern int break_flag;
334 extern symbol default_family;
335 extern int translate_space_to_dummy;