* All affected files: Update postal address of FSF.
[s-roff.git] / src / preproc / eqn / other.cpp
blob9f360df679126bd8d6b46577c9e8603fa10c2994
1 // -*- C++ -*-
2 /* Copyright (C) 1989, 1990, 1991, 1992, 2002 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
10 version.
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
15 for more details.
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, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
21 #include "eqn.h"
22 #include "pbox.h"
24 class accent_box : public pointer_box {
25 private:
26 box *ab;
27 public:
28 accent_box(box *, box *);
29 ~accent_box();
30 int compute_metrics(int);
31 void output();
32 void debug_print();
33 void check_tabs(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) : pointer_box(pp), ab(qq)
45 accent_box::~accent_box()
47 delete ab;
50 #if 0
51 int accent_box::compute_metrics(int style)
53 int r = p->compute_metrics(style);
54 p->compute_skew();
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",
62 uid, ab->uid, uid);
63 return r;
66 void accent_box::output()
68 printf("\\h'\\n[" WIDTH_FORMAT "]u-\\n[" WIDTH_FORMAT "]u/2u+\\n["
69 SKEW_FORMAT "]u'",
70 p->uid, ab->uid, p->uid);
71 printf("\\v'-\\n[" SUP_RAISE_FORMAT "]u'", uid);
72 ab->output();
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["
76 SKEW_FORMAT "]u)'",
77 p->uid, ab->uid, p->uid);
78 p->output();
80 #endif
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);
89 p->compute_skew();
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",
103 uid, ab->uid, uid);
104 if (r)
105 printf(".nr " MARK_REG " +\\n[" LEFT_WIDTH_FORMAT "]"
106 "-(\\n[" WIDTH_FORMAT "]/2)'\n",
107 uid, p->uid);
108 return r;
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);
118 ab->output();
119 printf(DELIMITER_CHAR);
120 printf("\\Z" DELIMITER_CHAR);
121 printf("\\h'\\n[" LEFT_WIDTH_FORMAT "]u-(\\n[" WIDTH_FORMAT "]u/2u)'",
122 uid, p->uid);
123 p->output();
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, "{ ");
137 p->debug_print();
138 fprintf(stderr, " } accent { ");
139 ab->debug_print();
140 fprintf(stderr, " }");
143 class overline_char_box : public simple_box {
144 public:
145 overline_char_box();
146 void output();
147 void debug_print();
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'"),
158 accent_width);
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 {
168 public:
169 overline_box(box *);
170 int compute_metrics(int);
171 void output();
172 void debug_print();
175 box *make_overline_box(box *p)
177 if (p->is_char())
178 return new accent_box(p, new overline_char_box);
179 else
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));
190 // 9
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);
195 return r;
198 void overline_box::output()
200 // 9
201 printf("\\Z" DELIMITER_CHAR);
202 printf("\\v'-\\n[" HEIGHT_FORMAT "]u-(%dM/2u)'",
203 p->uid, 7*default_rule_thickness);
204 if (draw_flag)
205 printf("\\D'l\\n[" WIDTH_FORMAT "]u 0'", p->uid);
206 else
207 printf("\\l'\\n[" WIDTH_FORMAT "]u\\&\\(ru'", p->uid);
208 printf(DELIMITER_CHAR);
209 p->output();
212 void overline_box::debug_print()
214 fprintf(stderr, "{ ");
215 p->debug_print();
216 fprintf(stderr, " } bar");
219 class uaccent_box : public pointer_box {
220 box *ab;
221 public:
222 uaccent_box(box *, box *);
223 ~uaccent_box();
224 int compute_metrics(int);
225 void output();
226 void compute_subscript_kern();
227 void check_tabs(int);
228 void debug_print();
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()
243 delete ab;
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);
261 if (r)
262 printf(".nr " MARK_REG " +\\n[" LEFT_WIDTH_FORMAT "]"
263 "-(\\n[" WIDTH_FORMAT "]/2)'\n",
264 uid, p->uid);
265 return r;
268 void uaccent_box::output()
270 printf("\\Z" DELIMITER_CHAR);
271 printf("\\h'\\n[" LEFT_WIDTH_FORMAT "]u-(\\n[" WIDTH_FORMAT "]u/2u)'",
272 uid, ab->uid);
273 printf("\\v'\\n[" DEPTH_FORMAT "]u'", p->uid);
274 ab->output();
275 printf(DELIMITER_CHAR);
276 printf("\\Z" DELIMITER_CHAR);
277 printf("\\h'\\n[" LEFT_WIDTH_FORMAT "]u-(\\n[" WIDTH_FORMAT "]u/2u)'",
278 uid, p->uid);
279 p->output();
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, "{ ");
298 p->debug_print();
299 fprintf(stderr, " } uaccent { ");
300 ab->debug_print();
301 fprintf(stderr, " }");
304 class underline_char_box : public simple_box {
305 public:
306 underline_char_box();
307 void output();
308 void debug_print();
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'"),
319 accent_width);
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 {
330 public:
331 underline_box(box *);
332 int compute_metrics(int);
333 void output();
334 void compute_subscript_kern();
335 void debug_print();
338 box *make_underline_box(box *p)
340 if (p->is_char())
341 return new uaccent_box(p, new underline_char_box);
342 else
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);
353 // 10
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);
358 return r;
361 void underline_box::output()
363 // 10
364 printf("\\Z" DELIMITER_CHAR);
365 printf("\\v'\\n[" DEPTH_FORMAT "]u+(%dM/2u)'",
366 p->uid, 7*default_rule_thickness);
367 if (draw_flag)
368 printf("\\D'l\\n[" WIDTH_FORMAT "]u 0'", p->uid);
369 else
370 printf("\\l'\\n[" WIDTH_FORMAT "]u\\&\\(ru'", p->uid);
371 printf(DELIMITER_CHAR);
372 p->output();
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, "{ ");
385 p->debug_print();
386 fprintf(stderr, " } under");
389 size_box::size_box(char *s, box *pp) : pointer_box(pp), size(s)
393 int size_box::compute_metrics(int style)
395 printf(".nr " SIZE_FORMAT " \\n[.ps]\n", uid);
396 printf(".ps %s\n", size);
397 printf(".nr " SMALL_SIZE_FORMAT " \\n[.ps]\n", uid);
398 int r = p->compute_metrics(style);
399 printf(".ps \\n[" SIZE_FORMAT "]u\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);
403 return r;
406 void size_box::output()
408 printf("\\s[\\n[" SMALL_SIZE_FORMAT "]u]", uid);
409 p->output();
410 printf("\\s[\\n[" SIZE_FORMAT "]u]", uid);
413 size_box::~size_box()
415 a_delete size;
418 void size_box::debug_print()
420 fprintf(stderr, "size %s { ", size);
421 p->debug_print();
422 fprintf(stderr, " }");
426 font_box::font_box(char *s, box *pp) : pointer_box(pp), f(s)
430 font_box::~font_box()
432 a_delete f;
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);
447 return r;
450 void font_box::output()
452 printf("\\f[%s]", f);
453 const char *old_roman_font = current_roman_font;
454 current_roman_font = f;
455 p->output();
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);
463 p->debug_print();
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);
478 return r;
481 void fat_box::output()
483 p->output();
484 printf("\\h'-\\n[" WIDTH_FORMAT "]u'", p->uid);
485 printf("\\h'%dM'", fat_offset);
486 p->output();
490 void fat_box::debug_print()
492 fprintf(stderr, "fat { ");
493 p->debug_print();
494 fprintf(stderr, " }");
498 vmotion_box::vmotion_box(int i, box *pp) : pointer_box(pp), n(i)
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);
506 if (n > 0) {
507 printf(".nr " HEIGHT_FORMAT " %dM+\\n[" HEIGHT_FORMAT "]\n",
508 uid, n, p->uid);
509 printf(".nr " DEPTH_FORMAT " \\n[" DEPTH_FORMAT "]\n", uid, p->uid);
511 else {
512 printf(".nr " DEPTH_FORMAT " %dM+\\n[" DEPTH_FORMAT "]>?0\n",
513 uid, -n, p->uid);
514 printf(".nr " HEIGHT_FORMAT " \\n[" HEIGHT_FORMAT "]\n",
515 uid, p->uid);
517 return r;
520 void vmotion_box::output()
522 printf("\\v'%dM'", -n);
523 p->output();
524 printf("\\v'%dM'", n);
527 void vmotion_box::debug_print()
529 if (n >= 0)
530 fprintf(stderr, "up %d { ", n);
531 else
532 fprintf(stderr, "down %d { ", -n);
533 p->debug_print();
534 fprintf(stderr, " }");
537 hmotion_box::hmotion_box(int i, box *pp) : pointer_box(pp), n(i)
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",
545 uid, p->uid, 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);
548 if (r)
549 printf(".nr " MARK_REG " +%dM\n", n);
550 return r;
553 void hmotion_box::output()
555 printf("\\h'%dM'", n);
556 p->output();
559 void hmotion_box::debug_print()
561 if (n >= 0)
562 fprintf(stderr, "fwd %d { ", n);
563 else
564 fprintf(stderr, "back %d { ", -n);
565 p->debug_print();
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);
585 return r;
588 void vcenter_box::output()
590 printf("\\v'-\\n[" SUP_RAISE_FORMAT "]u'", uid);
591 p->output();
592 printf("\\v'\\n[" SUP_RAISE_FORMAT "]u'", uid);
595 void vcenter_box::debug_print()
597 fprintf(stderr, "vcenter { ");
598 p->debug_print();
599 fprintf(stderr, " }");