|
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/. */ |
|
4 |
|
5 #ifndef GFX_MATH_TABLE_H |
|
6 #define GFX_MATH_TABLE_H |
|
7 |
|
8 #include "gfxFont.h" |
|
9 |
|
10 struct Coverage; |
|
11 struct GlyphAssembly; |
|
12 struct MATHTableHeader; |
|
13 struct MathConstants; |
|
14 struct MathGlyphConstruction; |
|
15 struct MathGlyphInfo; |
|
16 struct MathVariants; |
|
17 |
|
18 /** |
|
19 * Used by |gfxFontEntry| to represent the MATH table of an OpenType font. |
|
20 * Each |gfxFontEntry| owns at most one |gfxMathTable| instance. |
|
21 */ |
|
22 class gfxMathTable |
|
23 { |
|
24 public: |
|
25 /** |
|
26 * @param aMathTable The MATH table from the OpenType font |
|
27 * |
|
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. |
|
31 */ |
|
32 gfxMathTable(hb_blob_t* aMathTable); |
|
33 |
|
34 /** |
|
35 * Releases our reference to the MATH table and cleans up everything else. |
|
36 */ |
|
37 ~gfxMathTable(); |
|
38 |
|
39 /** |
|
40 * Returns the value of the specified constant from the MATH table. |
|
41 */ |
|
42 int32_t GetMathConstant(gfxFontEntry::MathConstant aConstant); |
|
43 |
|
44 /** |
|
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. |
|
47 */ |
|
48 bool |
|
49 GetMathItalicsCorrection(uint32_t aGlyphID, int16_t* aItalicCorrection); |
|
50 |
|
51 /** |
|
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 |
|
55 * |
|
56 * Returns the glyph index of the desired size variant or 0 if there is not |
|
57 * any such size variant. |
|
58 */ |
|
59 uint32_t GetMathVariantsSize(uint32_t aGlyphID, bool aVertical, |
|
60 uint16_t aSize); |
|
61 |
|
62 /** |
|
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 |
|
68 * (or Right), Glue. |
|
69 * |
|
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. |
|
74 * |
|
75 */ |
|
76 bool GetMathVariantsParts(uint32_t aGlyphID, bool aVertical, |
|
77 uint32_t aGlyphs[4]); |
|
78 |
|
79 protected: |
|
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(); |
|
84 |
|
85 private: |
|
86 // HarfBuzz blob where the MATH table is stored. |
|
87 hb_blob_t* mMathTable; |
|
88 |
|
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; |
|
96 uint32_t mGlyphID; |
|
97 bool mVertical; |
|
98 void SelectGlyphConstruction(uint32_t aGlyphID, bool aVertical); |
|
99 |
|
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); |
|
111 |
|
112 // Verify whether a structure or an offset belongs to the math data and can |
|
113 // be read safely. |
|
114 bool ValidStructure(const char* aStructStart, uint16_t aStructSize); |
|
115 bool ValidOffset(const char* aOffsetStart, uint16_t aOffset); |
|
116 |
|
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); |
|
120 }; |
|
121 |
|
122 #endif |