Simplify mfrac layout. (Don't try to force the division line to be on the baseline so that it is always raised to the correct place by a vertical align of .25em; instead, just shift the whole stack appropriately. This may cause misalignment if we can't measure the parts exactly, however, but should speed things up a bit.)

This commit is contained in:
Davide P. Cervone 2015-03-10 19:08:32 -04:00
parent d878d3add2
commit a6f9e65af3

View File

@ -34,7 +34,8 @@
var EVENT, TOUCH, HOVER; // filled in later var EVENT, TOUCH, HOVER; // filled in later
var SCRIPTFACTOR = Math.sqrt(1/2), var SCRIPTFACTOR = Math.sqrt(1/2),
AXISHEIGHT = .25; AXISHEIGHT = .25,
HFUZZ = .05, DFUZZ = 0; // adjustments to bounding box of character boxes
var STYLES = { var STYLES = {
".MathJax_CHTML_Display": { ".MathJax_CHTML_Display": {
@ -52,11 +53,8 @@
}, },
"mjx-math *": {display:"inline-block", "text-align":"left"}, "mjx-math *": {display:"inline-block", "text-align":"left"},
"mjx-mfrac": {"vertical-align":".25em"}, "mjx-numerator": {display:"block", "text-align":"center"},
"mjx-fbox": {width:"100%"}, "mjx-denominator": {display:"block", "text-align":"center"},
"mjx-ftable": {display:"table", width:"100%"},
"mjx-numerator": {display:"table-cell", "text-align":"center"},
"mjx-denominator": {display:"table-cell", "text-align":"center"},
".MJXc-fpad": {"padding-left":".1em", "padding-right":".1em"}, ".MJXc-fpad": {"padding-left":".1em", "padding-right":".1em"},
"mjx-stack": {display:"inline-block"}, "mjx-stack": {display:"inline-block"},
@ -555,8 +553,9 @@
} }
this.addCharList(node.firstChild,list,bbox); this.addCharList(node.firstChild,list,bbox);
this.cleanBBox(bbox); this.cleanBBox(bbox);
node.firstChild.style.paddingTop = this.Em(bbox.h); bbox.h += HFUZZ; bbox.d += DFUZZ; bbox.t += HFUZZ; bbox.b += DFUZZ;
node.firstChild.style.paddingBottom = this.Em(bbox.d); node.firstChild.style[bbox.h < 0 ? "marginTop" : "paddingTop"] = this.Em(bbox.h);
node.firstChild.style[bbox.d < 0 ? "marginBottom": "paddingBottom"] = this.Em(bbox.d);
return bbox; return bbox;
}, },
@ -911,7 +910,7 @@
if (this.inferred) return node; if (this.inferred) return node;
if (!this.CHTMLnodeID) {this.CHTMLnodeID = CHTML.GetID()}; if (!this.CHTMLnodeID) {this.CHTMLnodeID = CHTML.GetID()};
var id = (this.id || "MJXc-Node-"+this.CHTMLnodeID); var id = (this.id || "MJXc-Node-"+this.CHTMLnodeID);
return HTML.addElement(node,"mjx-"+this.type,{className:"MJXc-"+this.type, id:id}); return HTML.addElement(node,"mjx-"+this.type,{id:id});
}, },
CHTMLnodeElement: function () { CHTMLnodeElement: function () {
if (!this.CHTMLnodeID) {return null} if (!this.CHTMLnodeID) {return null}
@ -1580,7 +1579,7 @@
toCommonHTML: function (node) { toCommonHTML: function (node) {
node = this.CHTMLdefaultNode(node,{ node = this.CHTMLdefaultNode(node,{
childNodes:["mjx-numerator","mjx-denominator"], childNodes:["mjx-numerator","mjx-denominator"],
forceChild:true, noBBox:true forceChild:true, noBBox:true, childCount:2
}); });
var values = this.getValues("linethickness","displaystyle","scriptlevel", var values = this.getValues("linethickness","displaystyle","scriptlevel",
"numalign","denomalign","bevelled"); "numalign","denomalign","bevelled");
@ -1597,15 +1596,11 @@
// //
// Create the table for the fraction and set the alignment // Create the table for the fraction and set the alignment
// //
var frac = HTML.addElement(node,"mjx-itable",{},[ var num = node.firstChild, denom = node.lastChild;
["mjx-row",{},[["mjx-fbox",{},[["mjx-ftable",{},[["mjx-row"]]]]]]], var frac = HTML.addElement(node,"mjx-box");
["mjx-row"] frac.appendChild(num); frac.appendChild(denom); node.appendChild(frac);
]); if (values.numalign !== "center") num.style.textAlign = values.numalign;
var num = frac.firstChild.firstChild.firstChild.firstChild, denom = frac.lastChild; if (values.denomalign !== "center") denom.style.textAlign = values.denomalign;
num.appendChild(node.firstChild);
denom.appendChild(node.firstChild);
if (values.numalign !== "center") num.firstChild.style.textAlign = values.numalign;
if (values.denomalign !== "center") denom.firstChild.style.textAlign = values.denomalign;
// //
// Get the bounding boxes for the parts, and determine the placement // Get the bounding boxes for the parts, and determine the placement
// of the numerator and denominator // of the numerator and denominator
@ -1625,15 +1620,10 @@
t = Math.max(t,mt); t = Math.max(t,mt);
q = (u - nbox.d*sscale) - (a + t/2); if (q < p) u += (p - q); q = (u - nbox.d*sscale) - (a + t/2); if (q < p) u += (p - q);
q = (a - t/2) - (dbox.h*sscale - v); if (q < p) v += (p - q); q = (a - t/2) - (dbox.h*sscale - v); if (q < p) v += (p - q);
node.style.verticalAlign = CHTML.Em(a-t/2); frac.style.verticalAlign = CHTML.Em(t/2-v);
// num.style.borderBottom = CHTML.Em(t)+" solid";
// Add the rule to the table num.className += " MJXc-fpad"; nbox.L = nbox.R = .1;
// denom.className += " MJXc-fpad"; dbox.L = dbox.R = .1;
var rule = HTML.Element("mjx-row",{},[["mjx-cell",{},[["mjx-line"]]]]);
num.parentNode.appendChild(rule); rule = rule.firstChild.firstChild;
rule.style.borderTop = CHTML.Em(t)+" solid";
num.firstChild.className += " MJXc-fpad"; nbox.L = nbox.R = .1;
denom.firstChild.className += " MJXc-fpad"; dbox.L = dbox.R = .1;
} }
// //
// Determine the new bounding box and place the parts // Determine the new bounding box and place the parts
@ -1643,8 +1633,8 @@
CHTML.combineBBoxes(this.CHTML,dbox,0,-v,sscale); CHTML.combineBBoxes(this.CHTML,dbox,0,-v,sscale);
CHTML.cleanBBox(this.CHTML); CHTML.cleanBBox(this.CHTML);
u -= sscale*nbox.d + a + t/2; v -= sscale*dbox.h - a + t/2; u -= sscale*nbox.d + a + t/2; v -= sscale*dbox.h - a + t/2;
if (u > 0) num.firstChild.style.paddingBottom = CHTML.Em(u); if (u > 0) num.style.paddingBottom = CHTML.Em(u);
if (v > 0) denom.firstChild.style.paddingTop = CHTML.Em(v); if (v > 0) denom.style.paddingTop = CHTML.Em(v);
// //
// Add nulldelimiterspace around the fraction // Add nulldelimiterspace around the fraction
// (TeXBook pg 150 and Appendix G rule 15e) // (TeXBook pg 150 and Appendix G rule 15e)