layout/mathml/nsMathMLChar.h

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef nsMathMLChar_h___
michael@0 7 #define nsMathMLChar_h___
michael@0 8
michael@0 9 #include "nsAutoPtr.h"
michael@0 10 #include "nsMathMLOperators.h"
michael@0 11 #include "nsPoint.h"
michael@0 12 #include "nsRect.h"
michael@0 13 #include "nsString.h"
michael@0 14 #include "nsBoundingMetrics.h"
michael@0 15 #include "gfxFont.h"
michael@0 16
michael@0 17 class nsGlyphTable;
michael@0 18 class nsIFrame;
michael@0 19 class nsDisplayListBuilder;
michael@0 20 class nsDisplayListSet;
michael@0 21 class nsPresContext;
michael@0 22 class nsRenderingContext;
michael@0 23 class nsBoundingMetrics;
michael@0 24 class nsStyleContext;
michael@0 25 class nsFont;
michael@0 26
michael@0 27 // Hints for Stretch() to indicate criteria for stretching
michael@0 28 enum {
michael@0 29 // Don't stretch
michael@0 30 NS_STRETCH_NONE = 0x00,
michael@0 31 // Variable size stretches
michael@0 32 NS_STRETCH_VARIABLE_MASK = 0x0F,
michael@0 33 NS_STRETCH_NORMAL = 0x01, // try to stretch to requested size
michael@0 34 NS_STRETCH_NEARER = 0x02, // stretch very close to requested size
michael@0 35 NS_STRETCH_SMALLER = 0x04, // don't stretch more than requested size
michael@0 36 NS_STRETCH_LARGER = 0x08, // don't stretch less than requested size
michael@0 37 // A largeop in displaystyle
michael@0 38 NS_STRETCH_LARGEOP = 0x10,
michael@0 39 NS_STRETCH_INTEGRAL = 0x20,
michael@0 40
michael@0 41 // Intended for internal use:
michael@0 42 // Find the widest metrics that might be returned from a vertical stretch
michael@0 43 NS_STRETCH_MAXWIDTH = 0x40
michael@0 44 };
michael@0 45
michael@0 46 // A single glyph in our internal representation is either
michael@0 47 // 1) a 'code@font' pair from the mathfontFONTFAMILY.properties table. The
michael@0 48 // 'code' is interpreted as a Unicode point. The 'font' is a numeric
michael@0 49 // identifier given to the font to which the glyph belongs, which is 0 for the
michael@0 50 // FONTFAMILY and > 0 for 'external' fonts.
michael@0 51 // 2) a glyph index from the Open Type MATH table. In that case, all the glyphs
michael@0 52 // come from the font containing that table and 'font' is just set to -1.
michael@0 53 struct nsGlyphCode {
michael@0 54 union {
michael@0 55 char16_t code[2];
michael@0 56 uint32_t glyphID;
michael@0 57 };
michael@0 58 int8_t font;
michael@0 59
michael@0 60 bool IsGlyphID() const { return font == -1; }
michael@0 61
michael@0 62 int32_t Length() const {
michael@0 63 return (IsGlyphID() || code[1] == PRUnichar('\0') ? 1 : 2);
michael@0 64 }
michael@0 65 bool Exists() const
michael@0 66 {
michael@0 67 return IsGlyphID() ? glyphID != 0 : code[0] != 0;
michael@0 68 }
michael@0 69 bool operator==(const nsGlyphCode& other) const
michael@0 70 {
michael@0 71 return (other.font == font &&
michael@0 72 ((IsGlyphID() && other.glyphID == glyphID) ||
michael@0 73 (!IsGlyphID() && other.code[0] == code[0] &&
michael@0 74 other.code[1] == code[1])));
michael@0 75 }
michael@0 76 bool operator!=(const nsGlyphCode& other) const
michael@0 77 {
michael@0 78 return ! operator==(other);
michael@0 79 }
michael@0 80 };
michael@0 81
michael@0 82 // Class used to handle stretchy symbols (accent, delimiter and boundary
michael@0 83 // symbols).
michael@0 84 class nsMathMLChar
michael@0 85 {
michael@0 86 public:
michael@0 87 // constructor and destructor
michael@0 88 nsMathMLChar() {
michael@0 89 MOZ_COUNT_CTOR(nsMathMLChar);
michael@0 90 mStyleContext = nullptr;
michael@0 91 mUnscaledAscent = 0;
michael@0 92 mScaleX = mScaleY = 1.0;
michael@0 93 mDraw = DRAW_NORMAL;
michael@0 94 mMirrored = false;
michael@0 95 }
michael@0 96
michael@0 97 // not a virtual destructor: this class is not intended to be subclassed
michael@0 98 ~nsMathMLChar();
michael@0 99
michael@0 100 void Display(nsDisplayListBuilder* aBuilder,
michael@0 101 nsIFrame* aForFrame,
michael@0 102 const nsDisplayListSet& aLists,
michael@0 103 uint32_t aIndex,
michael@0 104 const nsRect* aSelectedRect = nullptr);
michael@0 105
michael@0 106 void PaintForeground(nsPresContext* aPresContext,
michael@0 107 nsRenderingContext& aRenderingContext,
michael@0 108 nsPoint aPt,
michael@0 109 bool aIsSelected);
michael@0 110
michael@0 111 // This is the method called to ask the char to stretch itself.
michael@0 112 // @param aContainerSize - IN - suggested size for the stretched char
michael@0 113 // @param aDesiredStretchSize - OUT - the size that the char wants
michael@0 114 nsresult
michael@0 115 Stretch(nsPresContext* aPresContext,
michael@0 116 nsRenderingContext& aRenderingContext,
michael@0 117 nsStretchDirection aStretchDirection,
michael@0 118 const nsBoundingMetrics& aContainerSize,
michael@0 119 nsBoundingMetrics& aDesiredStretchSize,
michael@0 120 uint32_t aStretchHint,
michael@0 121 bool aRTL);
michael@0 122
michael@0 123 void
michael@0 124 SetData(nsPresContext* aPresContext,
michael@0 125 nsString& aData);
michael@0 126
michael@0 127 void
michael@0 128 GetData(nsString& aData) {
michael@0 129 aData = mData;
michael@0 130 }
michael@0 131
michael@0 132 int32_t
michael@0 133 Length() {
michael@0 134 return mData.Length();
michael@0 135 }
michael@0 136
michael@0 137 nsStretchDirection
michael@0 138 GetStretchDirection() {
michael@0 139 return mDirection;
michael@0 140 }
michael@0 141
michael@0 142 // Sometimes we only want to pass the data to another routine,
michael@0 143 // this function helps to avoid copying
michael@0 144 const char16_t*
michael@0 145 get() {
michael@0 146 return mData.get();
michael@0 147 }
michael@0 148
michael@0 149 void
michael@0 150 GetRect(nsRect& aRect) {
michael@0 151 aRect = mRect;
michael@0 152 }
michael@0 153
michael@0 154 void
michael@0 155 SetRect(const nsRect& aRect) {
michael@0 156 mRect = aRect;
michael@0 157 }
michael@0 158
michael@0 159 // Get the maximum width that the character might have after a vertical
michael@0 160 // Stretch().
michael@0 161 //
michael@0 162 // @param aStretchHint can be the value that will be passed to Stretch().
michael@0 163 // It is used to determine whether the operator is stretchy or a largeop.
michael@0 164 // @param aMaxSize is the value of the "maxsize" attribute.
michael@0 165 // @param aMaxSizeIsAbsolute indicates whether the aMaxSize is an absolute
michael@0 166 // value in app units (true) or a multiplier of the base size (false).
michael@0 167 nscoord
michael@0 168 GetMaxWidth(nsPresContext* aPresContext,
michael@0 169 nsRenderingContext& aRenderingContext,
michael@0 170 uint32_t aStretchHint = NS_STRETCH_NORMAL,
michael@0 171 float aMaxSize = NS_MATHML_OPERATOR_SIZE_INFINITY,
michael@0 172 // Perhaps just nsOperatorFlags aFlags.
michael@0 173 // But need DisplayStyle for largeOp,
michael@0 174 // or remove the largeop bit from flags.
michael@0 175 bool aMaxSizeIsAbsolute = false);
michael@0 176
michael@0 177 // Metrics that _exactly_ enclose the char. The char *must* have *already*
michael@0 178 // being stretched before you can call the GetBoundingMetrics() method.
michael@0 179 // IMPORTANT: since chars have their own style contexts, and may be rendered
michael@0 180 // with glyphs that are not in the parent font, just calling the default
michael@0 181 // aRenderingContext.GetBoundingMetrics(aChar) can give incorrect results.
michael@0 182 void
michael@0 183 GetBoundingMetrics(nsBoundingMetrics& aBoundingMetrics) {
michael@0 184 aBoundingMetrics = mBoundingMetrics;
michael@0 185 }
michael@0 186
michael@0 187 void
michael@0 188 SetBoundingMetrics(nsBoundingMetrics& aBoundingMetrics) {
michael@0 189 mBoundingMetrics = aBoundingMetrics;
michael@0 190 }
michael@0 191
michael@0 192 // Hooks to access the extra leaf style contexts given to the MathMLChars.
michael@0 193 // They provide an interface to make them accessible to the Style System via
michael@0 194 // the Get/Set AdditionalStyleContext() APIs. Owners of MathMLChars
michael@0 195 // should honor these APIs.
michael@0 196 nsStyleContext* GetStyleContext() const;
michael@0 197
michael@0 198 void SetStyleContext(nsStyleContext* aStyleContext);
michael@0 199
michael@0 200 protected:
michael@0 201 friend class nsGlyphTable;
michael@0 202 friend class nsPropertiesTable;
michael@0 203 friend class nsOpenTypeTable;
michael@0 204 nsString mData;
michael@0 205
michael@0 206 private:
michael@0 207 nsRect mRect;
michael@0 208 nsStretchDirection mDirection;
michael@0 209 nsBoundingMetrics mBoundingMetrics;
michael@0 210 nsStyleContext* mStyleContext;
michael@0 211 // mGlyphs/mBmData are arrays describing the glyphs used to draw the operator.
michael@0 212 // See the drawing methods below.
michael@0 213 nsAutoPtr<gfxTextRun> mGlyphs[4];
michael@0 214 nsBoundingMetrics mBmData[4];
michael@0 215 // mUnscaledAscent is the actual ascent of the char.
michael@0 216 nscoord mUnscaledAscent;
michael@0 217 // mScaleX, mScaleY are the factors by which we scale the char.
michael@0 218 float mScaleX, mScaleY;
michael@0 219
michael@0 220 // mDraw indicates how we draw the stretchy operator:
michael@0 221 // - DRAW_NORMAL: we render the mData string normally.
michael@0 222 // - DRAW_VARIANT: we draw a larger size variant given by mGlyphs[0].
michael@0 223 // - DRAW_PARTS: we assemble several parts given by mGlyphs[0], ... mGlyphs[4]
michael@0 224 // XXXfredw: the MATH table can have any numbers of parts and extenders.
michael@0 225 enum DrawingMethod {
michael@0 226 DRAW_NORMAL, DRAW_VARIANT, DRAW_PARTS
michael@0 227 };
michael@0 228 DrawingMethod mDraw;
michael@0 229
michael@0 230 // mMirrored indicates whether the character is mirrored.
michael@0 231 bool mMirrored;
michael@0 232
michael@0 233 class StretchEnumContext;
michael@0 234 friend class StretchEnumContext;
michael@0 235
michael@0 236 // helper methods
michael@0 237 bool
michael@0 238 SetFontFamily(nsPresContext* aPresContext,
michael@0 239 const nsGlyphTable* aGlyphTable,
michael@0 240 const nsGlyphCode& aGlyphCode,
michael@0 241 const nsAString& aDefaultFamily,
michael@0 242 nsFont& aFont,
michael@0 243 nsRefPtr<gfxFontGroup>* aFontGroup);
michael@0 244
michael@0 245 nsresult
michael@0 246 StretchInternal(nsPresContext* aPresContext,
michael@0 247 gfxContext* aThebesContext,
michael@0 248 nsStretchDirection& aStretchDirection,
michael@0 249 const nsBoundingMetrics& aContainerSize,
michael@0 250 nsBoundingMetrics& aDesiredStretchSize,
michael@0 251 uint32_t aStretchHint,
michael@0 252 float aMaxSize = NS_MATHML_OPERATOR_SIZE_INFINITY,
michael@0 253 bool aMaxSizeIsAbsolute = false);
michael@0 254
michael@0 255 nsresult
michael@0 256 PaintVertically(nsPresContext* aPresContext,
michael@0 257 gfxContext* aThebesContext,
michael@0 258 nsRect& aRect);
michael@0 259
michael@0 260 nsresult
michael@0 261 PaintHorizontally(nsPresContext* aPresContext,
michael@0 262 gfxContext* aThebesContext,
michael@0 263 nsRect& aRect);
michael@0 264
michael@0 265 void
michael@0 266 ApplyTransforms(gfxContext* aThebesContext, int32_t aAppUnitsPerGfxUnit,
michael@0 267 nsRect &r);
michael@0 268 };
michael@0 269
michael@0 270 #endif /* nsMathMLChar_h___ */

mercurial