Skip to content

Commit dbe34c9

Browse files
committed
Handle vertical stretchy cells when equalrows is in effect, and reorganize stretching of columns
1 parent bf625ff commit dbe34c9

File tree

2 files changed

+68
-46
lines changed

2 files changed

+68
-46
lines changed

mathjax3-ts/output/chtml/Wrappers/mtable.ts

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,39 @@ export class CHTMLmtable<N, T, D> extends CHTMLWrapper<N, T, D> {
134134
this.rLines = this.getColumnAttributes('rowlines').map(x => (x === 'none' ? 0 : .07));
135135
this.cWidths = this.getColumnWidths();
136136
//
137-
// Stretch the columns (rows are already taken care of in the CHTMLmtr wrapper)
137+
// Stretch the rows and columns
138138
//
139+
this.stretchRows();
140+
this.stretchColumns();
141+
}
142+
143+
/*
144+
* Stretch the rows to the equal height or natural height
145+
*/
146+
protected stretchRows() {
147+
const equal = this.node.attributes.get('equalrows') as boolean;
148+
const HD = (equal ? this.getEqualRowHeight() : 0);
149+
const {H, D} = (equal ? this.getTableData() : {H: [0], D: [0]});
150+
for (let i = 0; i < this.numRows; i++) {
151+
const hd = (equal ? [(HD + H[i] - D[i]) / 2, (HD - H[i] + D[i]) / 2] : null);
152+
(this.childNodes[i] as CHTMLmtr<N, T, D>).stretchChildren(hd);
153+
}
154+
}
155+
156+
/*
157+
* Stretch the columns to their proper widths
158+
*/
159+
protected stretchColumns() {
139160
for (let i = 0; i < this.numCols; i++) {
140-
this.stretchColumn(i);
161+
const width = (typeof this.cWidths[i] === 'number' ? this.cWidths[i] as number : null);
162+
this.stretchColumn(i, width);
141163
}
142164
}
143165

144166
/*
145167
* Handle horizontal stretching within the ith column
146168
*/
147-
protected stretchColumn(i: number) {
169+
protected stretchColumn(i: number, W: number) {
148170
let stretchy: CHTMLWrapper<N, T, D>[] = [];
149171
//
150172
// Locate and count the stretchy children
@@ -162,21 +184,23 @@ export class CHTMLmtable<N, T, D> extends CHTMLWrapper<N, T, D> {
162184
let count = stretchy.length;
163185
let nodeCount = this.childNodes.length;
164186
if (count && nodeCount > 1) {
165-
let W = 0;
166-
//
167-
// If all the children are stretchy, find the largest one,
168-
// otherwise, find the width of the non-stretchy children.
169-
//
170-
let all = (count > 1 && count === nodeCount);
171-
for (const row of (this.childNodes as CHTMLmtr<N, T, D>[])) {
172-
const cell = row.childNodes[i + row.firstCell];
173-
if (cell) {
174-
const child = cell.childNodes[0];
175-
const noStretch = (child.stretch.dir === DIRECTION.None);
176-
if (all || noStretch) {
177-
const {w} = child.getBBox(noStretch);
178-
if (w > W) {
179-
W = w;
187+
if (W === null) {
188+
W = 0;
189+
//
190+
// If all the children are stretchy, find the largest one,
191+
// otherwise, find the width of the non-stretchy children.
192+
//
193+
let all = (count > 1 && count === nodeCount);
194+
for (const row of (this.childNodes as CHTMLmtr<N, T, D>[])) {
195+
const cell = row.childNodes[i + row.firstCell];
196+
if (cell) {
197+
const child = cell.childNodes[0];
198+
const noStretch = (child.stretch.dir === DIRECTION.None);
199+
if (all || noStretch) {
200+
const {w} = child.getBBox(noStretch);
201+
if (w > W) {
202+
W = w;
203+
}
180204
}
181205
}
182206
}

mathjax3-ts/output/chtml/Wrappers/mtr.ts

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,6 @@ export class CHTMLmtr<N, T, D> extends CHTMLWrapper<N, T, D> {
8383
return this.childNodes.map(cell => cell.getBBox());
8484
}
8585

86-
/*
87-
* @override
88-
* @constructor
89-
*/
90-
constructor(factory: CHTMLWrapperFactory<N, T, D>, node: MmlNode, parent: CHTMLWrapper<N, T, D> = null) {
91-
super(factory, node, parent);
92-
this.stretchChildren();
93-
}
94-
9586
/*
9687
* @override
9788
*/
@@ -104,8 +95,12 @@ export class CHTMLmtr<N, T, D> extends CHTMLWrapper<N, T, D> {
10495
/*
10596
* Handle vertical stretching of cells to match height of
10697
* other cells in the row.
98+
*
99+
* @param{number[]} HD The total height and depth for the row [H, D]
100+
*
101+
* If this isn't specified, the maximum height and depth is computed.
107102
*/
108-
protected stretchChildren() {
103+
public stretchChildren(HD: number[] = null) {
109104
let stretchy: CHTMLWrapper<N, T, D>[] = [];
110105
let children = (this.firstCell ? this.childNodes.slice(this.firstCell) : this.childNodes);
111106
//
@@ -120,31 +115,34 @@ export class CHTMLmtr<N, T, D> extends CHTMLWrapper<N, T, D> {
120115
let count = stretchy.length;
121116
let nodeCount = this.childNodes.length;
122117
if (count && nodeCount > 1) {
123-
let H = 0, D = 0;
124-
//
125-
// If all the children are stretchy, find the largest one,
126-
// otherwise, find the height and depth of the non-stretchy
127-
// children.
128-
//
129-
let all = (count > 1 && count === nodeCount);
130-
for (const mtd of children) {
131-
const child = mtd.childNodes[0];
132-
const noStretch = (child.stretch.dir === DIRECTION.None);
133-
if (all || noStretch) {
134-
const {h, d} = child.getBBox(noStretch);
135-
if (h > H) {
136-
H = h;
137-
}
138-
if (d > D) {
139-
D = d;
118+
if (HD === null) {
119+
let H = 0, D = 0;
120+
//
121+
// If all the children are stretchy, find the largest one,
122+
// otherwise, find the height and depth of the non-stretchy
123+
// children.
124+
//
125+
let all = (count > 1 && count === nodeCount);
126+
for (const mtd of children) {
127+
const child = mtd.childNodes[0];
128+
const noStretch = (child.stretch.dir === DIRECTION.None);
129+
if (all || noStretch) {
130+
const {h, d} = child.getBBox(noStretch);
131+
if (h > H) {
132+
H = h;
133+
}
134+
if (d > D) {
135+
D = d;
136+
}
140137
}
141138
}
139+
HD = [H, D];
142140
}
143141
//
144142
// Stretch the stretchable children
145143
//
146144
for (const child of stretchy) {
147-
child.coreMO().getStretchedVariant([H, D]);
145+
child.coreMO().getStretchedVariant(HD);
148146
}
149147
}
150148
}

0 commit comments

Comments
 (0)