2 /* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
3 Written by James Clark (jjc@jclark.com)
5 This file is part of groff.
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 2, or (at your option) any later
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
17 You should have received a copy of the GNU General Public License along
18 with groff; see the file COPYING. If not, write to the Free Software
19 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 class accent_box : public pointer_box {
28 accent_box(box *, box *);
30 int compute_metrics(int);
36 box *make_accent_box(box *p, box *q)
38 return new accent_box(p, q);
41 accent_box::accent_box(box *pp, box *qq) : ab(qq), pointer_box(pp)
45 accent_box::~accent_box()
51 int accent_box::compute_metrics(int style)
53 int r = p->compute_metrics(style);
55 ab->compute_metrics(style);
56 printf(".nr " WIDTH_FORMAT " 0\\n[" WIDTH_FORMAT "]\n", uid, p->uid);
57 printf(".nr " DEPTH_FORMAT " \\n[" DEPTH_FORMAT "]\n", uid, p->uid);
58 printf(".nr " SUP_RAISE_FORMAT " \\n[" HEIGHT_FORMAT "]-%dM>?0\n",
59 uid, p->uid, x_height);
60 printf(".nr " HEIGHT_FORMAT " \\n[" HEIGHT_FORMAT "]+\\n["
61 SUP_RAISE_FORMAT "]\n",
66 void accent_box::output()
68 printf("\\h'\\n[" WIDTH_FORMAT "]u-\\n[" WIDTH_FORMAT "]u/2u+\\n["
70 p->uid, ab->uid, p->uid);
71 printf("\\v'-\\n[" SUP_RAISE_FORMAT "]u'", uid);
73 printf("\\h'-\\n[" WIDTH_FORMAT "]u'", ab->uid);
74 printf("\\v'\\n[" SUP_RAISE_FORMAT "]u'", uid);
75 printf("\\h'-(\\n[" WIDTH_FORMAT "]u-\\n[" WIDTH_FORMAT "]u/2u+\\n["
77 p->uid, ab->uid, p->uid);
82 /* This version copes with the possibility of an accent's being wider
83 than its accentee. LEFT_WIDTH_FORMAT gives the distance from the
84 left edge of the resulting box to the middle of the accentee's box.*/
86 int accent_box::compute_metrics(int style)
88 int r = p->compute_metrics(style);
90 ab->compute_metrics(style);
91 printf(".nr " LEFT_WIDTH_FORMAT " 0\\n[" WIDTH_FORMAT "]/2"
92 ">?(\\n[" WIDTH_FORMAT "]/2-\\n[" SKEW_FORMAT "])\n",
93 uid, p->uid, ab->uid, p->uid);
94 printf(".nr " WIDTH_FORMAT " 0\\n[" WIDTH_FORMAT "]/2"
95 ">?(\\n[" WIDTH_FORMAT "]/2+\\n[" SKEW_FORMAT "])"
96 "+\\n[" LEFT_WIDTH_FORMAT "]\n",
97 uid, p->uid, ab->uid, p->uid, uid);
98 printf(".nr " DEPTH_FORMAT " \\n[" DEPTH_FORMAT "]\n", uid, p->uid);
99 printf(".nr " SUP_RAISE_FORMAT " \\n[" HEIGHT_FORMAT "]-%dM>?0\n",
100 uid, p->uid, x_height);
101 printf(".nr " HEIGHT_FORMAT " \\n[" HEIGHT_FORMAT "]+\\n["
102 SUP_RAISE_FORMAT "]\n",
105 printf(".nr " MARK_REG " +\\n[" LEFT_WIDTH_FORMAT "]"
106 "-(\\n[" WIDTH_FORMAT "]/2)'\n",
111 void accent_box::output()
113 printf("\\Z" DELIMITER_CHAR);
114 printf("\\h'\\n[" LEFT_WIDTH_FORMAT "]u+\\n[" SKEW_FORMAT "]u"
115 "-(\\n[" WIDTH_FORMAT "]u/2u)'",
116 uid, p->uid, ab->uid);
117 printf("\\v'-\\n[" SUP_RAISE_FORMAT "]u'", uid);
119 printf(DELIMITER_CHAR);
120 printf("\\Z" DELIMITER_CHAR);
121 printf("\\h'\\n[" LEFT_WIDTH_FORMAT "]u-(\\n[" WIDTH_FORMAT "]u/2u)'",
124 printf(DELIMITER_CHAR);
125 printf("\\h'\\n[" WIDTH_FORMAT "]u'", uid);
128 void accent_box::check_tabs(int level)
130 ab->check_tabs(level + 1);
131 p->check_tabs(level + 1);
134 void accent_box::debug_print()
136 fprintf(stderr, "{ ");
138 fprintf(stderr, " } accent { ");
140 fprintf(stderr, " }");
143 class overline_char_box : public simple_box {
150 overline_char_box::overline_char_box()
154 void overline_char_box::output()
156 printf("\\v'-%dM/2u-%dM'", 7*default_rule_thickness, x_height);
157 printf((draw_flag ? "\\D'l%dM 0'" : "\\l'%dM\\&\\(ru'"),
159 printf("\\v'%dM/2u+%dM'", 7*default_rule_thickness, x_height);
162 void overline_char_box::debug_print()
164 fprintf(stderr, "<overline char>");
167 class overline_box : public pointer_box {
170 int compute_metrics(int);
175 box *make_overline_box(box *p)
178 return new accent_box(p, new overline_char_box);
180 return new overline_box(p);
183 overline_box::overline_box(box *pp) : pointer_box(pp)
187 int overline_box::compute_metrics(int style)
189 int r = p->compute_metrics(cramped_style(style));
191 printf(".nr " HEIGHT_FORMAT " \\n[" HEIGHT_FORMAT "]+%dM\n",
192 uid, p->uid, default_rule_thickness*5);
193 printf(".nr " WIDTH_FORMAT " 0\\n[" WIDTH_FORMAT "]\n", uid, p->uid);
194 printf(".nr " DEPTH_FORMAT " \\n[" DEPTH_FORMAT "]\n", uid, p->uid);
198 void overline_box::output()
201 printf("\\Z" DELIMITER_CHAR);
202 printf("\\v'-\\n[" HEIGHT_FORMAT "]u-(%dM/2u)'",
203 p->uid, 7*default_rule_thickness);
205 printf("\\D'l\\n[" WIDTH_FORMAT "]u 0'", p->uid);
207 printf("\\l'\\n[" WIDTH_FORMAT "]u\\&\\(ru'", p->uid);
208 printf(DELIMITER_CHAR);
212 void overline_box::debug_print()
214 fprintf(stderr, "{ ");
216 fprintf(stderr, " } bar");
219 class uaccent_box : public pointer_box {
222 uaccent_box(box *, box *);
224 int compute_metrics(int);
226 void compute_subscript_kern();
227 void check_tabs(int);
231 box *make_uaccent_box(box *p, box *q)
233 return new uaccent_box(p, q);
236 uaccent_box::uaccent_box(box *pp, box *qq)
237 : pointer_box(pp), ab(qq)
241 uaccent_box::~uaccent_box()
246 int uaccent_box::compute_metrics(int style)
248 int r = p->compute_metrics(style);
249 ab->compute_metrics(style);
250 printf(".nr " LEFT_WIDTH_FORMAT " 0\\n[" WIDTH_FORMAT "]/2"
251 ">?(\\n[" WIDTH_FORMAT "]/2)\n",
252 uid, p->uid, ab->uid);
253 printf(".nr " WIDTH_FORMAT " 0\\n[" WIDTH_FORMAT "]/2"
254 ">?(\\n[" WIDTH_FORMAT "]/2)"
255 "+\\n[" LEFT_WIDTH_FORMAT "]\n",
256 uid, p->uid, ab->uid, uid);
257 printf(".nr " HEIGHT_FORMAT " \\n[" HEIGHT_FORMAT "]\n", uid, p->uid);
258 printf(".nr " DEPTH_FORMAT " \\n[" DEPTH_FORMAT "]"
259 "+\\n[" DEPTH_FORMAT "]\n",
260 uid, p->uid, ab->uid);
262 printf(".nr " MARK_REG " +\\n[" LEFT_WIDTH_FORMAT "]"
263 "-(\\n[" WIDTH_FORMAT "]/2)'\n",
268 void uaccent_box::output()
270 printf("\\Z" DELIMITER_CHAR);
271 printf("\\h'\\n[" LEFT_WIDTH_FORMAT "]u-(\\n[" WIDTH_FORMAT "]u/2u)'",
273 printf("\\v'\\n[" DEPTH_FORMAT "]u'", p->uid);
275 printf(DELIMITER_CHAR);
276 printf("\\Z" DELIMITER_CHAR);
277 printf("\\h'\\n[" LEFT_WIDTH_FORMAT "]u-(\\n[" WIDTH_FORMAT "]u/2u)'",
280 printf(DELIMITER_CHAR);
281 printf("\\h'\\n[" WIDTH_FORMAT "]u'", uid);
284 void uaccent_box::check_tabs(int level)
286 ab->check_tabs(level + 1);
287 p->check_tabs(level + 1);
290 void uaccent_box::compute_subscript_kern()
292 box::compute_subscript_kern(); // want 0 subscript kern
295 void uaccent_box::debug_print()
297 fprintf(stderr, "{ ");
299 fprintf(stderr, " } uaccent { ");
301 fprintf(stderr, " }");
304 class underline_char_box : public simple_box {
306 underline_char_box();
311 underline_char_box::underline_char_box()
315 void underline_char_box::output()
317 printf("\\v'%dM/2u'", 7*default_rule_thickness);
318 printf((draw_flag ? "\\D'l%dM 0'" : "\\l'%dM\\&\\(ru'"),
320 printf("\\v'-%dM/2u'", 7*default_rule_thickness);
323 void underline_char_box::debug_print()
325 fprintf(stderr, "<underline char>");
329 class underline_box : public pointer_box {
331 underline_box(box *);
332 int compute_metrics(int);
334 void compute_subscript_kern();
338 box *make_underline_box(box *p)
341 return new uaccent_box(p, new underline_char_box);
343 return new underline_box(p);
346 underline_box::underline_box(box *pp) : pointer_box(pp)
350 int underline_box::compute_metrics(int style)
352 int r = p->compute_metrics(style);
354 printf(".nr " DEPTH_FORMAT " \\n[" DEPTH_FORMAT "]+%dM\n",
355 uid, p->uid, default_rule_thickness*5);
356 printf(".nr " WIDTH_FORMAT " 0\\n[" WIDTH_FORMAT "]\n", uid, p->uid);
357 printf(".nr " HEIGHT_FORMAT " \\n[" HEIGHT_FORMAT "]\n", uid, p->uid);
361 void underline_box::output()
364 printf("\\Z" DELIMITER_CHAR);
365 printf("\\v'\\n[" DEPTH_FORMAT "]u+(%dM/2u)'",
366 p->uid, 7*default_rule_thickness);
368 printf("\\D'l\\n[" WIDTH_FORMAT "]u 0'", p->uid);
370 printf("\\l'\\n[" WIDTH_FORMAT "]u\\&\\(ru'", p->uid);
371 printf(DELIMITER_CHAR);
375 // we want an underline box to have 0 subscript kern
377 void underline_box::compute_subscript_kern()
379 box::compute_subscript_kern();
382 void underline_box::debug_print()
384 fprintf(stderr, "{ ");
386 fprintf(stderr, " } under");
389 size_box::size_box(char *s, box *pp) : size(s), pointer_box(pp)
393 int size_box::compute_metrics(int style)
395 printf(".nr " SIZE_FORMAT " \\n[.s]\n", uid);
396 printf(".ps %s\n", size);
397 printf(".nr " SMALL_SIZE_FORMAT " \\n[.s]\n", uid);
398 int r = p->compute_metrics(style);
399 printf(".ps \\n[" SIZE_FORMAT "]\n", uid);
400 printf(".nr " WIDTH_FORMAT " 0\\n[" WIDTH_FORMAT "]\n", uid, p->uid);
401 printf(".nr " HEIGHT_FORMAT " \\n[" HEIGHT_FORMAT "]\n", uid, p->uid);
402 printf(".nr " DEPTH_FORMAT " \\n[" DEPTH_FORMAT "]\n", uid, p->uid);
406 void size_box::output()
408 printf("\\s[\\n[" SMALL_SIZE_FORMAT "]]", uid);
410 printf("\\s[\\n[" SIZE_FORMAT "]]", uid);
413 size_box::~size_box()
418 void size_box::debug_print()
420 fprintf(stderr, "size %s { ", size);
422 fprintf(stderr, " }");
426 font_box::font_box(char *s, box *pp) : pointer_box(pp), f(s)
430 font_box::~font_box()
435 int font_box::compute_metrics(int style)
437 const char *old_roman_font = current_roman_font;
438 current_roman_font = f;
439 printf(".nr " FONT_FORMAT " \\n[.f]\n", uid);
440 printf(".ft %s\n", f);
441 int r = p->compute_metrics(style);
442 current_roman_font = old_roman_font;
443 printf(".ft \\n[" FONT_FORMAT "]\n", uid);
444 printf(".nr " WIDTH_FORMAT " 0\\n[" WIDTH_FORMAT "]\n", uid, p->uid);
445 printf(".nr " HEIGHT_FORMAT " \\n[" HEIGHT_FORMAT "]\n", uid, p->uid);
446 printf(".nr " DEPTH_FORMAT " \\n[" DEPTH_FORMAT "]\n", uid, p->uid);
450 void font_box::output()
452 printf("\\f[%s]", f);
453 const char *old_roman_font = current_roman_font;
454 current_roman_font = f;
456 current_roman_font = old_roman_font;
457 printf("\\f[\\n[" FONT_FORMAT "]]", uid);
460 void font_box::debug_print()
462 fprintf(stderr, "font %s { ", f);
464 fprintf(stderr, " }");
467 fat_box::fat_box(box *pp) : pointer_box(pp)
471 int fat_box::compute_metrics(int style)
473 int r = p->compute_metrics(style);
474 printf(".nr " WIDTH_FORMAT " 0\\n[" WIDTH_FORMAT "]+%dM\n",
475 uid, p->uid, fat_offset);
476 printf(".nr " HEIGHT_FORMAT " \\n[" HEIGHT_FORMAT "]\n", uid, p->uid);
477 printf(".nr " DEPTH_FORMAT " \\n[" DEPTH_FORMAT "]\n", uid, p->uid);
481 void fat_box::output()
484 printf("\\h'-\\n[" WIDTH_FORMAT "]u'", p->uid);
485 printf("\\h'%dM'", fat_offset);
490 void fat_box::debug_print()
492 fprintf(stderr, "fat { ");
494 fprintf(stderr, " }");
498 vmotion_box::vmotion_box(int i, box *pp) : n(i), pointer_box(pp)
502 int vmotion_box::compute_metrics(int style)
504 int r = p->compute_metrics(style);
505 printf(".nr " WIDTH_FORMAT " 0\\n[" WIDTH_FORMAT "]\n", uid, p->uid);
507 printf(".nr " HEIGHT_FORMAT " %dM+\\n[" HEIGHT_FORMAT "]\n",
509 printf(".nr " DEPTH_FORMAT " \\n[" DEPTH_FORMAT "]\n", uid, p->uid);
512 printf(".nr " DEPTH_FORMAT " %dM+\\n[" DEPTH_FORMAT "]>?0\n",
514 printf(".nr " HEIGHT_FORMAT " \\n[" HEIGHT_FORMAT "]\n",
520 void vmotion_box::output()
522 printf("\\v'%dM'", -n);
524 printf("\\v'%dM'", n);
527 void vmotion_box::debug_print()
530 fprintf(stderr, "up %d { ", n);
532 fprintf(stderr, "down %d { ", -n);
534 fprintf(stderr, " }");
537 hmotion_box::hmotion_box(int i, box *pp) : n(i), pointer_box(pp)
541 int hmotion_box::compute_metrics(int style)
543 int r = p->compute_metrics(style);
544 printf(".nr " WIDTH_FORMAT " 0\\n[" WIDTH_FORMAT "]+%dM\n",
546 printf(".nr " HEIGHT_FORMAT " \\n[" HEIGHT_FORMAT "]\n", uid, p->uid);
547 printf(".nr " DEPTH_FORMAT " \\n[" DEPTH_FORMAT "]\n", uid, p->uid);
549 printf(".nr " MARK_REG " +%dM\n", n);
553 void hmotion_box::output()
555 printf("\\h'%dM'", n);
559 void hmotion_box::debug_print()
562 fprintf(stderr, "fwd %d { ", n);
564 fprintf(stderr, "back %d { ", -n);
566 fprintf(stderr, " }");
569 vcenter_box::vcenter_box(box *pp) : pointer_box(pp)
573 int vcenter_box::compute_metrics(int style)
575 int r = p->compute_metrics(style);
576 printf(".nr " WIDTH_FORMAT " 0\\n[" WIDTH_FORMAT "]\n", uid, p->uid);
577 printf(".nr " SUP_RAISE_FORMAT " \\n[" DEPTH_FORMAT "]-\\n["
578 HEIGHT_FORMAT "]/2+%dM\n",
579 uid, p->uid, p->uid, axis_height);
580 printf(".nr " HEIGHT_FORMAT " \\n[" HEIGHT_FORMAT "]+\\n["
581 SUP_RAISE_FORMAT "]>?0\n", uid, p->uid, uid);
582 printf(".nr " DEPTH_FORMAT " \\n[" DEPTH_FORMAT "]-\\n["
583 SUP_RAISE_FORMAT "]>?0\n", uid, p->uid, uid);
588 void vcenter_box::output()
590 printf("\\v'-\\n[" SUP_RAISE_FORMAT "]u'", uid);
592 printf("\\v'\\n[" SUP_RAISE_FORMAT "]u'", uid);
595 void vcenter_box::debug_print()
597 fprintf(stderr, "vcenter { ");
599 fprintf(stderr, " }");