Skip to content

Commit bd135a7

Browse files
authored
Merge pull request #621 from mathjax/fix-smallmatrix
Handle scaled table rows (for smallmatrix) properly in CHTML and SVG
2 parents 1b4a161 + 61ddf8c commit bd135a7

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

ts/output/chtml/Wrappers/mtable.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,8 @@ CommonMtableMixin<CHTMLmtd<any, any, any>, CHTMLmtr<any, any, any>, CHTMLConstru
209209
* of the column space.)
210210
*/
211211
protected handleColumnSpacing() {
212-
const spacing = this.getEmHalfSpacing(this.fSpace[0], this.cSpace);
212+
const scale = (this.childNodes[0] ? 1 / this.childNodes[0].getBBox().rscale : 1);
213+
const spacing = this.getEmHalfSpacing(this.fSpace[0], this.cSpace, scale);
213214
const frame = this.frame;
214215
//
215216
// For each row...
@@ -281,7 +282,8 @@ CommonMtableMixin<CHTMLmtd<any, any, any>, CHTMLmtr<any, any, any>, CHTMLConstru
281282
* of the row space.)
282283
*/
283284
protected handleRowSpacing() {
284-
const spacing = this.getEmHalfSpacing(this.fSpace[1], this.rSpace);
285+
const scale = (this.childNodes[0] ? 1 / this.childNodes[0].getBBox().rscale : 1);
286+
const spacing = this.getEmHalfSpacing(this.fSpace[1], this.rSpace, scale);
285287
const frame = this.frame;
286288
//
287289
// For each row...

ts/output/common/Wrappers/mtable.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,11 @@ export interface CommonMtable<C extends AnyWrapper, R extends CommonMtr<C>> exte
257257
/**
258258
* @param {number} fspace The frame spacing to use
259259
* @param {number[]} space The array of spacing values to convert to strings
260+
* @param {number} scale A scaling factor to use for the sizes
260261
* @return {string[]} The half-spacing as stings with units of "em"
261262
* with frame spacing at the beginning and end
262263
*/
263-
getEmHalfSpacing(fspace: number, space: number[]): string[];
264+
getEmHalfSpacing(fspace: number, space: number[], scale?: number): string[];
264265

265266
/**
266267
* @return {number[]} The half-spacing for rows with frame spacing at the ends
@@ -1007,15 +1008,16 @@ export function CommonMtableMixin<
10071008
/**
10081009
* @param {number} fspace The frame spacing to use
10091010
* @param {number[]} space The array of spacing values to convert to strings
1011+
* @param {number} scale A scaling factor to use for the sizes
10101012
* @return {string[]} The half-spacing as stings with units of "em"
10111013
* with frame spacing at the beginning and end
10121014
*/
1013-
public getEmHalfSpacing(fspace: number, space: number[]): string[] {
1015+
public getEmHalfSpacing(fspace: number, space: number[], scale: number = 1): string[] {
10141016
//
10151017
// Get the column spacing values, and add the frame spacing values at the left and right
10161018
//
1017-
const fspaceEm = this.em(fspace);
1018-
const spaceEm = this.addEm(space, 2);
1019+
const fspaceEm = this.em(fspace * scale);
1020+
const spaceEm = this.addEm(space, 2 / scale);
10191021
spaceEm.unshift(fspaceEm);
10201022
spaceEm.push(fspaceEm);
10211023
return spaceEm;

ts/output/svg/Wrappers/mtr.ts

+13-10
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,14 @@ CommonMtrMixin<SVGmtd<any, any, any>, SVGConstructor<any, any, any>>(SVGWrapper)
107107
const cSpace = this.parent.getColumnHalfSpacing();
108108
const cLines = [this.parent.fLine, ...this.parent.cLines, this.parent.fLine];
109109
const cWidth = this.parent.getComputedWidths();
110+
const scale = 1 / this.getBBox().rscale;
110111
let x = cLines[0];
111112
for (let i = 0; i < this.numCells; i++) {
112113
const child = this.getChild(i);
113114
child.toSVG(svg);
114115
x += this.placeCell(child, {
115-
x: x, y: 0, lSpace: cSpace[i], rSpace: cSpace[i + 1], w: cWidth[i],
116-
lLine: cLines[i], rLine: cLines[i + 1]
116+
x: x, y: 0, lSpace: cSpace[i] * scale, rSpace: cSpace[i + 1] * scale, w: cWidth[i] * scale,
117+
lLine: cLines[i] * scale, rLine: cLines[i + 1] * scale
117118
});
118119
}
119120
}
@@ -125,26 +126,28 @@ CommonMtrMixin<SVGmtd<any, any, any>, SVGConstructor<any, any, any>>(SVGWrapper)
125126
*/
126127
public placeCell(cell: SVGmtd<N, T, D>, sizes: SizeData): number {
127128
const {x, y, lSpace, w, rSpace, lLine, rLine} = sizes;
128-
const [dx, dy] = cell.placeCell(x + lSpace, y, w, this.H, this.D);
129+
const scale = 1 / this.getBBox().rscale;
130+
const [h, d] = [this.H * scale, this.D * scale];
131+
const [t, b] = [this.tSpace * scale, this.bSpace * scale];
132+
const [dx, dy] = cell.placeCell(x + lSpace, y, w, h, d);
129133
const W = lSpace + w + rSpace;
130-
const [H, D] = [this.H + this.tSpace, this.D + this.bSpace];
131-
cell.placeColor(-(dx + lSpace + lLine / 2), -(D + this.bLine / 2 + dy),
132-
W + (lLine + rLine) / 2, H + D + (this.tLine + this.bLine) / 2);
134+
cell.placeColor(-(dx + lSpace + lLine / 2), -(d + b + dy), W + (lLine + rLine) / 2, h + d + t + b);
133135
return W + rLine;
134136
}
135137

136138
/**
137139
* Expand the backgound color to fill the entire row
138140
*/
139141
protected placeColor() {
142+
const scale = 1 / this.getBBox().rscale;
140143
const adaptor = this.adaptor;
141144
const child = adaptor.firstChild(this.element);
142145
if (child && adaptor.kind(child) === 'rect' && adaptor.getAttribute(child, 'data-bgcolor')) {
143-
const [TL, BL] = [this.tLine / 2, this.bLine / 2];
144-
const [TS, BS] = [this.tSpace, this.bSpace];
145-
const [H, D] = [this.H, this.D];
146+
const [TL, BL] = [(this.tLine / 2) * scale, (this.bLine / 2) * scale];
147+
const [TS, BS] = [this.tSpace * scale, this.bSpace * scale];
148+
const [H, D] = [this.H * scale, this.D * scale];
146149
adaptor.setAttribute(child, 'y', this.fixed(-(D + BS + BL)));
147-
adaptor.setAttribute(child, 'width', this.fixed(this.parent.getWidth()));
150+
adaptor.setAttribute(child, 'width', this.fixed(this.parent.getWidth() * scale));
148151
adaptor.setAttribute(child, 'height', this.fixed(TL + TS + H + D + BS + BL));
149152
}
150153
}

0 commit comments

Comments
 (0)