2 /* Copyright (C) 1989, 1990, 1991, 1992, 2004, 2007, 2009
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 3 of the License, or
11 (at your option) any later version.
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
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 // SUP_RAISE_FORMAT gives the first baseline
26 // BASELINE_SEP_FORMAT gives the separation between baselines
28 int pile_box::compute_metrics(int style)
31 for (i = 0; i < col.len; i++)
32 col.p[i]->compute_metrics(style);
33 printf(".nr " WIDTH_FORMAT " 0", uid);
34 for (i = 0; i < col.len; i++)
35 printf(">?\\n[" WIDTH_FORMAT "]", col.p[i]->uid);
37 printf(".nr " BASELINE_SEP_FORMAT " %dM",
38 uid, baseline_sep+col.space);
39 for (i = 1; i < col.len; i++)
40 printf(">?(\\n[" DEPTH_FORMAT "]+\\n[" HEIGHT_FORMAT "]+%dM)",
41 col.p[i-1]->uid, col.p[i]->uid, default_rule_thickness*5);
42 // round it so that it's a multiple of the vertical resolution
43 printf("/\\n(.V+(\\n(.V/2)*\\n(.V\n");
45 printf(".nr " SUP_RAISE_FORMAT " \\n[" BASELINE_SEP_FORMAT "]*%d/2"
47 uid, uid, col.len-1, axis_height - shift_down);
48 printf(".nr " HEIGHT_FORMAT " \\n[" SUP_RAISE_FORMAT "]+\\n["
50 uid, uid, col.p[0]->uid);
51 printf(".nr " DEPTH_FORMAT " \\n[" BASELINE_SEP_FORMAT "]*%d+\\n["
52 DEPTH_FORMAT "]-\\n[" SUP_RAISE_FORMAT "]\n",
53 uid, uid, col.len-1, col.p[col.len-1]->uid, uid);
57 void pile_box::output()
59 if (output_format == troff) {
61 printf("\\v'-\\n[" SUP_RAISE_FORMAT "]u'", uid);
62 for (i = 0; i < col.len; i++) {
67 printf("\\h'\\n[" WIDTH_FORMAT "]u-\\n[" WIDTH_FORMAT "]u/2u'",
71 printf("\\h'\\n[" WIDTH_FORMAT "]u-\\n[" WIDTH_FORMAT "]u'",
78 printf("\\h'-\\n[" WIDTH_FORMAT "]u'", col.p[i]->uid);
83 printf("\\h'\\n[" WIDTH_FORMAT "]u-\\n[" WIDTH_FORMAT "]u/2u'",
87 printf("\\h'\\n[" WIDTH_FORMAT "]u-\\n[" WIDTH_FORMAT "]u'",
94 printf("\\v'\\n[" BASELINE_SEP_FORMAT "]u'", uid);
96 printf("\\v'\\n[" SUP_RAISE_FORMAT "]u'", uid);
97 printf("\\v'-(%du*\\n[" BASELINE_SEP_FORMAT "]u)'", col.len - 1, uid);
98 printf("\\h'\\n[" WIDTH_FORMAT "]u'", uid);
100 else if (output_format == mathml) {
115 printf("<mtable columnalign='%s'>", av);
116 for (int i = 0; i < col.len; i++) {
117 printf("<mtr><mtd>");
119 printf("</mtd></mtr>");
125 pile_box::pile_box(box *pp) : col(pp)
129 void pile_box::check_tabs(int level)
131 col.list_check_tabs(level);
134 void pile_box::debug_print()
136 col.debug_print("pile");
139 int matrix_box::compute_metrics(int style)
144 for (i = 0; i < len; i++) {
145 for (j = 0; j < p[i]->len; j++)
146 p[i]->p[j]->compute_metrics(style);
147 if (p[i]->len > max_len)
149 if (p[i]->space > space)
152 for (i = 0; i < len; i++) {
153 printf(".nr " COLUMN_WIDTH_FORMAT " 0", uid, i);
154 for (j = 0; j < p[i]->len; j++)
155 printf(">?\\n[" WIDTH_FORMAT "]", p[i]->p[j]->uid);
158 printf(".nr " WIDTH_FORMAT " %dM",
159 uid, column_sep*(len-1)+2*matrix_side_sep);
160 for (i = 0; i < len; i++)
161 printf("+\\n[" COLUMN_WIDTH_FORMAT "]", uid, i);
163 printf(".nr " BASELINE_SEP_FORMAT " %dM",
164 uid, baseline_sep+space);
165 for (i = 0; i < len; i++)
166 for (j = 1; j < p[i]->len; j++)
167 printf(">?(\\n[" DEPTH_FORMAT "]+\\n[" HEIGHT_FORMAT "]+%dM)",
168 p[i]->p[j-1]->uid, p[i]->p[j]->uid, default_rule_thickness*5);
169 // round it so that it's a multiple of the vertical resolution
170 printf("/\\n(.V+(\\n(.V/2)*\\n(.V\n");
171 printf(".nr " SUP_RAISE_FORMAT " \\n[" BASELINE_SEP_FORMAT "]*%d/2"
173 uid, uid, max_len-1, axis_height - shift_down);
174 printf(".nr " HEIGHT_FORMAT " 0\\n[" SUP_RAISE_FORMAT "]+(0",
176 for (i = 0; i < len; i++)
177 printf(">?\\n[" HEIGHT_FORMAT "]", p[i]->p[0]->uid);
179 printf(".nr " DEPTH_FORMAT " \\n[" BASELINE_SEP_FORMAT "]*%d-\\n["
180 SUP_RAISE_FORMAT "]+(0",
181 uid, uid, max_len-1, uid);
182 for (i = 0; i < len; i++)
183 if (p[i]->len == max_len)
184 printf(">?\\n[" DEPTH_FORMAT "]", p[i]->p[max_len-1]->uid);
186 return FOUND_NOTHING;
189 void matrix_box::output()
191 if (output_format == troff) {
192 printf("\\h'%dM'", matrix_side_sep);
193 for (int i = 0; i < len; i++) {
195 printf("\\v'-\\n[" SUP_RAISE_FORMAT "]u'", uid);
196 for (j = 0; j < p[i]->len; j++) {
197 switch (p[i]->align) {
201 printf("\\h'\\n[" COLUMN_WIDTH_FORMAT "]u-\\n[" WIDTH_FORMAT "]u/2u'",
202 uid, i, p[i]->p[j]->uid);
205 printf("\\h'\\n[" COLUMN_WIDTH_FORMAT "]u-\\n[" WIDTH_FORMAT "]u'",
206 uid, i, p[i]->p[j]->uid);
211 p[i]->p[j]->output();
212 printf("\\h'-\\n[" WIDTH_FORMAT "]u'", p[i]->p[j]->uid);
213 switch (p[i]->align) {
217 printf("\\h'\\n[" WIDTH_FORMAT "]u-\\n[" COLUMN_WIDTH_FORMAT "]u/2u'",
218 p[i]->p[j]->uid, uid, i);
221 printf("\\h'\\n[" WIDTH_FORMAT "]u-\\n[" COLUMN_WIDTH_FORMAT "]u'",
222 p[i]->p[j]->uid, uid, i);
227 if (j != p[i]->len - 1)
228 printf("\\v'\\n[" BASELINE_SEP_FORMAT "]u'", uid);
230 printf("\\v'\\n[" SUP_RAISE_FORMAT "]u'", uid);
231 printf("\\v'-(%du*\\n[" BASELINE_SEP_FORMAT "]u)'", p[i]->len - 1, uid);
232 printf("\\h'\\n[" COLUMN_WIDTH_FORMAT "]u'", uid, i);
234 printf("\\h'%dM'", column_sep);
236 printf("\\h'%dM'", matrix_side_sep);
238 else if (output_format == mathml) {
239 int n = p[0]->len; // Each column must have the same number of rows in it
241 for (int i = 0; i < n; i++) {
243 for (int j = 0; j < len; j++) {
245 switch (p[j]->align) {
258 printf("<mtd columnalign='%s'>", av);
259 p[j]->p[i]->output();
268 matrix_box::matrix_box(column *pp)
271 for (int i = 0; i < 10; i++)
278 matrix_box::~matrix_box()
280 for (int i = 0; i < len; i++)
285 void matrix_box::append(column *pp)
287 if (len + 1 > maxlen) {
290 p = new column*[maxlen];
291 memcpy(p, oldp, sizeof(column*)*len);
297 void matrix_box::check_tabs(int level)
299 for (int i = 0; i < len; i++)
300 p[i]->list_check_tabs(level);
303 void matrix_box::debug_print()
305 fprintf(stderr, "matrix { ");
306 p[0]->debug_print("col");
307 for (int i = 1; i < len; i++) {
308 fprintf(stderr, " ");
309 p[i]->debug_print("col");
311 fprintf(stderr, " }");
314 column::column(box *pp) : box_list(pp), align(CENTER_ALIGN), space(0)
318 void column::set_alignment(alignment a)
323 void column::set_space(int n)
328 void column::debug_print(const char *s)
330 char c = '\0'; // shut up -Wall
344 fprintf(stderr, "%c%s %d { ", c, s, space);
345 list_debug_print(" above ");
346 fprintf(stderr, " }");