| 1 |
/* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */ |
| 2 |
/* vim: set ts=2 et sw=2 tw=80: */ |
| 3 |
|
| 4 |
/************************************************************* |
| 5 |
* |
| 6 |
* MathJax/jax/output/HTML-CSS/imageFonts.js |
| 7 |
* |
| 8 |
* Implements the image fallback fonts for the HTML-CSS OutputJax. |
| 9 |
* |
| 10 |
* --------------------------------------------------------------------- |
| 11 |
* |
| 12 |
* Copyright (c) 2009-2020 The MathJax Consortium |
| 13 |
* |
| 14 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 15 |
* you may not use this file except in compliance with the License. |
| 16 |
* You may obtain a copy of the License at |
| 17 |
* |
| 18 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 19 |
* |
| 20 |
* Unless required by applicable law or agreed to in writing, software |
| 21 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 22 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 23 |
* See the License for the specific language governing permissions and |
| 24 |
* limitations under the License. |
| 25 |
*/ |
| 26 |
|
| 27 |
(function (HUB,HTMLCSS,AJAX) { |
| 28 |
var VERSION = "2.7.9"; |
| 29 |
|
| 30 |
HUB.Register.LoadHook(HTMLCSS.fontDir + "/fontdata.js",function () { |
| 31 |
|
| 32 |
HTMLCSS.Augment({ |
| 33 |
allowWebFonts: false, |
| 34 |
|
| 35 |
imgDir: HTMLCSS.webfontDir+"/png", |
| 36 |
imgPacked: (MathJax.isPacked ? "" : "/unpacked"), |
| 37 |
imgSize: ['050','060','071','085',100,120,141,168,200,238,283,336,400,476], |
| 38 |
imgBaseIndex: 4, // set by initImg() |
| 39 |
imgSizeForEm: {}, // cache of indexes by em-size |
| 40 |
imgSizeForScale: {}, // cache of indexes by scale for a given em-size |
| 41 |
imgZoom: 1, // set by initImg for each equation |
| 42 |
|
| 43 |
handleImg: function (span,font,c,n,text) { |
| 44 |
if (text.length) {this.addText(span,text)} |
| 45 |
var orig = c[5].orig; if (!orig) {orig = c[5].orig = [c[0],c[1],c[2],c[3],c[4]]} |
| 46 |
var bscale = this.imgZoom; if (!span.scale) {span.scale = 1} |
| 47 |
var index = this.imgIndex(span.scale*bscale); |
| 48 |
if (index == this.imgEmWidth.length-1 && |
| 49 |
this.em*span.scale*bscale/this.imgEmWidth[index] > 1.1) |
| 50 |
{bscale = this.imgEmWidth[index]/(this.em*span.scale)} |
| 51 |
var factor = this.imgEmWidth[index]/(this.em*(span.scale||1)*bscale); |
| 52 |
c[0] = orig[0]*factor; c[1] = orig[1]*factor; c[2] = orig[2]*factor; |
| 53 |
c[3] = orig[3]*factor; c[4] = orig[4]*factor; |
| 54 |
var dir = this.imgDir+"/"+font.directory+"/"+this.imgSize[index]; |
| 55 |
var chr = n.toString(16).toUpperCase(); while (chr.length < 4) {chr = "0"+chr}; |
| 56 |
var file = dir+"/"+chr+".png"; |
| 57 |
var img = c[5].img[index]; |
| 58 |
var style = {width:Math.floor(img[0]/bscale+.5)+"px", height:Math.floor(img[1]/bscale+.5)+"px"}; |
| 59 |
if (img[2]) {style.verticalAlign = Math.floor(-img[2]/bscale+.5)+"px"} |
| 60 |
if (c[3] < 0) {style.marginLeft = this.Em(c[3]/1000)} |
| 61 |
if (c[4] != c[2]) {style.marginRight = this.Em((c[2]-c[4])/1000)} |
| 62 |
if (this.msieIE6) { |
| 63 |
style.filter = "progid:DXImageTransform.Microsoft." + |
| 64 |
"AlphaImageLoader(src='"+AJAX.urlRev(file)+"', sizingMethod='scale')"; |
| 65 |
file = this.directory+"/blank.gif" |
| 66 |
} |
| 67 |
this.addElement(span,"img",{src:AJAX.urlRev(file), style:style, isMathJax:true}); |
| 68 |
return ""; |
| 69 |
}, |
| 70 |
|
| 71 |
defineImageData: function (def) { |
| 72 |
for (var font in def) {if (def.hasOwnProperty(font)) { |
| 73 |
var FONT = HTMLCSS.FONTDATA.FONTS[font]; |
| 74 |
if (FONT) { |
| 75 |
font = def[font]; |
| 76 |
for (var n in font) {if (font.hasOwnProperty(n) && FONT[n]) {FONT[n][5] = {img: font[n]}}} |
| 77 |
} |
| 78 |
}} |
| 79 |
}, |
| 80 |
|
| 81 |
initImg: function (span) { |
| 82 |
if (this.imgSizeForEm[this.em]) {this.imgBaseIndex = this.imgSizeForEm[this.em]} |
| 83 |
for (var i = 0, m = this.imgEmWidth.length-1; i < m; i++) |
| 84 |
{if (this.em <= this.imgEmWidth[i]) break} |
| 85 |
if (i && this.imgEmWidth[i] - this.em > this.em - this.imgEmWidth[i-1]) {i--} |
| 86 |
this.imgSizeForEm[this.em] = this.imgBaseIndex = i; |
| 87 |
this.imgZoom = this.imgBrowserZoom(); |
| 88 |
}, |
| 89 |
|
| 90 |
imgIndex: function (scale) { |
| 91 |
if (!scale) {return this.imgBaseIndex} |
| 92 |
if (!this.imgSizeForScale[this.em]) {this.imgSizeForScale[this.em] = {}} |
| 93 |
if (this.imgSizeForScale[this.em][scale]) {return this.imgSizeForScale[this.em][scale]} |
| 94 |
var em = this.em * scale; |
| 95 |
for (var i = 0, m = this.imgEmWidth.length-1; i < m; i++) |
| 96 |
{if (em <= this.imgEmWidth[i]) break} |
| 97 |
if (i && this.imgEmWidth[i] - em > em - this.imgEmWidth[i-1]) {i--} |
| 98 |
this.imgSizeForScale[this.em][scale] = i; |
| 99 |
return i; |
| 100 |
}, |
| 101 |
|
| 102 |
imgBrowserZoom: function () {return 1} |
| 103 |
|
| 104 |
}); |
| 105 |
|
| 106 |
HUB.Browser.Select({ |
| 107 |
|
| 108 |
Firefox: function (browser) { |
| 109 |
var ZDIV = HTMLCSS.addElement(document.body,"div",{ |
| 110 |
style: { |
| 111 |
display:"none", visibility:"hidden", overflow:"scroll", |
| 112 |
position:"absolute", top:0, left: 0, width:"200px", height:"200px", |
| 113 |
padding:0, border:0, margin:0 |
| 114 |
} |
| 115 |
}); |
| 116 |
|
| 117 |
var ZFRAME = HTMLCSS.addElement(ZDIV,"div",{ |
| 118 |
style: { |
| 119 |
position:"absolute", left:0, top:0, right:0, bottom:0, |
| 120 |
padding:0, border:0, margin:0 |
| 121 |
} |
| 122 |
}); |
| 123 |
|
| 124 |
HTMLCSS.Augment({ |
| 125 |
imgSpaceBug: true, |
| 126 |
imgSpace: "\u00A0", |
| 127 |
|
| 128 |
imgZoomLevel: (browser.isMac ? |
| 129 |
{50:.3, 30:.5, 22:.67, 19:.8, 16:.9, 15:1, 13:1.1, 12:1.2, |
| 130 |
11:1.33, 10:1.5, 9:1.7, 7:2, 6:2.4, 5:3, 0:15} : |
| 131 |
{56:.3, 34:.5, 25:.67, 21:.8, 19:.9, 17:1, 15:1.1, 14:1.2, |
| 132 |
13:1.33, 11:1.5, 10:1.7, 8:2, 7:2.4, 6:3, 0:17} |
| 133 |
), |
| 134 |
|
| 135 |
imgZoomDiv: ZDIV, |
| 136 |
|
| 137 |
imgBrowserZoom: function () { |
| 138 |
var size = this.imgZoomLevel; |
| 139 |
ZDIV.style.display = ""; |
| 140 |
var ratio = (ZDIV.offsetWidth-ZFRAME.offsetWidth); |
| 141 |
ratio = (size[ratio] ? size[ratio] : size[0]/ratio); |
| 142 |
ZDIV.style.display = "none"; |
| 143 |
return ratio; |
| 144 |
} |
| 145 |
}); |
| 146 |
}, |
| 147 |
|
| 148 |
Safari: function (browser) { |
| 149 |
// for iPhone and iTouch |
| 150 |
// var webkit = (navigator.appVersion+"AppleWebKit/530").match(/AppleWebKit\/(\d+)/)[1]; |
| 151 |
HTMLCSS.Augment({ |
| 152 |
// imgHeightBug: (!browser.isMac || webkit > 525), |
| 153 |
// imgDepthBug: (!browser.isMac || webkit > 525), |
| 154 |
imgBrowserZoom: function () {return 3} |
| 155 |
}); |
| 156 |
}, |
| 157 |
|
| 158 |
Chrome: function (browser) { |
| 159 |
HTMLCSS.Augment({ |
| 160 |
imgHeightBug: true, |
| 161 |
imgBrowserZoom: function () {return 3} |
| 162 |
}); |
| 163 |
}, |
| 164 |
|
| 165 |
Opera: function (browser) { |
| 166 |
HTMLCSS.Augment({ |
| 167 |
imgSpaceBug: true, |
| 168 |
imgSpace: "\u00A0\u00A0", |
| 169 |
|
| 170 |
imgDoc: (document.compatMode == "BackCompat" ? document.body : |
| 171 |
document.documentElement), |
| 172 |
|
| 173 |
imgBrowserZoom: function () { |
| 174 |
if (browser.isMac) {return 3} // Mac Opera scales very nicely |
| 175 |
var H = this.imgDoc.clientHeight, d = Math.floor(15*H/window.innerHeight); |
| 176 |
if (this.imgDoc.clientWidth < this.imgDoc.scrollWidth-d) {H += d} |
| 177 |
return parseFloat((window.innerHeight/H).toFixed(1)); |
| 178 |
} |
| 179 |
}); |
| 180 |
} |
| 181 |
}); |
| 182 |
|
| 183 |
var GETWIDTHS = function () { |
| 184 |
var img = HTMLCSS.FONTDATA.FONTS["MathJax_Main"][0x2014][5].img; // em-dash |
| 185 |
HTMLCSS.imgEmWidth = []; |
| 186 |
for (var i = 0, m = img.length; i < m; i++) {HTMLCSS.imgEmWidth[i] = img[i][0]} |
| 187 |
}; |
| 188 |
|
| 189 |
var IMGDIR = HTMLCSS.imgDir + HTMLCSS.imgPacked; |
| 190 |
|
| 191 |
MathJax.Callback.Queue( |
| 192 |
["Require",AJAX,IMGDIR+"/imagedata.js"], |
| 193 |
GETWIDTHS, |
| 194 |
["loadComplete",AJAX,HTMLCSS.directory+"/imageFonts.js"] |
| 195 |
); |
| 196 |
|
| 197 |
}); |
| 198 |
|
| 199 |
})(MathJax.Hub,MathJax.OutputJax["HTML-CSS"],MathJax.Ajax); |