2 /* Copyright (C) 1989, 1990, 1991, 1992, 2002, 2004
3 Free Software Foundation, Inc.
4 Written by James Clark (jjc@jclark.com)
6 This file is part of groff.
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
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
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. */
25 const char *current_roman_font;
32 int script_size_reduction = -1; // negative means reduce by a percentage
34 int positive_space = -1;
35 int negative_space = -1;
44 int accent_width = 31;
45 int delimiter_factor = 900;
46 int delimiter_shortfall = 50;
48 int null_delimiter_space = 12;
51 int medium_space = 22;
56 // we don't use num3, because we don't have \atop
59 int axis_height = 26; // in 100ths of an em
63 int default_rule_thickness = 4;
69 int big_op_spacing1 = 11;
70 int big_op_spacing2 = 17;
71 int big_op_spacing3 = 20;
72 int big_op_spacing4 = 60;
73 int big_op_spacing5 = 10;
75 // These are for piles and matrices.
77 int baseline_sep = 140; // = num1 + denom1
78 int shift_down = 26; // = axis_height
79 int column_sep = 100; // = em space
80 int matrix_side_sep = 17; // = thin space
82 int nroff = 0; // should we grok ndefine or tdefine?
88 { "fat_offset", &fat_offset },
89 { "over_hang", &over_hang },
90 { "accent_width", &accent_width },
91 { "delimiter_factor", &delimiter_factor },
92 { "delimiter_shortfall", &delimiter_shortfall },
93 { "null_delimiter_space", &null_delimiter_space },
94 { "script_space", &script_space },
95 { "thin_space", &thin_space },
96 { "medium_space", &medium_space },
97 { "thick_space", &thick_space },
100 { "denom1", &denom1 },
101 { "denom2", &denom2 },
102 { "axis_height", &axis_height },
106 { "default_rule_thickness", &default_rule_thickness },
109 { "sup_drop", &sup_drop },
110 { "sub_drop", &sub_drop },
111 { "x_height", &x_height },
112 { "big_op_spacing1", &big_op_spacing1 },
113 { "big_op_spacing2", &big_op_spacing2 },
114 { "big_op_spacing3", &big_op_spacing3 },
115 { "big_op_spacing4", &big_op_spacing4 },
116 { "big_op_spacing5", &big_op_spacing5 },
117 { "minimum_size", &minimum_size },
118 { "baseline_sep", &baseline_sep },
119 { "shift_down", &shift_down },
120 { "column_sep", &column_sep },
121 { "matrix_side_sep", &matrix_side_sep },
122 { "draw_lines", &draw_flag },
123 { "body_height", &body_height },
124 { "body_depth", &body_depth },
129 void set_param(const char *name, int value)
131 for (int i = 0; param_table[i].name != 0; i++)
132 if (strcmp(param_table[i].name, name) == 0) {
133 *param_table[i].ptr = value;
136 error("unrecognised parameter `%1'", name);
139 int script_style(int style)
141 return style > SCRIPT_STYLE ? style - 2 : style;
144 int cramped_style(int style)
146 return (style & 1) ? style - 1 : style;
149 void set_space(int n)
157 // Return 0 if the specified size is bad.
158 // The caller is responsible for giving the error message.
160 int set_gsize(const char *s)
162 const char *p = (*s == '+' || *s == '-') ? s + 1 : s;
164 long n = strtol(p, &end, 10);
165 if (n <= 0 || *end != '\0' || n > INT_MAX)
171 if (gsize > INT_MAX - n)
186 void set_script_reduction(int n)
188 script_size_reduction = n;
191 const char *get_gfont()
193 return gfont ? gfont : "I";
196 const char *get_grfont()
198 return grfont ? grfont : "R";
201 const char *get_gbfont()
203 return gbfont ? gbfont : "B";
206 void set_gfont(const char *s)
212 void set_grfont(const char *s)
218 void set_gbfont(const char *s)
224 // this must be precisely 2 characters in length
225 #define COMPATIBLE_REG "0C"
229 printf(".nr " COMPATIBLE_REG " \\n(.C\n");
231 printf(".ds " LINE_STRING "\n");
236 printf("\\*(" LINE_STRING "\n");
239 void restore_compatibility()
241 printf(".cp \\n(" COMPATIBLE_REG "\n");
244 void do_text(const char *s)
247 printf(".as " LINE_STRING " \"%s\n", s);
251 void set_minimum_size(int n)
256 void set_script_size()
258 if (minimum_size < 0)
260 if (script_size_reduction >= 0)
261 printf(".ps \\n[.s]-%d>?%d\n", script_size_reduction, minimum_size);
263 printf(".ps (u;\\n[.ps]*7+5/10>?%d)\n", minimum_size);
266 int box::next_uid = 0;
268 box::box() : spacing_type(ORDINARY_TYPE), uid(next_uid++)
276 void box::top_level()
279 // putc('\n', stderr);
281 printf(".nr " SAVED_FONT_REG " \\n[.f]\n");
283 printf(".nr " SAVED_PREV_FONT_REG " \\n[.f]\n");
284 printf(".ft %s\n", get_gfont());
285 printf(".nr " SAVED_SIZE_REG " \\n[.ps]\n");
287 char buf[INT_DIGITS + 1];
288 sprintf(buf, "%d", gsize);
289 b = new size_box(strsave(buf), b);
291 current_roman_font = get_grfont();
292 // This catches tabs used within \Z (which aren't allowed).
294 int r = b->compute_metrics(DISPLAY_STYLE);
295 printf(".ft \\n[" SAVED_PREV_FONT_REG "]\n");
296 printf(".ft \\n[" SAVED_FONT_REG "]\n");
297 printf(".nr " MARK_OR_LINEUP_FLAG_REG " %d\n", r);
298 if (r == FOUND_MARK) {
299 printf(".nr " SAVED_MARK_REG " \\n[" MARK_REG "]\n");
300 printf(".nr " MARK_WIDTH_REG " 0\\n[" WIDTH_FORMAT "]\n", b->uid);
302 else if (r == FOUND_LINEUP)
303 printf(".if r" SAVED_MARK_REG " .as1 " LINE_STRING " \\h'\\n["
304 SAVED_MARK_REG "]u-\\n[" MARK_REG "]u'\n");
306 assert(r == FOUND_NOTHING);
307 // The problem here is that the argument to \f is read in copy mode,
308 // so we cannot use \E there; so we hide it in a string instead.
309 // Another problem is that if we use \R directly, then the space will
310 // prevent it working in a macro argument.
311 printf(".ds " SAVE_FONT_STRING " "
312 "\\R'" SAVED_INLINE_FONT_REG " \\\\n[.f]'"
314 "\\R'" SAVED_INLINE_PREV_FONT_REG " \\\\n[.f]'"
315 "\\R'" SAVED_INLINE_SIZE_REG " \\\\n[.ps]'"
317 "\\R'" SAVED_INLINE_PREV_SIZE_REG " \\\\n[.ps]'"
319 ".ds " RESTORE_FONT_STRING " "
320 "\\f[\\\\n[" SAVED_INLINE_PREV_FONT_REG "]]"
321 "\\f[\\\\n[" SAVED_INLINE_FONT_REG "]]"
322 "\\s'\\\\n[" SAVED_INLINE_PREV_SIZE_REG "]u'"
323 "\\s'\\\\n[" SAVED_INLINE_SIZE_REG "]u'"
325 printf(".as1 " LINE_STRING " \\&\\E*[" SAVE_FONT_STRING "]");
326 printf("\\f[%s]", get_gfont());
327 printf("\\s'\\En[" SAVED_SIZE_REG "]u'");
328 current_roman_font = get_grfont();
330 printf("\\E*[" RESTORE_FONT_STRING "]\n");
331 if (r == FOUND_LINEUP)
332 printf(".if r" SAVED_MARK_REG " .as1 " LINE_STRING " \\h'\\n["
333 MARK_WIDTH_REG "]u-\\n[" SAVED_MARK_REG "]u-(\\n["
334 WIDTH_FORMAT "]u-\\n[" MARK_REG "]u)'\n",
338 printf(".ne \\n[" HEIGHT_FORMAT "]u-%dM>?0+(\\n["
339 DEPTH_FORMAT "]u-%dM>?0)\n",
340 b->uid, body_height, b->uid, body_depth);
345 // gpic defines this register so as to make geqn not produce `\x's
346 #define EQN_NO_EXTRA_SPACE_REG "0x"
348 void box::extra_space()
350 printf(".if !r" EQN_NO_EXTRA_SPACE_REG " "
351 ".nr " EQN_NO_EXTRA_SPACE_REG " 0\n");
352 if (positive_space >= 0 || negative_space >= 0) {
353 if (positive_space > 0)
354 printf(".if !\\n[" EQN_NO_EXTRA_SPACE_REG "] "
355 ".as1 " LINE_STRING " \\x'-%dM'\n", positive_space);
356 if (negative_space > 0)
357 printf(".if !\\n[" EQN_NO_EXTRA_SPACE_REG "] "
358 ".as1 " LINE_STRING " \\x'%dM'\n", negative_space);
359 positive_space = negative_space = -1;
362 printf(".if !\\n[" EQN_NO_EXTRA_SPACE_REG "] "
363 ".if \\n[" HEIGHT_FORMAT "]>%dM .as1 " LINE_STRING
364 " \\x'-(\\n[" HEIGHT_FORMAT
366 uid, body_height, uid, body_height);
367 printf(".if !\\n[" EQN_NO_EXTRA_SPACE_REG "] "
368 ".if \\n[" DEPTH_FORMAT "]>%dM .as1 " LINE_STRING
369 " \\x'\\n[" DEPTH_FORMAT
371 uid, body_depth, uid, body_depth);
375 int box::compute_metrics(int)
377 printf(".nr " WIDTH_FORMAT " 0\n", uid);
378 printf(".nr " HEIGHT_FORMAT " 0\n", uid);
379 printf(".nr " DEPTH_FORMAT " 0\n", uid);
380 return FOUND_NOTHING;
383 void box::compute_subscript_kern()
385 printf(".nr " SUB_KERN_FORMAT " 0\n", uid);
388 void box::compute_skew()
390 printf(".nr " SKEW_FORMAT " 0\n", uid);
397 void box::check_tabs(int)
406 int box::left_is_italic()
411 int box::right_is_italic()
416 void box::hint(unsigned)
420 void box::handle_char_type(int, int)
425 box_list::box_list(box *pp)
428 for (int i = 0; i < 10; i++)
435 void box_list::append(box *pp)
437 if (len + 1 > maxlen) {
440 p = new box*[maxlen];
441 memcpy(p, oldp, sizeof(box*)*len);
447 box_list::~box_list()
449 for (int i = 0; i < len; i++)
454 void box_list::list_check_tabs(int level)
456 for (int i = 0; i < len; i++)
457 p[i]->check_tabs(level);
461 pointer_box::pointer_box(box *pp) : p(pp)
463 spacing_type = p->spacing_type;
466 pointer_box::~pointer_box()
471 int pointer_box::compute_metrics(int style)
473 int r = p->compute_metrics(style);
474 printf(".nr " WIDTH_FORMAT " 0\\n[" WIDTH_FORMAT "]\n", uid, p->uid);
475 printf(".nr " HEIGHT_FORMAT " \\n[" HEIGHT_FORMAT "]\n", uid, p->uid);
476 printf(".nr " DEPTH_FORMAT " \\n[" DEPTH_FORMAT "]\n", uid, p->uid);
480 void pointer_box::compute_subscript_kern()
482 p->compute_subscript_kern();
483 printf(".nr " SUB_KERN_FORMAT " \\n[" SUB_KERN_FORMAT "]\n", uid, p->uid);
486 void pointer_box::compute_skew()
489 printf(".nr " SKEW_FORMAT " 0\\n[" SKEW_FORMAT "]\n",
493 void pointer_box::check_tabs(int level)
495 p->check_tabs(level);
498 int simple_box::compute_metrics(int)
500 printf(".nr " WIDTH_FORMAT " 0\\w" DELIMITER_CHAR, uid);
502 printf(DELIMITER_CHAR "\n");
503 printf(".nr " HEIGHT_FORMAT " 0>?\\n[rst]\n", uid);
504 printf(".nr " DEPTH_FORMAT " 0-\\n[rsb]>?0\n", uid);
505 printf(".nr " SUB_KERN_FORMAT " 0-\\n[ssc]>?0\n", uid);
506 printf(".nr " SKEW_FORMAT " 0\\n[skw]\n", uid);
507 return FOUND_NOTHING;
510 void simple_box::compute_subscript_kern()
512 // do nothing, we already computed it in do_metrics
515 void simple_box::compute_skew()
517 // do nothing, we already computed it in do_metrics
525 int simple_box::is_simple()
530 quoted_text_box::quoted_text_box(char *s) : text(s)
534 quoted_text_box::~quoted_text_box()
539 void quoted_text_box::output()
545 tab_box::tab_box() : disabled(0)
549 // We treat a tab_box as having width 0 for width computations.
551 void tab_box::output()
557 void tab_box::check_tabs(int level)
560 error("tabs allowed only at outermost level");
565 space_box::space_box()
567 spacing_type = SUPPRESS_TYPE;
570 void space_box::output()
572 printf("\\h'%dM'", thick_space);
575 half_space_box::half_space_box()
577 spacing_type = SUPPRESS_TYPE;
580 void half_space_box::output()
582 printf("\\h'%dM'", thin_space);
585 void box_list::list_debug_print(const char *sep)
588 for (int i = 1; i < len; i++) {
589 fprintf(stderr, "%s", sep);
594 void quoted_text_box::debug_print()
596 fprintf(stderr, "\"%s\"", (text ? text : ""));
599 void half_space_box::debug_print()
601 fprintf(stderr, "^");
604 void space_box::debug_print()
606 fprintf(stderr, "~");
609 void tab_box::debug_print()
611 fprintf(stderr, "<tab>");