mglyph.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 SVGmglyph wrapper for the MmlMglyph object
  19. *
  20. * @author dpvc@mathjax.org (Davide Cervone)
  21. */
  22. import {SVGWrapper, SVGConstructor} from '../Wrapper.js';
  23. import {CommonMglyphMixin} from '../../common/Wrappers/mglyph.js';
  24. import {MmlMglyph} from '../../../core/MmlTree/MmlNodes/mglyph.js';
  25. import {SVGTextNode} from './TextNode.js';
  26. import {OptionList} from '../../../util/Options.js';
  27. /*****************************************************************/
  28. /**
  29. * The SVGmglyph wrapper for the MmlMglyph object
  30. *
  31. * @template N The HTMLElement node class
  32. * @template T The Text node class
  33. * @template D The Document class
  34. */
  35. // @ts-ignore
  36. export class SVGmglyph<N, T, D> extends
  37. CommonMglyphMixin<SVGConstructor<any, any, any>>(SVGWrapper) {
  38. /**
  39. * The mglyph wrapper
  40. */
  41. public static kind = MmlMglyph.prototype.kind;
  42. /**
  43. * @override
  44. */
  45. public toSVG(parent: N) {
  46. const svg = this.standardSVGnode(parent);
  47. if (this.charWrapper) {
  48. (this.charWrapper as SVGTextNode<N, T, D>).toSVG(svg);
  49. return;
  50. }
  51. const {src, alt} = this.node.attributes.getList('src', 'alt');
  52. const h = this.fixed(this.height);
  53. const w = this.fixed(this.width);
  54. const y = this.fixed(this.height + (this.valign || 0));
  55. const properties: OptionList = {
  56. width: w, height: h,
  57. transform: 'translate(0 ' + y + ') matrix(1 0 0 -1 0 0)',
  58. preserveAspectRatio: 'none',
  59. 'aria-label': alt,
  60. href: src
  61. };
  62. const img = this.svg('image', properties);
  63. this.adaptor.append(svg, img);
  64. }
  65. }