mtd.ts 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 SVGmtd wrapper for the MmlMtd object
  19. *
  20. * @author dpvc@mathjax.org (Davide Cervone)
  21. */
  22. import {SVGWrapper, SVGConstructor} from '../Wrapper.js';
  23. import {CommonMtdMixin} from '../../common/Wrappers/mtd.js';
  24. import {MmlMtd} from '../../../core/MmlTree/MmlNodes/mtd.js';
  25. /*****************************************************************/
  26. /**
  27. * The SVGmtd wrapper for the MmlMtd object
  28. *
  29. * @template N The HTMLElement node class
  30. * @template T The Text node class
  31. * @template D The Document class
  32. */
  33. // @ts-ignore
  34. export class SVGmtd<N, T, D> extends
  35. CommonMtdMixin<SVGConstructor<any, any, any>>(SVGWrapper) {
  36. /**
  37. * The mtd wrapper
  38. */
  39. public static kind = MmlMtd.prototype.kind;
  40. /**
  41. * @param {number} x The x offset of the left side of the cell
  42. * @param {number} y The y offset of the baseline of the cell
  43. * @param {number} W The width of the cell
  44. * @param {number} H The height of the cell
  45. * @param {number} D The depth of the cell
  46. * @return {[number, number]} The x and y offsets used
  47. */
  48. public placeCell(x: number, y: number, W: number, H: number, D: number): [number, number] {
  49. const bbox = this.getBBox();
  50. const h = Math.max(bbox.h, .75);
  51. const d = Math.max(bbox.d, .25);
  52. const calign = this.node.attributes.get('columnalign') as string;
  53. const ralign = this.node.attributes.get('rowalign') as string;
  54. const alignX = this.getAlignX(W, bbox, calign);
  55. const alignY = this.getAlignY(H, D, h, d, ralign);
  56. this.place(x + alignX, y + alignY);
  57. return [alignX, alignY];
  58. }
  59. /**
  60. * @param {number} x The x offset of the left side of the cell
  61. * @param {number} y The y position of the bottom of the cell
  62. * @param {number} W The width of the cell
  63. * @param {number} H The height + depth of the cell
  64. */
  65. public placeColor(x: number, y: number, W: number, H: number) {
  66. const adaptor = this.adaptor;
  67. const child = this.firstChild();
  68. if (child && adaptor.kind(child) === 'rect' && adaptor.getAttribute(child, 'data-bgcolor')) {
  69. adaptor.setAttribute(child, 'x', this.fixed(x));
  70. adaptor.setAttribute(child, 'y', this.fixed(y));
  71. adaptor.setAttribute(child, 'width', this.fixed(W));
  72. adaptor.setAttribute(child, 'height', this.fixed(H));
  73. }
  74. }
  75. }