Debian Codegraph @

unpacked/jax/output/HTML-CSS/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/HTML-CSS/autoload/mglyph.js
7 *
8 * Implements the HTML-CSS output for <mglyph> elements.
9 *
10 * ---------------------------------------------------------------------
11 *
12 * Copyright (c) 2010-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("HTML-CSS Jax Ready",function () {
28 var VERSION = "2.7.9";
29 var MML = MathJax.ElementJax.mml,
30 HTMLCSS = MathJax.OutputJax["HTML-CSS"],
31 LOCALE = MathJax.Localization;
32
33 MML.mglyph.Augment({
34 toHTML: function (span,variant) {
35 var SPAN = span, values = this.getValues("src","width","height","valign","alt"), err;
36 span = this.HTMLcreateSpan(span);
37 if (values.src === "") {
38 var index = this.Get("index");
39 if (index) {
40 variant = this.HTMLgetVariant(); var font = variant.defaultFont;
41 if (font) {
42 font.noStyleChar = true; font.testString = String.fromCharCode(index) + 'ABCabc';
43 if (HTMLCSS.Font.testFont(font)) {
44 this.HTMLhandleVariant(span,variant,String.fromCharCode(index));
45 } else {
46 if (values.alt === "")
47 {values.alt = LOCALE._(["MathML","BadMglyphFont"],"Bad font: %1",font.family)}
48 err = MML.Error(values.alt,{mathsize:"75%"});
49 this.Append(err); err.toHTML(span); this.data.pop();
50 span.bbox = err.HTMLspanElement().bbox;
51 }
52 }
53 }
54 } else {
55 if (!this.img) {this.img = MML.mglyph.GLYPH[values.src]}
56 if (!this.img) {
57 this.img = MML.mglyph.GLYPH[values.src] = {img: new Image(), status: "pending"};
58 var img = this.img.img;
59 img.onload = MathJax.Callback(["HTMLimgLoaded",this]);
60 img.onerror = MathJax.Callback(["HTMLimgError",this]);
61 img.src = values.src;
62 MathJax.Hub.RestartAfter(img.onload);
63 }
64 if (this.img.status !== "OK") {
65 err = MML.Error(
66 LOCALE._(["MathML","BadMglyph"],"Bad mglyph: %1",values.src),
67 {mathsize:"75%"});
68 this.Append(err); err.toHTML(span); this.data.pop();
69 span.bbox = err.HTMLspanElement().bbox;
70 } else {
71 var mu = this.HTMLgetMu(span);
72 var scale = this.HTMLgetScale();
73 img = HTMLCSS.addElement(span,"img",{isMathJax:true, src:values.src, alt:values.alt, title:values.alt});
74 if (values.width) {
75 img.style.width = HTMLCSS.Em(HTMLCSS.length2em(values.width,mu,this.img.img.width/HTMLCSS.em) * scale);
76 }
77 if (values.height) {
78 img.style.height = HTMLCSS.Em(HTMLCSS.length2em(values.height,mu,this.img.img.height/HTMLCSS.em) * scale);
79 }
80 span.bbox.w = span.bbox.rw = img.offsetWidth/HTMLCSS.em;
81 span.bbox.h = img.offsetHeight/HTMLCSS.em;
82 if (values.valign) {
83 span.bbox.d = -HTMLCSS.length2em(values.valign,mu,this.img.img.height/HTMLCSS.em) * scale;
84 img.style.verticalAlign = HTMLCSS.Em(-span.bbox.d);
85 span.bbox.h -= span.bbox.d;
86 }
87 }
88 }
89 if (!SPAN.bbox) {
90 SPAN.bbox = {w: span.bbox.w, h: span.bbox.h, d: span.bbox.d,
91 rw: span.bbox.rw, lw: span.bbox.lw};
92 } else if (span.bbox) {
93 SPAN.bbox.w += span.bbox.w;
94 if (SPAN.bbox.w > SPAN.bbox.rw) {SPAN.bbox.rw = SPAN.bbox.w}
95 if (span.bbox.h > SPAN.bbox.h) {SPAN.bbox.h = span.bbox.h}
96 if (span.bbox.d > SPAN.bbox.d) {SPAN.bbox.d = span.bbox.d}
97 }
98 this.HTMLhandleSpace(span);
99 this.HTMLhandleColor(span);
100 return span;
101 },
102 HTMLimgLoaded: function (event,status) {
103 if (typeof(event) === "string") {status = event}
104 this.img.status = (status || "OK")
105 },
106 HTMLimgError: function () {this.img.img.onload("error")}
107 },{
108 GLYPH: {} // global list of all loaded glyphs
109 });
110
111 MathJax.Hub.Startup.signal.Post("HTML-CSS mglyph Ready");
112 MathJax.Ajax.loadComplete(HTMLCSS.autoloadDir+"/mglyph.js");
113
114 });
115