Tue, 06 Jan 2015 21:39:09 +0100
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 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef NSFONTMETRICS__H__ |
michael@0 | 7 | #define NSFONTMETRICS__H__ |
michael@0 | 8 | |
michael@0 | 9 | #include <stdint.h> // for uint32_t |
michael@0 | 10 | #include <sys/types.h> // for int32_t |
michael@0 | 11 | #include "gfxFont.h" // for gfxFont, gfxFontGroup |
michael@0 | 12 | #include "mozilla/Assertions.h" // for MOZ_ASSERT_HELPER2 |
michael@0 | 13 | #include "nsAutoPtr.h" // for nsRefPtr |
michael@0 | 14 | #include "nsCOMPtr.h" // for nsCOMPtr |
michael@0 | 15 | #include "nsCoord.h" // for nscoord |
michael@0 | 16 | #include "nsError.h" // for nsresult |
michael@0 | 17 | #include "nsFont.h" // for nsFont |
michael@0 | 18 | #include "nsISupports.h" // for NS_INLINE_DECL_REFCOUNTING |
michael@0 | 19 | #include "nscore.h" // for char16_t |
michael@0 | 20 | |
michael@0 | 21 | class gfxUserFontSet; |
michael@0 | 22 | class gfxTextPerfMetrics; |
michael@0 | 23 | class nsDeviceContext; |
michael@0 | 24 | class nsIAtom; |
michael@0 | 25 | class nsRenderingContext; |
michael@0 | 26 | struct nsBoundingMetrics; |
michael@0 | 27 | |
michael@0 | 28 | /** |
michael@0 | 29 | * Font metrics |
michael@0 | 30 | * |
michael@0 | 31 | * This class may be somewhat misnamed. A better name might be |
michael@0 | 32 | * nsFontList. The style system uses the nsFont struct for various |
michael@0 | 33 | * font properties, one of which is font-family, which can contain a |
michael@0 | 34 | * *list* of font names. The nsFont struct is "realized" by asking the |
michael@0 | 35 | * device context to cough up an nsFontMetrics object, which contains |
michael@0 | 36 | * a list of real font handles, one for each font mentioned in |
michael@0 | 37 | * font-family (and for each fallback when we fall off the end of that |
michael@0 | 38 | * list). |
michael@0 | 39 | * |
michael@0 | 40 | * The style system needs to have access to certain metrics, such as |
michael@0 | 41 | * the em height (for the CSS "em" unit), and we use the first Western |
michael@0 | 42 | * font's metrics for that purpose. The platform-specific |
michael@0 | 43 | * implementations are expected to select non-Western fonts that "fit" |
michael@0 | 44 | * reasonably well with the Western font that is loaded at Init time. |
michael@0 | 45 | */ |
michael@0 | 46 | class nsFontMetrics MOZ_FINAL |
michael@0 | 47 | { |
michael@0 | 48 | public: |
michael@0 | 49 | nsFontMetrics(); |
michael@0 | 50 | |
michael@0 | 51 | NS_INLINE_DECL_REFCOUNTING(nsFontMetrics) |
michael@0 | 52 | |
michael@0 | 53 | /** |
michael@0 | 54 | * Initialize the font metrics. Call this after creating the font metrics. |
michael@0 | 55 | * Font metrics you get from the font cache do NOT need to be initialized |
michael@0 | 56 | * |
michael@0 | 57 | * @see nsDeviceContext#GetMetricsFor() |
michael@0 | 58 | */ |
michael@0 | 59 | nsresult Init(const nsFont& aFont, nsIAtom* aLanguage, |
michael@0 | 60 | nsDeviceContext *aContext, |
michael@0 | 61 | gfxUserFontSet *aUserFontSet, |
michael@0 | 62 | gfxTextPerfMetrics *aTextPerf); |
michael@0 | 63 | |
michael@0 | 64 | /** |
michael@0 | 65 | * Destroy this font metrics. This breaks the association between |
michael@0 | 66 | * the font metrics and the device context. |
michael@0 | 67 | */ |
michael@0 | 68 | void Destroy(); |
michael@0 | 69 | |
michael@0 | 70 | /** |
michael@0 | 71 | * Return the font's x-height. |
michael@0 | 72 | */ |
michael@0 | 73 | nscoord XHeight(); |
michael@0 | 74 | |
michael@0 | 75 | /** |
michael@0 | 76 | * Return the font's superscript offset (the distance from the |
michael@0 | 77 | * baseline to where a superscript's baseline should be placed). |
michael@0 | 78 | * The value returned will be positive. |
michael@0 | 79 | */ |
michael@0 | 80 | nscoord SuperscriptOffset(); |
michael@0 | 81 | |
michael@0 | 82 | /** |
michael@0 | 83 | * Return the font's subscript offset (the distance from the |
michael@0 | 84 | * baseline to where a subscript's baseline should be placed). |
michael@0 | 85 | * The value returned will be positive. |
michael@0 | 86 | */ |
michael@0 | 87 | nscoord SubscriptOffset(); |
michael@0 | 88 | |
michael@0 | 89 | /** |
michael@0 | 90 | * Return the font's strikeout offset (the distance from the |
michael@0 | 91 | * baseline to where a strikeout should be placed) and size. |
michael@0 | 92 | * Positive values are above the baseline, negative below. |
michael@0 | 93 | */ |
michael@0 | 94 | void GetStrikeout(nscoord& aOffset, nscoord& aSize); |
michael@0 | 95 | |
michael@0 | 96 | /** |
michael@0 | 97 | * Return the font's underline offset (the distance from the |
michael@0 | 98 | * baseline to where a underline should be placed) and size. |
michael@0 | 99 | * Positive values are above the baseline, negative below. |
michael@0 | 100 | */ |
michael@0 | 101 | void GetUnderline(nscoord& aOffset, nscoord& aSize); |
michael@0 | 102 | |
michael@0 | 103 | /** |
michael@0 | 104 | * Returns the amount of internal leading for the font. |
michael@0 | 105 | * This is normally the difference between the max ascent |
michael@0 | 106 | * and the em ascent. |
michael@0 | 107 | */ |
michael@0 | 108 | nscoord InternalLeading(); |
michael@0 | 109 | |
michael@0 | 110 | /** |
michael@0 | 111 | * Returns the amount of external leading for the font. |
michael@0 | 112 | * em ascent(?) plus external leading is the font designer's |
michael@0 | 113 | * recommended line-height for this font. |
michael@0 | 114 | */ |
michael@0 | 115 | nscoord ExternalLeading(); |
michael@0 | 116 | |
michael@0 | 117 | /** |
michael@0 | 118 | * Returns the height of the em square. |
michael@0 | 119 | * This is em ascent plus em descent. |
michael@0 | 120 | */ |
michael@0 | 121 | nscoord EmHeight(); |
michael@0 | 122 | |
michael@0 | 123 | /** |
michael@0 | 124 | * Returns the ascent part of the em square. |
michael@0 | 125 | */ |
michael@0 | 126 | nscoord EmAscent(); |
michael@0 | 127 | |
michael@0 | 128 | /** |
michael@0 | 129 | * Returns the descent part of the em square. |
michael@0 | 130 | */ |
michael@0 | 131 | nscoord EmDescent(); |
michael@0 | 132 | |
michael@0 | 133 | /** |
michael@0 | 134 | * Returns the height of the bounding box. |
michael@0 | 135 | * This is max ascent plus max descent. |
michael@0 | 136 | */ |
michael@0 | 137 | nscoord MaxHeight(); |
michael@0 | 138 | |
michael@0 | 139 | /** |
michael@0 | 140 | * Returns the maximum distance characters in this font extend |
michael@0 | 141 | * above the base line. |
michael@0 | 142 | */ |
michael@0 | 143 | nscoord MaxAscent(); |
michael@0 | 144 | |
michael@0 | 145 | /** |
michael@0 | 146 | * Returns the maximum distance characters in this font extend |
michael@0 | 147 | * below the base line. |
michael@0 | 148 | */ |
michael@0 | 149 | nscoord MaxDescent(); |
michael@0 | 150 | |
michael@0 | 151 | /** |
michael@0 | 152 | * Returns the maximum character advance for the font. |
michael@0 | 153 | */ |
michael@0 | 154 | nscoord MaxAdvance(); |
michael@0 | 155 | |
michael@0 | 156 | /** |
michael@0 | 157 | * Returns the average character width |
michael@0 | 158 | */ |
michael@0 | 159 | nscoord AveCharWidth(); |
michael@0 | 160 | |
michael@0 | 161 | /** |
michael@0 | 162 | * Returns the often needed width of the space character |
michael@0 | 163 | */ |
michael@0 | 164 | nscoord SpaceWidth(); |
michael@0 | 165 | |
michael@0 | 166 | /** |
michael@0 | 167 | * Returns the font associated with these metrics. The return value |
michael@0 | 168 | * is only defined after Init() has been called. |
michael@0 | 169 | */ |
michael@0 | 170 | const nsFont &Font() { return mFont; } |
michael@0 | 171 | |
michael@0 | 172 | /** |
michael@0 | 173 | * Returns the language associated with these metrics |
michael@0 | 174 | */ |
michael@0 | 175 | nsIAtom* Language() { return mLanguage; } |
michael@0 | 176 | |
michael@0 | 177 | int32_t GetMaxStringLength(); |
michael@0 | 178 | |
michael@0 | 179 | // Get the width for this string. aWidth will be updated with the |
michael@0 | 180 | // width in points, not twips. Callers must convert it if they |
michael@0 | 181 | // want it in another format. |
michael@0 | 182 | nscoord GetWidth(const char* aString, uint32_t aLength, |
michael@0 | 183 | nsRenderingContext *aContext); |
michael@0 | 184 | nscoord GetWidth(const char16_t* aString, uint32_t aLength, |
michael@0 | 185 | nsRenderingContext *aContext); |
michael@0 | 186 | |
michael@0 | 187 | // Draw a string using this font handle on the surface passed in. |
michael@0 | 188 | void DrawString(const char *aString, uint32_t aLength, |
michael@0 | 189 | nscoord aX, nscoord aY, |
michael@0 | 190 | nsRenderingContext *aContext); |
michael@0 | 191 | void DrawString(const char16_t* aString, uint32_t aLength, |
michael@0 | 192 | nscoord aX, nscoord aY, |
michael@0 | 193 | nsRenderingContext *aContext, |
michael@0 | 194 | nsRenderingContext *aTextRunConstructionContext); |
michael@0 | 195 | |
michael@0 | 196 | nsBoundingMetrics GetBoundingMetrics(const char16_t *aString, |
michael@0 | 197 | uint32_t aLength, |
michael@0 | 198 | nsRenderingContext *aContext); |
michael@0 | 199 | |
michael@0 | 200 | // Returns the LOOSE_INK_EXTENTS bounds of the text for determing the |
michael@0 | 201 | // overflow area of the string. |
michael@0 | 202 | nsBoundingMetrics GetInkBoundsForVisualOverflow(const char16_t *aString, |
michael@0 | 203 | uint32_t aLength, |
michael@0 | 204 | nsRenderingContext *aContext); |
michael@0 | 205 | |
michael@0 | 206 | void SetTextRunRTL(bool aIsRTL) { mTextRunRTL = aIsRTL; } |
michael@0 | 207 | bool GetTextRunRTL() { return mTextRunRTL; } |
michael@0 | 208 | |
michael@0 | 209 | gfxFontGroup* GetThebesFontGroup() { return mFontGroup; } |
michael@0 | 210 | gfxUserFontSet* GetUserFontSet() { return mFontGroup->GetUserFontSet(); } |
michael@0 | 211 | |
michael@0 | 212 | int32_t AppUnitsPerDevPixel() { return mP2A; } |
michael@0 | 213 | |
michael@0 | 214 | private: |
michael@0 | 215 | // Private destructor, to discourage deletion outside of Release(): |
michael@0 | 216 | ~nsFontMetrics(); |
michael@0 | 217 | |
michael@0 | 218 | const gfxFont::Metrics& GetMetrics() const; |
michael@0 | 219 | |
michael@0 | 220 | nsFont mFont; |
michael@0 | 221 | nsRefPtr<gfxFontGroup> mFontGroup; |
michael@0 | 222 | nsCOMPtr<nsIAtom> mLanguage; |
michael@0 | 223 | nsDeviceContext *mDeviceContext; |
michael@0 | 224 | int32_t mP2A; |
michael@0 | 225 | bool mTextRunRTL; |
michael@0 | 226 | }; |
michael@0 | 227 | |
michael@0 | 228 | #endif /* NSFONTMETRICS__H__ */ |