diff --git a/unpacked/jax/output/HTML-CSS/jax.js b/unpacked/jax/output/HTML-CSS/jax.js index 67c367fdb..da00b16c8 100644 --- a/unpacked/jax/output/HTML-CSS/jax.js +++ b/unpacked/jax/output/HTML-CSS/jax.js @@ -38,50 +38,56 @@ var FONTTEST = MathJax.Object.Subclass({ timeout: (isMobile? 15:8)*1000, // timeout for loading web fonts - - FontInfo: { - STIX: {family: "STIXSizeOneSym", testString: "() {} []"}, - TeX: {family: "MathJax_Size1", testString: "() {} []"}, - // - // These are the new web fonts. The strange use of single quotes is because the - // testing routine adds quotes at the beginning and ending, so for this list of - // names, we need to take those into account. We need a list because the names are - // not handled consistently between Mac and Windows in the font data, as they are - // in the TeX and original STIX fonts (sigh). - // - "STIX-Web": {family: "STIX MathJax Size1','STIXMathJax_Size1-Regular", testString: "() {} []"}, - "Asana-Math": {family: "Asana MathJax Size1','AsanaMathJax_Size1-Regular'", testString: "() {} []"}, - "Gyre-Pagella": {family: "Gyre Pagella MathJax Size1','GyrePagellaMathJax_Size1-Regular", testString: "() {} []"}, - "Gyre-Termes": {family: "Gyre Termes MathJax Size1','GyreTermesMathJax_Size1-Regular", testString: "() {} []"}, - "Latin-Modern": {family: "Latin Modern MathJax Size1','LatinModernMathJax_Size1-Regular", testString: "() {} []"}, - "Neo-Euler": {family: "Neo Euler MathJax Size1','NeoEulerMathJax_Size1-Regular", testString: "() {} []"} - }, comparisonFont: ["sans-serif","monospace","script","Times","Courier","Arial","Helvetica"], testSize: ["40px","50px","60px","30px","20px"], + // + // Fedora aliases STIXSizeOneSym to STIX Word, so MathJax thinks STIX is + // available, but the fonts aren't actually correct. This is to test if + // STIXSizeOneSym has letters in it (so is actually STIX Word). + // + FedoraSTIXcheck: {family:"STIXSizeOneSym", testString:"abcABC", noStyleChar:true}, Init: function () { - this.div = MathJax.HTML.addElement(document.body,"div",{ - id: "MathJax_Font_Test", - style: {position:"absolute", visibility:"hidden", top:0, left:0, width: "auto", - padding:0, border:0, margin:0, whiteSpace:"nowrap", - textAlign:"left", textIndent:0, textTransform:"none", - lineHeight:"normal", letterSpacing:"normal", wordSpacing:"normal", - fontSize:this.testSize[0], fontWeight:"normal", fontStyle:"normal", - fontSizeAdjust:"none"} - },[""]); + // + // Wrap the Font_Test DIV in a 0x0 DIV so that it takes no room + // + this.div = MathJax.HTML.addElement(document.body,"div",{style: { + position:"absolute", width:0, height:0, overflow:"hidden", + padding:0, border:0, margin:0 + }},[["div",{ + id: "MathJax_Font_Test", + style: {position:"absolute", visibility:"hidden", top:0, left:0, width: "auto", + padding:0, border:0, margin:0, whiteSpace:"nowrap", + textAlign:"left", textIndent:0, textTransform:"none", + lineHeight:"normal", letterSpacing:"normal", wordSpacing:"normal", + fontSize:this.testSize[0], fontWeight:"normal", fontStyle:"normal", + fontSizeAdjust:"none"} + },[""]]] + ).firstChild; this.text = this.div.firstChild; }, findFont: function (fonts,pref) { - if (pref && this.testCollection(pref)) {return pref} - for (var i = 0, m = fonts.length; i < m; i++) { - if (fonts[i] === pref) continue; - if (this.testCollection(fonts[i])) {return fonts[i]} + var found = null; + if (pref && this.testCollection(pref)) { + found = pref; + } else { + for (var i = 0, m = fonts.length; i < m; i++) { + if (fonts[i] === pref) continue; + if (this.testCollection(fonts[i])) {found = fonts[i]; break} + } } - return null; + if (found === "STIX" && this.testFont(this.FedoraSTIXcheck)) {found = null} + return found; }, - testCollection: function (name) {return this.testFont(this.FontInfo[name])}, + testCollection: function (name) { + var font = {testString: "() {} []"}; + font.family = {TeX:"MathJax_Size1", STIX:"STIXSizeOneSym"}[name] || + name.replace(/-(Math)?/,"")+"MathJax_Size1"; + if (name === "STIX") {font.noStyleChar = true} + return this.testFont(font); + }, testFont: function (font) { if (font.isWebFont && HTMLCSS.FontFaceBug) { @@ -90,12 +96,27 @@ this.div.style.fontWeight = (font.weight||"normal"); this.div.style.fontStyle = (font.style||"normal"); } + // + // Hack: Fix up web font names for local access. + // (The names for Windows and Mac are different, unlike in the STIX and + // TeX fonts, so we have to work out a list of names here.) + // + // This should be removed when the web fonts are fixed. FIXME + // + var family = font.familyFixed || font.family; + if (!family.match(/^(STIX|MathJax)|'/)) { + family = family.replace(/_/g," ").replace(/([a-z])([A-Z])/g,"$1 $2") + "','" + family + "-"; + if (font.weight) {family += "Bold"}; if (font.style) {family += "Italic"} + if (!font.weight && !font.style) {family += "Regular"} + font.familyFixed = family = "'"+family+"'" + } + var W = this.getComparisonWidths(font.testString,font.noStyleChar); var found = null; if (W) { - this.div.style.fontFamily = "'"+font.family+"',"+this.comparisonFont[0]; + this.div.style.fontFamily = family+","+this.comparisonFont[0]; if (this.div.offsetWidth == W[0]) { - this.div.style.fontFamily = "'"+font.family+"',"+this.comparisonFont[W[2]]; + this.div.style.fontFamily = family+","+this.comparisonFont[W[2]]; if (this.div.offsetWidth == W[1]) {found = false} } if (found === null && (this.div.offsetWidth != W[3] || this.div.offsetHeight != W[4])) { @@ -341,27 +362,43 @@ maxStretchyParts: 1000, // limit the number of parts allowed for // stretchy operators. See issue 366. + fontName: { + TeXLocal: "TeX", + TeXWeb: ["","TeX"], + TeXImage: ["",""], + STIXLocal: ["STIX","STIX-Web"], + STIXWeb: "STIX-Web", + AsanaMathWeb: "Asana-Math", + GyrePagellaWeb: "Gyre-Pagella", + GyreTermesWeb: "Gyre-Termes", + LatinModernWeb: "Latin-Modern", + NeoEulerWeb: "Neo-Euler" + }, + Config: function () { if (!this.require) {this.require = []} - this.Font = FONTTEST(); - this.SUPER(arguments).Config.call(this); var settings = this.settings; - if (this.adjustAvailableFonts) {this.adjustAvailableFonts(this.config.availableFonts)} - if (settings.scale) {this.config.scale = settings.scale} - if (settings.font && settings.font !== "Auto") { - if (settings.font === "TeXLocal") {this.config.availableFonts = ["TeX"]; this.config.preferredFont = "TeX"; this.config.webFont = "TeX"} - else if (settings.font === "TeXWeb") {this.config.availableFonts = []; this.config.preferredFont = ""; this.config.webFont = "TeX"} - else if (settings.font === "TeXimage") {this.config.availableFonts = []; this.config.preferredFont = ""; this.config.webFont = ""} - else if (settings.font === "STIXlocal") {this.config.availableFonts = ["STIX"]; this.config.preferredFont = "STIX"; this.config.webFont = "STIX-Web"} - else if (settings.font === "STIXWeb") {this.config.availableFonts = []; this.config.preferredFont = ""; this.config.webFont = "STIX-Web"} - else if (settings.font === "AsanaMathWeb") {this.config.availableFonts = []; this.config.preferredFont = ""; this.config.webFont = "Asana-Math"} - else if (settings.font === "GyrePagellaWeb") {this.config.availableFonts = []; this.config.preferredFont = ""; this.config.webFont = "Gyre-Pagella"} - else if (settings.font === "GyreTermesWeb") {this.config.availableFonts = []; this.config.preferredFont = ""; this.config.webFont = "Gyre-Termes"} - else if (settings.font === "LatinModernWeb") {this.config.availableFonts = []; this.config.preferredFont = ""; this.config.webFont = "Latin-Modern"} - else if (settings.font === "NeoEulerWeb") {this.config.availableFonts = []; this.config.preferredFont = ""; this.config.webFont = "Neo-Euler"} + this.Font = FONTTEST(); this.SUPER(arguments).Config.call(this); + var settings = this.settings, config = this.config, font = settings.font; + if (this.adjustAvailableFonts) {this.adjustAvailableFonts(config.availableFonts)} + if (settings.scale) {config.scale = settings.scale} + if (font && font !== "Auto" && this.fontName[font]) { + config.availableFonts = []; delete config.fonts; + if (this.fontName[font] instanceof Array) { + config.preferredFont = this.fontName[font][0]; + config.webFont = this.fontName[font][1]; + } else { + config.preferredFont = config.webFont = this.fontName[font]; + } + if (config.preferredFont) {config.availableFonts[0] = config.preferredFont} } - var font = this.Font.findFont(this.config.availableFonts,this.config.preferredFont); - if (!font && this.allowWebFonts) {font = this.config.webFont; if (font) {this.webFonts = true}} - if (!font && this.config.imageFont) {font = this.config.imageFont; this.imgFonts = true} + if (config.fonts) { + config.availableFonts = config.fonts; + config.preferredFont = config.webFont = config.fonts[0]; + if (config.webFont === "STIX") {config.webFont += "-Web"} + } + font = this.Font.findFont(config.availableFonts,config.preferredFont); + if (!font && this.allowWebFonts) {font = config.webFont; if (font) {this.webFonts = true}} + if (!font && this.config.imageFont) {font = config.imageFont; this.imgFonts = true} if (font) { this.fontInUse = font; this.fontDir += "/" + font; this.webfontDir += "/" + font; this.require.push(this.fontDir+"/fontdata.js"); @@ -451,6 +488,8 @@ // Safari/Windows doesn't display Plane1, // so disable STIX for these browsers. // + // ### FIXME ### Do we need to disable the other web fonts for these? + // for (var i = 0, m = fonts.length; i < m; i++) {if (fonts[i] === "STIX") {fonts.splice(i,1); m--; i--;}} if (this.config.preferredFont === "STIX") {this.config.preferredFont = fonts[0]} @@ -756,8 +795,14 @@ initHTML: function (math,span) {}, initFont: function (name) { var FONTS = HTMLCSS.FONTDATA.FONTS, AVAIL = HTMLCSS.config.availableFonts; - if (AVAIL && AVAIL.length && HTMLCSS.Font.testFont(FONTS[name])) - {FONTS[name].available = true; return null} + if (AVAIL && AVAIL.length && HTMLCSS.Font.testFont(FONTS[name])) { + FONTS[name].available = true; + if (FONTS[name].familyFixed) { + FONTS[name].family = FONTS[name].familyFixed; + delete FONTS[name].familyFixed; + } + return null; + } if (!this.allowWebFonts) {return null} FONTS[name].isWebFont = true; if (HTMLCSS.FontFaceBug) { diff --git a/unpacked/jax/output/SVG/jax.js b/unpacked/jax/output/SVG/jax.js index 541f28f0a..d3f320a8f 100644 --- a/unpacked/jax/output/SVG/jax.js +++ b/unpacked/jax/output/SVG/jax.js @@ -102,18 +102,15 @@ hideProcessedMath: true, // use display:none until all math is processed Config: function () { - var settings = HUB.config.menuSettings; - if (settings.scale) {this.config.scale = settings.scale} this.SUPER(arguments).Config.apply(this,arguments); - this.fontInUse = this.config.font; - if (settings.font && settings.font !== "Auto") { - if (settings.font === "TeXWeb") {this.fontInUse = "TeX"} - else if (settings.font === "STIXWeb") {this.fontInUse = "STIX-Web"} - else if (settings.font === "AsanaMathWeb") {this.fontInUse = "Asana-Math"} - else if (settings.font === "GyrePagellaWeb") {this.fontInUse = "Gyre-Pagella"} - else if (settings.font === "GyreTermesWeb") {this.fontInUse = "Gyre-Termes"} - else if (settings.font === "LatinModernWeb") {this.fontInUse = "Latin-Modern"} - else if (settings.font === "NeoEulerWeb") {this.fontInUse = "Neo-Euler"} + var settings = HUB.config.menuSettings, config = this.config, font = settings.font; + if (settings.scale) {config.scale = settings.scale} + if (font && font !== "Auto") { + font = font.replace(/(Local|Web|Image)$/i,""); + font = font.replace(/([a-z])([A-Z])/,"$1-$2"); + this.fontInUse = font; + } else { + this.fontInUse = config.font || "TeX"; } this.fontDir += "/" + this.fontInUse; if (!this.require) {this.require = []}