Handle hidden elements properly in HTML-CSS and SVG now that we are not looking up by frame ID. Also, cache hidden elements in SVG like in HTML-CSS.

This commit is contained in:
Davide P. Cervone 2016-08-21 19:33:04 -04:00
parent 03db3c7b59
commit 9f0059cfb4
2 changed files with 17 additions and 10 deletions

View File

@ -606,6 +606,7 @@
} else if (this.msieDisappearingBug) {span.style.display = "inline-block"} } else if (this.msieDisappearingBug) {span.style.display = "inline-block"}
div.className += " MathJax_Processing"; div.className += " MathJax_Processing";
script.parentNode.insertBefore(div,script); script.parentNode.insertBefore(div,script);
jax.HTMLCSS.span = span; jax.HTMLCSS.div = div; // save for use in Translate()
// //
// Add the test span for determining scales and linebreak widths // Add the test span for determining scales and linebreak widths
// //
@ -626,14 +627,13 @@
ex = test.firstChild.offsetHeight/60; ex = test.firstChild.offsetHeight/60;
em = test.lastChild.firstChild.offsetHeight/60; em = test.lastChild.firstChild.offsetHeight/60;
cwidth = Math.max(0,div.previousSibling.firstChild.offsetWidth - 2); cwidth = Math.max(0,div.previousSibling.firstChild.offsetWidth - 2);
if (relwidth) {maxwidth = cwidth}
if (ex === 0 || ex === "NaN") { if (ex === 0 || ex === "NaN") {
// can't read width, so move to hidden div for processing // can't read width, so move to hidden div for processing
hidden.push(div); hidden.push(div);
jax.HTMLCSS.isHidden = true; jax.HTMLCSS.isHidden = true;
ex = this.defaultEx; em = this.defaultEm; cwidth = this.defaultWidth; ex = this.defaultEx; em = this.defaultEm; cwidth = this.defaultWidth;
if (relwidth) {maxwidth = cwidth}
} }
if (relwidth) {maxwidth = cwidth}
scale = (this.config.matchFontHeight ? ex/this.TeX.x_height/em : 1); scale = (this.config.matchFontHeight ? ex/this.TeX.x_height/em : 1);
scale = Math.floor(Math.max(this.config.minScaleAdjust/100,scale)*this.config.scale); scale = Math.floor(Math.max(this.config.minScaleAdjust/100,scale)*this.config.scale);
jax.HTMLCSS.scale = scale/100; jax.HTMLCSS.fontSize = scale+"%"; jax.HTMLCSS.scale = scale/100; jax.HTMLCSS.fontSize = scale+"%";
@ -683,8 +683,7 @@
// Get the data about the math // Get the data about the math
// //
var jax = script.MathJax.elementJax, math = jax.root, var jax = script.MathJax.elementJax, math = jax.root,
div = script.previousSibling; div = jax.HTMLCSS.div, span = jax.HTMLCSS.div;
span = (jax.HTMLCSS.display ? (div||{}).firstChild||div : div);
if (!div) return; if (!div) return;
// //
// Set the font metrics // Set the font metrics
@ -699,7 +698,6 @@
this.savePreview(script); this.savePreview(script);
try { try {
math.setTeXclass(); math.setTeXclass();
jax.HTMLCSS.span = span; jax.HTMLCSS.div = div; // save for phase II and III
math.toHTML(span,div,this.PHASE.I); math.toHTML(span,div,this.PHASE.I);
} catch (err) { } catch (err) {
if (err.restart) {while (span.firstChild) {span.removeChild(span.firstChild)}} if (err.restart) {while (span.firstChild) {span.removeChild(span.firstChild)}}

View File

@ -261,6 +261,7 @@
// Determine the scaling factors for each script // Determine the scaling factors for each script
// (this only requires one reflow rather than a reflow for each equation) // (this only requires one reflow rather than a reflow for each equation)
// //
var hidden = [];
for (i = 0; i < m; i++) { for (i = 0; i < m; i++) {
script = scripts[i]; if (!script.parentNode) continue; script = scripts[i]; if (!script.parentNode) continue;
test = script.previousSibling; div = test.previousSibling; test = script.previousSibling; div = test.previousSibling;
@ -269,8 +270,7 @@
cwidth = Math.max(0,(div.previousSibling.firstChild.offsetWidth-2) / this.config.scale * 100); cwidth = Math.max(0,(div.previousSibling.firstChild.offsetWidth-2) / this.config.scale * 100);
if (ex === 0 || ex === "NaN") { if (ex === 0 || ex === "NaN") {
// can't read width, so move to hidden div for processing // can't read width, so move to hidden div for processing
// (this will cause a reflow for each math element that is hidden) hidden.push(div);
this.hiddenDiv.appendChild(div);
jax.SVG.isHidden = true; jax.SVG.isHidden = true;
ex = this.defaultEx; cwidth = this.defaultWidth; ex = this.defaultEx; cwidth = this.defaultWidth;
} }
@ -280,6 +280,10 @@
jax.SVG.cwidth = cwidth/em * 1000; jax.SVG.cwidth = cwidth/em * 1000;
jax.SVG.lineWidth = (linebreak ? this.length2em(width,1,maxwidth/em*1000) : SVG.BIGDIMEN); jax.SVG.lineWidth = (linebreak ? this.length2em(width,1,maxwidth/em*1000) : SVG.BIGDIMEN);
} }
for (i = 0, n = hidden.length; i < n; i++) {
this.hiddenDiv.appendChild(hidden[i]);
this.addElement(this.hiddenDiv,"br");
}
// //
// Remove the test spans used for determining scales and linebreak widths // Remove the test spans used for determining scales and linebreak widths
// //
@ -314,10 +318,15 @@
// //
// Get the data about the math // Get the data about the math
// //
var jax = script.MathJax.elementJax, math = jax.root, var jax = script.MathJax.elementJax, math = jax.root, div, span,
div = script.previousSibling;
span = (jax.SVG.display ? (div||{}).firstChild||div : div),
localCache = (SVG.config.useFontCache && !SVG.config.useGlobalCache); localCache = (SVG.config.useFontCache && !SVG.config.useGlobalCache);
if (jax.SVG.isHidden) {
span = document.getElementById(jax.inputID+"-Frame");
div = (jax.SVG.display ? span.parentElement : span);
} else {
div = script.previousSibling;
span = (jax.SVG.display ? (div||{}).firstChild||div : div);
}
if (!div) return; if (!div) return;
// //
// Set the font metrics // Set the font metrics