Make web font loop into an extension (first draft)
This commit is contained in:
parent
c9766d4da8
commit
2755cbd037
|
@ -1741,10 +1741,6 @@ MathJax.Hub = {
|
||||||
showMathMenuMSIE: true, // separtely determine if MSIE should have math menu
|
showMathMenuMSIE: true, // separtely determine if MSIE should have math menu
|
||||||
// (since the code for that is a bit delicate)
|
// (since the code for that is a bit delicate)
|
||||||
|
|
||||||
matchWebFonts: false, // true means look for web fonts that may cause changes in the
|
|
||||||
// scaling factors for the math (off by default since it
|
|
||||||
// uses a loop every time math is rendered).
|
|
||||||
|
|
||||||
menuSettings: {
|
menuSettings: {
|
||||||
zoom: "None", // when to do MathZoom
|
zoom: "None", // when to do MathZoom
|
||||||
CTRL: false, // require CTRL for MathZoom?
|
CTRL: false, // require CTRL for MathZoom?
|
||||||
|
|
|
@ -44,10 +44,6 @@ MathJax.OutputJax["HTML-CSS"] = MathJax.OutputJax({
|
||||||
undefinedFamily: "STIXGeneral,'Arial Unicode MS',serif", // fonts to use for unknown unicode characters
|
undefinedFamily: "STIXGeneral,'Arial Unicode MS',serif", // fonts to use for unknown unicode characters
|
||||||
mtextFontInherit: false, // to make <mtext> be in page font rather than MathJax font
|
mtextFontInherit: false, // to make <mtext> be in page font rather than MathJax font
|
||||||
|
|
||||||
fontCheckDelay: 500, // initial delay for the first check for web fonts
|
|
||||||
// (set to null to prevent the checks)
|
|
||||||
fontCheckTimeout: 15 * 1000, // how long to keep looking for font changes (15 seconds)
|
|
||||||
|
|
||||||
EqnChunk: (MathJax.Hub.Browser.isMobile ? 10: 50),
|
EqnChunk: (MathJax.Hub.Browser.isMobile ? 10: 50),
|
||||||
// number of equations to process before showing them
|
// number of equations to process before showing them
|
||||||
EqnChunkFactor: 1.5, // chunk size is multiplied by this after each chunk
|
EqnChunkFactor: 1.5, // chunk size is multiplied by this after each chunk
|
||||||
|
|
|
@ -627,16 +627,6 @@
|
||||||
|
|
||||||
postTranslate: function (state,partial) {
|
postTranslate: function (state,partial) {
|
||||||
var scripts = state.jax[this.id];
|
var scripts = state.jax[this.id];
|
||||||
if (!partial && HUB.config.matchWebFonts && this.config.matchFontHeight) {
|
|
||||||
//
|
|
||||||
// Check for changes in the web fonts that might affect the font
|
|
||||||
// size for math elements. This is a periodic check that goes on
|
|
||||||
// until a timeout is reached.
|
|
||||||
//
|
|
||||||
AJAX.timer.start(AJAX,["checkFonts",this,state.jax[this.id]],
|
|
||||||
this.config.fontCheckDelay,this.config.fontCheckTimeout);
|
|
||||||
|
|
||||||
}
|
|
||||||
if (!this.hideProcessedMath) return;
|
if (!this.hideProcessedMath) return;
|
||||||
//
|
//
|
||||||
// Reveal this chunk of math
|
// Reveal this chunk of math
|
||||||
|
@ -671,57 +661,6 @@
|
||||||
state.HTMLCSSlast = state.HTMLCSSeqn;
|
state.HTMLCSSlast = state.HTMLCSSeqn;
|
||||||
},
|
},
|
||||||
|
|
||||||
checkFonts: function (check,scripts) {
|
|
||||||
if (check.time(function () {})) return;
|
|
||||||
var size = [], i, m;
|
|
||||||
//
|
|
||||||
// Add the elements used for testing ex and em sizes
|
|
||||||
//
|
|
||||||
for (i = 0, m = scripts.length; i < m; i++) {
|
|
||||||
script = scripts[i];
|
|
||||||
if (script.parentNode && script.MathJax.elementJax) {
|
|
||||||
script.parentNode.insertBefore(this.EmExSpan.cloneNode(true),script);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// Check to see if anything has changed
|
|
||||||
//
|
|
||||||
for (i = 0, m = scripts.length; i < m; i++) {
|
|
||||||
script = scripts[i]; if (!script.parentNode) continue;
|
|
||||||
var jax = script.MathJax.elementJax; if (!jax) continue;
|
|
||||||
var span = document.getElementById(jax.inputID+"-Frame");
|
|
||||||
//
|
|
||||||
// Check if ex or mex has changed
|
|
||||||
//
|
|
||||||
var test = script.previousSibling, div = test.previousSibling;
|
|
||||||
var ex = test.firstChild.offsetHeight/60;
|
|
||||||
var em = test.lastChild.lastChild.offsetHeight/60;
|
|
||||||
if (ex === 0 || ex === "NaN") {ex = this.defaultEx; em = this.defaultEm}
|
|
||||||
if (ex !== jax.HTMLCSS.ex || em !== jax.HTMLCSS.em) {
|
|
||||||
var scale = ex/this.TeX.x_height/em;
|
|
||||||
scale = Math.floor(Math.max(this.config.minScaleAdjust/100,scale)*this.config.scale);
|
|
||||||
if (scale/100 !== jax.scale) {size.push(script); scripts[i] = {}}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// Remove markers
|
|
||||||
//
|
|
||||||
for (i = 0, m = scripts.length; i < m; i++) {
|
|
||||||
script = scripts[i];
|
|
||||||
if (script.parentNode && script.MathJax.elementJax) {
|
|
||||||
script.parentNode.removeChild(script.previousSibling);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// Rerender the changed items
|
|
||||||
//
|
|
||||||
if (size.length) {MathJax.Hub.Queue(["Rerender",MathJax.Hub,[size],{}])}
|
|
||||||
//
|
|
||||||
// Try again later
|
|
||||||
//
|
|
||||||
setTimeout(check,check.delay);
|
|
||||||
},
|
|
||||||
|
|
||||||
getJaxFromMath: function (math) {
|
getJaxFromMath: function (math) {
|
||||||
if (math.parentNode.className === "MathJax_Display") {math = math.parentNode}
|
if (math.parentNode.className === "MathJax_Display") {math = math.parentNode}
|
||||||
do {math = math.nextSibling} while (math && math.nodeName.toLowerCase() !== "script");
|
do {math = math.nextSibling} while (math && math.nodeName.toLowerCase() !== "script");
|
||||||
|
|
|
@ -37,10 +37,6 @@ MathJax.OutputJax.NativeMML = MathJax.OutputJax({
|
||||||
minScaleAdjust: 50, // minimum scaling to adjust to surrounding text
|
minScaleAdjust: 50, // minimum scaling to adjust to surrounding text
|
||||||
// (since the code for that is a bit delicate)
|
// (since the code for that is a bit delicate)
|
||||||
|
|
||||||
fontCheckDelay: 500, // initial delay for the first width check for web fonts
|
|
||||||
// (set to null to prevent the width checks)
|
|
||||||
fontCheckTimeout: 15 * 1000, // how long to keep looking for width changes (15 seconds)
|
|
||||||
|
|
||||||
styles: {
|
styles: {
|
||||||
"DIV.MathJax_MathML": {
|
"DIV.MathJax_MathML": {
|
||||||
"text-align": "center",
|
"text-align": "center",
|
||||||
|
|
|
@ -327,15 +327,6 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
postTranslate: function (state) {
|
postTranslate: function (state) {
|
||||||
if (!isMSIE && HUB.config.matchWebFonts) {
|
|
||||||
//
|
|
||||||
// Check for changes in the web fonts that might affect the sizes
|
|
||||||
// of math elements. This is a periodic check that goes on until
|
|
||||||
// a timeout is reached.
|
|
||||||
//
|
|
||||||
AJAX.timer.start(AJAX,["checkFonts",this,state.jax[this.id]],
|
|
||||||
this.config.fontCheckDelay,this.config.fontCheckTimeout);
|
|
||||||
}
|
|
||||||
if (this.forceReflow) {
|
if (this.forceReflow) {
|
||||||
//
|
//
|
||||||
// Firefox messes up some mtable's when they are dynamically created
|
// Firefox messes up some mtable's when they are dynamically created
|
||||||
|
@ -346,106 +337,6 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
//
|
|
||||||
// Check to see if web fonts have been loaded that change the ex size
|
|
||||||
// of the surrounding font, the ex size within the math, or the widths
|
|
||||||
// of math elements. We do this by rechecking the ex and mex sizes
|
|
||||||
// (to see if the font scaling needs adjusting) and by checking the
|
|
||||||
// size of the inner mrow of math elements and mtd elements. The
|
|
||||||
// sizes of these have been stored in the NativeMML object of the
|
|
||||||
// element jax so that we can check for them here.
|
|
||||||
//
|
|
||||||
checkFonts: function (check,scripts) {
|
|
||||||
if (check.time(function () {})) return;
|
|
||||||
var adjust = [], mtd = [], size = [], i, m, script;
|
|
||||||
//
|
|
||||||
// Add the elements used for testing ex and em sizes
|
|
||||||
//
|
|
||||||
for (i = 0, m = scripts.length; i < m; i++) {
|
|
||||||
script = scripts[i];
|
|
||||||
if (script.parentNode && script.MathJax.elementJax) {
|
|
||||||
script.parentNode.insertBefore(this.EmExSpan.cloneNode(true),script);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// Check to see if anything has changed
|
|
||||||
//
|
|
||||||
for (i = 0, m = scripts.length; i < m; i++) {
|
|
||||||
script = scripts[i]; if (!script.parentNode) continue;
|
|
||||||
var jax = script.MathJax.elementJax; if (!jax) continue;
|
|
||||||
var span = document.getElementById(jax.inputID+"-Frame");
|
|
||||||
var math = span.getElementsByTagName("math")[0]; if (!math) continue;
|
|
||||||
jax = jax.NativeMML;
|
|
||||||
//
|
|
||||||
// Check if ex or mex has changed
|
|
||||||
//
|
|
||||||
var test = script.previousSibling;
|
|
||||||
var ex = test.firstChild.offsetWidth/60;
|
|
||||||
var mex = test.lastChild.offsetWidth/60;
|
|
||||||
if (ex === 0 || ex === "NaN") {ex = this.defaultEx; mex = this.defaultMEx}
|
|
||||||
var newEx = (ex !== jax.ex);
|
|
||||||
if (newEx || mex != jax.mex) {
|
|
||||||
var scale = (this.config.matchFontHeight && mex > 1 ? ex/mex : 1);
|
|
||||||
scale = Math.floor(Math.max(this.config.minScaleAdjust/100,scale) * this.config.scale);
|
|
||||||
if (scale/100 !== jax.scale) {size.push([span.style,scale])}
|
|
||||||
jax.scale = scale/100; jax.fontScale = scale+"%"; jax.ex = ex; jax.mex = mex;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Check width of math elements
|
|
||||||
//
|
|
||||||
if ("scrollWidth" in jax && (newEx || jax.scrollWidth !== math.firstChild.scrollWidth)) {
|
|
||||||
jax.scrollWidth = math.firstChild.scrollWidth;
|
|
||||||
adjust.push([math.parentNode.style,jax.scrollWidth/jax.ex/jax.scale]);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// Check widths of mtd elements
|
|
||||||
//
|
|
||||||
if (math.MathJaxMtds) {
|
|
||||||
for (j = 0, n = math.MathJaxMtds.length; j < n; j++) {
|
|
||||||
if (!math.MathJaxMtds[j].parentNode) continue;
|
|
||||||
if (newEx || math.MathJaxMtds[j].firstChild.scrollWidth !== jax.mtds[j]) {
|
|
||||||
jax.mtds[j] = math.MathJaxMtds[j].firstChild.scrollWidth;
|
|
||||||
mtd.push([math.MathJaxMtds[j],jax.mtds[j]/jax.ex]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// Remove markers
|
|
||||||
//
|
|
||||||
for (i = 0, m = scripts.length; i < m; i++) {
|
|
||||||
script = scripts[i];
|
|
||||||
if (script.parentNode && script.MathJax.elementJax) {
|
|
||||||
script.parentNode.removeChild(script.previousSibling);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// Adjust scaling factor
|
|
||||||
//
|
|
||||||
for (i = 0, m = size.length; i < m; i++) {
|
|
||||||
size[i][0].fontSize = size[i][1] + "%";
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// Adjust width of spans containing math elements that have changed
|
|
||||||
//
|
|
||||||
for (i = 0, m = adjust.length; i < m; i++) {
|
|
||||||
adjust[i][0].width = adjust[i][1].toFixed(3)+"ex";
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// Adjust widths of mtd elements that have changed
|
|
||||||
//
|
|
||||||
for (i = 0, m = mtd.length; i < m; i++) {
|
|
||||||
var style = mtd[i][0].getAttribute("style");
|
|
||||||
style = style.replace(/(($|;)\s*min-width:).*?ex/,"$1 "+mtd[i][1].toFixed(3)+"ex");
|
|
||||||
mtd[i][0].setAttribute("style",style);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// Try again later
|
|
||||||
//
|
|
||||||
setTimeout(check,check.delay);
|
|
||||||
},
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Remove MathML preceeding the script
|
// Remove MathML preceeding the script
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in New Issue
Block a user