Add config option for matching font heights in NativeMML and HTML-CSS output (can't do it for SVG, since we aren't using native fonts)

This commit is contained in:
Davide P. Cervone 2013-09-29 08:51:49 -04:00
parent bbf543a840
commit c05ab62ecc
4 changed files with 10 additions and 6 deletions

View File

@ -35,6 +35,7 @@ MathJax.OutputJax["HTML-CSS"] = MathJax.OutputJax({
webfontDir: MathJax.OutputJax.fontDir + "/HTML-CSS", // font name added later
config: {
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
preferredFont: "TeX", // preferred local font (TeX or STIX)

View File

@ -534,7 +534,8 @@
ex = this.defaultEx; em = this.defaultEm;
if (relwidth) {maxwidth = this.defaultWidth}
}
scale = Math.floor(Math.max(this.config.minScaleAdjust/100,(ex/this.TeX.x_height)/em) * this.config.scale);
scale = (this.config.matchFontHeight ? ex/this.TeX.x_height/em : 1);
scale = Math.floor(Math.max(this.config.minScaleAdjust/100,scale)*this.config.scale);
jax.HTMLCSS.scale = scale/100; jax.HTMLCSS.fontSize = scale+"%";
jax.HTMLCSS.em = jax.HTMLCSS.outerEm = em; this.em = em * scale/100; jax.HTMLCSS.ex = ex;
jax.HTMLCSS.lineWidth = (linebreak ? this.length2em(width,1,maxwidth/this.em) : 1000000);
@ -584,7 +585,7 @@
this.em = MML.mbase.prototype.em = jax.HTMLCSS.em * jax.HTMLCSS.scale;
this.outerEm = jax.HTMLCSS.em; this.scale = jax.HTMLCSS.scale;
this.linebreakWidth = jax.HTMLCSS.lineWidth;
span.style.fontSize = jax.HTMLCSS.fontSize;
if (this.scale !== 1) {span.style.fontSize = jax.HTMLCSS.fontSize}
//
// Typeset the math
//

View File

@ -32,6 +32,7 @@ MathJax.OutputJax.NativeMML = MathJax.OutputJax({
extensionDir: MathJax.OutputJax.extensionDir + "/NativeMML",
config: {
matchFontHeight: true, // try to match math font height to surrounding font?
scale: 100, // scaling factor for all math
minScaleAdjust: 50, // minimum scaling to adjust to surrounding text
// (since the code for that is a bit delicate)

View File

@ -257,11 +257,12 @@
ex = test.firstChild.offsetWidth/60;
mex = test.lastChild.offsetWidth/60;
if (ex === 0 || ex === "NaN") {ex = this.defaultEx; mex = this.defaultMEx}
scale = (mex > 1 ? ex/mex : 1) * this.config.scale;
scale = Math.floor(Math.max(this.config.minScaleAdjust/100,scale));
jax.NativeMML.ex = ex; jax.NativeMML.scale = scale/100;
scale = (this.config.matchFontHeight && mex > 1 ? ex/mex : 1);
scale = Math.floor(Math.max(this.config.minScaleAdjust/100,scale) * this.config.scale);
jax.NativeMML.ex = ex;
} else {scale = 100}
jax.NativeMML.fontSize = scale+"%";
jax.NativeMML.scale = scale/100;
}
//
// Remove the test spans used for determining scales
@ -286,9 +287,9 @@
var jax = script.MathJax.elementJax, math = jax.root;
var span = document.getElementById(jax.inputID+"-Frame"),
container = span.firstChild, mspan = container.firstChild;
span.style.fontSize = jax.NativeMML.fontSize;
this.ex = jax.NativeMML.ex || this.defaultEx;
this.scale = jax.NativeMML.scale || 1;
if (this.scale !== 1) {span.style.fontSize = jax.NativeMML.fontSize}
//
// Convert to MathML (if restarted, remove any partial math)
//