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