mirror of
https://github.com/OpenXE-org/OpenXE.git
synced 2024-12-26 14:40:29 +01:00
20 lines
5.3 KiB
JavaScript
20 lines
5.3 KiB
JavaScript
/*
|
|
* /MathJax/extensions/MatchWebFonts.js
|
|
*
|
|
* Copyright (c) 2009-2013 The MathJax Consortium
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
(function(c,b){var e="2.3";var a=MathJax.Hub.CombineConfig("MatchWebFonts",{matchFor:{"HTML-CSS":true,NativeMML:true,SVG:true},fontCheckDelay:500,fontCheckTimeout:15*1000,});var d=MathJax.Extension.MatchWebFonts={version:e,config:a};c.Register.StartupHook("HTML-CSS Jax Ready",function(){var f=MathJax.OutputJax["HTML-CSS"];var g=f.postTranslate;f.Augment({postTranslate:function(i,h){if(!h&&a.matchFor["HTML-CSS"]&&this.config.matchFontHeight){b.timer.start(b,["checkFonts",this,i.jax[this.id]],a.fontCheckDelay,a.fontCheckTimeout)}return g.apply(this,arguments)},checkFonts:function(o,r){if(o.time(function(){})){return}var w=[],s,p,h=false;for(s=0,p=r.length;s<p;s++){script=r[s];if(script.parentNode&&script.MathJax.elementJax){script.parentNode.insertBefore(this.EmExSpan.cloneNode(true),script)}}for(s=0,p=r.length;s<p;s++){script=r[s];if(!script.parentNode){continue}h=true;var k=script.MathJax.elementJax;if(!k){continue}var v=document.getElementById(k.inputID+"-Frame");var u=script.previousSibling;var t=u.firstChild.offsetHeight/60;var l=u.lastChild.lastChild.offsetHeight/60;if(t===0||t==="NaN"){t=this.defaultEx;l=this.defaultEm}if(t!==k.HTMLCSS.ex||l!==k.HTMLCSS.em){var q=t/this.TeX.x_height/l;q=Math.floor(Math.max(this.config.minScaleAdjust/100,q)*this.config.scale);if(q/100!==k.scale){w.push(script);r[s]={}}}}for(s=0,p=r.length;s<p;s++){script=r[s];if(script.parentNode&&script.MathJax.elementJax){script.parentNode.removeChild(script.previousSibling)}}if(w.length){c.Queue(["Rerender",c,[w],{}])}if(h){setTimeout(o,o.delay)}}})});c.Register.StartupHook("SVG Jax Ready",function(){var g=MathJax.OutputJax.SVG;var f=g.postTranslate;g.Augment({postTranslate:function(i,h){if(!h&&a.matchFor.SVG){b.timer.start(b,["checkFonts",this,i.jax[this.id]],a.fontCheckDelay,a.fontCheckTimeout)}return f.apply(this,arguments)},checkFonts:function(l,p){if(l.time(function(){})){return}var u=[],q,o,h=false;for(q=0,o=p.length;q<o;q++){script=p[q];if(script.parentNode&&script.MathJax.elementJax){script.parentNode.insertBefore(this.ExSpan.cloneNode(true),script)}}for(q=0,o=p.length;q<o;q++){script=p[q];if(!script.parentNode){continue}h=true;var k=script.MathJax.elementJax;if(!k){continue}var t=document.getElementById(k.inputID+"-Frame");var s=script.previousSibling;var r=s.firstChild.offsetHeight/60;if(r===0||r==="NaN"){r=this.defaultEx;em=this.defaultEm}if(r!==k.SVG.ex){u.push(script);p[q]={}}}for(q=0,o=p.length;q<o;q++){script=p[q];if(script.parentNode&&script.MathJax.elementJax){script.parentNode.removeChild(script.previousSibling)}}if(u.length){c.Queue(["Rerender",c,[u],{}])}if(h){setTimeout(l,l.delay)}}})});c.Register.StartupHook("NativeMML Jax Ready",function(){var f=MathJax.OutputJax.NativeMML;var g=f.postTranslate;f.Augment({postTranslate:function(h){if(!c.Browser.isMSIE&&a.matchFor.NativeMML){b.timer.start(b,["checkFonts",this,h.jax[this.id]],a.fontCheckDelay,a.fontCheckTimeout)}g.apply(this,arguments)},checkFonts:function(l,r){if(l.time(function(){})){return}var z=[],B=[],A=[],s,o,w;for(s=0,o=r.length;s<o;s++){w=r[s];if(w.parentNode&&w.MathJax.elementJax){w.parentNode.insertBefore(this.EmExSpan.cloneNode(true),w)}}for(s=0,o=r.length;s<o;s++){w=r[s];if(!w.parentNode){continue}var k=w.MathJax.elementJax;if(!k){continue}var y=document.getElementById(k.inputID+"-Frame");var x=y.getElementsByTagName("math")[0];if(!x){continue}k=k.NativeMML;var u=w.previousSibling;var t=u.firstChild.offsetWidth/60;var q=u.lastChild.offsetWidth/60;if(t===0||t==="NaN"){t=this.defaultEx;q=this.defaultMEx}var v=(t!==k.ex);if(v||q!=k.mex){var p=(this.config.matchFontHeight&&q>1?t/q:1);p=Math.floor(Math.max(this.config.minScaleAdjust/100,p)*this.config.scale);if(p/100!==k.scale){A.push([y.style,p])}k.scale=p/100;k.fontScale=p+"%";k.ex=t;k.mex=q}if("scrollWidth" in k&&(v||k.scrollWidth!==x.firstChild.scrollWidth)){k.scrollWidth=x.firstChild.scrollWidth;z.push([x.parentNode.style,k.scrollWidth/k.ex/k.scale])}if(x.MathJaxMtds){for(j=0,n=x.MathJaxMtds.length;j<n;j++){if(!x.MathJaxMtds[j].parentNode){continue}if(v||x.MathJaxMtds[j].firstChild.scrollWidth!==k.mtds[j]){k.mtds[j]=x.MathJaxMtds[j].firstChild.scrollWidth;B.push([x.MathJaxMtds[j],k.mtds[j]/k.ex])}}}}for(s=0,o=r.length;s<o;s++){w=r[s];if(w.parentNode&&w.MathJax.elementJax){w.parentNode.removeChild(w.previousSibling)}}for(s=0,o=A.length;s<o;s++){A[s][0].fontSize=A[s][1]+"%"}for(s=0,o=z.length;s<o;s++){z[s][0].width=z[s][1].toFixed(3)+"ex"}for(s=0,o=B.length;s<o;s++){var h=B[s][0].getAttribute("style");h=h.replace(/(($|;)\s*min-width:).*?ex/,"$1 "+B[s][1].toFixed(3)+"ex");B[s][0].setAttribute("style",h)}setTimeout(l,l.delay)}})});c.Startup.signal.Post("MathWebFont Extension Ready");b.loadComplete("[MathJax]/extensions/MatchWebFonts.js")})(MathJax.Hub,MathJax.Ajax);
|