Change fonts from having ascent=descent to having midpoint at .25em, and adjust font handling to do offsets from that.

This commit is contained in:
Davide P. Cervone 2015-08-02 15:14:14 -04:00
parent 26ebc33c37
commit ead271e0e6
61 changed files with 13 additions and 11 deletions

View File

@ -33,7 +33,7 @@
var EVENT, TOUCH, HOVER; // filled in later var EVENT, TOUCH, HOVER; // filled in later
var AXISHEIGHT = .25, var CENTERLINE = .25,
STRUTHEIGHT = 1, STRUTHEIGHT = 1,
AFUZZ = .08, HFUZZ = .025, DFUZZ = .025; // adjustments to bounding box of character boxes AFUZZ = .08, HFUZZ = .025, DFUZZ = .025; // adjustments to bounding box of character boxes
@ -62,7 +62,7 @@
}, },
"mjx-math": { "mjx-math": {
"display": "inline-block", "display": "inline-block",
"border-collapse":"collapse" "border-collapse":"collapse"
}, },
"mjx-math *": {display:"inline-block", "text-align":"left"}, "mjx-math *": {display:"inline-block", "text-align":"left"},
@ -823,7 +823,7 @@
}, },
// //
// Get the height, depth and width of a character // Get the height, depth, and width of a character
// (height and depth are of the font, not the character). // (height and depth are of the font, not the character).
// WARNING: causes reflow of the page! // WARNING: causes reflow of the page!
// //
@ -939,9 +939,10 @@
} }
if (list.length) this.addCharList(node.firstChild,list,bbox); if (list.length) this.addCharList(node.firstChild,list,bbox);
bbox.clean(); bbox.clean();
if (bbox.d < 0) {bbox.D = bbox.d; bbox.d = 0} if (bbox.a == null) bbox.a = CENTERLINE;
if (bbox.h || bbox.a) node.firstChild.style[bbox.h < 0 ? "marginTop" : "paddingTop"] = this.Em(bbox.h-(bbox.a||0)); if (bbox.d + bbox.a < 0) {bbox.D = bbox.d; bbox.d = -bbox.a}
if (bbox.d) node.firstChild.style[bbox.d < 0 ? "marginBottom": "paddingBottom"] = this.Em(bbox.d); if (bbox.h - bbox.a) node.firstChild.style[bbox.h - bbox.a < 0 ? "marginTop" : "paddingTop"] = this.Em(bbox.h-bbox.a);
if (bbox.d + bbox.a) node.firstChild.style[bbox.d + bbox.a < 0 ? "marginBottom": "paddingBottom"] = this.Em(bbox.d+bbox.a);
return bbox; return bbox;
}, },
@ -996,7 +997,7 @@
var s = 1.1*(H - h)/k + .3; // space to cover by extender var s = 1.1*(H - h)/k + .3; // space to cover by extender
s /= (ebox.h+ebox.d); // scale factor; s /= (ebox.h+ebox.d); // scale factor;
this.Transform(ext, this.Transform(ext,
"translateY("+CHTML.Em(-ebox.d+.25)+") scaleY("+s.toFixed(3).replace(/0+$/,"")+")", "translateY("+CHTML.Em(-ebox.d+.25-s*CENTERLINE)+") scaleY("+s.toFixed(3).replace(/0+$/,"")+")",
"left "+CHTML.Em(ebox.d) "left "+CHTML.Em(ebox.d)
); );
ext.style.paddingTop=ext.style.paddingBottom = 0; ext.style.paddingTop=ext.style.paddingBottom = 0;
@ -1073,8 +1074,9 @@
this.adjustHeights([left,ext,mid,ext2,right],hbox); this.adjustHeights([left,ext,mid,ext2,right],hbox);
if (ebox.D) ebox.d = ebox.D; if (ebox.D) ebox.d = ebox.D;
hbox.t = hbox.h; hbox.b = hbox.d; hbox.t = hbox.h; hbox.b = hbox.d;
if (hbox.h !== ebox.h) node.style.marginTop = CHTML.Em(ebox.h - hbox.h); var mt = ebox.h - hbox.h - CENTERLINE, mb = ebox.d - hbox.d + CENTERLINE;
if (hbox.d !== ebox.d) node.style.marginBottom = CHTML.Em(ebox.d - hbox.d); if (mt) node.style.marginTop = CHTML.Em(mt);
if (mb) node.style.marginBottom = CHTML.Em(mb);
hbox.h = ebox.h; hbox.d = ebox.d; hbox.h = ebox.h; hbox.d = ebox.d;
if (BBOX) {hbox.scale = BBOX.scale; hbox.rscale = BBOX.rscale} if (BBOX) {hbox.scale = BBOX.scale; hbox.rscale = BBOX.rscale}
return hbox; return hbox;
@ -2061,7 +2063,7 @@
stack.appendChild(over); stack.appendChild(base); stack.appendChild(over); stack.appendChild(base);
} }
if (obox.D) obox.d = obox.D; if (obox.D) obox.d = obox.D;
if (obox.d < 0) { if (obox.d + CENTERLINE < 0) {
// //
// For negative depths, set the height and align to top // For negative depths, set the height and align to top
// in order to avoid extra baseline space // in order to avoid extra baseline space
@ -2112,7 +2114,7 @@
node.firstChild.lastChild.appendChild(under); node.firstChild.lastChild.appendChild(under);
} }
if (ubox.D) ubox.d = ubox.D; if (ubox.D) ubox.d = ubox.D;
if (ubox.d < 0) { if (ubox.d + CENTERLINE < 0) {
// //
// For negative depths, set the height and align to top // For negative depths, set the height and align to top
// in order to avoid extra baseline space // in order to avoid extra baseline space