]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/groff/troff/env.h
unfinished sblive driver, playback/mixer only for now - not enabled in
[FreeBSD/FreeBSD.git] / contrib / groff / troff / env.h
1 // -*- C++ -*-
2 /* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
3      Written by James Clark (jjc@jclark.com)
4
5 This file is part of groff.
6
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.
11
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.
16
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. */
20
21 struct size_range {
22   int min;
23   int max;
24 };
25
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);
39 };
40
41 inline font_size::font_size() : p(0)
42 {
43 }
44
45 inline int font_size::operator==(font_size fs)
46 {
47   return p == fs.p;
48 }
49
50 inline int font_size::operator!=(font_size fs)
51 {
52   return p != fs.p;
53 }
54
55 inline int font_size::to_scaled_points()
56 {
57   return p;
58 }
59
60 inline int font_size::to_points()
61 {
62   return p/sizescale;
63 }
64
65 struct environment;
66
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 *);
72
73 struct tab;
74
75 enum tab_type { TAB_NONE, TAB_LEFT, TAB_CENTER, TAB_RIGHT };
76
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();
90 };
91
92 const unsigned MARGIN_CHARACTER_ON = 1;
93 const unsigned MARGIN_CHARACTER_NEXT = 2;
94
95 struct charinfo;
96 struct node;
97 struct breakpoint;
98 struct font_family;
99 struct pending_output_line;
100
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 */
181
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;
205   
206   environment(symbol);
207   environment(const environment *);     // for temporary environment
208   ~environment();
209   int is_dummy() { return dummy; }
210   int is_empty();
211   int is_composite() { return composite; }
212   void set_composite() { composite = 1; }
213   vunits get_vertical_spacing(); // .v
214   vunits get_post_vertical_spacing(); // .pvs
215   int get_line_spacing();        // .L
216   vunits total_post_vertical_spacing();
217   int get_point_size() { return size.to_scaled_points(); }
218   font_size get_font_size() { return size; }
219   int get_size() { return size.to_units(); }
220   int get_requested_point_size() { return requested_size; }
221   int get_char_height() { return char_height; }
222   int get_char_slant() { return char_slant; }
223   hunits get_digit_width();
224   int get_font() { return fontno; }; // .f
225   font_family *get_family() { return family; }
226   int get_bold();               // .b
227   int get_adjust_mode();        // .j
228   int get_fill();               // .u
229   hunits get_indent();          // .i
230   hunits get_temporary_indent();
231   hunits get_line_length();      // .l
232   hunits get_saved_line_length(); // .ll
233   hunits get_saved_indent();      // .in
234   hunits get_title_length();
235   hunits get_prev_char_width(); // .w
236   hunits get_prev_char_skew();
237   vunits get_prev_char_height();
238   vunits get_prev_char_depth();
239   hunits get_text_length();     // .k 
240   hunits get_prev_text_length(); // .n
241   hunits get_space_width() { return env_space_width(this); }
242   int get_space_size() { return space_size; }   // in ems/36
243   int get_sentence_space_size() { return sentence_space_size; }
244   hunits get_narrow_space_width() { return env_narrow_space_width(this); }
245   hunits get_half_narrow_space_width()
246     { return env_half_narrow_space_width(this); }
247   hunits get_input_line_position();
248   const char *get_tabs();
249   int get_hyphenation_flags();
250   int get_hyphen_line_max();
251   int get_hyphen_line_count();
252   hunits get_hyphenation_space();
253   hunits get_hyphenation_margin();
254   int get_center_lines();
255   int get_right_justify_lines();
256   int get_prev_line_interrupted() { return prev_line_interrupted; }
257   node *make_char_node(charinfo *);
258   node *extract_output_line();
259   void width_registers();
260   void wrap_up_tab();
261   void set_font(int);
262   void set_font(symbol);
263   void set_family(symbol);
264   void set_size(int);
265   void set_char_height(int);
266   void set_char_slant(int);
267   void set_input_line_position(hunits); // used by \n(hp
268   void interrupt();
269   void spread() { spread_flag = 1; }
270   void do_break();                      // .br
271   void final_break();
272   void newline();
273   void handle_tab(int is_leader = 0); // do a tab or leader
274   void add_node(node *);
275   void add_char(charinfo *);
276   void add_hyphen_indicator();
277   void add_italic_correction();
278   void space();
279   void space_newline();
280   const char *get_font_family_string();
281   const char *get_name_string();
282   const char *get_point_size_string();
283   const char *get_requested_point_size_string();
284   void output_pending_lines();
285   
286   friend void title_length();
287   friend void space_size();
288   friend void fill();
289   friend void no_fill();
290   friend void adjust();
291   friend void no_adjust();
292   friend void center();
293   friend void right_justify();
294   friend void vertical_spacing();
295   friend void post_vertical_spacing();
296   friend void line_spacing();
297   friend void line_length();
298   friend void indent();
299   friend void temporary_indent();
300   friend void underline();
301   friend void input_trap();
302   friend void set_tabs();
303   friend void margin_character();
304   friend void no_number();
305   friend void number_lines();
306   friend void leader_character();
307   friend void tab_character();
308   friend void hyphenate_request();
309   friend void no_hyphenate();
310   friend void hyphen_line_max_request();
311   friend void hyphenation_space_request();
312   friend void hyphenation_margin_request();
313   friend void line_width();
314 #if 0
315   friend void tabs_save();
316   friend void tabs_restore();
317 #endif
318   friend void title();
319 #ifdef WIDOW_CONTROL
320   friend void widow_control_request();
321 #endif /* WIDOW_CONTROL */
322 };
323         
324 extern environment *curenv;
325 extern void pop_env();
326 extern void push_env(int);
327
328 void init_environments();
329 void read_hyphen_file(const char *name);
330
331 extern int break_flag;
332 extern symbol default_family;
333 extern int translate_space_to_dummy;