Debian Codegraph @

unpacked/jax/output/SVG/autoload/mmultiscripts.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/SVG/autoload/mmultiscripts.js
7 *
8 * Implements the SVG output for <mmultiscripts> elements.
9 *
10 * ---------------------------------------------------------------------
11 *
12 * Copyright (c) 2011-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("SVG Jax Ready",function () {
28 var VERSION = "2.7.9";
29 var MML = MathJax.ElementJax.mml,
30 SVG = MathJax.OutputJax.SVG;
31
32 MML.mmultiscripts.Augment({
33 toSVG: function (HW,D) {
34 this.SVGgetStyles();
35 var svg = this.SVG(), scale = this.SVGgetScale(svg); this.SVGhandleSpace(svg);
36 var base = (this.data[this.base] ? this.SVGdataStretched(this.base,HW,D) : SVG.BBOX.G().Clean());
37 var x_height = SVG.TeX.x_height * scale,
38 s = SVG.TeX.scriptspace * scale * .75; // FIXME: .75 can be removed when IC is right?
39
40 var BOX = this.SVGgetScripts(s);
41 var sub = BOX[0], sup = BOX[1], presub = BOX[2], presup = BOX[3];
42
43 var sscale = (this.data[1]||this).SVGgetScale();
44 var q = SVG.TeX.sup_drop * sscale, r = SVG.TeX.sub_drop * sscale;
45 var u = base.h - q, v = base.d + r, delta = 0, p;
46 if (base.ic) {delta = base.ic}
47 if (this.data[this.base] &&
48 (this.data[this.base].type === "mi" || this.data[this.base].type === "mo")) {
49 if (SVG.isChar(this.data[this.base].data.join("")) && base.scale === 1 &&
50 !base.stretched && !this.data[this.base].Get("largeop")) {u = v = 0}
51 }
52 var min = this.getValues("subscriptshift","superscriptshift"), mu = this.SVGgetMu(svg);
53 min.subscriptshift = (min.subscriptshift === "" ? 0 : SVG.length2em(min.subscriptshift,mu));
54 min.superscriptshift = (min.superscriptshift === "" ? 0 : SVG.length2em(min.superscriptshift,mu));
55
56 var dx = 0;
57 if (presub) {dx = presub.w+delta} else if (presup) {dx = presup.w-delta}
58 svg.Add(base,Math.max(0,dx),0);
59
60 if (!sup && !presup) {
61 v = Math.max(v,SVG.TeX.sub1*scale,min.subscriptshift);
62 if (sub) {v = Math.max(v,sub.h-(4/5)*x_height)}
63 if (presub) {v = Math.max(v,presub.h-(4/5)*x_height)}
64 if (sub) {svg.Add(sub,dx+base.w+s-delta,-v)}
65 if (presub) {svg.Add(presub,0,-v)}
66 } else {
67 if (!sub && !presub) {
68 var values = this.getValues("displaystyle","texprimestyle");
69 p = SVG.TeX[(values.displaystyle ? "sup1" : (values.texprimestyle ? "sup3" : "sup2"))];
70 u = Math.max(u,p*scale,min.superscriptshift);
71 if (sup) {u = Math.max(u,sup.d+(1/4)*x_height)}
72 if (presup) {u = Math.max(u,presup.d+(1/4)*x_height)}
73 if (sup) {svg.Add(sup,dx+base.w+s,u)}
74 if (presup) {svg.Add(presup,0,u)}
75 } else {
76 v = Math.max(v,SVG.TeX.sub2*scale);
77 var t = SVG.TeX.rule_thickness * scale;
78 var h = (sub||presub).h, d = (sup||presup).d;
79 if (presub) {h = Math.max(h,presub.h)}
80 if (presup) {d = Math.max(d,presup.d)}
81 if ((u - d) - (h - v) < 3*t) {
82 v = 3*t - u + d + h; q = (4/5)*x_height - (u - d);
83 if (q > 0) {u += q; v -= q}
84 }
85 u = Math.max(u,min.superscriptshift); v = Math.max(v,min.subscriptshift);
86 if (sup) {svg.Add(sup,dx+base.w+s,u)}
87 if (presup) {svg.Add(presup,dx+delta-presup.w,u)}
88 if (sub) {svg.Add(sub,dx+base.w+s-delta,-v)}
89 if (presub) {svg.Add(presub,dx-presub.w,-v)}
90 }
91 }
92 svg.Clean();
93 this.SVGhandleColor(svg);
94 this.SVGsaveData(svg);
95 var data = this.SVGdata;
96 data.dx = dx; data.s = s; data.u = u, data.v = v; data.delta = delta;
97 return svg;
98 },
99 SVGgetScripts: function (s) {
100 var sup, sub, BOX = [];
101 var i = 1, m = this.data.length, W = 0;
102 for (var k = 0; k < 4; k += 2) {
103 while (i < m && (this.data[i]||{}).type !== "mprescripts") {
104 var box = [null,null,null,null];
105 for (var j = k; j < k+2; j++) {
106 if (this.data[i] && this.data[i].type !== "none" && this.data[i].type !== "mprescripts") {
107 if (!BOX[j]) {BOX[j] = SVG.BBOX.G()}
108 box[j] = this.data[i].toSVG();
109 }
110 if ((this.data[i]||{}).type !== "mprescripts") i++;
111 }
112 var isPre = (k === 2);
113 if (isPre) W += Math.max((box[k]||{w:0}).w,(box[k+1]||{w:0}).w);
114 if (box[k]) BOX[k].Add(box[k].With({x:W-(isPre?box[k].w:0)}));
115 if (box[k+1]) BOX[k+1].Add(box[k+1].With({x:W-(isPre?box[k+1].w:0)}));
116 sub = BOX[k]||{w:0}; sup = BOX[k+1]||{w:0};
117 sub.w = sup.w = W = Math.max(sub.w,sup.w);
118 }
119 i++; W = 0;
120 }
121 for (j = 0; j < 4; j++) {if (BOX[j]) {BOX[j].w += s; BOX[j].Clean()}}
122 return BOX;
123 }
124 });
125
126 MathJax.Hub.Startup.signal.Post("SVG mmultiscripts Ready");
127 MathJax.Ajax.loadComplete(SVG.autoloadDir+"/mmultiscripts.js");
128
129 });
130