tex.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 The MathJax TeXFont object
  19. *
  20. * @author dpvc@mathjax.org (Davide Cervone)
  21. */
  22. import {SVGFontData, SVGFontDataClass, SVGCharOptions, SVGVariantData, SVGDelimiterData,
  23. DelimiterMap, CharMapMap} from '../FontData.js';
  24. import {CommonTeXFontMixin} from '../../common/fonts/tex.js';
  25. import {OptionList} from '../../../util/Options.js';
  26. import {boldItalic} from './tex/bold-italic.js';
  27. import {bold} from './tex/bold.js';
  28. import {doubleStruck} from './tex/double-struck.js';
  29. import {frakturBold} from './tex/fraktur-bold.js';
  30. import {fraktur} from './tex/fraktur.js';
  31. import {italic} from './tex/italic.js';
  32. import {largeop} from './tex/largeop.js';
  33. import {monospace} from './tex/monospace.js';
  34. import {normal} from './tex/normal.js';
  35. import {sansSerifBoldItalic} from './tex/sans-serif-bold-italic.js';
  36. import {sansSerifBold} from './tex/sans-serif-bold.js';
  37. import {sansSerifItalic} from './tex/sans-serif-italic.js';
  38. import {sansSerif} from './tex/sans-serif.js';
  39. import {scriptBold} from './tex/script-bold.js';
  40. import {script} from './tex/script.js';
  41. import {smallop} from './tex/smallop.js';
  42. import {texCalligraphicBold} from './tex/tex-calligraphic-bold.js';
  43. import {texCalligraphic} from './tex/tex-calligraphic.js';
  44. import {texMathit} from './tex/tex-mathit.js';
  45. import {texOldstyleBold} from './tex/tex-oldstyle-bold.js';
  46. import {texOldstyle} from './tex/tex-oldstyle.js';
  47. import {texSize3} from './tex/tex-size3.js';
  48. import {texSize4} from './tex/tex-size4.js';
  49. import {texVariant} from './tex/tex-variant.js';
  50. import {delimiters} from '../../common/fonts/tex/delimiters.js';
  51. /***********************************************************************************/
  52. /**
  53. * The TeXFont class
  54. */
  55. export class TeXFont extends
  56. CommonTeXFontMixin<SVGCharOptions, SVGVariantData, SVGDelimiterData, SVGFontDataClass>(SVGFontData) {
  57. /**
  58. * The stretchy delimiter data
  59. */
  60. protected static defaultDelimiters: DelimiterMap<SVGDelimiterData> = delimiters;
  61. /**
  62. * The character data by variant
  63. */
  64. protected static defaultChars: CharMapMap<SVGCharOptions> = {
  65. 'normal': normal,
  66. 'bold': bold,
  67. 'italic': italic,
  68. 'bold-italic': boldItalic,
  69. 'double-struck': doubleStruck,
  70. 'fraktur': fraktur,
  71. 'bold-fraktur': frakturBold,
  72. 'script': script,
  73. 'bold-script': scriptBold,
  74. 'sans-serif': sansSerif,
  75. 'bold-sans-serif': sansSerifBold,
  76. 'sans-serif-italic': sansSerifItalic,
  77. 'sans-serif-bold-italic': sansSerifBoldItalic,
  78. 'monospace': monospace,
  79. '-smallop': smallop,
  80. '-largeop': largeop,
  81. '-size3': texSize3,
  82. '-size4': texSize4,
  83. '-tex-calligraphic': texCalligraphic,
  84. '-tex-bold-calligraphic': texCalligraphicBold,
  85. '-tex-mathit': texMathit,
  86. '-tex-oldstyle': texOldstyle,
  87. '-tex-bold-oldstyle': texOldstyleBold,
  88. '-tex-variant': texVariant
  89. };
  90. /**
  91. * The cacheIDs to use for the variants in font-caching
  92. */
  93. protected static variantCacheIds: {[name: string]: string} = {
  94. 'normal': 'N',
  95. 'bold': 'B',
  96. 'italic': 'I',
  97. 'bold-italic': 'BI',
  98. 'double-struck': 'D',
  99. 'fraktur': 'F',
  100. 'bold-fraktur': 'BF',
  101. 'script': 'S',
  102. 'bold-script': 'BS',
  103. 'sans-serif': 'SS',
  104. 'bold-sans-serif': 'BSS',
  105. 'sans-serif-italic': 'SSI',
  106. 'sans-serif-bold-italic': 'SSBI',
  107. 'monospace': 'M',
  108. '-smallop': 'SO',
  109. '-largeop': 'LO',
  110. '-size3': 'S3',
  111. '-size4': 'S4',
  112. '-tex-calligraphic': 'C',
  113. '-tex-bold-calligraphic': 'BC',
  114. '-tex-mathit': 'MI',
  115. '-tex-oldstyle': 'OS',
  116. '-tex-bold-oldstyle': 'BOS',
  117. '-tex-variant': 'V'
  118. };
  119. /**
  120. * @override
  121. */
  122. constructor(options: OptionList = null) {
  123. super(options);
  124. //
  125. // Add the cacheIDs to the variants
  126. //
  127. const CLASS = this.constructor as typeof TeXFont;
  128. for (const variant of Object.keys(CLASS.variantCacheIds)) {
  129. this.variant[variant].cacheID = 'TEX-' + CLASS.variantCacheIds[variant];
  130. }
  131. }
  132. }