TeXAtom.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*************************************************************
  2. *
  3. * Copyright (c) 2017-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 CommonTeXAtom wrapper mixin for the MmlTeXAtom object
  19. *
  20. * @author dpvc@mathjax.org (Davide Cervone)
  21. */
  22. import {AnyWrapper, WrapperConstructor, Constructor} from '../Wrapper.js';
  23. import {BBox} from '../../../util/BBox.js';
  24. import {TEXCLASS} from '../../../core/MmlTree/MmlNode.js';
  25. /*****************************************************************/
  26. /**
  27. * The CommonTeXAtom interface
  28. */
  29. export interface CommonTeXAtom extends AnyWrapper {
  30. }
  31. /**
  32. * Shorthand for the CommonTeXAtom constructor
  33. */
  34. export type TeXAtomConstructor = Constructor<CommonTeXAtom>;
  35. /*****************************************************************/
  36. /**
  37. * The CommonTeXAtom wrapper mixin for the TeXAtom object
  38. *
  39. * @template T The Wrapper class constructor type
  40. */
  41. export function CommonTeXAtomMixin<T extends WrapperConstructor>(Base: T): TeXAtomConstructor & T {
  42. return class extends Base {
  43. /**
  44. * @override
  45. */
  46. public computeBBox(bbox: BBox, recompute: boolean = false) {
  47. super.computeBBox(bbox, recompute);
  48. if (this.childNodes[0] && this.childNodes[0].bbox.ic) {
  49. bbox.ic = this.childNodes[0].bbox.ic;
  50. }
  51. //
  52. // Center VCENTER atoms vertically
  53. //
  54. if (this.node.texClass === TEXCLASS.VCENTER) {
  55. const {h, d} = bbox;
  56. const a = this.font.params.axis_height;
  57. const dh = ((h + d) / 2 + a) - h; // new height minus old height
  58. bbox.h += dh;
  59. bbox.d -= dh;
  60. }
  61. }
  62. };
  63. }