PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/talk2/mathjax/unpacked/jax/output/SVG/autoload/mmultiscripts.js

https://github.com/williamstein/mazur-explicit-formula
JavaScript | 121 lines | 90 code | 9 blank | 22 comment | 39 complexity | 75e008abf8a20a23fcebf130f8f0e010 MD5 | raw file
Possible License(s): Apache-2.0, GPL-2.0, MIT
  1. /*************************************************************
  2. *
  3. * MathJax/jax/output/SVG/autoload/mmultiscripts.js
  4. *
  5. * Implements the SVG output for <mmultiscripts> elements.
  6. *
  7. * ---------------------------------------------------------------------
  8. *
  9. * Copyright (c) 2011-2012 Design Science, Inc.
  10. *
  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
  14. *
  15. * http://www.apache.org/licenses/LICENSE-2.0
  16. *
  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.
  22. */
  23. MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () {
  24. var VERSION = "2.1";
  25. var MML = MathJax.ElementJax.mml,
  26. SVG = MathJax.OutputJax.SVG;
  27. MML.mmultiscripts.Augment({
  28. toSVG: function (HW,D) {
  29. this.SVGgetStyles();
  30. var svg = this.SVG(); this.SVGhandleSpace(svg);
  31. var scale = this.SVGgetScale();
  32. var base = (this.data[this.base] ? this.SVGdataStretched(this.base,HW,D) : SVG.BBOX.G().Clean());
  33. var x_height = SVG.TeX.x_height * scale,
  34. s = SVG.TeX.scriptspace * scale * .75; // FIXME: .75 can be removed when IC is right?
  35. var BOX = this.SVGgetScripts(s);
  36. var sub = BOX[0], sup = BOX[1], presub = BOX[2], presup = BOX[3];
  37. var sscale = (this.data[1]||this).SVGgetScale();
  38. var q = SVG.TeX.sup_drop * sscale, r = SVG.TeX.sub_drop * sscale;
  39. var u = base.h - q, v = base.d + r, delta = 0, p;
  40. if (base.ic) {delta = base.ic}
  41. if (this.data[this.base] &&
  42. (this.data[this.base].type === "mi" || this.data[this.base].type === "mo")) {
  43. if (this.data[this.base].data.join("").length === 1 && base.scale === 1 &&
  44. !base.stretched && !this.data[this.base].Get("largeop")) {u = v = 0}
  45. }
  46. var min = this.getValues("subscriptshift","superscriptshift"), mu = this.SVGgetMu(svg);
  47. min.subscriptshift = (min.subscriptshift === "" ? 0 : SVG.length2em(min.subscriptshift,mu));
  48. min.superscriptshift = (min.superscriptshift === "" ? 0 : SVG.length2em(min.superscriptshift,mu));
  49. var dx = 0;
  50. if (presub) {dx = presub.w+delta} else if (presup) {dx = presup.w-delta}
  51. svg.Add(base,Math.max(0,dx),0);
  52. if (!sup && !presup) {
  53. v = Math.max(v,SVG.TeX.sub1*scale,min.subscriptshift);
  54. if (sub) {v = Math.max(v,sub.h-(4/5)*x_height)}
  55. if (presub) {v = Math.max(v,presub.h-(4/5)*x_height)}
  56. if (sub) {svg.Add(sub,dx+base.w+s-delta,-v)}
  57. if (presub) {svg.Add(presub,0,-v)}
  58. } else {
  59. if (!sub && !presub) {
  60. var values = this.getValues("displaystyle","texprimestyle");
  61. p = SVG.TeX[(values.displaystyle ? "sup1" : (values.texprimestyle ? "sup3" : "sup2"))];
  62. u = Math.max(u,p*scale,min.superscriptshift);
  63. if (sup) {u = Math.max(u,sup.d+(1/4)*x_height)}
  64. if (presup) {u = Math.max(u,presup.d+(1/4)*x_height)}
  65. if (sup) {svg.Add(sup,dx+base.w+s,u)}
  66. if (presup) {svg.Add(presup,0,u)}
  67. } else {
  68. v = Math.max(v,SVG.TeX.sub2*scale);
  69. var t = SVG.TeX.rule_thickness * scale;
  70. var h = (sub||presub).h, d = (sup||presup).d;
  71. if (presub) {h = Math.max(h,presub.h)}
  72. if (presup) {d = Math.max(d,presup.d)}
  73. if ((u - d) - (h - v) < 3*t) {
  74. v = 3*t - u + d + h; q = (4/5)*x_height - (u - d);
  75. if (q > 0) {u += q; v -= q}
  76. }
  77. u = Math.max(u,min.superscriptshift); v = Math.max(v,min.subscriptshift);
  78. if (sup) {svg.Add(sup,dx+base.w+s,u)}
  79. if (presup) {svg.Add(presup,dx+delta-presup.w,u)}
  80. if (sub) {svg.Add(sub,dx+base.w+s-delta,-v)}
  81. if (presub) {svg.Add(presub,dx-presub.w,-v)}
  82. }
  83. }
  84. svg.Clean();
  85. this.SVGhandleColor(svg);
  86. this.SVGsaveData(svg);
  87. return svg;
  88. },
  89. SVGgetScripts: function (s) {
  90. var sup, sub, BOX = [];
  91. var i = 1, m = this.data.length, W = 0;
  92. for (var k = 0; k < 4; k += 2) {
  93. while (i < m && this.data[i].type !== "mprescripts") {
  94. for (var j = k; j < k+2; j++) {
  95. if (this.data[i] && this.data[i].type !== "none") {
  96. if (!BOX[j]) {BOX[j] = SVG.BBOX.G()}
  97. BOX[j].Add(this.data[i].toSVG().With({x:W}));
  98. }
  99. i++;
  100. }
  101. sub = BOX[k]||{w:0}; sup = BOX[k+1]||{w:0};
  102. sub.w = sup.w = W = Math.max(sub.w,sup.w);
  103. }
  104. i++; W = 0;
  105. }
  106. for (j = 0; j < 4; j++) {if (BOX[j]) {BOX[j].w += s; BOX[j].Clean()}}
  107. return BOX;
  108. }
  109. });
  110. MathJax.Hub.Startup.signal.Post("SVG mmultiscripts Ready");
  111. MathJax.Ajax.loadComplete(SVG.autoloadDir+"/mmultiscripts.js");
  112. });