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