4 /* Copyright (C) 1989, 1990, 1991, 1992, 2004 Free Software Foundation, Inc.
5 Written by James Clark (jjc@jclark.com)
7 This file is part of groff.
9 groff is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2, or (at your option) any later
14 groff is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License along
20 with groff; see the file COPYING. If not, write to the Free Software
21 Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
27 // SUP_RAISE_FORMAT gives the first baseline
28 // BASELINE_SEP_FORMAT gives the separation between baselines
30 int pile_box::compute_metrics(int style
)
33 for (i
= 0; i
< col
.len
; i
++)
34 col
.p
[i
]->compute_metrics(style
);
35 printf(".nr " WIDTH_FORMAT
" 0", uid
);
36 for (i
= 0; i
< col
.len
; i
++)
37 printf(">?\\n[" WIDTH_FORMAT
"]", col
.p
[i
]->uid
);
39 printf(".nr " BASELINE_SEP_FORMAT
" %dM",
40 uid
, baseline_sep
+col
.space
);
41 for (i
= 1; i
< col
.len
; i
++)
42 printf(">?(\\n[" DEPTH_FORMAT
"]+\\n[" HEIGHT_FORMAT
"]+%dM)",
43 col
.p
[i
-1]->uid
, col
.p
[i
]->uid
, default_rule_thickness
*5);
44 // round it so that it's a multiple of the vertical resolution
45 printf("/\\n(.V+(\\n(.V/2)*\\n(.V\n");
47 printf(".nr " SUP_RAISE_FORMAT
" \\n[" BASELINE_SEP_FORMAT
"]*%d/2"
49 uid
, uid
, col
.len
-1, axis_height
- shift_down
);
50 printf(".nr " HEIGHT_FORMAT
" \\n[" SUP_RAISE_FORMAT
"]+\\n["
52 uid
, uid
, col
.p
[0]->uid
);
53 printf(".nr " DEPTH_FORMAT
" \\n[" BASELINE_SEP_FORMAT
"]*%d+\\n["
54 DEPTH_FORMAT
"]-\\n[" SUP_RAISE_FORMAT
"]\n",
55 uid
, uid
, col
.len
-1, col
.p
[col
.len
-1]->uid
, uid
);
59 void pile_box::output()
62 printf("\\v'-\\n[" SUP_RAISE_FORMAT
"]u'", uid
);
63 for (i
= 0; i
< col
.len
; i
++) {
68 printf("\\h'\\n[" WIDTH_FORMAT
"]u-\\n[" WIDTH_FORMAT
"]u/2u'",
72 printf("\\h'\\n[" WIDTH_FORMAT
"]u-\\n[" WIDTH_FORMAT
"]u'",
79 printf("\\h'-\\n[" WIDTH_FORMAT
"]u'", col
.p
[i
]->uid
);
84 printf("\\h'\\n[" WIDTH_FORMAT
"]u-\\n[" WIDTH_FORMAT
"]u/2u'",
88 printf("\\h'\\n[" WIDTH_FORMAT
"]u-\\n[" WIDTH_FORMAT
"]u'",
95 printf("\\v'\\n[" BASELINE_SEP_FORMAT
"]u'", uid
);
97 printf("\\v'\\n[" SUP_RAISE_FORMAT
"]u'", uid
);
98 printf("\\v'-(%du*\\n[" BASELINE_SEP_FORMAT
"]u)'", col
.len
- 1, uid
);
99 printf("\\h'\\n[" WIDTH_FORMAT
"]u'", uid
);
102 pile_box::pile_box(box
*pp
) : col(pp
)
106 void pile_box::check_tabs(int level
)
108 col
.list_check_tabs(level
);
111 void pile_box::debug_print()
113 col
.debug_print("pile");
116 int matrix_box::compute_metrics(int style
)
121 for (i
= 0; i
< len
; i
++) {
122 for (j
= 0; j
< p
[i
]->len
; j
++)
123 p
[i
]->p
[j
]->compute_metrics(style
);
124 if (p
[i
]->len
> max_len
)
126 if (p
[i
]->space
> space
)
129 for (i
= 0; i
< len
; i
++) {
130 printf(".nr " COLUMN_WIDTH_FORMAT
" 0", uid
, i
);
131 for (j
= 0; j
< p
[i
]->len
; j
++)
132 printf(">?\\n[" WIDTH_FORMAT
"]", p
[i
]->p
[j
]->uid
);
135 printf(".nr " WIDTH_FORMAT
" %dM",
136 uid
, column_sep
*(len
-1)+2*matrix_side_sep
);
137 for (i
= 0; i
< len
; i
++)
138 printf("+\\n[" COLUMN_WIDTH_FORMAT
"]", uid
, i
);
140 printf(".nr " BASELINE_SEP_FORMAT
" %dM",
141 uid
, baseline_sep
+space
);
142 for (i
= 0; i
< len
; i
++)
143 for (j
= 1; j
< p
[i
]->len
; j
++)
144 printf(">?(\\n[" DEPTH_FORMAT
"]+\\n[" HEIGHT_FORMAT
"]+%dM)",
145 p
[i
]->p
[j
-1]->uid
, p
[i
]->p
[j
]->uid
, default_rule_thickness
*5);
146 // round it so that it's a multiple of the vertical resolution
147 printf("/\\n(.V+(\\n(.V/2)*\\n(.V\n");
148 printf(".nr " SUP_RAISE_FORMAT
" \\n[" BASELINE_SEP_FORMAT
"]*%d/2"
150 uid
, uid
, max_len
-1, axis_height
- shift_down
);
151 printf(".nr " HEIGHT_FORMAT
" 0\\n[" SUP_RAISE_FORMAT
"]+(0",
153 for (i
= 0; i
< len
; i
++)
154 printf(">?\\n[" HEIGHT_FORMAT
"]", p
[i
]->p
[0]->uid
);
156 printf(".nr " DEPTH_FORMAT
" \\n[" BASELINE_SEP_FORMAT
"]*%d-\\n["
157 SUP_RAISE_FORMAT
"]+(0",
158 uid
, uid
, max_len
-1, uid
);
159 for (i
= 0; i
< len
; i
++)
160 if (p
[i
]->len
== max_len
)
161 printf(">?\\n[" DEPTH_FORMAT
"]", p
[i
]->p
[max_len
-1]->uid
);
163 return FOUND_NOTHING
;
166 void matrix_box::output()
168 printf("\\h'%dM'", matrix_side_sep
);
169 for (int i
= 0; i
< len
; i
++) {
171 printf("\\v'-\\n[" SUP_RAISE_FORMAT
"]u'", uid
);
172 for (j
= 0; j
< p
[i
]->len
; j
++) {
173 switch (p
[i
]->align
) {
177 printf("\\h'\\n[" COLUMN_WIDTH_FORMAT
"]u-\\n[" WIDTH_FORMAT
"]u/2u'",
178 uid
, i
, p
[i
]->p
[j
]->uid
);
181 printf("\\h'\\n[" COLUMN_WIDTH_FORMAT
"]u-\\n[" WIDTH_FORMAT
"]u'",
182 uid
, i
, p
[i
]->p
[j
]->uid
);
187 p
[i
]->p
[j
]->output();
188 printf("\\h'-\\n[" WIDTH_FORMAT
"]u'", p
[i
]->p
[j
]->uid
);
189 switch (p
[i
]->align
) {
193 printf("\\h'\\n[" WIDTH_FORMAT
"]u-\\n[" COLUMN_WIDTH_FORMAT
"]u/2u'",
194 p
[i
]->p
[j
]->uid
, uid
, i
);
197 printf("\\h'\\n[" WIDTH_FORMAT
"]u-\\n[" COLUMN_WIDTH_FORMAT
"]u'",
198 p
[i
]->p
[j
]->uid
, uid
, i
);
203 if (j
!= p
[i
]->len
- 1)
204 printf("\\v'\\n[" BASELINE_SEP_FORMAT
"]u'", uid
);
206 printf("\\v'\\n[" SUP_RAISE_FORMAT
"]u'", uid
);
207 printf("\\v'-(%du*\\n[" BASELINE_SEP_FORMAT
"]u)'", p
[i
]->len
- 1, uid
);
208 printf("\\h'\\n[" COLUMN_WIDTH_FORMAT
"]u'", uid
, i
);
210 printf("\\h'%dM'", column_sep
);
212 printf("\\h'%dM'", matrix_side_sep
);
215 matrix_box::matrix_box(column
*pp
)
218 for (int i
= 0; i
< 10; i
++)
225 matrix_box::~matrix_box()
227 for (int i
= 0; i
< len
; i
++)
232 void matrix_box::append(column
*pp
)
234 if (len
+ 1 > maxlen
) {
237 p
= new column
*[maxlen
];
238 memcpy(p
, oldp
, sizeof(column
*)*len
);
244 void matrix_box::check_tabs(int level
)
246 for (int i
= 0; i
< len
; i
++)
247 p
[i
]->list_check_tabs(level
);
250 void matrix_box::debug_print()
252 fprintf(stderr
, "matrix { ");
253 p
[0]->debug_print("col");
254 for (int i
= 1; i
< len
; i
++) {
255 fprintf(stderr
, " ");
256 p
[i
]->debug_print("col");
258 fprintf(stderr
, " }");
261 column::column(box
*pp
) : box_list(pp
), align(CENTER_ALIGN
), space(0)
265 void column::set_alignment(alignment a
)
270 void column::set_space(int n
)
275 void column::debug_print(const char *s
)
277 char c
= '\0'; // shut up -Wall
291 fprintf(stderr
, "%c%s %d { ", c
, s
, space
);
292 list_debug_print(" above ");
293 fprintf(stderr
, " }");