msqrt.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*************************************************************
  2. *
  3. * Copyright (c) 2018-2022 The MathJax Consortium
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /**
  18. * @fileoverview Implements the SVGmsqrt wrapper for the MmlMsqrt object
  19. *
  20. * @author dpvc@mathjax.org (Davide Cervone)
  21. */
  22. import {SVGWrapper, SVGConstructor} from '../Wrapper.js';
  23. import {CommonMsqrtMixin} from '../../common/Wrappers/msqrt.js';
  24. import {BBox} from '../../../util/BBox.js';
  25. import {MmlMsqrt} from '../../../core/MmlTree/MmlNodes/msqrt.js';
  26. /*****************************************************************/
  27. /**
  28. * The SVGmsqrt wrapper for the MmlMsqrt object
  29. *
  30. * @template N The HTMLElement node class
  31. * @template T The Text node class
  32. * @template D The Document class
  33. */
  34. export class SVGmsqrt<N, T, D> extends CommonMsqrtMixin<SVGConstructor<any, any, any>>(SVGWrapper) {
  35. /**
  36. * The msqrt wrapper
  37. */
  38. public static kind = MmlMsqrt.prototype.kind;
  39. /**
  40. * Indent due to root
  41. */
  42. public dx: number = 0;
  43. /**
  44. * @override
  45. */
  46. public toSVG(parent: N) {
  47. const surd = this.childNodes[this.surd];
  48. const base = this.childNodes[this.base];
  49. const root = (this.root ? this.childNodes[this.root] : null);
  50. //
  51. // Get the parameters for the spacing of the parts
  52. //
  53. const sbox = surd.getBBox();
  54. const bbox = base.getOuterBBox();
  55. const q = this.getPQ(sbox)[1];
  56. const t = this.font.params.rule_thickness * this.bbox.scale;
  57. const H = bbox.h + q + t;
  58. //
  59. // Create the SVG structure for the root
  60. //
  61. const SVG = this.standardSVGnode(parent);
  62. const BASE = this.adaptor.append(SVG, this.svg('g'));
  63. //
  64. // Place the children
  65. //
  66. this.addRoot(SVG, root, sbox, H);
  67. surd.toSVG(SVG);
  68. surd.place(this.dx, H - sbox.h);
  69. base.toSVG(BASE);
  70. base.place(this.dx + sbox.w, 0);
  71. this.adaptor.append(SVG, this.svg('rect', {
  72. width: this.fixed(bbox.w), height: this.fixed(t),
  73. x: this.fixed(this.dx + sbox.w), y: this.fixed(H - t)
  74. }));
  75. }
  76. /**
  77. * Add root HTML (overridden in mroot)
  78. *
  79. * @param {N} ROOT The container for the root
  80. * @param {SVGWrapper} root The wrapped MML root content
  81. * @param {BBox} sbox The bounding box of the surd
  82. * @param {number} H The height of the root as a whole
  83. */
  84. protected addRoot(_ROOT: N, _root: SVGWrapper<N, T, D>, _sbox: BBox, _H: number) {
  85. }
  86. }