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