1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/thebes/gfxMathTable.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,122 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef GFX_MATH_TABLE_H 1.9 +#define GFX_MATH_TABLE_H 1.10 + 1.11 +#include "gfxFont.h" 1.12 + 1.13 +struct Coverage; 1.14 +struct GlyphAssembly; 1.15 +struct MATHTableHeader; 1.16 +struct MathConstants; 1.17 +struct MathGlyphConstruction; 1.18 +struct MathGlyphInfo; 1.19 +struct MathVariants; 1.20 + 1.21 +/** 1.22 + * Used by |gfxFontEntry| to represent the MATH table of an OpenType font. 1.23 + * Each |gfxFontEntry| owns at most one |gfxMathTable| instance. 1.24 + */ 1.25 +class gfxMathTable 1.26 +{ 1.27 +public: 1.28 + /** 1.29 + * @param aMathTable The MATH table from the OpenType font 1.30 + * 1.31 + * The gfxMathTable object takes over ownership of the blob references 1.32 + * that are passed in, and will hb_blob_destroy() them when finished; 1.33 + * the caller should -not- destroy this reference. 1.34 + */ 1.35 + gfxMathTable(hb_blob_t* aMathTable); 1.36 + 1.37 + /** 1.38 + * Releases our reference to the MATH table and cleans up everything else. 1.39 + */ 1.40 + ~gfxMathTable(); 1.41 + 1.42 + /** 1.43 + * Returns the value of the specified constant from the MATH table. 1.44 + */ 1.45 + int32_t GetMathConstant(gfxFontEntry::MathConstant aConstant); 1.46 + 1.47 + /** 1.48 + * If the MATH table contains an italic correction for that glyph, this 1.49 + * function gets the value and returns true. Otherwise it returns false. 1.50 + */ 1.51 + bool 1.52 + GetMathItalicsCorrection(uint32_t aGlyphID, int16_t* aItalicCorrection); 1.53 + 1.54 + /** 1.55 + * @param aGlyphID glyph index of the character we want to stretch 1.56 + * @param aVertical direction of the stretching (vertical/horizontal) 1.57 + * @param aSize the desired size variant 1.58 + * 1.59 + * Returns the glyph index of the desired size variant or 0 if there is not 1.60 + * any such size variant. 1.61 + */ 1.62 + uint32_t GetMathVariantsSize(uint32_t aGlyphID, bool aVertical, 1.63 + uint16_t aSize); 1.64 + 1.65 + /** 1.66 + * @param aGlyphID glyph index of the character we want to stretch 1.67 + * @param aVertical direction of the stretching (vertical/horizontal) 1.68 + * @param aGlyphs pre-allocated buffer of 4 elements where the glyph 1.69 + * indexes (or 0 for absent parts) will be stored. The parts are stored in 1.70 + * the order expected by the nsMathMLChar: Top (or Left), Middle, Bottom 1.71 + * (or Right), Glue. 1.72 + * 1.73 + * Tries to fill-in aGlyphs with the relevant glyph indexes and returns 1.74 + * whether the operation was successful. The function returns false if 1.75 + * there is not any assembly for the character we want to stretch or if 1.76 + * the format is not supported by the nsMathMLChar code. 1.77 + * 1.78 + */ 1.79 + bool GetMathVariantsParts(uint32_t aGlyphID, bool aVertical, 1.80 + uint32_t aGlyphs[4]); 1.81 + 1.82 +protected: 1.83 + friend class gfxFontEntry; 1.84 + // This allows gfxFontEntry to verify the validity of the main headers 1.85 + // before starting to use the MATH table. 1.86 + bool HasValidHeaders(); 1.87 + 1.88 +private: 1.89 + // HarfBuzz blob where the MATH table is stored. 1.90 + hb_blob_t* mMathTable; 1.91 + 1.92 + // Cached values for the latest (mGlyphID, mVertical) pair that has been 1.93 + // accessed and the corresponding glyph construction. These are verified 1.94 + // by SelectGlyphConstruction and updated if necessary. 1.95 + // mGlyphConstruction will be set to nullptr if no construction is defined 1.96 + // for the glyph. If non-null, its mGlyphAssembly and mVariantCount fields 1.97 + // may be safely read, but no further validation will have been done. 1.98 + const MathGlyphConstruction* mGlyphConstruction; 1.99 + uint32_t mGlyphID; 1.100 + bool mVertical; 1.101 + void SelectGlyphConstruction(uint32_t aGlyphID, bool aVertical); 1.102 + 1.103 + // Access to some structures of the MATH table. 1.104 + // These accessors just return a pointer, but do NOT themselves check the 1.105 + // validity of anything. Until we've checked that HasValidHeaders (which 1.106 + // does validate them) returns true, they might return pointers that cannot 1.107 + // even safely be dereferenced. GetGlyphAssembly may return nullptr if the 1.108 + // given glyph has no assembly defined. 1.109 + const MATHTableHeader* GetMATHTableHeader(); 1.110 + const MathConstants* GetMathConstants(); 1.111 + const MathGlyphInfo* GetMathGlyphInfo(); 1.112 + const MathVariants* GetMathVariants(); 1.113 + const GlyphAssembly* GetGlyphAssembly(uint32_t aGlyphID, bool aVertical); 1.114 + 1.115 + // Verify whether a structure or an offset belongs to the math data and can 1.116 + // be read safely. 1.117 + bool ValidStructure(const char* aStructStart, uint16_t aStructSize); 1.118 + bool ValidOffset(const char* aOffsetStart, uint16_t aOffset); 1.119 + 1.120 + // Get the coverage index of a glyph index from an Open Type coverage table 1.121 + // or -1 if the glyph index is not found. 1.122 + int32_t GetCoverageIndex(const Coverage* aCoverage, uint32_t aGlyph); 1.123 +}; 1.124 + 1.125 +#endif