From 1aa86d7cf6e493bd748b92c19f5e176334cacb20 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Sun, 17 Aug 2014 14:14:39 -0400 Subject: [PATCH] Add noReflows flag to prevent taking measurements that cause reflows, when possible. This provides a 30 to 40% speed improvement, but can cause poor results in some browsers. --- unpacked/jax/output/HTML-CSS/config.js | 1 + unpacked/jax/output/HTML-CSS/jax.js | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/unpacked/jax/output/HTML-CSS/config.js b/unpacked/jax/output/HTML-CSS/config.js index b1aa6d59d..79512627a 100644 --- a/unpacked/jax/output/HTML-CSS/config.js +++ b/unpacked/jax/output/HTML-CSS/config.js @@ -35,6 +35,7 @@ MathJax.OutputJax["HTML-CSS"] = MathJax.OutputJax({ webfontDir: MathJax.OutputJax.fontDir + "/HTML-CSS", // font name added later config: { + noReflows: false, // true will use internal measurements and avoid browser reflows matchFontHeight: true, // try to match math font height to surrounding font? scale: 100, minScaleAdjust: 50, // global math scaling factor, and minimum adjusted scale factor availableFonts: ["STIX","TeX"], // list of local fonts to check for diff --git a/unpacked/jax/output/HTML-CSS/jax.js b/unpacked/jax/output/HTML-CSS/jax.js index a095e8f59..726d7076f 100644 --- a/unpacked/jax/output/HTML-CSS/jax.js +++ b/unpacked/jax/output/HTML-CSS/jax.js @@ -26,7 +26,6 @@ * limitations under the License. */ - (function (AJAX,HUB,HTMLCSS) { var MML, isMobile = HUB.Browser.isMobile; @@ -177,6 +176,7 @@ loadWebFont: function (font) { HUB.Startup.signal.Post("HTML-CSS Jax - Web-Font "+HTMLCSS.fontInUse+"/"+font.directory); var n = MESSAGE(["LoadWebFont","Loading web-font %1",HTMLCSS.fontInUse+"/"+font.directory]); + if (HTMLCSS.noReflows) return; var done = MathJax.Callback({}); // called when font is loaded var callback = MathJax.Callback(["loadComplete",this,font,n,done]); AJAX.timer.start(AJAX,[this.checkWebFont,font,callback],0,this.timeout); @@ -832,6 +832,7 @@ }, getHD: function (span) { + if (span.bbox && this.config.noReflows) {return {h:span.bbox.h, d:span.bbox.d}} var position = span.style.position; span.style.position = "absolute"; this.HDimg.style.height = "0px"; @@ -845,6 +846,7 @@ return HD; }, getW: function (span) { + if (span.bbox && this.config.noReflows) {return span.bbox.w} var W, H, w = (span.bbox||{}).w, start = span; if (span.bbox && span.bbox.exactW) {return w} if ((span.bbox && w >= 0 && !this.initialSkipBug && !this.msieItalicWidthBug) || @@ -886,7 +888,7 @@ for (i = 0, m = SPANS.length; i < m; i++) { span = SPANS[i]; if (!span) continue; bbox = span.bbox; parent = this.parentNode(span); - if (bbox.exactW || bbox.width || bbox.w === 0 || bbox.isMultiline) { + if (bbox.exactW || bbox.width || bbox.w === 0 || bbox.isMultiline || this.config.noReflows) { if (!parent.bbox) {parent.bbox = bbox} continue; } @@ -1077,7 +1079,8 @@ width:0, height:H, verticalAlign:D}, bbox: {h:h, d:d, w:w, rw:w, lw:0, exactW:true}, noAdjust:true, HH:h+d, isMathJax:true }); - if (w > 0 && rule.offsetWidth == 0) {rule.style.width = this.Em(w)} + // ### FIXME: figure out which IE has this bug and make a flag for it + if (w > 0 && !this.noReflows && rule.offsetWidth == 0) {rule.style.width = this.Em(w)} if (span.isBox || span.className == "mspace") {span.bbox = rule.bbox, span.HH = h+d} return rule; },