Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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_FT2FONTS_H |
michael@0 | 7 | #define GFX_FT2FONTS_H |
michael@0 | 8 | |
michael@0 | 9 | #include "mozilla/MemoryReporting.h" |
michael@0 | 10 | #include "cairo.h" |
michael@0 | 11 | #include "gfxTypes.h" |
michael@0 | 12 | #include "gfxFont.h" |
michael@0 | 13 | #include "gfxFT2FontBase.h" |
michael@0 | 14 | #include "gfxContext.h" |
michael@0 | 15 | #include "gfxFontUtils.h" |
michael@0 | 16 | #include "gfxUserFontSet.h" |
michael@0 | 17 | |
michael@0 | 18 | class FT2FontEntry; |
michael@0 | 19 | |
michael@0 | 20 | class gfxFT2Font : public gfxFT2FontBase { |
michael@0 | 21 | public: // new functions |
michael@0 | 22 | gfxFT2Font(cairo_scaled_font_t *aCairoFont, |
michael@0 | 23 | FT2FontEntry *aFontEntry, |
michael@0 | 24 | const gfxFontStyle *aFontStyle, |
michael@0 | 25 | bool aNeedsBold); |
michael@0 | 26 | virtual ~gfxFT2Font (); |
michael@0 | 27 | |
michael@0 | 28 | FT2FontEntry *GetFontEntry(); |
michael@0 | 29 | |
michael@0 | 30 | static already_AddRefed<gfxFT2Font> |
michael@0 | 31 | GetOrMakeFont(const nsAString& aName, const gfxFontStyle *aStyle, |
michael@0 | 32 | bool aNeedsBold = false); |
michael@0 | 33 | |
michael@0 | 34 | static already_AddRefed<gfxFT2Font> |
michael@0 | 35 | GetOrMakeFont(FT2FontEntry *aFontEntry, const gfxFontStyle *aStyle, |
michael@0 | 36 | bool aNeedsBold = false); |
michael@0 | 37 | |
michael@0 | 38 | struct CachedGlyphData { |
michael@0 | 39 | CachedGlyphData() |
michael@0 | 40 | : glyphIndex(0xffffffffU) { } |
michael@0 | 41 | |
michael@0 | 42 | CachedGlyphData(uint32_t gid) |
michael@0 | 43 | : glyphIndex(gid) { } |
michael@0 | 44 | |
michael@0 | 45 | uint32_t glyphIndex; |
michael@0 | 46 | int32_t lsbDelta; |
michael@0 | 47 | int32_t rsbDelta; |
michael@0 | 48 | int32_t xAdvance; |
michael@0 | 49 | }; |
michael@0 | 50 | |
michael@0 | 51 | const CachedGlyphData* GetGlyphDataForChar(uint32_t ch) { |
michael@0 | 52 | CharGlyphMapEntryType *entry = mCharGlyphCache.PutEntry(ch); |
michael@0 | 53 | |
michael@0 | 54 | if (!entry) |
michael@0 | 55 | return nullptr; |
michael@0 | 56 | |
michael@0 | 57 | if (entry->mData.glyphIndex == 0xffffffffU) { |
michael@0 | 58 | // this is a new entry, fill it |
michael@0 | 59 | FillGlyphDataForChar(ch, &entry->mData); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | return &entry->mData; |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | virtual void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf, |
michael@0 | 66 | FontCacheSizes* aSizes) const; |
michael@0 | 67 | virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf, |
michael@0 | 68 | FontCacheSizes* aSizes) const; |
michael@0 | 69 | |
michael@0 | 70 | #ifdef USE_SKIA |
michael@0 | 71 | virtual mozilla::TemporaryRef<mozilla::gfx::GlyphRenderingOptions> GetGlyphRenderingOptions(); |
michael@0 | 72 | #endif |
michael@0 | 73 | |
michael@0 | 74 | protected: |
michael@0 | 75 | virtual bool ShapeText(gfxContext *aContext, |
michael@0 | 76 | const char16_t *aText, |
michael@0 | 77 | uint32_t aOffset, |
michael@0 | 78 | uint32_t aLength, |
michael@0 | 79 | int32_t aScript, |
michael@0 | 80 | gfxShapedText *aShapedText, |
michael@0 | 81 | bool aPreferPlatformShaping); |
michael@0 | 82 | |
michael@0 | 83 | void FillGlyphDataForChar(uint32_t ch, CachedGlyphData *gd); |
michael@0 | 84 | |
michael@0 | 85 | void AddRange(const char16_t *aText, |
michael@0 | 86 | uint32_t aOffset, |
michael@0 | 87 | uint32_t aLength, |
michael@0 | 88 | gfxShapedText *aShapedText); |
michael@0 | 89 | |
michael@0 | 90 | typedef nsBaseHashtableET<nsUint32HashKey, CachedGlyphData> CharGlyphMapEntryType; |
michael@0 | 91 | typedef nsTHashtable<CharGlyphMapEntryType> CharGlyphMap; |
michael@0 | 92 | CharGlyphMap mCharGlyphCache; |
michael@0 | 93 | }; |
michael@0 | 94 | |
michael@0 | 95 | #ifndef ANDROID // not needed on Android, uses the standard gfxFontGroup directly |
michael@0 | 96 | class gfxFT2FontGroup : public gfxFontGroup { |
michael@0 | 97 | public: // new functions |
michael@0 | 98 | gfxFT2FontGroup (const nsAString& families, |
michael@0 | 99 | const gfxFontStyle *aStyle, |
michael@0 | 100 | gfxUserFontSet *aUserFontSet); |
michael@0 | 101 | virtual ~gfxFT2FontGroup (); |
michael@0 | 102 | |
michael@0 | 103 | protected: // from gfxFontGroup |
michael@0 | 104 | |
michael@0 | 105 | virtual gfxFontGroup *Copy(const gfxFontStyle *aStyle); |
michael@0 | 106 | |
michael@0 | 107 | |
michael@0 | 108 | protected: // new functions |
michael@0 | 109 | |
michael@0 | 110 | static bool FontCallback (const nsAString & fontName, |
michael@0 | 111 | const nsACString & genericName, |
michael@0 | 112 | bool aUseFontSet, |
michael@0 | 113 | void *closure); |
michael@0 | 114 | bool mEnableKerning; |
michael@0 | 115 | |
michael@0 | 116 | void GetPrefFonts(nsIAtom *aLangGroup, |
michael@0 | 117 | nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList); |
michael@0 | 118 | void GetCJKPrefFonts(nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList); |
michael@0 | 119 | void FamilyListToArrayList(const nsString& aFamilies, |
michael@0 | 120 | nsIAtom *aLangGroup, |
michael@0 | 121 | nsTArray<nsRefPtr<gfxFontEntry> > *aFontEntryList); |
michael@0 | 122 | already_AddRefed<gfxFT2Font> WhichFontSupportsChar(const nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList, |
michael@0 | 123 | uint32_t aCh); |
michael@0 | 124 | already_AddRefed<gfxFont> WhichPrefFontSupportsChar(uint32_t aCh); |
michael@0 | 125 | already_AddRefed<gfxFont> |
michael@0 | 126 | WhichSystemFontSupportsChar(uint32_t aCh, int32_t aRunScript); |
michael@0 | 127 | |
michael@0 | 128 | nsTArray<gfxTextRange> mRanges; |
michael@0 | 129 | nsString mString; |
michael@0 | 130 | }; |
michael@0 | 131 | #endif // !ANDROID |
michael@0 | 132 | |
michael@0 | 133 | #endif /* GFX_FT2FONTS_H */ |
michael@0 | 134 |