msubsup.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 SVGmsubsup wrapper for the MmlMsubsup object
  19. * and the special cases SVGmsub and SVGmsup
  20. *
  21. * @author dpvc@mathjax.org (Davide Cervone)
  22. */
  23. import {SVGWrapper, Constructor} from '../Wrapper.js';
  24. import {SVGscriptbase} from './scriptbase.js';
  25. import {CommonMsubMixin} from '../../common/Wrappers/msubsup.js';
  26. import {CommonMsupMixin} from '../../common/Wrappers/msubsup.js';
  27. import {CommonMsubsupMixin} from '../../common/Wrappers/msubsup.js';
  28. import {MmlMsubsup, MmlMsub, MmlMsup} from '../../../core/MmlTree/MmlNodes/msubsup.js';
  29. /*****************************************************************/
  30. /**
  31. * The SVGmsub wrapper for the MmlMsub object
  32. *
  33. * @template N The HTMLElement node class
  34. * @template T The Text node class
  35. * @template D The Document class
  36. */
  37. // @ts-ignore
  38. export class SVGmsub<N, T, D> extends
  39. CommonMsubMixin<SVGWrapper<any, any, any>, Constructor<SVGscriptbase<any, any, any>>>(SVGscriptbase) {
  40. /**
  41. * The msub wrapper
  42. */
  43. public static kind = MmlMsub.prototype.kind;
  44. }
  45. /*****************************************************************/
  46. /**
  47. * The SVGmsup wrapper for the MmlMsup object
  48. *
  49. * @template N The HTMLElement node class
  50. * @template T The Text node class
  51. * @template D The Document class
  52. */
  53. // @ts-ignore
  54. export class SVGmsup<N, T, D> extends
  55. CommonMsupMixin<SVGWrapper<any, any, any>, Constructor<SVGscriptbase<any, any, any>>>(SVGscriptbase) {
  56. /**
  57. * The msup wrapper
  58. */
  59. public static kind = MmlMsup.prototype.kind;
  60. }
  61. /*****************************************************************/
  62. /**
  63. * The SVGmsubsup wrapper for the MmlMsubsup object
  64. *
  65. * @template N The HTMLElement node class
  66. * @template T The Text node class
  67. * @template D The Document class
  68. */
  69. // @ts-ignore
  70. export class SVGmsubsup<N, T, D> extends
  71. CommonMsubsupMixin<SVGWrapper<any, any, any>, Constructor<SVGscriptbase<any, any, any>>>(SVGscriptbase) {
  72. /**
  73. * The msubsup wrapper
  74. */
  75. public static kind = MmlMsubsup.prototype.kind;
  76. /**
  77. * @override
  78. */
  79. public toSVG(parent: N) {
  80. const svg = this.standardSVGnode(parent);
  81. const [base, sup, sub] = [this.baseChild, this.supChild, this.subChild];
  82. const w = this.getBaseWidth();
  83. const x = this.getAdjustedIc();
  84. const [u, v] = this.getUVQ();
  85. base.toSVG(svg);
  86. sup.toSVG(svg);
  87. sub.toSVG(svg);
  88. sub.place(w, v);
  89. sup.place(w + x, u);
  90. }
  91. }