gfx/thebes/gfxMathTable.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial