nsMathMLOperators.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef nsMathMLOperators_h___
  6. #define nsMathMLOperators_h___
  7. #include <stdint.h>
  8. #include "nsStringFwd.h"
  9. enum nsStretchDirection {
  10. NS_STRETCH_DIRECTION_UNSUPPORTED = -1,
  11. NS_STRETCH_DIRECTION_DEFAULT = 0,
  12. NS_STRETCH_DIRECTION_HORIZONTAL = 1,
  13. NS_STRETCH_DIRECTION_VERTICAL = 2
  14. };
  15. typedef uint32_t nsOperatorFlags;
  16. enum {
  17. // define the bits used to handle the operator
  18. NS_MATHML_OPERATOR_MUTABLE = 1<<30,
  19. NS_MATHML_OPERATOR_EMBELLISH_ANCESTOR = 1<<29,
  20. NS_MATHML_OPERATOR_EMBELLISH_ISOLATED = 1<<28,
  21. NS_MATHML_OPERATOR_CENTERED = 1<<27,
  22. NS_MATHML_OPERATOR_INVISIBLE = 1<<26,
  23. // define the bits used in the Operator Dictionary
  24. // the very last two bits tell us the form
  25. NS_MATHML_OPERATOR_FORM = 0x3,
  26. NS_MATHML_OPERATOR_FORM_INFIX = 1,
  27. NS_MATHML_OPERATOR_FORM_PREFIX = 2,
  28. NS_MATHML_OPERATOR_FORM_POSTFIX = 3,
  29. // the next 2 bits tell us the direction
  30. NS_MATHML_OPERATOR_DIRECTION = 0x3<<2,
  31. NS_MATHML_OPERATOR_DIRECTION_HORIZONTAL = 1<<2,
  32. NS_MATHML_OPERATOR_DIRECTION_VERTICAL = 2<<2,
  33. // other bits used in the Operator Dictionary
  34. NS_MATHML_OPERATOR_STRETCHY = 1<<4,
  35. NS_MATHML_OPERATOR_FENCE = 1<<5,
  36. NS_MATHML_OPERATOR_ACCENT = 1<<6,
  37. NS_MATHML_OPERATOR_LARGEOP = 1<<7,
  38. NS_MATHML_OPERATOR_SEPARATOR = 1<<8,
  39. NS_MATHML_OPERATOR_MOVABLELIMITS = 1<<9,
  40. NS_MATHML_OPERATOR_SYMMETRIC = 1<<10,
  41. NS_MATHML_OPERATOR_INTEGRAL = 1<<11,
  42. NS_MATHML_OPERATOR_MIRRORABLE = 1<<12,
  43. // Additional bits not stored in the dictionary
  44. NS_MATHML_OPERATOR_MINSIZE_ABSOLUTE = 1<<13,
  45. NS_MATHML_OPERATOR_MAXSIZE_ABSOLUTE = 1<<14,
  46. NS_MATHML_OPERATOR_LSPACE_ATTR = 1<<15,
  47. NS_MATHML_OPERATOR_RSPACE_ATTR = 1<<16
  48. };
  49. #define NS_MATHML_OPERATOR_SIZE_INFINITY NS_IEEEPositiveInfinity()
  50. class nsMathMLOperators {
  51. public:
  52. static void AddRefTable(void);
  53. static void ReleaseTable(void);
  54. static void CleanUp();
  55. // LookupOperator:
  56. // Given the string value of an operator and its form (last two bits of flags),
  57. // this method returns true if the operator is found in the Operator Dictionary.
  58. // Attributes of the operator are returned in the output parameters.
  59. // If the operator is not found under the supplied form but is found under a
  60. // different form, the method returns true as well. The caller can test the
  61. // output parameter aFlags to know exactly under which form the operator was
  62. // found in the Operator Dictionary.
  63. static bool
  64. LookupOperator(const nsString& aOperator,
  65. const nsOperatorFlags aForm,
  66. nsOperatorFlags* aFlags,
  67. float* aLeadingSpace,
  68. float* aTrailingSpace);
  69. // LookupOperators:
  70. // Helper to return all the forms under which an operator is listed in the
  71. // Operator Dictionary. The caller must pass arrays of size 4, and use
  72. // aFlags[NS_MATHML_OPERATOR_FORM_{INFIX|POSTFIX|PREFIX}],
  73. // aLeadingSpace[], etc, to access the attributes of the operator under a
  74. // particular form. If the operator wasn't found under a form, its entry
  75. // aFlags[form] is set to zero.
  76. static void
  77. LookupOperators(const nsString& aOperator,
  78. nsOperatorFlags* aFlags,
  79. float* aLeadingSpace,
  80. float* aTrailingSpace);
  81. // Helper functions used by the nsMathMLChar class.
  82. static bool
  83. IsMirrorableOperator(const nsString& aOperator);
  84. // Helper function used by the nsMathMLChar class.
  85. static nsStretchDirection GetStretchyDirection(const nsString& aOperator);
  86. };
  87. ////////////////////////////////////////////////////////////////////////////
  88. // Macros that retrieve the bits used to handle operators
  89. #define NS_MATHML_OPERATOR_IS_MUTABLE(_flags) \
  90. (NS_MATHML_OPERATOR_MUTABLE == ((_flags) & NS_MATHML_OPERATOR_MUTABLE))
  91. #define NS_MATHML_OPERATOR_HAS_EMBELLISH_ANCESTOR(_flags) \
  92. (NS_MATHML_OPERATOR_EMBELLISH_ANCESTOR == ((_flags) & NS_MATHML_OPERATOR_EMBELLISH_ANCESTOR))
  93. #define NS_MATHML_OPERATOR_EMBELLISH_IS_ISOLATED(_flags) \
  94. (NS_MATHML_OPERATOR_EMBELLISH_ISOLATED == ((_flags) & NS_MATHML_OPERATOR_EMBELLISH_ISOLATED))
  95. #define NS_MATHML_OPERATOR_IS_CENTERED(_flags) \
  96. (NS_MATHML_OPERATOR_CENTERED == ((_flags) & NS_MATHML_OPERATOR_CENTERED))
  97. #define NS_MATHML_OPERATOR_IS_INVISIBLE(_flags) \
  98. (NS_MATHML_OPERATOR_INVISIBLE == ((_flags) & NS_MATHML_OPERATOR_INVISIBLE))
  99. #define NS_MATHML_OPERATOR_GET_FORM(_flags) \
  100. ((_flags) & NS_MATHML_OPERATOR_FORM)
  101. #define NS_MATHML_OPERATOR_GET_DIRECTION(_flags) \
  102. ((_flags) & NS_MATHML_OPERATOR_DIRECTION)
  103. #define NS_MATHML_OPERATOR_FORM_IS_INFIX(_flags) \
  104. (NS_MATHML_OPERATOR_FORM_INFIX == ((_flags) & NS_MATHML_OPERATOR_FORM))
  105. #define NS_MATHML_OPERATOR_FORM_IS_PREFIX(_flags) \
  106. (NS_MATHML_OPERATOR_FORM_PREFIX == ((_flags) & NS_MATHML_OPERATOR_FORM))
  107. #define NS_MATHML_OPERATOR_FORM_IS_POSTFIX(_flags) \
  108. (NS_MATHML_OPERATOR_FORM_POSTFIX == ((_flags) & NS_MATHML_OPERATOR_FORM))
  109. #define NS_MATHML_OPERATOR_IS_DIRECTION_VERTICAL(_flags) \
  110. (NS_MATHML_OPERATOR_DIRECTION_VERTICAL == ((_flags) & NS_MATHML_OPERATOR_DIRECTION))
  111. #define NS_MATHML_OPERATOR_IS_DIRECTION_HORIZONTAL(_flags) \
  112. (NS_MATHML_OPERATOR_DIRECTION_HORIZONTAL == ((_flags) & NS_MATHML_OPERATOR_DIRECTION))
  113. #define NS_MATHML_OPERATOR_IS_STRETCHY(_flags) \
  114. (NS_MATHML_OPERATOR_STRETCHY == ((_flags) & NS_MATHML_OPERATOR_STRETCHY))
  115. #define NS_MATHML_OPERATOR_IS_FENCE(_flags) \
  116. (NS_MATHML_OPERATOR_FENCE == ((_flags) & NS_MATHML_OPERATOR_FENCE))
  117. #define NS_MATHML_OPERATOR_IS_ACCENT(_flags) \
  118. (NS_MATHML_OPERATOR_ACCENT == ((_flags) & NS_MATHML_OPERATOR_ACCENT))
  119. #define NS_MATHML_OPERATOR_IS_LARGEOP(_flags) \
  120. (NS_MATHML_OPERATOR_LARGEOP == ((_flags) & NS_MATHML_OPERATOR_LARGEOP))
  121. #define NS_MATHML_OPERATOR_IS_SEPARATOR(_flags) \
  122. (NS_MATHML_OPERATOR_SEPARATOR == ((_flags) & NS_MATHML_OPERATOR_SEPARATOR))
  123. #define NS_MATHML_OPERATOR_IS_MOVABLELIMITS(_flags) \
  124. (NS_MATHML_OPERATOR_MOVABLELIMITS == ((_flags) & NS_MATHML_OPERATOR_MOVABLELIMITS))
  125. #define NS_MATHML_OPERATOR_IS_SYMMETRIC(_flags) \
  126. (NS_MATHML_OPERATOR_SYMMETRIC == ((_flags) & NS_MATHML_OPERATOR_SYMMETRIC))
  127. #define NS_MATHML_OPERATOR_IS_INTEGRAL(_flags) \
  128. (NS_MATHML_OPERATOR_INTEGRAL == ((_flags) & NS_MATHML_OPERATOR_INTEGRAL))
  129. #define NS_MATHML_OPERATOR_IS_MIRRORABLE(_flags) \
  130. (NS_MATHML_OPERATOR_MIRRORABLE == ((_flags) & NS_MATHML_OPERATOR_MIRRORABLE))
  131. #define NS_MATHML_OPERATOR_MINSIZE_IS_ABSOLUTE(_flags) \
  132. (NS_MATHML_OPERATOR_MINSIZE_ABSOLUTE == ((_flags) & NS_MATHML_OPERATOR_MINSIZE_ABSOLUTE))
  133. #define NS_MATHML_OPERATOR_MAXSIZE_IS_ABSOLUTE(_flags) \
  134. (NS_MATHML_OPERATOR_MAXSIZE_ABSOLUTE == ((_flags) & NS_MATHML_OPERATOR_MAXSIZE_ABSOLUTE))
  135. #define NS_MATHML_OPERATOR_HAS_LSPACE_ATTR(_flags) \
  136. (NS_MATHML_OPERATOR_LSPACE_ATTR == ((_flags) & NS_MATHML_OPERATOR_LSPACE_ATTR))
  137. #define NS_MATHML_OPERATOR_HAS_RSPACE_ATTR(_flags) \
  138. (NS_MATHML_OPERATOR_RSPACE_ATTR == ((_flags) & NS_MATHML_OPERATOR_RSPACE_ATTR))
  139. #endif /* nsMathMLOperators_h___ */