mtd.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 CommonMtd wrapper mixin for the MmlMtd object
  19. *
  20. * @author dpvc@mathjax.org (Davide Cervone)
  21. */
  22. import {AnyWrapper, WrapperConstructor, Constructor} from '../Wrapper.js';
  23. import {CommonMtable} from '../../common/Wrappers/mtable.js';
  24. import {CommonMtr} from '../../common/Wrappers/mtr.js';
  25. /*****************************************************************/
  26. /**
  27. * The CommonMtd interface
  28. */
  29. export interface CommonMtd extends AnyWrapper {
  30. }
  31. /**
  32. * Shorthand for the CommonMtd constructor
  33. */
  34. export type MtdConstructor = Constructor<CommonMtd>;
  35. /*****************************************************************/
  36. /**
  37. * The CommonMtd wrapper mixin for the MmlMtd object
  38. *
  39. * @template T The Wrapper class constructor type
  40. */
  41. export function CommonMtdMixin<T extends WrapperConstructor>(Base: T): MtdConstructor & T {
  42. return class extends Base {
  43. /**
  44. * @override
  45. */
  46. get fixesPWidth() {
  47. return false;
  48. }
  49. /**
  50. * @override
  51. */
  52. public invalidateBBox() {
  53. this.bboxComputed = false;
  54. }
  55. /**
  56. * @override
  57. */
  58. public getWrapWidth(_j: number) {
  59. const table = this.parent.parent as any as CommonMtable<AnyWrapper, CommonMtr<AnyWrapper>>;
  60. const row = this.parent as CommonMtr<AnyWrapper>;
  61. const i = this.node.childPosition() - (row.labeled ? 1 : 0);
  62. return (typeof(table.cWidths[i]) === 'number' ? table.cWidths[i] : table.getTableData().W[i]) as number;
  63. }
  64. /**
  65. * @override
  66. */
  67. public getChildAlign(_i: number) {
  68. return this.node.attributes.get('columnalign') as string;
  69. }
  70. };
  71. }