2 /* Copyright (C) 1989, 1990, 1991, 1992, 2002, 2007
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 class accent_box
: public pointer_box
{
29 accent_box(box
*, box
*);
31 int compute_metrics(int);
37 box
*make_accent_box(box
*p
, box
*q
)
39 return new accent_box(p
, q
);
42 accent_box::accent_box(box
*pp
, box
*qq
) : pointer_box(pp
), ab(qq
)
46 accent_box::~accent_box()
52 int accent_box::compute_metrics(int style
)
54 int r
= p
->compute_metrics(style
);
56 ab
->compute_metrics(style
);
57 printf(".nr " WIDTH_FORMAT
" 0\\n[" WIDTH_FORMAT
"]\n", uid
, p
->uid
);
58 printf(".nr " DEPTH_FORMAT
" \\n[" DEPTH_FORMAT
"]\n", uid
, p
->uid
);
59 printf(".nr " SUP_RAISE_FORMAT
" \\n[" HEIGHT_FORMAT
"]-%dM>?0\n",
60 uid
, p
->uid
, x_height
);
61 printf(".nr " HEIGHT_FORMAT
" \\n[" HEIGHT_FORMAT
"]+\\n["
62 SUP_RAISE_FORMAT
"]\n",
67 void accent_box::output()
69 if (output_format
== troff
) {
70 printf("\\h'\\n[" WIDTH_FORMAT
"]u-\\n[" WIDTH_FORMAT
"]u/2u+\\n["
72 p
->uid
, ab
->uid
, p
->uid
);
73 printf("\\v'-\\n[" SUP_RAISE_FORMAT
"]u'", uid
);
75 printf("\\h'-\\n[" WIDTH_FORMAT
"]u'", ab
->uid
);
76 printf("\\v'\\n[" SUP_RAISE_FORMAT
"]u'", uid
);
77 printf("\\h'-(\\n[" WIDTH_FORMAT
"]u-\\n[" WIDTH_FORMAT
"]u/2u+\\n["
79 p
->uid
, ab
->uid
, p
->uid
);
82 else if (output_format
== mathml
) {
83 printf("<mover accent='true'>");
91 /* This version copes with the possibility of an accent's being wider
92 than its accentee. LEFT_WIDTH_FORMAT gives the distance from the
93 left edge of the resulting box to the middle of the accentee's box.*/
95 int accent_box::compute_metrics(int style
)
97 int r
= p
->compute_metrics(style
);
99 ab
->compute_metrics(style
);
100 printf(".nr " LEFT_WIDTH_FORMAT
" 0\\n[" WIDTH_FORMAT
"]/2"
101 ">?(\\n[" WIDTH_FORMAT
"]/2-\\n[" SKEW_FORMAT
"])\n",
102 uid
, p
->uid
, ab
->uid
, p
->uid
);
103 printf(".nr " WIDTH_FORMAT
" 0\\n[" WIDTH_FORMAT
"]/2"
104 ">?(\\n[" WIDTH_FORMAT
"]/2+\\n[" SKEW_FORMAT
"])"
105 "+\\n[" LEFT_WIDTH_FORMAT
"]\n",
106 uid
, p
->uid
, ab
->uid
, p
->uid
, uid
);
107 printf(".nr " DEPTH_FORMAT
" \\n[" DEPTH_FORMAT
"]\n", uid
, p
->uid
);
108 printf(".nr " SUP_RAISE_FORMAT
" \\n[" HEIGHT_FORMAT
"]-%dM>?0\n",
109 uid
, p
->uid
, x_height
);
110 printf(".nr " HEIGHT_FORMAT
" \\n[" HEIGHT_FORMAT
"]+\\n["
111 SUP_RAISE_FORMAT
"]\n",
114 printf(".nr " MARK_REG
" +\\n[" LEFT_WIDTH_FORMAT
"]"
115 "-(\\n[" WIDTH_FORMAT
"]/2)'\n",
120 void accent_box::output()
122 if (output_format
== troff
) {
123 printf("\\Z" DELIMITER_CHAR
);
124 printf("\\h'\\n[" LEFT_WIDTH_FORMAT
"]u+\\n[" SKEW_FORMAT
"]u"
125 "-(\\n[" WIDTH_FORMAT
"]u/2u)'",
126 uid
, p
->uid
, ab
->uid
);
127 printf("\\v'-\\n[" SUP_RAISE_FORMAT
"]u'", uid
);
129 printf(DELIMITER_CHAR
);
130 printf("\\Z" DELIMITER_CHAR
);
131 printf("\\h'\\n[" LEFT_WIDTH_FORMAT
"]u-(\\n[" WIDTH_FORMAT
"]u/2u)'",
134 printf(DELIMITER_CHAR
);
135 printf("\\h'\\n[" WIDTH_FORMAT
"]u'", uid
);
137 else if (output_format
== mathml
) {
138 printf("<mover accent='true'>");
145 void accent_box::check_tabs(int level
)
147 ab
->check_tabs(level
+ 1);
148 p
->check_tabs(level
+ 1);
151 void accent_box::debug_print()
153 fprintf(stderr
, "{ ");
155 fprintf(stderr
, " } accent { ");
157 fprintf(stderr
, " }");
160 class overline_char_box
: public simple_box
{
167 overline_char_box::overline_char_box()
171 void overline_char_box::output()
173 if (output_format
== troff
) {
174 printf("\\v'-%dM/2u-%dM'", 7*default_rule_thickness
, x_height
);
175 printf((draw_flag
? "\\D'l%dM 0'" : "\\l'%dM\\&\\(ru'"),
177 printf("\\v'%dM/2u+%dM'", 7*default_rule_thickness
, x_height
);
179 else if (output_format
== mathml
)
180 printf("<mo>¯</mo>");
183 void overline_char_box::debug_print()
185 fprintf(stderr
, "<overline char>");
188 class overline_box
: public pointer_box
{
191 int compute_metrics(int);
196 box
*make_overline_box(box
*p
)
199 return new accent_box(p
, new overline_char_box
);
201 return new overline_box(p
);
204 overline_box::overline_box(box
*pp
) : pointer_box(pp
)
208 int overline_box::compute_metrics(int style
)
210 int r
= p
->compute_metrics(cramped_style(style
));
212 printf(".nr " HEIGHT_FORMAT
" \\n[" HEIGHT_FORMAT
"]+%dM\n",
213 uid
, p
->uid
, default_rule_thickness
*5);
214 printf(".nr " WIDTH_FORMAT
" 0\\n[" WIDTH_FORMAT
"]\n", uid
, p
->uid
);
215 printf(".nr " DEPTH_FORMAT
" \\n[" DEPTH_FORMAT
"]\n", uid
, p
->uid
);
219 void overline_box::output()
221 if (output_format
== troff
) {
223 printf("\\Z" DELIMITER_CHAR
);
224 printf("\\v'-\\n[" HEIGHT_FORMAT
"]u-(%dM/2u)'",
225 p
->uid
, 7*default_rule_thickness
);
227 printf("\\D'l\\n[" WIDTH_FORMAT
"]u 0'", p
->uid
);
229 printf("\\l'\\n[" WIDTH_FORMAT
"]u\\&\\(ru'", p
->uid
);
230 printf(DELIMITER_CHAR
);
233 else if (output_format
== mathml
) {
234 printf("<mover accent='false'>");
236 printf("<mo>¯</mo></mover>");
240 void overline_box::debug_print()
242 fprintf(stderr
, "{ ");
244 fprintf(stderr
, " } bar");
247 class uaccent_box
: public pointer_box
{
250 uaccent_box(box
*, box
*);
252 int compute_metrics(int);
254 void compute_subscript_kern();
255 void check_tabs(int);
259 box
*make_uaccent_box(box
*p
, box
*q
)
261 return new uaccent_box(p
, q
);
264 uaccent_box::uaccent_box(box
*pp
, box
*qq
)
265 : pointer_box(pp
), ab(qq
)
269 uaccent_box::~uaccent_box()
274 int uaccent_box::compute_metrics(int style
)
276 int r
= p
->compute_metrics(style
);
277 ab
->compute_metrics(style
);
278 printf(".nr " LEFT_WIDTH_FORMAT
" 0\\n[" WIDTH_FORMAT
"]/2"
279 ">?(\\n[" WIDTH_FORMAT
"]/2)\n",
280 uid
, p
->uid
, ab
->uid
);
281 printf(".nr " WIDTH_FORMAT
" 0\\n[" WIDTH_FORMAT
"]/2"
282 ">?(\\n[" WIDTH_FORMAT
"]/2)"
283 "+\\n[" LEFT_WIDTH_FORMAT
"]\n",
284 uid
, p
->uid
, ab
->uid
, uid
);
285 printf(".nr " HEIGHT_FORMAT
" \\n[" HEIGHT_FORMAT
"]\n", uid
, p
->uid
);
286 printf(".nr " DEPTH_FORMAT
" \\n[" DEPTH_FORMAT
"]"
287 "+\\n[" DEPTH_FORMAT
"]\n",
288 uid
, p
->uid
, ab
->uid
);
290 printf(".nr " MARK_REG
" +\\n[" LEFT_WIDTH_FORMAT
"]"
291 "-(\\n[" WIDTH_FORMAT
"]/2)'\n",
296 void uaccent_box::output()
298 if (output_format
== troff
) {
299 printf("\\Z" DELIMITER_CHAR
);
300 printf("\\h'\\n[" LEFT_WIDTH_FORMAT
"]u-(\\n[" WIDTH_FORMAT
"]u/2u)'",
302 printf("\\v'\\n[" DEPTH_FORMAT
"]u'", p
->uid
);
304 printf(DELIMITER_CHAR
);
305 printf("\\Z" DELIMITER_CHAR
);
306 printf("\\h'\\n[" LEFT_WIDTH_FORMAT
"]u-(\\n[" WIDTH_FORMAT
"]u/2u)'",
309 printf(DELIMITER_CHAR
);
310 printf("\\h'\\n[" WIDTH_FORMAT
"]u'", uid
);
312 else if (output_format
== mathml
) {
313 printf("<munder accent='true'>");
320 void uaccent_box::check_tabs(int level
)
322 ab
->check_tabs(level
+ 1);
323 p
->check_tabs(level
+ 1);
326 void uaccent_box::compute_subscript_kern()
328 box::compute_subscript_kern(); // want 0 subscript kern
331 void uaccent_box::debug_print()
333 fprintf(stderr
, "{ ");
335 fprintf(stderr
, " } uaccent { ");
337 fprintf(stderr
, " }");
340 class underline_char_box
: public simple_box
{
342 underline_char_box();
347 underline_char_box::underline_char_box()
351 void underline_char_box::output()
353 if (output_format
== troff
) {
354 printf("\\v'%dM/2u'", 7*default_rule_thickness
);
355 printf((draw_flag
? "\\D'l%dM 0'" : "\\l'%dM\\&\\(ru'"),
357 printf("\\v'-%dM/2u'", 7*default_rule_thickness
);
359 else if (output_format
== mathml
)
360 printf("<mo>_</mo>");
363 void underline_char_box::debug_print()
365 fprintf(stderr
, "<underline char>");
369 class underline_box
: public pointer_box
{
371 underline_box(box
*);
372 int compute_metrics(int);
374 void compute_subscript_kern();
378 box
*make_underline_box(box
*p
)
381 return new uaccent_box(p
, new underline_char_box
);
383 return new underline_box(p
);
386 underline_box::underline_box(box
*pp
) : pointer_box(pp
)
390 int underline_box::compute_metrics(int style
)
392 int r
= p
->compute_metrics(style
);
394 printf(".nr " DEPTH_FORMAT
" \\n[" DEPTH_FORMAT
"]+%dM\n",
395 uid
, p
->uid
, default_rule_thickness
*5);
396 printf(".nr " WIDTH_FORMAT
" 0\\n[" WIDTH_FORMAT
"]\n", uid
, p
->uid
);
397 printf(".nr " HEIGHT_FORMAT
" \\n[" HEIGHT_FORMAT
"]\n", uid
, p
->uid
);
401 void underline_box::output()
403 if (output_format
== troff
) {
405 printf("\\Z" DELIMITER_CHAR
);
406 printf("\\v'\\n[" DEPTH_FORMAT
"]u+(%dM/2u)'",
407 p
->uid
, 7*default_rule_thickness
);
409 printf("\\D'l\\n[" WIDTH_FORMAT
"]u 0'", p
->uid
);
411 printf("\\l'\\n[" WIDTH_FORMAT
"]u\\&\\(ru'", p
->uid
);
412 printf(DELIMITER_CHAR
);
415 else if (output_format
== mathml
) {
416 printf("<munder accent='true'>");
418 printf("<mo>¯</mo></munder>");
422 // we want an underline box to have 0 subscript kern
424 void underline_box::compute_subscript_kern()
426 box::compute_subscript_kern();
429 void underline_box::debug_print()
431 fprintf(stderr
, "{ ");
433 fprintf(stderr
, " } under");
436 size_box::size_box(char *s
, box
*pp
) : pointer_box(pp
), size(s
)
440 int size_box::compute_metrics(int style
)
442 printf(".nr " SIZE_FORMAT
" \\n[.ps]\n", uid
);
443 printf(".ps %s\n", size
);
444 printf(".nr " SMALL_SIZE_FORMAT
" \\n[.ps]\n", uid
);
445 int r
= p
->compute_metrics(style
);
446 printf(".ps \\n[" SIZE_FORMAT
"]u\n", uid
);
447 printf(".nr " WIDTH_FORMAT
" 0\\n[" WIDTH_FORMAT
"]\n", uid
, p
->uid
);
448 printf(".nr " HEIGHT_FORMAT
" \\n[" HEIGHT_FORMAT
"]\n", uid
, p
->uid
);
449 printf(".nr " DEPTH_FORMAT
" \\n[" DEPTH_FORMAT
"]\n", uid
, p
->uid
);
453 void size_box::output()
455 if (output_format
== troff
) {
456 printf("\\s[\\n[" SMALL_SIZE_FORMAT
"]u]", uid
);
458 printf("\\s[\\n[" SIZE_FORMAT
"]u]", uid
);
460 else if (output_format
== mathml
) {
461 printf("<mstyle mathsize='%s'>", size
);
467 size_box::~size_box()
472 void size_box::debug_print()
474 fprintf(stderr
, "size %s { ", size
);
476 fprintf(stderr
, " }");
480 font_box::font_box(char *s
, box
*pp
) : pointer_box(pp
), f(s
)
484 font_box::~font_box()
489 int font_box::compute_metrics(int style
)
491 const char *old_roman_font
= current_roman_font
;
492 current_roman_font
= f
;
493 printf(".nr " FONT_FORMAT
" \\n[.f]\n", uid
);
494 printf(".ft %s\n", f
);
495 int r
= p
->compute_metrics(style
);
496 current_roman_font
= old_roman_font
;
497 printf(".ft \\n[" FONT_FORMAT
"]\n", uid
);
498 printf(".nr " WIDTH_FORMAT
" 0\\n[" WIDTH_FORMAT
"]\n", uid
, p
->uid
);
499 printf(".nr " HEIGHT_FORMAT
" \\n[" HEIGHT_FORMAT
"]\n", uid
, p
->uid
);
500 printf(".nr " DEPTH_FORMAT
" \\n[" DEPTH_FORMAT
"]\n", uid
, p
->uid
);
504 void font_box::output()
506 if (output_format
== troff
) {
507 printf("\\f[%s]", f
);
508 const char *old_roman_font
= current_roman_font
;
509 current_roman_font
= f
;
511 current_roman_font
= old_roman_font
;
512 printf("\\f[\\n[" FONT_FORMAT
"]]", uid
);
514 else if (output_format
== mathml
) {
515 const char *mlfont
= f
;
516 // bold and italic are already in MathML; translate eqn roman here
532 printf("<mstyle mathvariant='%s'>", mlfont
);
538 void font_box::debug_print()
540 fprintf(stderr
, "font %s { ", f
);
542 fprintf(stderr
, " }");
545 fat_box::fat_box(box
*pp
) : pointer_box(pp
)
549 int fat_box::compute_metrics(int style
)
551 int r
= p
->compute_metrics(style
);
552 printf(".nr " WIDTH_FORMAT
" 0\\n[" WIDTH_FORMAT
"]+%dM\n",
553 uid
, p
->uid
, fat_offset
);
554 printf(".nr " HEIGHT_FORMAT
" \\n[" HEIGHT_FORMAT
"]\n", uid
, p
->uid
);
555 printf(".nr " DEPTH_FORMAT
" \\n[" DEPTH_FORMAT
"]\n", uid
, p
->uid
);
559 void fat_box::output()
561 if (output_format
== troff
) {
563 printf("\\h'-\\n[" WIDTH_FORMAT
"]u'", p
->uid
);
564 printf("\\h'%dM'", fat_offset
);
567 else if (output_format
== mathml
) {
568 printf("<mstyle mathvariant='double-struck'>");
575 void fat_box::debug_print()
577 fprintf(stderr
, "fat { ");
579 fprintf(stderr
, " }");
583 vmotion_box::vmotion_box(int i
, box
*pp
) : pointer_box(pp
), n(i
)
587 int vmotion_box::compute_metrics(int style
)
589 int r
= p
->compute_metrics(style
);
590 printf(".nr " WIDTH_FORMAT
" 0\\n[" WIDTH_FORMAT
"]\n", uid
, p
->uid
);
592 printf(".nr " HEIGHT_FORMAT
" %dM+\\n[" HEIGHT_FORMAT
"]\n",
594 printf(".nr " DEPTH_FORMAT
" \\n[" DEPTH_FORMAT
"]\n", uid
, p
->uid
);
597 printf(".nr " DEPTH_FORMAT
" %dM+\\n[" DEPTH_FORMAT
"]>?0\n",
599 printf(".nr " HEIGHT_FORMAT
" \\n[" HEIGHT_FORMAT
"]\n",
605 void vmotion_box::output()
607 if (output_format
== troff
) {
608 printf("\\v'%dM'", -n
);
610 printf("\\v'%dM'", n
);
612 else if (output_format
== mathml
) {
613 printf("<merror>eqn vertical motion cannot be expressed "
614 "in MathML</merror>");
619 void vmotion_box::debug_print()
622 fprintf(stderr
, "up %d { ", n
);
624 fprintf(stderr
, "down %d { ", -n
);
626 fprintf(stderr
, " }");
629 hmotion_box::hmotion_box(int i
, box
*pp
) : pointer_box(pp
), n(i
)
633 int hmotion_box::compute_metrics(int style
)
635 int r
= p
->compute_metrics(style
);
636 printf(".nr " WIDTH_FORMAT
" 0\\n[" WIDTH_FORMAT
"]+%dM\n",
638 printf(".nr " HEIGHT_FORMAT
" \\n[" HEIGHT_FORMAT
"]\n", uid
, p
->uid
);
639 printf(".nr " DEPTH_FORMAT
" \\n[" DEPTH_FORMAT
"]\n", uid
, p
->uid
);
641 printf(".nr " MARK_REG
" +%dM\n", n
);
645 void hmotion_box::output()
647 if (output_format
== troff
) {
648 printf("\\h'%dM'", n
);
651 else if (output_format
== mathml
) {
652 printf("<merror>eqn horizontal motion cannot be expessed "
653 "in MathML</merror>");
658 void hmotion_box::debug_print()
661 fprintf(stderr
, "fwd %d { ", n
);
663 fprintf(stderr
, "back %d { ", -n
);
665 fprintf(stderr
, " }");
668 vcenter_box::vcenter_box(box
*pp
) : pointer_box(pp
)
672 int vcenter_box::compute_metrics(int style
)
674 int r
= p
->compute_metrics(style
);
675 printf(".nr " WIDTH_FORMAT
" 0\\n[" WIDTH_FORMAT
"]\n", uid
, p
->uid
);
676 printf(".nr " SUP_RAISE_FORMAT
" \\n[" DEPTH_FORMAT
"]-\\n["
677 HEIGHT_FORMAT
"]/2+%dM\n",
678 uid
, p
->uid
, p
->uid
, axis_height
);
679 printf(".nr " HEIGHT_FORMAT
" \\n[" HEIGHT_FORMAT
"]+\\n["
680 SUP_RAISE_FORMAT
"]>?0\n", uid
, p
->uid
, uid
);
681 printf(".nr " DEPTH_FORMAT
" \\n[" DEPTH_FORMAT
"]-\\n["
682 SUP_RAISE_FORMAT
"]>?0\n", uid
, p
->uid
, uid
);
687 void vcenter_box::output()
689 if (output_format
== troff
)
690 printf("\\v'-\\n[" SUP_RAISE_FORMAT
"]u'", uid
);
692 if (output_format
== troff
)
693 printf("\\v'\\n[" SUP_RAISE_FORMAT
"]u'", uid
);
696 void vcenter_box::debug_print()
698 fprintf(stderr
, "vcenter { ");
700 fprintf(stderr
, " }");