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 GFX_GDIFONT_H |
michael@0 | 7 | #define GFX_GDIFONT_H |
michael@0 | 8 | |
michael@0 | 9 | #include "mozilla/MemoryReporting.h" |
michael@0 | 10 | #include "gfxFont.h" |
michael@0 | 11 | #include "gfxGDIFontList.h" |
michael@0 | 12 | |
michael@0 | 13 | #include "nsDataHashtable.h" |
michael@0 | 14 | #include "nsHashKeys.h" |
michael@0 | 15 | |
michael@0 | 16 | #include "cairo.h" |
michael@0 | 17 | |
michael@0 | 18 | class gfxGDIFont : public gfxFont |
michael@0 | 19 | { |
michael@0 | 20 | public: |
michael@0 | 21 | gfxGDIFont(GDIFontEntry *aFontEntry, |
michael@0 | 22 | const gfxFontStyle *aFontStyle, |
michael@0 | 23 | bool aNeedsBold, |
michael@0 | 24 | AntialiasOption anAAOption = kAntialiasDefault); |
michael@0 | 25 | |
michael@0 | 26 | virtual ~gfxGDIFont(); |
michael@0 | 27 | |
michael@0 | 28 | HFONT GetHFONT() { if (!mMetrics) Initialize(); return mFont; } |
michael@0 | 29 | |
michael@0 | 30 | gfxFloat GetAdjustedSize() { if (!mMetrics) Initialize(); return mAdjustedSize; } |
michael@0 | 31 | |
michael@0 | 32 | cairo_font_face_t *CairoFontFace() { return mFontFace; } |
michael@0 | 33 | cairo_scaled_font_t *CairoScaledFont() { return mScaledFont; } |
michael@0 | 34 | |
michael@0 | 35 | /* overrides for the pure virtual methods in gfxFont */ |
michael@0 | 36 | virtual const gfxFont::Metrics& GetMetrics(); |
michael@0 | 37 | |
michael@0 | 38 | virtual uint32_t GetSpaceGlyph(); |
michael@0 | 39 | |
michael@0 | 40 | virtual bool SetupCairoFont(gfxContext *aContext); |
michael@0 | 41 | |
michael@0 | 42 | /* override Measure to add padding for antialiasing */ |
michael@0 | 43 | virtual RunMetrics Measure(gfxTextRun *aTextRun, |
michael@0 | 44 | uint32_t aStart, uint32_t aEnd, |
michael@0 | 45 | BoundingBoxType aBoundingBoxType, |
michael@0 | 46 | gfxContext *aContextForTightBoundingBox, |
michael@0 | 47 | Spacing *aSpacing); |
michael@0 | 48 | |
michael@0 | 49 | /* required for MathML to suppress effects of ClearType "padding" */ |
michael@0 | 50 | virtual gfxFont* CopyWithAntialiasOption(AntialiasOption anAAOption); |
michael@0 | 51 | |
michael@0 | 52 | virtual bool ProvidesGlyphWidths() { return true; } |
michael@0 | 53 | |
michael@0 | 54 | // get hinted glyph width in pixels as 16.16 fixed-point value |
michael@0 | 55 | virtual int32_t GetGlyphWidth(gfxContext *aCtx, uint16_t aGID); |
michael@0 | 56 | |
michael@0 | 57 | virtual void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf, |
michael@0 | 58 | FontCacheSizes* aSizes) const; |
michael@0 | 59 | virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf, |
michael@0 | 60 | FontCacheSizes* aSizes) const; |
michael@0 | 61 | |
michael@0 | 62 | virtual FontType GetType() const { return FONT_TYPE_GDI; } |
michael@0 | 63 | |
michael@0 | 64 | protected: |
michael@0 | 65 | virtual void CreatePlatformShaper(); |
michael@0 | 66 | |
michael@0 | 67 | /* override to check for uniscribe failure and fall back to GDI */ |
michael@0 | 68 | virtual bool ShapeText(gfxContext *aContext, |
michael@0 | 69 | const char16_t *aText, |
michael@0 | 70 | uint32_t aOffset, |
michael@0 | 71 | uint32_t aLength, |
michael@0 | 72 | int32_t aScript, |
michael@0 | 73 | gfxShapedText *aShapedText, |
michael@0 | 74 | bool aPreferPlatformShaping); |
michael@0 | 75 | |
michael@0 | 76 | void Initialize(); // creates metrics and Cairo fonts |
michael@0 | 77 | |
michael@0 | 78 | // Fill the given LOGFONT record according to our style, but don't adjust |
michael@0 | 79 | // the lfItalic field if we're going to use a cairo transform for fake |
michael@0 | 80 | // italics. |
michael@0 | 81 | void FillLogFont(LOGFONTW& aLogFont, gfxFloat aSize, bool aUseGDIFakeItalic); |
michael@0 | 82 | |
michael@0 | 83 | // mPlatformShaper is used for the GDI shaper, mUniscribeShaper |
michael@0 | 84 | // for the Uniscribe version if needed |
michael@0 | 85 | nsAutoPtr<gfxFontShaper> mUniscribeShaper; |
michael@0 | 86 | |
michael@0 | 87 | HFONT mFont; |
michael@0 | 88 | cairo_font_face_t *mFontFace; |
michael@0 | 89 | |
michael@0 | 90 | Metrics *mMetrics; |
michael@0 | 91 | uint32_t mSpaceGlyph; |
michael@0 | 92 | |
michael@0 | 93 | bool mNeedsBold; |
michael@0 | 94 | |
michael@0 | 95 | // cache of glyph widths in 16.16 fixed-point pixels |
michael@0 | 96 | nsAutoPtr<nsDataHashtable<nsUint32HashKey,int32_t> > mGlyphWidths; |
michael@0 | 97 | }; |
michael@0 | 98 | |
michael@0 | 99 | #endif /* GFX_GDIFONT_H */ |