Add separate (shorter) timeout for web fonts, and after first web font fails, give up on web fonts and use image fonts instead (if available)
git-svn-id: https://mathjax.svn.sourceforge.net/svnroot/mathjax/trunk@607 b8fd5906-0fad-46e2-a0d3-10d94ff285d1
This commit is contained in:
parent
d0800c8c3c
commit
81a1413d19
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -29,7 +29,7 @@ if (document.getElementById && document.childNodes && document.createElement) {
|
||||||
if (!window.MathJax) {window.MathJax= {}}
|
if (!window.MathJax) {window.MathJax= {}}
|
||||||
if (!MathJax.Hub) { // skip if already loaded
|
if (!MathJax.Hub) { // skip if already loaded
|
||||||
|
|
||||||
MathJax.version = "1.0.3";
|
MathJax.version = "1.0.4";
|
||||||
|
|
||||||
/**********************************************************/
|
/**********************************************************/
|
||||||
|
|
||||||
|
@ -723,10 +723,10 @@ MathJax.version = "1.0.3";
|
||||||
//
|
//
|
||||||
// Start the timer for the given callback checker
|
// Start the timer for the given callback checker
|
||||||
//
|
//
|
||||||
start: function (AJAX,check,delay) {
|
start: function (AJAX,check,delay,timeout) {
|
||||||
check = BASE.Callback(check);
|
check = BASE.Callback(check);
|
||||||
check.execute = this.execute; check.time = this.time;
|
check.execute = this.execute; check.time = this.time;
|
||||||
check.STATUS = AJAX.STATUS; check.timeout = AJAX.timeout;
|
check.STATUS = AJAX.STATUS; check.timeout = timeout || AJAX.timeout;
|
||||||
check.delay = check.total = 0;
|
check.delay = check.total = 0;
|
||||||
setTimeout(check,delay);
|
setTimeout(check,delay);
|
||||||
},
|
},
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function (HTMLCSS,MML,AJAX) {
|
(function (HTMLCSS,MML,AJAX) {
|
||||||
var VERSION = "1.0";
|
var VERSION = "1.0.1";
|
||||||
|
|
||||||
var MAIN = "MathJax_Main",
|
var MAIN = "MathJax_Main",
|
||||||
BOLD = "MathJax_Main-bold",
|
BOLD = "MathJax_Main-bold",
|
||||||
|
@ -406,8 +406,8 @@
|
||||||
// Handle error with reversed glyphs for \bigcap and \bigcup in version 1 of fonts
|
// Handle error with reversed glyphs for \bigcap and \bigcup in version 1 of fonts
|
||||||
//
|
//
|
||||||
HTMLCSS.Font.oldLoadComplete = HTMLCSS.Font.loadComplete;
|
HTMLCSS.Font.oldLoadComplete = HTMLCSS.Font.loadComplete;
|
||||||
HTMLCSS.Font.loadComplete = function (font,n,status) {
|
HTMLCSS.Font.loadComplete = function (font,n,done,status) {
|
||||||
if (n != null) {this.oldLoadComplete(font,n,status)}
|
if (n != null) {this.oldLoadComplete(font,n,done,status)}
|
||||||
if (font.family === SIZE1 || font.family === SIZE2) {
|
if (font.family === SIZE1 || font.family === SIZE2) {
|
||||||
if (font.version === 1) {
|
if (font.version === 1) {
|
||||||
HTMLCSS.FONTDATA.VARIANT["-largeOp"].remap = {0x22C2: 0x22C3, 0x22C3: 0x22C2};
|
HTMLCSS.FONTDATA.VARIANT["-largeOp"].remap = {0x22C2: 0x22C3, 0x22C3: 0x22C2};
|
||||||
|
|
|
@ -26,6 +26,8 @@
|
||||||
(function (MML,AJAX,HUB,HTMLCSS) {
|
(function (MML,AJAX,HUB,HTMLCSS) {
|
||||||
|
|
||||||
var FONTTEST = MathJax.Object.Subclass({
|
var FONTTEST = MathJax.Object.Subclass({
|
||||||
|
timeout: 5*1000, // timeout for loading web fonts
|
||||||
|
|
||||||
FontInfo: {
|
FontInfo: {
|
||||||
STIX: {family: "STIXSizeOneSym", testString: "() {} []"},
|
STIX: {family: "STIXSizeOneSym", testString: "() {} []"},
|
||||||
TeX: {family: "MathJax_Size1", testString: "() {} []"}
|
TeX: {family: "MathJax_Size1", testString: "() {} []"}
|
||||||
|
@ -126,12 +128,14 @@
|
||||||
loadWebFont: function (font) {
|
loadWebFont: function (font) {
|
||||||
HUB.Startup.signal.Post("HTML-CSS Jax - Web-Font "+HTMLCSS.fontInUse+"/"+font.directory);
|
HUB.Startup.signal.Post("HTML-CSS Jax - Web-Font "+HTMLCSS.fontInUse+"/"+font.directory);
|
||||||
var n = MathJax.Message.File("Web-Font "+HTMLCSS.fontInUse+"/"+font.directory);
|
var n = MathJax.Message.File("Web-Font "+HTMLCSS.fontInUse+"/"+font.directory);
|
||||||
var callback = MathJax.Callback(["loadComplete",this,font,n]);
|
var done = MathJax.Callback({}); // called when font is loaded
|
||||||
AJAX.timer.start(AJAX,[this.checkWebFont,font,callback],1);
|
var callback = MathJax.Callback(["loadComplete",this,font,n,done]);
|
||||||
return callback;
|
AJAX.timer.start(AJAX,[this.checkWebFont,font,callback],1,this.timeout);
|
||||||
|
return done;
|
||||||
},
|
},
|
||||||
loadComplete: function (font,n,status) {
|
loadComplete: function (font,n,done,status) {
|
||||||
if (status !== AJAX.STATUS.OK) {
|
MathJax.Message.Clear(n);
|
||||||
|
if (status === AJAX.STATUS.OK) {done(); return}
|
||||||
this.loadError(font);
|
this.loadError(font);
|
||||||
if (HUB.Browser.isFirefox && HTMLCSS.allowWebFonts) {
|
if (HUB.Browser.isFirefox && HTMLCSS.allowWebFonts) {
|
||||||
var host = document.location.protocol + "//" + document.location.hostname;
|
var host = document.location.protocol + "//" + document.location.hostname;
|
||||||
|
@ -140,8 +144,7 @@
|
||||||
if (AJAX.fileURL(HTMLCSS.webfontDir).substr(0,host.length) !== host)
|
if (AJAX.fileURL(HTMLCSS.webfontDir).substr(0,host.length) !== host)
|
||||||
{this.firefoxFontError(font)}
|
{this.firefoxFontError(font)}
|
||||||
}
|
}
|
||||||
}
|
HTMLCSS.loadWebFontError(font,done);
|
||||||
MathJax.Message.Clear(n);
|
|
||||||
},
|
},
|
||||||
loadError: function (font) {
|
loadError: function (font) {
|
||||||
MathJax.Message.Set("Can't load web font "+HTMLCSS.fontInUse+"/"+font.directory,null,2000);
|
MathJax.Message.Set("Can't load web font "+HTMLCSS.fontInUse+"/"+font.directory,null,2000);
|
||||||
|
@ -1050,6 +1053,24 @@
|
||||||
if (HTMLCSS.FontFaceBug) {font.family = font.name}
|
if (HTMLCSS.FontFaceBug) {font.family = font.name}
|
||||||
HUB.RestartAfter(this.Font.loadWebFont(font));
|
HUB.RestartAfter(this.Font.loadWebFont(font));
|
||||||
},
|
},
|
||||||
|
loadWebFontError: function (font,done) {
|
||||||
|
//
|
||||||
|
// After the first web font fails to load, switch to image fonts, if possible
|
||||||
|
// otherwise, give up on web fonts all together
|
||||||
|
//
|
||||||
|
HUB.Startup.signal.Post("HTML-CSS Jax - disable web fonts");
|
||||||
|
font.isWebFont = false;
|
||||||
|
if (this.config.imageFont && this.config.imageFont === this.fontInUse) {
|
||||||
|
this.imgFonts = true;
|
||||||
|
HUB.Startup.signal.Post("HTML-CSS Jax - switch to image fonts");
|
||||||
|
HUB.Startup.signal.Post("HTML-CSS Jax - using image fonts");
|
||||||
|
MathJax.Message.Set("Web-Fonts not available -- using image fonts instead",null,3000);
|
||||||
|
AJAX.Require(this.directory+"/imageFonts.js",done);
|
||||||
|
} else {
|
||||||
|
this.allowWebFonts = false;
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
Element: MathJax.HTML.Element,
|
Element: MathJax.HTML.Element,
|
||||||
addElement: MathJax.HTML.addElement,
|
addElement: MathJax.HTML.addElement,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user