Cache measurements of unknown characters so they don't have to be remeasured later.
This commit is contained in:
parent
563dd09fa7
commit
c58b546ad7
|
@ -69,6 +69,13 @@
|
||||||
"MathJax_Typewriter": "Typewriter/Regular/Main.js",
|
"MathJax_Typewriter": "Typewriter/Regular/Main.js",
|
||||||
"MathJax_Caligraphic-bold": "Caligraphic/Bold/Main.js"
|
"MathJax_Caligraphic-bold": "Caligraphic/Bold/Main.js"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
UNKNOWN: {
|
||||||
|
R: {className:"MJXc-TeX-unknown-R"},
|
||||||
|
I: {className:"MJXc-TeX-unknown-I"},
|
||||||
|
B: {className:"MJXc-TeX-unknown-B"},
|
||||||
|
BI: {className:"MJXc-TeX-unknown-BI"}
|
||||||
|
},
|
||||||
|
|
||||||
VARIANT: {
|
VARIANT: {
|
||||||
"normal": {fonts:[MAIN,SIZE1,AMS], cache: {},
|
"normal": {fonts:[MAIN,SIZE1,AMS], cache: {},
|
||||||
|
|
|
@ -104,13 +104,16 @@
|
||||||
".MJXc-space2": {"margin-left":".222em"},
|
".MJXc-space2": {"margin-left":".222em"},
|
||||||
".MJXc-space3": {"margin-left":".278em"},
|
".MJXc-space3": {"margin-left":".278em"},
|
||||||
|
|
||||||
".MJXc-TeX-unknown": {"font-family":UNKNOWNFAMILY},
|
".MJXc-TeX-unknown-R": {"font-family":UNKNOWNFAMILY, "font-style":"normal", "font-weight":"normal"},
|
||||||
|
".MJXc-TeX-unknown-I": {"font-family":UNKNOWNFAMILY, "font-style":"italic", "font-weight":"normal"},
|
||||||
|
".MJXc-TeX-unknown-B": {"font-family":UNKNOWNFAMILY, "font-style":"normal", "font-weight":"bold"},
|
||||||
|
".MJXc-TeX-unknown-BI": {"font-family":UNKNOWNFAMILY, "font-style":"italic","font-weight":"bold"},
|
||||||
|
|
||||||
"mjx-chartest": {
|
"mjx-chartest": {
|
||||||
display:"block",
|
display:"block",
|
||||||
position:"absolute", top:0,
|
position:"absolute", top:0,
|
||||||
"line-height":"normal",
|
"line-height":"normal",
|
||||||
"font-size":"500%",
|
"font-size":"500%"
|
||||||
"font-family":UNKNOWNFAMILY
|
|
||||||
},
|
},
|
||||||
"mjx-chartest mjx-char": {display:"inline"},
|
"mjx-chartest mjx-char": {display:"inline"},
|
||||||
"mjx-chartest mjx-box": {"padding-top": "500px"},
|
"mjx-chartest mjx-box": {"padding-top": "500px"},
|
||||||
|
@ -526,6 +529,7 @@
|
||||||
// it isnt' found in the given variant.
|
// it isnt' found in the given variant.
|
||||||
//
|
//
|
||||||
lookupChar: function (variant,n) {
|
lookupChar: function (variant,n) {
|
||||||
|
var VARIANT = variant;
|
||||||
while (variant) {
|
while (variant) {
|
||||||
for (var i = 0, m = variant.fonts.length; i < m; i++) {
|
for (var i = 0, m = variant.fonts.length; i < m; i++) {
|
||||||
var font = this.FONTDATA.FONTS[variant.fonts[i]];
|
var font = this.FONTDATA.FONTS[variant.fonts[i]];
|
||||||
|
@ -544,28 +548,34 @@
|
||||||
}
|
}
|
||||||
variant = this.FONTDATA.VARIANT[variant.chain];
|
variant = this.FONTDATA.VARIANT[variant.chain];
|
||||||
}
|
}
|
||||||
return this.unknownChar(variant,n);
|
return this.unknownChar(VARIANT,n);
|
||||||
},
|
},
|
||||||
//
|
//
|
||||||
// Create a fake font entry for an unknown character.
|
// Create a fake font entry for an unknown character.
|
||||||
//
|
//
|
||||||
unknownChar: function (variant,n) {
|
unknownChar: function (variant,n) {
|
||||||
HUB.signal.Post(["CommonHTML Jax - unknown char",n,variant]);
|
HUB.signal.Post(["CommonHTML Jax - unknown char",n,variant]);
|
||||||
|
var id = ""; if (variant.bold) id += "B"; if (variant.italic) id += "I";
|
||||||
|
var unknown = this.FONTDATA.UNKNOWN[id||"R"]; // cache of previously measured characters
|
||||||
|
if (!unknown[n]) this.getUnknownChar(unknown,n);
|
||||||
|
return {type:"unknown", n:n, font:unknown};
|
||||||
|
},
|
||||||
|
getUnknownChar: function (unknown,n) {
|
||||||
var c = this.unicodeChar(n);
|
var c = this.unicodeChar(n);
|
||||||
var HDW = this.getHDW(c); var a = (HDW.h-HDW.d)/2+AFUZZ; // ### FIXME: is this really the axis of the surrounding text?
|
var HDW = this.getHDW(c,unknown.className);
|
||||||
var unknown = {type:"unknown", n:n, font:{className:"MJXc-TeX-unknown"}};
|
var a = (HDW.h-HDW.d)/2+AFUZZ; // ### FIXME: is this really the axis of the surrounding text?
|
||||||
unknown.font[n] = [.8,.2,HDW.w,0,HDW.w,{a:a, A:HDW.h-a, d:HDW.d}];
|
// ### FIXME: provide a means of setting the height and depth for individual characters
|
||||||
unknown.font[n].c = c
|
unknown[n] = [.8,.2,HDW.w,0,HDW.w,{a:a, A:HDW.h-a, d:HDW.d}];
|
||||||
return unknown;
|
unknown[n].c = c;
|
||||||
},
|
},
|
||||||
//
|
//
|
||||||
// Get the height, depth and width of a character
|
// Get the height, depth and width of a character
|
||||||
// (height and depth are of the font, not the character).
|
// (height and depth are of the font, not the character).
|
||||||
// WARNING: causes reflow of the page!
|
// WARNING: causes reflow of the page!
|
||||||
//
|
//
|
||||||
getHDW: function (c) {
|
getHDW: function (c,name) {
|
||||||
var test1 = HTML.addElement(document.body,"mjx-chartest",{},[["mjx-char",{},[c]]]);
|
var test1 = HTML.addElement(document.body,"mjx-chartest",{className:name},[["mjx-char",{},[c]]]);
|
||||||
var test2 = HTML.addElement(document.body,"mjx-chartest",{},[["mjx-char",{},[c,["mjx-box"]]]]);
|
var test2 = HTML.addElement(document.body,"mjx-chartest",{className:name},[["mjx-char",{},[c,["mjx-box"]]]]);
|
||||||
var em = window.parseFloat(window.getComputedStyle(test1).fontSize);
|
var em = window.parseFloat(window.getComputedStyle(test1).fontSize);
|
||||||
var d = (test2.offsetHeight-500)/em;
|
var d = (test2.offsetHeight-500)/em;
|
||||||
var w = test1.offsetWidth/em, h = test1.offsetHeight/em - d;
|
var w = test1.offsetWidth/em, h = test1.offsetHeight/em - d;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user