gfxMathTable.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #ifndef GFX_MATH_TABLE_H
  5. #define GFX_MATH_TABLE_H
  6. #include "gfxFont.h"
  7. /**
  8. * Used by |gfxFont| to represent the MATH table of an OpenType font.
  9. * Each |gfxFont| owns at most one |gfxMathTable| instance.
  10. */
  11. class gfxMathTable
  12. {
  13. public:
  14. /**
  15. * @param aFace The HarfBuzz face containing the math table.
  16. * @param aSize The font size to pass to HarfBuzz.
  17. */
  18. gfxMathTable(hb_face_t *aFace, gfxFloat aSize);
  19. /**
  20. * Releases our reference to the MATH table and cleans up everything else.
  21. */
  22. ~gfxMathTable();
  23. enum MathConstant {
  24. // The order of the constants must match the order of the fields
  25. // defined in the MATH table.
  26. ScriptPercentScaleDown,
  27. ScriptScriptPercentScaleDown,
  28. DelimitedSubFormulaMinHeight,
  29. DisplayOperatorMinHeight,
  30. MathLeading,
  31. AxisHeight,
  32. AccentBaseHeight,
  33. FlattenedAccentBaseHeight,
  34. SubscriptShiftDown,
  35. SubscriptTopMax,
  36. SubscriptBaselineDropMin,
  37. SuperscriptShiftUp,
  38. SuperscriptShiftUpCramped,
  39. SuperscriptBottomMin,
  40. SuperscriptBaselineDropMax,
  41. SubSuperscriptGapMin,
  42. SuperscriptBottomMaxWithSubscript,
  43. SpaceAfterScript,
  44. UpperLimitGapMin,
  45. UpperLimitBaselineRiseMin,
  46. LowerLimitGapMin,
  47. LowerLimitBaselineDropMin,
  48. StackTopShiftUp,
  49. StackTopDisplayStyleShiftUp,
  50. StackBottomShiftDown,
  51. StackBottomDisplayStyleShiftDown,
  52. StackGapMin,
  53. StackDisplayStyleGapMin,
  54. StretchStackTopShiftUp,
  55. StretchStackBottomShiftDown,
  56. StretchStackGapAboveMin,
  57. StretchStackGapBelowMin,
  58. FractionNumeratorShiftUp,
  59. FractionNumeratorDisplayStyleShiftUp,
  60. FractionDenominatorShiftDown,
  61. FractionDenominatorDisplayStyleShiftDown,
  62. FractionNumeratorGapMin,
  63. FractionNumDisplayStyleGapMin,
  64. FractionRuleThickness,
  65. FractionDenominatorGapMin,
  66. FractionDenomDisplayStyleGapMin,
  67. SkewedFractionHorizontalGap,
  68. SkewedFractionVerticalGap,
  69. OverbarVerticalGap,
  70. OverbarRuleThickness,
  71. OverbarExtraAscender,
  72. UnderbarVerticalGap,
  73. UnderbarRuleThickness,
  74. UnderbarExtraDescender,
  75. RadicalVerticalGap,
  76. RadicalDisplayStyleVerticalGap,
  77. RadicalRuleThickness,
  78. RadicalExtraAscender,
  79. RadicalKernBeforeDegree,
  80. RadicalKernAfterDegree,
  81. RadicalDegreeBottomRaisePercent
  82. };
  83. /**
  84. * Returns the value of the specified constant from the MATH table.
  85. */
  86. gfxFloat Constant(MathConstant aConstant) const;
  87. /**
  88. * Returns the value of the specified constant in app units.
  89. */
  90. nscoord Constant(MathConstant aConstant,
  91. uint32_t aAppUnitsPerDevPixel) const
  92. {
  93. return NSToCoordRound(Constant(aConstant) * aAppUnitsPerDevPixel);
  94. }
  95. /**
  96. * If the MATH table contains an italic correction for that glyph, this
  97. * function returns the corresponding value. Otherwise it returns 0.
  98. */
  99. gfxFloat
  100. ItalicsCorrection(uint32_t aGlyphID) const;
  101. /**
  102. * @param aGlyphID glyph index of the character we want to stretch
  103. * @param aVertical direction of the stretching (vertical/horizontal)
  104. * @param aSize the desired size variant
  105. *
  106. * Returns the glyph index of the desired size variant or 0 if there is not
  107. * any such size variant.
  108. */
  109. uint32_t VariantsSize(uint32_t aGlyphID, bool aVertical,
  110. uint16_t aSize) const;
  111. /**
  112. * @param aGlyphID glyph index of the character we want to stretch
  113. * @param aVertical direction of the stretching (vertical/horizontal)
  114. * @param aGlyphs pre-allocated buffer of 4 elements where the glyph
  115. * indexes (or 0 for absent parts) will be stored. The parts are stored in
  116. * the order expected by the nsMathMLChar: Top (or Left), Middle, Bottom
  117. * (or Right), Glue.
  118. *
  119. * Tries to fill-in aGlyphs with the relevant glyph indexes and returns
  120. * whether the operation was successful. The function returns false if
  121. * there is not any assembly for the character we want to stretch or if
  122. * the format is not supported by the nsMathMLChar code.
  123. *
  124. */
  125. bool VariantsParts(uint32_t aGlyphID, bool aVertical,
  126. uint32_t aGlyphs[4]) const;
  127. private:
  128. // size-specific font object, owned by the gfxMathTable
  129. hb_font_t *mHBFont;
  130. static const unsigned int kMaxCachedSizeCount = 10;
  131. struct MathVariantCacheEntry {
  132. uint32_t glyphID;
  133. bool vertical;
  134. uint32_t sizes[kMaxCachedSizeCount];
  135. uint32_t parts[4];
  136. bool arePartsValid;
  137. };
  138. mutable MathVariantCacheEntry mMathVariantCache;
  139. void ClearCache() const;
  140. void UpdateMathVariantCache(uint32_t aGlyphID, bool aVertical) const;
  141. };
  142. #endif