Debian Codegraph @

unpacked/jax/output/CommonHTML/autoload/mglyph.js

raw
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/CommonHTML/autoload/mglyph.js
7 *
8 * Implements the CommonHTML output for <mglyph> elements.
9 *
10 * ---------------------------------------------------------------------
11 *
12 * Copyright (c) 2015-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 MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () {
28 var VERSION = "2.7.9";
29 var MML = MathJax.ElementJax.mml,
30 CHTML = MathJax.OutputJax.CommonHTML,
31 LOCALE = MathJax.Localization;
32
33 MML.mglyph.Augment({
34 toCommonHTML: function (node,options) {
35 var values = this.getValues("src","width","height","valign","alt");
36 node = this.CHTMLcreateNode(node);
37 this.CHTMLhandleStyle(node);
38 this.CHTMLhandleScale(node);
39 if (values.src === "") {
40 var index = this.Get("index");
41 this.CHTMLgetVariant();
42 if (index && this.CHTMLvariant.style)
43 this.CHTMLhandleText(node,String.fromCharCode(index),this.CHTMLvariant);
44 } else {
45 var bbox = this.CHTML;
46 if (!bbox.img) bbox.img = MML.mglyph.GLYPH[values.src];
47 if (!bbox.img) {
48 bbox.img = MML.mglyph.GLYPH[values.src] = {img: new Image(), status: "pending"};
49 bbox.img.img.onload = MathJax.Callback(["CHTMLimgLoaded",this]);
50 bbox.img.img.onerror = MathJax.Callback(["CHTMLimgError",this]);
51 bbox.img.img.src = values.src;
52 MathJax.Hub.RestartAfter(bbox.img.img.onload);
53 }
54 if (bbox.img.status !== "OK") {
55 var err = MML.Error(LOCALE._(["MathML","BadMglyph"],"Bad mglyph: %1",values.src));
56 err.data[0].data[0].mathsize = "75%";
57 this.Append(err); err.toCommonHTML(node); this.data.pop();
58 bbox.combine(err.CHTML,0,0,1);
59 } else {
60 var img = CHTML.addElement(node,"img",{
61 isMathJax:true, src:values.src, alt:values.alt, title:values.alt
62 });
63 var w = values.width, h = values.height;
64 var W = bbox.img.img.width/CHTML.em, H = bbox.img.img.height/CHTML.em;
65 var WW = W, HH = H;
66 if (w !== "") {W = this.CHTMLlength2em(w,WW); H = (WW ? W/WW * HH : 0)}
67 if (h !== "") {H = this.CHTMLlength2em(h,HH); if (w === "") W = (HH ? H/HH * WW : 0)}
68 img.style.width = CHTML.Em(W); bbox.w = bbox.r = W;
69 img.style.height = CHTML.Em(H); bbox.h = bbox.t = H;
70 if (values.valign) {
71 bbox.d = bbox.b = -this.CHTMLlength2em(values.valign,HH);
72 img.style.verticalAlign = CHTML.Em(-bbox.d);
73 bbox.h -= bbox.d; bbox.t = bbox.h;
74 }
75 }
76 }
77 this.CHTMLhandleSpace(node);
78 this.CHTMLhandleBBox(node);
79 this.CHTMLhandleColor(node);
80 return node;
81 },
82 CHTMLimgLoaded: function (event,status) {
83 if (typeof(event) === "string") status = event;
84 this.CHTML.img.status = (status || "OK");
85 },
86 CHTMLimgError: function () {this.CHTML.img.img.onload("error")}
87 },{
88 GLYPH: {} // global list of all loaded glyphs
89 });
90
91 MathJax.Hub.Startup.signal.Post("CommonHTML mglyph Ready");
92 MathJax.Ajax.loadComplete(CHTML.autoloadDir+"/mglyph.js");
93 });
94