1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef GFX_MATH_TABLE_H
6 #define GFX_MATH_TABLE_H
12 struct MATHTableHeader
;
14 struct MathGlyphConstruction
;
19 * Used by |gfxFontEntry| to represent the MATH table of an OpenType font.
20 * Each |gfxFontEntry| owns at most one |gfxMathTable| instance.
26 * @param aMathTable The MATH table from the OpenType font
28 * The gfxMathTable object takes over ownership of the blob references
29 * that are passed in, and will hb_blob_destroy() them when finished;
30 * the caller should -not- destroy this reference.
32 explicit gfxMathTable(hb_blob_t
* aMathTable
);
35 * Releases our reference to the MATH table and cleans up everything else.
40 * Returns the value of the specified constant from the MATH table.
42 int32_t GetMathConstant(gfxFontEntry::MathConstant aConstant
);
45 * If the MATH table contains an italic correction for that glyph, this
46 * function gets the value and returns true. Otherwise it returns false.
49 GetMathItalicsCorrection(uint32_t aGlyphID
, int16_t* aItalicCorrection
);
52 * @param aGlyphID glyph index of the character we want to stretch
53 * @param aVertical direction of the stretching (vertical/horizontal)
54 * @param aSize the desired size variant
56 * Returns the glyph index of the desired size variant or 0 if there is not
57 * any such size variant.
59 uint32_t GetMathVariantsSize(uint32_t aGlyphID
, bool aVertical
,
63 * @param aGlyphID glyph index of the character we want to stretch
64 * @param aVertical direction of the stretching (vertical/horizontal)
65 * @param aGlyphs pre-allocated buffer of 4 elements where the glyph
66 * indexes (or 0 for absent parts) will be stored. The parts are stored in
67 * the order expected by the nsMathMLChar: Top (or Left), Middle, Bottom
70 * Tries to fill-in aGlyphs with the relevant glyph indexes and returns
71 * whether the operation was successful. The function returns false if
72 * there is not any assembly for the character we want to stretch or if
73 * the format is not supported by the nsMathMLChar code.
76 bool GetMathVariantsParts(uint32_t aGlyphID
, bool aVertical
,
80 friend class gfxFontEntry
;
81 // This allows gfxFontEntry to verify the validity of the main headers
82 // before starting to use the MATH table.
83 bool HasValidHeaders();
86 // HarfBuzz blob where the MATH table is stored.
87 hb_blob_t
* mMathTable
;
89 // Cached values for the latest (mGlyphID, mVertical) pair that has been
90 // accessed and the corresponding glyph construction. These are verified
91 // by SelectGlyphConstruction and updated if necessary.
92 // mGlyphConstruction will be set to nullptr if no construction is defined
93 // for the glyph. If non-null, its mGlyphAssembly and mVariantCount fields
94 // may be safely read, but no further validation will have been done.
95 const MathGlyphConstruction
* mGlyphConstruction
;
98 void SelectGlyphConstruction(uint32_t aGlyphID
, bool aVertical
);
100 // Access to some structures of the MATH table.
101 // These accessors just return a pointer, but do NOT themselves check the
102 // validity of anything. Until we've checked that HasValidHeaders (which
103 // does validate them) returns true, they might return pointers that cannot
104 // even safely be dereferenced. GetGlyphAssembly may return nullptr if the
105 // given glyph has no assembly defined.
106 const MATHTableHeader
* GetMATHTableHeader();
107 const MathConstants
* GetMathConstants();
108 const MathGlyphInfo
* GetMathGlyphInfo();
109 const MathVariants
* GetMathVariants();
110 const GlyphAssembly
* GetGlyphAssembly(uint32_t aGlyphID
, bool aVertical
);
112 // Verify whether a structure or an offset belongs to the math data and can
114 bool ValidStructure(const char* aStructStart
, uint16_t aStructSize
);
115 bool ValidOffset(const char* aOffsetStart
, uint16_t aOffset
);
117 // Get the coverage index of a glyph index from an Open Type coverage table
118 // or -1 if the glyph index is not found.
119 int32_t GetCoverageIndex(const Coverage
* aCoverage
, uint32_t aGlyph
);