Make glyph data be part of BBOX.GLYPH, and make sure that resets don't increment the counter for local <defs> elements.
This commit is contained in:
parent
b2ce6ef0a0
commit
11e4ba5101
|
@ -153,8 +153,8 @@
|
||||||
this.textSVG = this.Element("svg");
|
this.textSVG = this.Element("svg");
|
||||||
|
|
||||||
// Global defs for font glyphs
|
// Global defs for font glyphs
|
||||||
DEFS = this.addElement(this.addElement(this.hiddenDiv.parentNode,"svg"),"defs",{id:"MathJax_SVG_glyphs"});
|
BBOX.GLYPH.defs = this.addElement(this.addElement(this.hiddenDiv.parentNode,"svg"),
|
||||||
GLYPHS = {};
|
"defs",{id:"MathJax_SVG_glyphs"});
|
||||||
|
|
||||||
// Used in preTranslate to get scaling factors
|
// Used in preTranslate to get scaling factors
|
||||||
this.ExSpan = HTML.Element("span",
|
this.ExSpan = HTML.Element("span",
|
||||||
|
@ -298,7 +298,8 @@
|
||||||
//
|
//
|
||||||
var jax = script.MathJax.elementJax, math = jax.root,
|
var jax = script.MathJax.elementJax, math = jax.root,
|
||||||
span = document.getElementById(jax.inputID+"-Frame"),
|
span = document.getElementById(jax.inputID+"-Frame"),
|
||||||
div = (jax.SVG.display ? (span||{}).parentNode : span);
|
div = (jax.SVG.display ? (span||{}).parentNode : span),
|
||||||
|
localCache = (SVG.config.useFontCache && !SVG.config.useGlobalCache);
|
||||||
if (!div) return;
|
if (!div) return;
|
||||||
//
|
//
|
||||||
// Set the font metrics
|
// Set the font metrics
|
||||||
|
@ -310,10 +311,12 @@
|
||||||
//
|
//
|
||||||
this.mathDiv = div;
|
this.mathDiv = div;
|
||||||
span.appendChild(this.textSVG);
|
span.appendChild(this.textSVG);
|
||||||
|
if (localCache) {SVG.resetGlyphs()}
|
||||||
this.initSVG(math,span);
|
this.initSVG(math,span);
|
||||||
math.setTeXclass();
|
math.setTeXclass();
|
||||||
try {math.toSVG(span,div)} catch (err) {
|
try {math.toSVG(span,div)} catch (err) {
|
||||||
if (err.restart) {while (span.firstChild) {span.removeChild(span.firstChild)}}
|
if (err.restart) {while (span.firstChild) {span.removeChild(span.firstChild)}}
|
||||||
|
if (localCache) {BBOX.GLYPH.n--}
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
span.removeChild(this.textSVG);
|
span.removeChild(this.textSVG);
|
||||||
|
@ -376,17 +379,18 @@
|
||||||
state.SVGlast = state.SVGeqn;
|
state.SVGlast = state.SVGeqn;
|
||||||
},
|
},
|
||||||
|
|
||||||
clearGlyphs: function (reset) {
|
resetGlyphs: function (reset) {
|
||||||
if (this.config.useFontCache) {
|
if (this.config.useFontCache) {
|
||||||
|
var GLYPH = BBOX.GLYPH;
|
||||||
if (this.config.useGlobalCache) {
|
if (this.config.useGlobalCache) {
|
||||||
DEFS = document.getElementById("MathJax_SVG_Glyphs");
|
GLYPH.defs = document.getElementById("MathJax_SVG_Glyphs");
|
||||||
DEFS.innerHTML = "";
|
GLYPH.defs.innerHTML = "";
|
||||||
} else {
|
} else {
|
||||||
DEFS = this.Element("defs");
|
GLYPH.defs = this.Element("defs");
|
||||||
DEFN++;
|
GLYPH.n++;
|
||||||
}
|
}
|
||||||
GLYPHS = {};
|
GLYPH.glyphs = {};
|
||||||
if (reset) {DEFN = 0}
|
if (reset) {GLYPH.n = 0}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1024,21 +1028,19 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var GLYPHS, DEFS, DEFN = 0; // data for which glyphs are used
|
|
||||||
|
|
||||||
BBOX.GLYPH = BBOX.Subclass({
|
BBOX.GLYPH = BBOX.Subclass({
|
||||||
type: "path", removeable: false,
|
type: "path", removeable: false,
|
||||||
Init: function (scale,id,h,d,w,l,r,p) {
|
Init: function (scale,id,h,d,w,l,r,p) {
|
||||||
var def, t = SVG.config.blacker;
|
var def, t = SVG.config.blacker, GLYPH = BBOX.GLYPH;
|
||||||
var cache = SVG.config.useFontCache;
|
var cache = SVG.config.useFontCache;
|
||||||
var transform = (scale === 1 ? null : "scale("+SVG.Fixed(scale)+")");
|
var transform = (scale === 1 ? null : "scale("+SVG.Fixed(scale)+")");
|
||||||
if (cache && !SVG.config.useGlobalCache) {id = "E"+DEFN+"-"+id}
|
if (cache && !SVG.config.useGlobalCache) {id = "E"+GLYPH.n+"-"+id}
|
||||||
if (!cache || !GLYPHS[id]) {
|
if (!cache || !GLYPH.glyphs[id]) {
|
||||||
def = {"stroke-width":t};
|
def = {"stroke-width":t};
|
||||||
if (cache) {def.id = id} else if (transform) {def.transform = transform}
|
if (cache) {def.id = id} else if (transform) {def.transform = transform}
|
||||||
if (p !== "") {def.d = "M"+p+"Z"}
|
if (p !== "") {def.d = "M"+p+"Z"}
|
||||||
this.SUPER(arguments).Init.call(this,def);
|
this.SUPER(arguments).Init.call(this,def);
|
||||||
if (cache) {DEFS.appendChild(this.element); GLYPHS[id] = true;}
|
if (cache) {GLYPH.defs.appendChild(this.element); GLYPH.glyphs[id] = true;}
|
||||||
}
|
}
|
||||||
if (cache) {
|
if (cache) {
|
||||||
def = {}; if (transform) {def.transform = transform}
|
def = {}; if (transform) {def.transform = transform}
|
||||||
|
@ -1050,6 +1052,10 @@
|
||||||
this.H = Math.max(0,this.h); this.D = Math.max(0,this.d);
|
this.H = Math.max(0,this.h); this.D = Math.max(0,this.d);
|
||||||
this.x = this.y = 0; this.scale = scale;
|
this.x = this.y = 0; this.scale = scale;
|
||||||
}
|
}
|
||||||
|
},{
|
||||||
|
glyphs: {}, // which glpyhs have been used
|
||||||
|
defs: null, // the SVG <defs> element where glyphs are stored
|
||||||
|
n: 0 // the ID for local <defs> for self-contained SVG elements
|
||||||
});
|
});
|
||||||
|
|
||||||
HUB.Register.StartupHook("mml Jax Ready",function () {
|
HUB.Register.StartupHook("mml Jax Ready",function () {
|
||||||
|
@ -2000,11 +2006,7 @@
|
||||||
MML.math.Augment({
|
MML.math.Augment({
|
||||||
SVG: BBOX.Subclass({type:"svg", removeable: false}),
|
SVG: BBOX.Subclass({type:"svg", removeable: false}),
|
||||||
toSVG: function (span,div) {
|
toSVG: function (span,div) {
|
||||||
//
|
|
||||||
// Clear the font cache, if necessary
|
|
||||||
//
|
|
||||||
var CONFIG = SVG.config;
|
var CONFIG = SVG.config;
|
||||||
if (span && CONFIG.useFontCache && !CONFIG.useGlobalCache) {SVG.clearGlyphs()}
|
|
||||||
//
|
//
|
||||||
// All the data should be in an inferrerd row
|
// All the data should be in an inferrerd row
|
||||||
//
|
//
|
||||||
|
@ -2024,7 +2026,8 @@
|
||||||
this.SVGhandleColor(box);
|
this.SVGhandleColor(box);
|
||||||
var svg = this.SVG();
|
var svg = this.SVG();
|
||||||
svg.element.setAttribute("xmlns:xlink",XLINKNS);
|
svg.element.setAttribute("xmlns:xlink",XLINKNS);
|
||||||
if (CONFIG.useFontCache && !CONFIG.useGlobalCache) {svg.element.appendChild(DEFS)}
|
if (CONFIG.useFontCache && !CONFIG.useGlobalCache)
|
||||||
|
{svg.element.appendChild(BBOX.GLYPH.defs)}
|
||||||
svg.Add(box); svg.Clean();
|
svg.Add(box); svg.Clean();
|
||||||
this.SVGsaveData(svg);
|
this.SVGsaveData(svg);
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in New Issue
Block a user