1
/*************************************************************
3
* MathJax/jax/output/SVG/autoload/mglyph.js
5
* Implements the SVG output for <mglyph> elements.
7
* ---------------------------------------------------------------------
9
* Copyright (c) 2011-2012 Design Science, Inc.
11
* Licensed under the Apache License, Version 2.0 (the "License");
12
* you may not use this file except in compliance with the License.
13
* You may obtain a copy of the License at
15
* http://www.apache.org/licenses/LICENSE-2.0
17
* Unless required by applicable law or agreed to in writing, software
18
* distributed under the License is distributed on an "AS IS" BASIS,
19
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
* See the License for the specific language governing permissions and
21
* limitations under the License.
24
MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () {
26
var MML = MathJax.ElementJax.mml,
27
SVG = MathJax.OutputJax.SVG,
30
var XLINKNS = "http://www.w3.org/1999/xlink";
32
BBOX.MGLYPH = BBOX.Subclass({
33
type: "image", removeable: false,
34
Init: function (img,w,h,align,mu,def) {
35
if (def == null) {def = {}}
36
var W = img.width*1000/SVG.em, H = img.height*1000/SVG.em, y = 0;
37
if (w !== "") {W = SVG.length2em(w,mu,W)}
38
if (h !== "") {H = SVG.length2em(h,mu,H)}
39
if (align !== "" && align.match(/\d/)) {y = SVG.length2em(align,mu); def.y = -y}
40
def.height = Math.floor(H); def.width = Math.floor(W);
41
def.transform = "translate(0,"+H+") matrix(1 0 0 -1 0 0)";
42
def.preserveAspectRatio = "none";
43
this.SUPER(arguments).Init.call(this,def);
44
this.element.setAttributeNS(XLINKNS,"href",img.src);
45
this.w = this.r = W; this.h = this.H = H + y;
46
this.d = this.D = -y; this.l = 0;
51
toSVG: function (variant,scale) {
52
this.SVGgetStyles(); var svg = this.SVG(), img, err;
53
this.SVGhandleSpace(svg);
54
var values = this.getValues("src","width","height","valign","alt");
55
if (values.src === "") {
56
values = this.getValues("index","fontfamily");
58
if (!scale) {scale = this.SVGgetScale()}
59
var def = {}; if (values.fontfamily) {def["font-family"] = values.fontfamily}
60
svg.Add(BBOX.TEXT(scale,String.fromCharCode(values.index),def));
63
if (!this.img) {this.img = MML.mglyph.GLYPH[values.src]}
65
this.img = MML.mglyph.GLYPH[values.src] = {img: new Image(), status: "pending"};
67
img.onload = MathJax.Callback(["SVGimgLoaded",this]);
68
img.onerror = MathJax.Callback(["SVGimgError",this]);
70
MathJax.Hub.RestartAfter(img.onload);
72
if (this.img.status !== "OK") {
73
err = MML.merror("Bad mglyph: "+values.src).With({mathsize:"75%"});
74
this.Append(err); svg = err.toSVG(); this.data.pop();
76
var mu = this.SVGgetMu(svg);
77
svg.Add(BBOX.MGLYPH(this.img.img,values.width,values.height,values.valign,mu,
78
{src:values.src, alt:values.alt, title:values.alt}));
82
this.SVGhandleColor(svg);
83
this.SVGsaveData(svg);
86
SVGimgLoaded: function (event,status) {
87
if (typeof(event) === "string") {status = event}
88
this.img.status = (status || "OK")
90
SVGimgError: function () {this.img.img.onload("error")}
92
GLYPH: {} // global list of all loaded glyphs
95
MathJax.Hub.Startup.signal.Post("SVG mglyph Ready");
96
MathJax.Ajax.loadComplete(SVG.autoloadDir+"/mglyph.js");