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