michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsMathMLChar_h___ michael@0: #define nsMathMLChar_h___ michael@0: michael@0: #include "nsAutoPtr.h" michael@0: #include "nsMathMLOperators.h" michael@0: #include "nsPoint.h" michael@0: #include "nsRect.h" michael@0: #include "nsString.h" michael@0: #include "nsBoundingMetrics.h" michael@0: #include "gfxFont.h" michael@0: michael@0: class nsGlyphTable; michael@0: class nsIFrame; michael@0: class nsDisplayListBuilder; michael@0: class nsDisplayListSet; michael@0: class nsPresContext; michael@0: class nsRenderingContext; michael@0: class nsBoundingMetrics; michael@0: class nsStyleContext; michael@0: class nsFont; michael@0: michael@0: // Hints for Stretch() to indicate criteria for stretching michael@0: enum { michael@0: // Don't stretch michael@0: NS_STRETCH_NONE = 0x00, michael@0: // Variable size stretches michael@0: NS_STRETCH_VARIABLE_MASK = 0x0F, michael@0: NS_STRETCH_NORMAL = 0x01, // try to stretch to requested size michael@0: NS_STRETCH_NEARER = 0x02, // stretch very close to requested size michael@0: NS_STRETCH_SMALLER = 0x04, // don't stretch more than requested size michael@0: NS_STRETCH_LARGER = 0x08, // don't stretch less than requested size michael@0: // A largeop in displaystyle michael@0: NS_STRETCH_LARGEOP = 0x10, michael@0: NS_STRETCH_INTEGRAL = 0x20, michael@0: michael@0: // Intended for internal use: michael@0: // Find the widest metrics that might be returned from a vertical stretch michael@0: NS_STRETCH_MAXWIDTH = 0x40 michael@0: }; michael@0: michael@0: // A single glyph in our internal representation is either michael@0: // 1) a 'code@font' pair from the mathfontFONTFAMILY.properties table. The michael@0: // 'code' is interpreted as a Unicode point. The 'font' is a numeric michael@0: // identifier given to the font to which the glyph belongs, which is 0 for the michael@0: // FONTFAMILY and > 0 for 'external' fonts. michael@0: // 2) a glyph index from the Open Type MATH table. In that case, all the glyphs michael@0: // come from the font containing that table and 'font' is just set to -1. michael@0: struct nsGlyphCode { michael@0: union { michael@0: char16_t code[2]; michael@0: uint32_t glyphID; michael@0: }; michael@0: int8_t font; michael@0: michael@0: bool IsGlyphID() const { return font == -1; } michael@0: michael@0: int32_t Length() const { michael@0: return (IsGlyphID() || code[1] == PRUnichar('\0') ? 1 : 2); michael@0: } michael@0: bool Exists() const michael@0: { michael@0: return IsGlyphID() ? glyphID != 0 : code[0] != 0; michael@0: } michael@0: bool operator==(const nsGlyphCode& other) const michael@0: { michael@0: return (other.font == font && michael@0: ((IsGlyphID() && other.glyphID == glyphID) || michael@0: (!IsGlyphID() && other.code[0] == code[0] && michael@0: other.code[1] == code[1]))); michael@0: } michael@0: bool operator!=(const nsGlyphCode& other) const michael@0: { michael@0: return ! operator==(other); michael@0: } michael@0: }; michael@0: michael@0: // Class used to handle stretchy symbols (accent, delimiter and boundary michael@0: // symbols). michael@0: class nsMathMLChar michael@0: { michael@0: public: michael@0: // constructor and destructor michael@0: nsMathMLChar() { michael@0: MOZ_COUNT_CTOR(nsMathMLChar); michael@0: mStyleContext = nullptr; michael@0: mUnscaledAscent = 0; michael@0: mScaleX = mScaleY = 1.0; michael@0: mDraw = DRAW_NORMAL; michael@0: mMirrored = false; michael@0: } michael@0: michael@0: // not a virtual destructor: this class is not intended to be subclassed michael@0: ~nsMathMLChar(); michael@0: michael@0: void Display(nsDisplayListBuilder* aBuilder, michael@0: nsIFrame* aForFrame, michael@0: const nsDisplayListSet& aLists, michael@0: uint32_t aIndex, michael@0: const nsRect* aSelectedRect = nullptr); michael@0: michael@0: void PaintForeground(nsPresContext* aPresContext, michael@0: nsRenderingContext& aRenderingContext, michael@0: nsPoint aPt, michael@0: bool aIsSelected); michael@0: michael@0: // This is the method called to ask the char to stretch itself. michael@0: // @param aContainerSize - IN - suggested size for the stretched char michael@0: // @param aDesiredStretchSize - OUT - the size that the char wants michael@0: nsresult michael@0: Stretch(nsPresContext* aPresContext, michael@0: nsRenderingContext& aRenderingContext, michael@0: nsStretchDirection aStretchDirection, michael@0: const nsBoundingMetrics& aContainerSize, michael@0: nsBoundingMetrics& aDesiredStretchSize, michael@0: uint32_t aStretchHint, michael@0: bool aRTL); michael@0: michael@0: void michael@0: SetData(nsPresContext* aPresContext, michael@0: nsString& aData); michael@0: michael@0: void michael@0: GetData(nsString& aData) { michael@0: aData = mData; michael@0: } michael@0: michael@0: int32_t michael@0: Length() { michael@0: return mData.Length(); michael@0: } michael@0: michael@0: nsStretchDirection michael@0: GetStretchDirection() { michael@0: return mDirection; michael@0: } michael@0: michael@0: // Sometimes we only want to pass the data to another routine, michael@0: // this function helps to avoid copying michael@0: const char16_t* michael@0: get() { michael@0: return mData.get(); michael@0: } michael@0: michael@0: void michael@0: GetRect(nsRect& aRect) { michael@0: aRect = mRect; michael@0: } michael@0: michael@0: void michael@0: SetRect(const nsRect& aRect) { michael@0: mRect = aRect; michael@0: } michael@0: michael@0: // Get the maximum width that the character might have after a vertical michael@0: // Stretch(). michael@0: // michael@0: // @param aStretchHint can be the value that will be passed to Stretch(). michael@0: // It is used to determine whether the operator is stretchy or a largeop. michael@0: // @param aMaxSize is the value of the "maxsize" attribute. michael@0: // @param aMaxSizeIsAbsolute indicates whether the aMaxSize is an absolute michael@0: // value in app units (true) or a multiplier of the base size (false). michael@0: nscoord michael@0: GetMaxWidth(nsPresContext* aPresContext, michael@0: nsRenderingContext& aRenderingContext, michael@0: uint32_t aStretchHint = NS_STRETCH_NORMAL, michael@0: float aMaxSize = NS_MATHML_OPERATOR_SIZE_INFINITY, michael@0: // Perhaps just nsOperatorFlags aFlags. michael@0: // But need DisplayStyle for largeOp, michael@0: // or remove the largeop bit from flags. michael@0: bool aMaxSizeIsAbsolute = false); michael@0: michael@0: // Metrics that _exactly_ enclose the char. The char *must* have *already* michael@0: // being stretched before you can call the GetBoundingMetrics() method. michael@0: // IMPORTANT: since chars have their own style contexts, and may be rendered michael@0: // with glyphs that are not in the parent font, just calling the default michael@0: // aRenderingContext.GetBoundingMetrics(aChar) can give incorrect results. michael@0: void michael@0: GetBoundingMetrics(nsBoundingMetrics& aBoundingMetrics) { michael@0: aBoundingMetrics = mBoundingMetrics; michael@0: } michael@0: michael@0: void michael@0: SetBoundingMetrics(nsBoundingMetrics& aBoundingMetrics) { michael@0: mBoundingMetrics = aBoundingMetrics; michael@0: } michael@0: michael@0: // Hooks to access the extra leaf style contexts given to the MathMLChars. michael@0: // They provide an interface to make them accessible to the Style System via michael@0: // the Get/Set AdditionalStyleContext() APIs. Owners of MathMLChars michael@0: // should honor these APIs. michael@0: nsStyleContext* GetStyleContext() const; michael@0: michael@0: void SetStyleContext(nsStyleContext* aStyleContext); michael@0: michael@0: protected: michael@0: friend class nsGlyphTable; michael@0: friend class nsPropertiesTable; michael@0: friend class nsOpenTypeTable; michael@0: nsString mData; michael@0: michael@0: private: michael@0: nsRect mRect; michael@0: nsStretchDirection mDirection; michael@0: nsBoundingMetrics mBoundingMetrics; michael@0: nsStyleContext* mStyleContext; michael@0: // mGlyphs/mBmData are arrays describing the glyphs used to draw the operator. michael@0: // See the drawing methods below. michael@0: nsAutoPtr mGlyphs[4]; michael@0: nsBoundingMetrics mBmData[4]; michael@0: // mUnscaledAscent is the actual ascent of the char. michael@0: nscoord mUnscaledAscent; michael@0: // mScaleX, mScaleY are the factors by which we scale the char. michael@0: float mScaleX, mScaleY; michael@0: michael@0: // mDraw indicates how we draw the stretchy operator: michael@0: // - DRAW_NORMAL: we render the mData string normally. michael@0: // - DRAW_VARIANT: we draw a larger size variant given by mGlyphs[0]. michael@0: // - DRAW_PARTS: we assemble several parts given by mGlyphs[0], ... mGlyphs[4] michael@0: // XXXfredw: the MATH table can have any numbers of parts and extenders. michael@0: enum DrawingMethod { michael@0: DRAW_NORMAL, DRAW_VARIANT, DRAW_PARTS michael@0: }; michael@0: DrawingMethod mDraw; michael@0: michael@0: // mMirrored indicates whether the character is mirrored. michael@0: bool mMirrored; michael@0: michael@0: class StretchEnumContext; michael@0: friend class StretchEnumContext; michael@0: michael@0: // helper methods michael@0: bool michael@0: SetFontFamily(nsPresContext* aPresContext, michael@0: const nsGlyphTable* aGlyphTable, michael@0: const nsGlyphCode& aGlyphCode, michael@0: const nsAString& aDefaultFamily, michael@0: nsFont& aFont, michael@0: nsRefPtr* aFontGroup); michael@0: michael@0: nsresult michael@0: StretchInternal(nsPresContext* aPresContext, michael@0: gfxContext* aThebesContext, michael@0: nsStretchDirection& aStretchDirection, michael@0: const nsBoundingMetrics& aContainerSize, michael@0: nsBoundingMetrics& aDesiredStretchSize, michael@0: uint32_t aStretchHint, michael@0: float aMaxSize = NS_MATHML_OPERATOR_SIZE_INFINITY, michael@0: bool aMaxSizeIsAbsolute = false); michael@0: michael@0: nsresult michael@0: PaintVertically(nsPresContext* aPresContext, michael@0: gfxContext* aThebesContext, michael@0: nsRect& aRect); michael@0: michael@0: nsresult michael@0: PaintHorizontally(nsPresContext* aPresContext, michael@0: gfxContext* aThebesContext, michael@0: nsRect& aRect); michael@0: michael@0: void michael@0: ApplyTransforms(gfxContext* aThebesContext, int32_t aAppUnitsPerGfxUnit, michael@0: nsRect &r); michael@0: }; michael@0: michael@0: #endif /* nsMathMLChar_h___ */