From c9f50f77978d2e3232d94692f117937e90942362 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Sat, 22 Feb 2014 10:21:44 -0500 Subject: [PATCH 1/8] Add extra DIV to prevent Font_Test DIV from adding space to the page, even temporarily. --- unpacked/jax/output/HTML-CSS/jax.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/unpacked/jax/output/HTML-CSS/jax.js b/unpacked/jax/output/HTML-CSS/jax.js index 67c367fdb7..d3ad84c688 100644 --- a/unpacked/jax/output/HTML-CSS/jax.js +++ b/unpacked/jax/output/HTML-CSS/jax.js @@ -60,15 +60,22 @@ testSize: ["40px","50px","60px","30px","20px"], 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; }, From 0d2dc7fe272a447ded223fab64de4777503d7eb0 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Sat, 22 Feb 2014 14:25:10 -0500 Subject: [PATCH 2/8] Hack to allow new web fonts to be used locally. The naming of the new fonts should be changed to use the same name for both PC and Mac formats, but that is for a future release. Still need to test Linux. --- unpacked/jax/output/HTML-CSS/jax.js | 54 +++++++++++++++++------------ 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/unpacked/jax/output/HTML-CSS/jax.js b/unpacked/jax/output/HTML-CSS/jax.js index d3ad84c688..089d9d5015 100644 --- a/unpacked/jax/output/HTML-CSS/jax.js +++ b/unpacked/jax/output/HTML-CSS/jax.js @@ -38,24 +38,6 @@ 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"], @@ -88,7 +70,12 @@ return null; }, - 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"; + return this.testFont(font); + }, testFont: function (font) { if (font.isWebFont && HTMLCSS.FontFaceBug) { @@ -97,12 +84,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])) { @@ -763,8 +765,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) { From 4ea4816553cf794894b6aec9a710242a7ec19128 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Sat, 22 Feb 2014 14:30:52 -0500 Subject: [PATCH 3/8] Simplify handling of new web fonts when selected by menu. --- unpacked/jax/output/HTML-CSS/jax.js | 51 ++++++++++++++++++----------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/unpacked/jax/output/HTML-CSS/jax.js b/unpacked/jax/output/HTML-CSS/jax.js index 089d9d5015..2b9037ca94 100644 --- a/unpacked/jax/output/HTML-CSS/jax.js +++ b/unpacked/jax/output/HTML-CSS/jax.js @@ -350,27 +350,38 @@ 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"} - } - 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} + 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 = []; + 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} + } + 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"); @@ -460,6 +471,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]} From 36194fe36aa3f6f2d875fef0c163926486017fe4 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Sat, 22 Feb 2014 14:31:37 -0500 Subject: [PATCH 4/8] Add a new fonts parameter for HTML-CSS to simplify font configuration. --- unpacked/jax/output/HTML-CSS/jax.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/unpacked/jax/output/HTML-CSS/jax.js b/unpacked/jax/output/HTML-CSS/jax.js index 2b9037ca94..c9d95f8be7 100644 --- a/unpacked/jax/output/HTML-CSS/jax.js +++ b/unpacked/jax/output/HTML-CSS/jax.js @@ -370,7 +370,7 @@ if (this.adjustAvailableFonts) {this.adjustAvailableFonts(config.availableFonts)} if (settings.scale) {config.scale = settings.scale} if (font && font !== "Auto" && this.fontName[font]) { - config.availableFonts = []; + config.availableFonts = []; delete config.fonts; if (this.fontName[font] instanceof Array) { config.preferredFont = this.fontName[font][0]; config.webFont = this.fontName[font][1]; @@ -379,6 +379,11 @@ } if (config.preferredFont) {config.availableFonts[0] = config.preferredFont} } + 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} From ff8e0528063a195aabd4dbba865c06e581c92e5a Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Sat, 22 Feb 2014 14:57:14 -0500 Subject: [PATCH 5/8] Simplify font selection code for SVG output. --- unpacked/jax/output/SVG/jax.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/unpacked/jax/output/SVG/jax.js b/unpacked/jax/output/SVG/jax.js index 541f28f0a4..d3f320a8f7 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 = []} From 4d4db67ad0cf2714a6d39c8e7a603a25939cf225 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Mon, 3 Mar 2014 18:33:12 -0500 Subject: [PATCH 6/8] Make testCollection properly mark STIX fonts as not having the style characters, and fix testing for STIX or MathJax at beginning of font names. --- unpacked/jax/output/HTML-CSS/jax.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/unpacked/jax/output/HTML-CSS/jax.js b/unpacked/jax/output/HTML-CSS/jax.js index c9d95f8be7..8238d2fc9d 100644 --- a/unpacked/jax/output/HTML-CSS/jax.js +++ b/unpacked/jax/output/HTML-CSS/jax.js @@ -74,6 +74,7 @@ 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); }, @@ -92,7 +93,7 @@ // This should be removed when the web fonts are fixed. FIXME // var family = font.familyFixed || font.family; - if (!family.match(/$(STIX|MathJax)|'/)) { + 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"} From 81d9cce510adf75b65256bc2570c782c7c12ba71 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Mon, 3 Mar 2014 18:34:50 -0500 Subject: [PATCH 7/8] Work around stupid Fedora stix font package that incorrectly aliases all STIXGeneral fonts to STIX-Word fonts. Resolves issue #501. --- unpacked/jax/output/HTML-CSS/jax.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/unpacked/jax/output/HTML-CSS/jax.js b/unpacked/jax/output/HTML-CSS/jax.js index 8238d2fc9d..da00b16c84 100644 --- a/unpacked/jax/output/HTML-CSS/jax.js +++ b/unpacked/jax/output/HTML-CSS/jax.js @@ -40,6 +40,12 @@ timeout: (isMobile? 15:8)*1000, // timeout for loading web fonts 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 () { // @@ -62,12 +68,17 @@ }, 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) { From cfb40e91906d215fc00960e849664f5f81a06761 Mon Sep 17 00:00:00 2001 From: "Davide P. Cervone" Date: Wed, 5 Mar 2014 09:51:41 -0500 Subject: [PATCH 8/8] Add one more font name to check for new web fonts locally. --- unpacked/jax/output/HTML-CSS/jax.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/unpacked/jax/output/HTML-CSS/jax.js b/unpacked/jax/output/HTML-CSS/jax.js index da00b16c84..5cd53cbaae 100644 --- a/unpacked/jax/output/HTML-CSS/jax.js +++ b/unpacked/jax/output/HTML-CSS/jax.js @@ -105,7 +105,8 @@ // var family = font.familyFixed || font.family; if (!family.match(/^(STIX|MathJax)|'/)) { - family = family.replace(/_/g," ").replace(/([a-z])([A-Z])/g,"$1 $2") + "','" + family + "-"; + family = family.replace(/_/g," ").replace(/([a-z])([A-Z])/g,"$1 $2").replace(/ Jax/,"Jax") + + "','" + family + "','" + family + "-"; if (font.weight) {family += "Bold"}; if (font.style) {family += "Italic"} if (!font.weight && !font.style) {family += "Regular"} font.familyFixed = family = "'"+family+"'"