gfx/thebes/gfxFT2Fonts.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.

     1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     2  * This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef GFX_FT2FONTS_H
     7 #define GFX_FT2FONTS_H
     9 #include "mozilla/MemoryReporting.h"
    10 #include "cairo.h"
    11 #include "gfxTypes.h"
    12 #include "gfxFont.h"
    13 #include "gfxFT2FontBase.h"
    14 #include "gfxContext.h"
    15 #include "gfxFontUtils.h"
    16 #include "gfxUserFontSet.h"
    18 class FT2FontEntry;
    20 class gfxFT2Font : public gfxFT2FontBase {
    21 public: // new functions
    22     gfxFT2Font(cairo_scaled_font_t *aCairoFont,
    23                FT2FontEntry *aFontEntry,
    24                const gfxFontStyle *aFontStyle,
    25                bool aNeedsBold);
    26     virtual ~gfxFT2Font ();
    28     FT2FontEntry *GetFontEntry();
    30     static already_AddRefed<gfxFT2Font>
    31     GetOrMakeFont(const nsAString& aName, const gfxFontStyle *aStyle,
    32                   bool aNeedsBold = false);
    34     static already_AddRefed<gfxFT2Font>
    35     GetOrMakeFont(FT2FontEntry *aFontEntry, const gfxFontStyle *aStyle,
    36                   bool aNeedsBold = false);
    38     struct CachedGlyphData {
    39         CachedGlyphData()
    40             : glyphIndex(0xffffffffU) { }
    42         CachedGlyphData(uint32_t gid)
    43             : glyphIndex(gid) { }
    45         uint32_t glyphIndex;
    46         int32_t lsbDelta;
    47         int32_t rsbDelta;
    48         int32_t xAdvance;
    49     };
    51     const CachedGlyphData* GetGlyphDataForChar(uint32_t ch) {
    52         CharGlyphMapEntryType *entry = mCharGlyphCache.PutEntry(ch);
    54         if (!entry)
    55             return nullptr;
    57         if (entry->mData.glyphIndex == 0xffffffffU) {
    58             // this is a new entry, fill it
    59             FillGlyphDataForChar(ch, &entry->mData);
    60         }
    62         return &entry->mData;
    63     }
    65     virtual void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
    66                                         FontCacheSizes* aSizes) const;
    67     virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
    68                                         FontCacheSizes* aSizes) const;
    70 #ifdef USE_SKIA
    71     virtual mozilla::TemporaryRef<mozilla::gfx::GlyphRenderingOptions> GetGlyphRenderingOptions();
    72 #endif
    74 protected:
    75     virtual bool ShapeText(gfxContext      *aContext,
    76                            const char16_t *aText,
    77                            uint32_t         aOffset,
    78                            uint32_t         aLength,
    79                            int32_t          aScript,
    80                            gfxShapedText   *aShapedText,
    81                            bool             aPreferPlatformShaping);
    83     void FillGlyphDataForChar(uint32_t ch, CachedGlyphData *gd);
    85     void AddRange(const char16_t *aText,
    86                   uint32_t         aOffset,
    87                   uint32_t         aLength,
    88                   gfxShapedText   *aShapedText);
    90     typedef nsBaseHashtableET<nsUint32HashKey, CachedGlyphData> CharGlyphMapEntryType;
    91     typedef nsTHashtable<CharGlyphMapEntryType> CharGlyphMap;
    92     CharGlyphMap mCharGlyphCache;
    93 };
    95 #ifndef ANDROID // not needed on Android, uses the standard gfxFontGroup directly
    96 class gfxFT2FontGroup : public gfxFontGroup {
    97 public: // new functions
    98     gfxFT2FontGroup (const nsAString& families,
    99                     const gfxFontStyle *aStyle,
   100                     gfxUserFontSet *aUserFontSet);
   101     virtual ~gfxFT2FontGroup ();
   103 protected: // from gfxFontGroup
   105     virtual gfxFontGroup *Copy(const gfxFontStyle *aStyle);
   108 protected: // new functions
   110     static bool FontCallback (const nsAString & fontName, 
   111                                 const nsACString & genericName, 
   112                                 bool aUseFontSet,
   113                                 void *closure);
   114     bool mEnableKerning;
   116     void GetPrefFonts(nsIAtom *aLangGroup,
   117                       nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList);
   118     void GetCJKPrefFonts(nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList);
   119     void FamilyListToArrayList(const nsString& aFamilies,
   120                                nsIAtom *aLangGroup,
   121                                nsTArray<nsRefPtr<gfxFontEntry> > *aFontEntryList);
   122     already_AddRefed<gfxFT2Font> WhichFontSupportsChar(const nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList,
   123                                                        uint32_t aCh);
   124     already_AddRefed<gfxFont> WhichPrefFontSupportsChar(uint32_t aCh);
   125     already_AddRefed<gfxFont>
   126         WhichSystemFontSupportsChar(uint32_t aCh, int32_t aRunScript);
   128     nsTArray<gfxTextRange> mRanges;
   129     nsString mString;
   130 };
   131 #endif // !ANDROID
   133 #endif /* GFX_FT2FONTS_H */

mercurial