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