2 /* Copyright (C) 1989, 1990, 1991, 1992, 2002, 2004, 2007, 2009
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 3 of the License, or
11 (at your option) any later version.
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
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 const char *current_roman_font;
31 int script_size_reduction = -1; // negative means reduce by a percentage
33 int positive_space = -1;
34 int negative_space = -1;
43 int accent_width = 31;
44 int delimiter_factor = 900;
45 int delimiter_shortfall = 50;
47 int null_delimiter_space = 12;
50 int medium_space = 22;
55 // we don't use num3, because we don't have \atop
58 int axis_height = 26; // in 100ths of an em
62 int default_rule_thickness = 4;
68 int big_op_spacing1 = 11;
69 int big_op_spacing2 = 17;
70 int big_op_spacing3 = 20;
71 int big_op_spacing4 = 60;
72 int big_op_spacing5 = 10;
74 // These are for piles and matrices.
76 int baseline_sep = 140; // = num1 + denom1
77 int shift_down = 26; // = axis_height
78 int column_sep = 100; // = em space
79 int matrix_side_sep = 17; // = thin space
81 int nroff = 0; // should we grok ndefine or tdefine?
87 { "fat_offset", &fat_offset },
88 { "over_hang", &over_hang },
89 { "accent_width", &accent_width },
90 { "delimiter_factor", &delimiter_factor },
91 { "delimiter_shortfall", &delimiter_shortfall },
92 { "null_delimiter_space", &null_delimiter_space },
93 { "script_space", &script_space },
94 { "thin_space", &thin_space },
95 { "medium_space", &medium_space },
96 { "thick_space", &thick_space },
99 { "denom1", &denom1 },
100 { "denom2", &denom2 },
101 { "axis_height", &axis_height },
105 { "default_rule_thickness", &default_rule_thickness },
108 { "sup_drop", &sup_drop },
109 { "sub_drop", &sub_drop },
110 { "x_height", &x_height },
111 { "big_op_spacing1", &big_op_spacing1 },
112 { "big_op_spacing2", &big_op_spacing2 },
113 { "big_op_spacing3", &big_op_spacing3 },
114 { "big_op_spacing4", &big_op_spacing4 },
115 { "big_op_spacing5", &big_op_spacing5 },
116 { "minimum_size", &minimum_size },
117 { "baseline_sep", &baseline_sep },
118 { "shift_down", &shift_down },
119 { "column_sep", &column_sep },
120 { "matrix_side_sep", &matrix_side_sep },
121 { "draw_lines", &draw_flag },
122 { "body_height", &body_height },
123 { "body_depth", &body_depth },
128 void set_param(const char *name, int value)
130 for (int i = 0; param_table[i].name != 0; i++)
131 if (strcmp(param_table[i].name, name) == 0) {
132 *param_table[i].ptr = value;
135 error("unrecognised parameter `%1'", name);
138 int script_style(int style)
140 return style > SCRIPT_STYLE ? style - 2 : style;
143 int cramped_style(int style)
145 return (style & 1) ? style - 1 : style;
148 void set_space(int n)
156 // Return 0 if the specified size is bad.
157 // The caller is responsible for giving the error message.
159 int set_gsize(const char *s)
161 const char *p = (*s == '+' || *s == '-') ? s + 1 : s;
163 long n = strtol(p, &end, 10);
164 if (n <= 0 || *end != '\0' || n > INT_MAX)
170 if (gsize > INT_MAX - n)
185 void set_script_reduction(int n)
187 script_size_reduction = n;
190 const char *get_gfont()
192 return gfont ? gfont : "I";
195 const char *get_grfont()
197 return grfont ? grfont : "R";
200 const char *get_gbfont()
202 return gbfont ? gbfont : "B";
205 void set_gfont(const char *s)
211 void set_grfont(const char *s)
217 void set_gbfont(const char *s)
223 // this must be precisely 2 characters in length
224 #define COMPATIBLE_REG "0C"
228 if (output_format == troff) {
229 printf(".nr " COMPATIBLE_REG " \\n(.C\n");
231 printf(".ds " LINE_STRING "\n");
237 if (output_format == troff)
238 printf("\\*(" LINE_STRING "\n");
239 else if (output_format == mathml && !xhtml)
243 void restore_compatibility()
245 if (output_format == troff)
246 printf(".cp \\n(" COMPATIBLE_REG "\n");
249 void do_text(const char *s)
251 if (output_format == troff) {
253 printf(".as " LINE_STRING " \"%s\n", s);
256 else if (output_format == mathml) {
258 if (xhtml && strlen(s) > 0)
263 void set_minimum_size(int n)
268 void set_script_size()
270 if (minimum_size < 0)
272 if (script_size_reduction >= 0)
273 printf(".ps \\n[.s]-%d>?%d\n", script_size_reduction, minimum_size);
275 printf(".ps (u;\\n[.ps]*7+5/10>?%d)\n", minimum_size);
278 int box::next_uid = 0;
280 box::box() : spacing_type(ORDINARY_TYPE), uid(next_uid++)
288 void box::top_level()
291 if (output_format == troff) {
293 // putc('\n', stderr);
294 printf(".nr " SAVED_FONT_REG " \\n[.f]\n");
296 printf(".nr " SAVED_PREV_FONT_REG " \\n[.f]\n");
297 printf(".ft %s\n", get_gfont());
298 printf(".nr " SAVED_SIZE_REG " \\n[.ps]\n");
300 char buf[INT_DIGITS + 1];
301 sprintf(buf, "%d", gsize);
302 b = new size_box(strsave(buf), b);
304 current_roman_font = get_grfont();
305 // This catches tabs used within \Z (which aren't allowed).
307 int r = b->compute_metrics(DISPLAY_STYLE);
308 printf(".ft \\n[" SAVED_PREV_FONT_REG "]\n");
309 printf(".ft \\n[" SAVED_FONT_REG "]\n");
310 printf(".nr " MARK_OR_LINEUP_FLAG_REG " %d\n", r);
311 if (r == FOUND_MARK) {
312 printf(".nr " SAVED_MARK_REG " \\n[" MARK_REG "]\n");
313 printf(".nr " MARK_WIDTH_REG " 0\\n[" WIDTH_FORMAT "]\n", b->uid);
315 else if (r == FOUND_LINEUP)
316 printf(".if r" SAVED_MARK_REG " .as1 " LINE_STRING " \\h'\\n["
317 SAVED_MARK_REG "]u-\\n[" MARK_REG "]u'\n");
319 assert(r == FOUND_NOTHING);
320 // If we use \R directly, the space will prevent it working in a
321 // macro argument; so we hide it in a string instead.
322 printf(".ds " SAVE_FONT_STRING " "
323 "\\R'" SAVED_INLINE_FONT_REG " \\En[.f]'"
325 "\\R'" SAVED_INLINE_PREV_FONT_REG " \\En[.f]'"
326 "\\R'" SAVED_INLINE_SIZE_REG " \\En[.ps]'"
328 "\\R'" SAVED_INLINE_PREV_SIZE_REG " \\En[.ps]'"
330 ".ds " RESTORE_FONT_STRING " "
331 "\\f[\\En[" SAVED_INLINE_PREV_FONT_REG "]]"
332 "\\f[\\En[" SAVED_INLINE_FONT_REG "]]"
333 "\\s'\\En[" SAVED_INLINE_PREV_SIZE_REG "]u'"
334 "\\s'\\En[" SAVED_INLINE_SIZE_REG "]u'"
336 printf(".as1 " LINE_STRING " \\&\\E*[" SAVE_FONT_STRING "]");
337 printf("\\f[%s]", get_gfont());
338 printf("\\s'\\En[" SAVED_SIZE_REG "]u'");
339 current_roman_font = get_grfont();
341 printf("\\E*[" RESTORE_FONT_STRING "]\n");
342 if (r == FOUND_LINEUP)
343 printf(".if r" SAVED_MARK_REG " .as1 " LINE_STRING " \\h'\\n["
344 MARK_WIDTH_REG "]u-\\n[" SAVED_MARK_REG "]u-(\\n["
345 WIDTH_FORMAT "]u-\\n[" MARK_REG "]u)'\n",
349 printf(".ne \\n[" HEIGHT_FORMAT "]u-%dM>?0+(\\n["
350 DEPTH_FORMAT "]u-%dM>?0)\n",
351 b->uid, body_height, b->uid, body_depth);
353 else if (output_format == mathml) {
364 // gpic defines this register so as to make geqn not produce `\x's
365 #define EQN_NO_EXTRA_SPACE_REG "0x"
367 void box::extra_space()
369 printf(".if !r" EQN_NO_EXTRA_SPACE_REG " "
370 ".nr " EQN_NO_EXTRA_SPACE_REG " 0\n");
371 if (positive_space >= 0 || negative_space >= 0) {
372 if (positive_space > 0)
373 printf(".if !\\n[" EQN_NO_EXTRA_SPACE_REG "] "
374 ".as1 " LINE_STRING " \\x'-%dM'\n", positive_space);
375 if (negative_space > 0)
376 printf(".if !\\n[" EQN_NO_EXTRA_SPACE_REG "] "
377 ".as1 " LINE_STRING " \\x'%dM'\n", negative_space);
378 positive_space = negative_space = -1;
381 printf(".if !\\n[" EQN_NO_EXTRA_SPACE_REG "] "
382 ".if \\n[" HEIGHT_FORMAT "]>%dM .as1 " LINE_STRING
383 " \\x'-(\\n[" HEIGHT_FORMAT
385 uid, body_height, uid, body_height);
386 printf(".if !\\n[" EQN_NO_EXTRA_SPACE_REG "] "
387 ".if \\n[" DEPTH_FORMAT "]>%dM .as1 " LINE_STRING
388 " \\x'\\n[" DEPTH_FORMAT
390 uid, body_depth, uid, body_depth);
394 int box::compute_metrics(int)
396 printf(".nr " WIDTH_FORMAT " 0\n", uid);
397 printf(".nr " HEIGHT_FORMAT " 0\n", uid);
398 printf(".nr " DEPTH_FORMAT " 0\n", uid);
399 return FOUND_NOTHING;
402 void box::compute_subscript_kern()
404 printf(".nr " SUB_KERN_FORMAT " 0\n", uid);
407 void box::compute_skew()
409 printf(".nr " SKEW_FORMAT " 0\n", uid);
416 void box::check_tabs(int)
425 int box::left_is_italic()
430 int box::right_is_italic()
435 void box::hint(unsigned)
439 void box::handle_char_type(int, int)
444 box_list::box_list(box *pp)
447 for (int i = 0; i < 10; i++)
454 void box_list::append(box *pp)
456 if (len + 1 > maxlen) {
459 p = new box*[maxlen];
460 memcpy(p, oldp, sizeof(box*)*len);
466 box_list::~box_list()
468 for (int i = 0; i < len; i++)
473 void box_list::list_check_tabs(int level)
475 for (int i = 0; i < len; i++)
476 p[i]->check_tabs(level);
480 pointer_box::pointer_box(box *pp) : p(pp)
482 spacing_type = p->spacing_type;
485 pointer_box::~pointer_box()
490 int pointer_box::compute_metrics(int style)
492 int r = p->compute_metrics(style);
493 printf(".nr " WIDTH_FORMAT " 0\\n[" WIDTH_FORMAT "]\n", uid, p->uid);
494 printf(".nr " HEIGHT_FORMAT " \\n[" HEIGHT_FORMAT "]\n", uid, p->uid);
495 printf(".nr " DEPTH_FORMAT " \\n[" DEPTH_FORMAT "]\n", uid, p->uid);
499 void pointer_box::compute_subscript_kern()
501 p->compute_subscript_kern();
502 printf(".nr " SUB_KERN_FORMAT " \\n[" SUB_KERN_FORMAT "]\n", uid, p->uid);
505 void pointer_box::compute_skew()
508 printf(".nr " SKEW_FORMAT " 0\\n[" SKEW_FORMAT "]\n",
512 void pointer_box::check_tabs(int level)
514 p->check_tabs(level);
517 int simple_box::compute_metrics(int)
519 printf(".nr " WIDTH_FORMAT " 0\\w" DELIMITER_CHAR, uid);
521 printf(DELIMITER_CHAR "\n");
522 printf(".nr " HEIGHT_FORMAT " 0>?\\n[rst]\n", uid);
523 printf(".nr " DEPTH_FORMAT " 0-\\n[rsb]>?0\n", uid);
524 printf(".nr " SUB_KERN_FORMAT " 0-\\n[ssc]>?0\n", uid);
525 printf(".nr " SKEW_FORMAT " 0\\n[skw]\n", uid);
526 return FOUND_NOTHING;
529 void simple_box::compute_subscript_kern()
531 // do nothing, we already computed it in do_metrics
534 void simple_box::compute_skew()
536 // do nothing, we already computed it in do_metrics
544 int simple_box::is_simple()
549 quoted_text_box::quoted_text_box(char *s) : text(s)
553 quoted_text_box::~quoted_text_box()
558 void quoted_text_box::output()
561 if (output_format == troff)
563 else if (output_format == mathml) {
564 fputs("<mtext>", stdout);
566 fputs("</mtext>", stdout);
571 tab_box::tab_box() : disabled(0)
575 // We treat a tab_box as having width 0 for width computations.
577 void tab_box::output()
583 void tab_box::check_tabs(int level)
586 error("tabs allowed only at outermost level");
591 space_box::space_box()
593 spacing_type = SUPPRESS_TYPE;
596 void space_box::output()
598 if (output_format == troff)
599 printf("\\h'%dM'", thick_space);
600 else if (output_format == mathml)
601 //    doesn't display right under Firefox 1.5.
602 printf("<mtext> </mtext>");
605 half_space_box::half_space_box()
607 spacing_type = SUPPRESS_TYPE;
610 void half_space_box::output()
612 if (output_format == troff)
613 printf("\\h'%dM'", thin_space);
614 else if (output_format == mathml)
615 printf("<mtext> </mtext>");
618 void box_list::list_debug_print(const char *sep)
621 for (int i = 1; i < len; i++) {
622 fprintf(stderr, "%s", sep);
627 void quoted_text_box::debug_print()
629 fprintf(stderr, "\"%s\"", (text ? text : ""));
632 void half_space_box::debug_print()
634 fprintf(stderr, "^");
637 void space_box::debug_print()
639 fprintf(stderr, "~");
642 void tab_box::debug_print()
644 fprintf(stderr, "<tab>");