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 GFX_MATH_TABLE_H michael@0: #define GFX_MATH_TABLE_H michael@0: michael@0: #include "gfxFont.h" michael@0: michael@0: struct Coverage; michael@0: struct GlyphAssembly; michael@0: struct MATHTableHeader; michael@0: struct MathConstants; michael@0: struct MathGlyphConstruction; michael@0: struct MathGlyphInfo; michael@0: struct MathVariants; michael@0: michael@0: /** michael@0: * Used by |gfxFontEntry| to represent the MATH table of an OpenType font. michael@0: * Each |gfxFontEntry| owns at most one |gfxMathTable| instance. michael@0: */ michael@0: class gfxMathTable michael@0: { michael@0: public: michael@0: /** michael@0: * @param aMathTable The MATH table from the OpenType font michael@0: * michael@0: * The gfxMathTable object takes over ownership of the blob references michael@0: * that are passed in, and will hb_blob_destroy() them when finished; michael@0: * the caller should -not- destroy this reference. michael@0: */ michael@0: gfxMathTable(hb_blob_t* aMathTable); michael@0: michael@0: /** michael@0: * Releases our reference to the MATH table and cleans up everything else. michael@0: */ michael@0: ~gfxMathTable(); michael@0: michael@0: /** michael@0: * Returns the value of the specified constant from the MATH table. michael@0: */ michael@0: int32_t GetMathConstant(gfxFontEntry::MathConstant aConstant); michael@0: michael@0: /** michael@0: * If the MATH table contains an italic correction for that glyph, this michael@0: * function gets the value and returns true. Otherwise it returns false. michael@0: */ michael@0: bool michael@0: GetMathItalicsCorrection(uint32_t aGlyphID, int16_t* aItalicCorrection); michael@0: michael@0: /** michael@0: * @param aGlyphID glyph index of the character we want to stretch michael@0: * @param aVertical direction of the stretching (vertical/horizontal) michael@0: * @param aSize the desired size variant michael@0: * michael@0: * Returns the glyph index of the desired size variant or 0 if there is not michael@0: * any such size variant. michael@0: */ michael@0: uint32_t GetMathVariantsSize(uint32_t aGlyphID, bool aVertical, michael@0: uint16_t aSize); michael@0: michael@0: /** michael@0: * @param aGlyphID glyph index of the character we want to stretch michael@0: * @param aVertical direction of the stretching (vertical/horizontal) michael@0: * @param aGlyphs pre-allocated buffer of 4 elements where the glyph michael@0: * indexes (or 0 for absent parts) will be stored. The parts are stored in michael@0: * the order expected by the nsMathMLChar: Top (or Left), Middle, Bottom michael@0: * (or Right), Glue. michael@0: * michael@0: * Tries to fill-in aGlyphs with the relevant glyph indexes and returns michael@0: * whether the operation was successful. The function returns false if michael@0: * there is not any assembly for the character we want to stretch or if michael@0: * the format is not supported by the nsMathMLChar code. michael@0: * michael@0: */ michael@0: bool GetMathVariantsParts(uint32_t aGlyphID, bool aVertical, michael@0: uint32_t aGlyphs[4]); michael@0: michael@0: protected: michael@0: friend class gfxFontEntry; michael@0: // This allows gfxFontEntry to verify the validity of the main headers michael@0: // before starting to use the MATH table. michael@0: bool HasValidHeaders(); michael@0: michael@0: private: michael@0: // HarfBuzz blob where the MATH table is stored. michael@0: hb_blob_t* mMathTable; michael@0: michael@0: // Cached values for the latest (mGlyphID, mVertical) pair that has been michael@0: // accessed and the corresponding glyph construction. These are verified michael@0: // by SelectGlyphConstruction and updated if necessary. michael@0: // mGlyphConstruction will be set to nullptr if no construction is defined michael@0: // for the glyph. If non-null, its mGlyphAssembly and mVariantCount fields michael@0: // may be safely read, but no further validation will have been done. michael@0: const MathGlyphConstruction* mGlyphConstruction; michael@0: uint32_t mGlyphID; michael@0: bool mVertical; michael@0: void SelectGlyphConstruction(uint32_t aGlyphID, bool aVertical); michael@0: michael@0: // Access to some structures of the MATH table. michael@0: // These accessors just return a pointer, but do NOT themselves check the michael@0: // validity of anything. Until we've checked that HasValidHeaders (which michael@0: // does validate them) returns true, they might return pointers that cannot michael@0: // even safely be dereferenced. GetGlyphAssembly may return nullptr if the michael@0: // given glyph has no assembly defined. michael@0: const MATHTableHeader* GetMATHTableHeader(); michael@0: const MathConstants* GetMathConstants(); michael@0: const MathGlyphInfo* GetMathGlyphInfo(); michael@0: const MathVariants* GetMathVariants(); michael@0: const GlyphAssembly* GetGlyphAssembly(uint32_t aGlyphID, bool aVertical); michael@0: michael@0: // Verify whether a structure or an offset belongs to the math data and can michael@0: // be read safely. michael@0: bool ValidStructure(const char* aStructStart, uint16_t aStructSize); michael@0: bool ValidOffset(const char* aOffsetStart, uint16_t aOffset); michael@0: michael@0: // Get the coverage index of a glyph index from an Open Type coverage table michael@0: // or -1 if the glyph index is not found. michael@0: int32_t GetCoverageIndex(const Coverage* aCoverage, uint32_t aGlyph); michael@0: }; michael@0: michael@0: #endif