9427b107340098a5526127bd176c81429a689588
[platform/upstream/groff.git] / src / preproc / eqn / mark.cpp
1 // -*- C++ -*-
2 /* Copyright (C) 1989-2020 Free Software Foundation, Inc.
3      Written by James Clark (jjc@jclark.com)
4
5 This file is part of groff.
6
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 3 of the License, or
10 (at your option) any later version.
11
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.
16
17 You should have received a copy of the GNU General Public License
18 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "eqn.h"
21 #include "pbox.h"
22
23 class mark_box : public pointer_box {
24 public:
25   mark_box(box *);
26   int compute_metrics(int);
27   void output();
28   void debug_print();
29 };
30
31 // we push down marks so that they don't interfere with spacing
32
33 box *make_mark_box(box *p)
34 {
35   list_box *b = p->to_list_box();
36   if (b != 0) {
37     b->list.p[0] = make_mark_box(b->list.p[0]);
38     return b;
39   }
40   else
41     return new mark_box(p);
42 }
43
44 mark_box::mark_box(box *pp) : pointer_box(pp)
45 {
46 }
47
48 void mark_box::output()
49 {
50   p->output();
51 }
52
53 int mark_box::compute_metrics(int style)
54 {
55   int res = p->compute_metrics(style);
56   if (res)
57     error("multiple marks and lineups");
58   printf(".nr " WIDTH_FORMAT " 0\\n[" WIDTH_FORMAT "]\n", uid, p->uid);
59   printf(".nr " HEIGHT_FORMAT " \\n[" HEIGHT_FORMAT "]\n", uid, p->uid);
60   printf(".nr " DEPTH_FORMAT " \\n[" DEPTH_FORMAT "]\n", uid, p->uid);
61   printf(".nr " MARK_REG " 0\n");
62   return FOUND_MARK;
63 }
64
65 void mark_box::debug_print()
66 {
67   fprintf(stderr, "mark { ");
68   p->debug_print();
69   fprintf(stderr, " }");
70 }
71
72
73 class lineup_box : public pointer_box {
74 public:
75   lineup_box(box *);
76   void output();
77   int compute_metrics(int style);
78   void debug_print();
79 };
80
81 // we push down lineups so that they don't interfere with spacing
82
83 box *make_lineup_box(box *p)
84 {
85   list_box *b = p->to_list_box();
86   if (b != 0) {
87     b->list.p[0] = make_lineup_box(b->list.p[0]);
88     return b;
89   }
90   else
91     return new lineup_box(p);
92 }
93
94 lineup_box::lineup_box(box *pp) : pointer_box(pp)
95 {
96 }
97
98 void lineup_box::output()
99 {
100   p->output();
101 }
102
103 int lineup_box::compute_metrics(int style)
104 {
105   int res = p->compute_metrics(style);
106   if (res)
107     error("multiple marks and lineups");
108   printf(".nr " WIDTH_FORMAT " 0\\n[" WIDTH_FORMAT "]\n", uid, p->uid);
109   printf(".nr " HEIGHT_FORMAT " \\n[" HEIGHT_FORMAT "]\n", uid, p->uid);
110   printf(".nr " DEPTH_FORMAT " \\n[" DEPTH_FORMAT "]\n", uid, p->uid);
111   printf(".nr " MARK_REG " 0\n");
112   return FOUND_LINEUP;
113 }
114
115 void lineup_box::debug_print()
116 {
117   fprintf(stderr, "lineup { ");
118   p->debug_print();
119   fprintf(stderr, " }");
120 }