1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsMathMLOperators_h_
#define nsMathMLOperators_h_
#include <stdint.h>
#include "mozilla/EnumSet.h"
#include "mozilla/FloatingPoint.h"
#include "nsStringFwd.h"
enum class StretchDirection : uint8_t {
Unsupported,
Default,
Horizontal,
Vertical,
};
enum class OperatorBoolean : uint16_t {
ForcesMathMLChar,
Mutable,
HasEmbellishAncestor,
EmbellishIsIsolated,
Invisible,
Stretchy,
Fence,
Accent,
LargeOperator,
Separator,
MovableLimits,
Symmetric,
MinSizeIsAbsolute,
MaxSizeIsAbsolute,
HasLSpaceAttribute,
HasRSpaceAttribute,
};
using OperatorBooleans = mozilla::EnumSet<OperatorBoolean>;
enum class OperatorForm : uint8_t {
Unknown,
Infix,
Prefix,
Postfix,
};
constexpr uint8_t OperatorFormMask = 0x3;
enum class OperatorDirection : uint8_t {
Unknown,
Horizontal,
Vertical,
};
constexpr uint8_t OperatorDirectionShift = 2;
constexpr uint8_t OperatorDirectionMask = 0x3 << OperatorDirectionShift;
class nsOperatorFlags {
public:
OperatorBooleans& Booleans() { return mBooleans; }
const OperatorBooleans& Booleans() const { return mBooleans; }
OperatorForm Form() const {
return static_cast<OperatorForm>(mFormAndDirection & OperatorFormMask);
}
OperatorDirection Direction() const {
return static_cast<OperatorDirection>(
(mFormAndDirection & OperatorDirectionMask) >> OperatorDirectionShift);
}
void SetForm(OperatorForm aForm) {
mFormAndDirection &= ~OperatorFormMask;
mFormAndDirection |= static_cast<uint8_t>(aForm);
}
void SetDirection(OperatorDirection aDirection) {
mFormAndDirection &= ~OperatorDirectionMask;
mFormAndDirection |= static_cast<uint8_t>(aDirection)
<< OperatorDirectionShift;
}
void Clear() {
mBooleans.clear();
mFormAndDirection = 0;
}
private:
OperatorBooleans mBooleans;
uint8_t mFormAndDirection = 0;
};
constexpr inline float kMathMLOperatorSizeInfinity =
mozilla::PositiveInfinity<float>();
class nsMathMLOperators {
public:
static void AddRefTable(void);
static void ReleaseTable(void);
static void CleanUp();
// LookupOperator:
// Given the string value of an operator and its form (last two bits of
// flags), this method returns attributes of the operator in the output
// parameters. The return value indicates whether an entry was found.
static bool LookupOperator(const nsString& aOperator,
const OperatorForm aForm, nsOperatorFlags* aFlags,
float* aLeadingSpace, float* aTrailingSpace);
// LookupOperatorWithFallback:
// Same as LookupOperator but if the operator is not found under the supplied
// form, then the other forms are tried in the following order: infix, postfix
// prefix. The caller can test the output parameter aFlags to know exactly
// under which form the operator was found in the Operator Dictionary.
static bool LookupOperatorWithFallback(const nsString& aOperator,
const OperatorForm aForm,
nsOperatorFlags* aFlags,
float* aLeadingSpace,
float* aTrailingSpace);
// Helper functions used by the nsMathMLChar class.
static bool IsMirrorableOperator(const nsString& aOperator);
static nsString GetMirroredOperator(const nsString& aOperator);
// Helper functions used by the nsMathMLChar class to determine whether
// aOperator corresponds to an integral operator.
static bool IsIntegralOperator(const nsString& aOperator);
// Helper function used by the nsMathMLChar class.
static StretchDirection GetStretchyDirection(const nsString& aOperator);
};
#endif /* nsMathMLOperators_h_ */
|