gfxFT2Fonts.h (2656B)
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- 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/. */ 5 6 #ifndef GFX_FT2FONTS_H 7 #define GFX_FT2FONTS_H 8 9 #include "mozilla/MemoryReporting.h" 10 #include "gfxTypes.h" 11 #include "gfxFont.h" 12 #include "gfxFT2FontBase.h" 13 #include "gfxContext.h" 14 #include "gfxFontUtils.h" 15 #include "gfxUserFontSet.h" 16 17 class FT2FontEntry; 18 19 class gfxFT2Font final : public gfxFT2FontBase { 20 public: // new functions 21 gfxFT2Font(const RefPtr<mozilla::gfx::UnscaledFontFreeType>& aUnscaledFont, 22 RefPtr<mozilla::gfx::SharedFTFace>&& aFTFace, 23 FT2FontEntry* aFontEntry, const gfxFontStyle* aFontStyle, 24 int aLoadFlags); 25 26 FT2FontEntry* GetFontEntry(); 27 28 already_AddRefed<mozilla::gfx::ScaledFont> GetScaledFont( 29 const TextRunDrawParams& aRunParams) override; 30 31 bool ShouldHintMetrics() const override; 32 33 void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf, 34 FontCacheSizes* aSizes) const override; 35 void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf, 36 FontCacheSizes* aSizes) const override; 37 38 protected: 39 ~gfxFT2Font() override; 40 41 struct CachedGlyphData { 42 CachedGlyphData() : glyphIndex(0xffffffffU) {} 43 44 explicit CachedGlyphData(uint32_t gid) : glyphIndex(gid) {} 45 46 uint32_t glyphIndex; 47 int32_t lsbDelta; 48 int32_t rsbDelta; 49 int32_t xAdvance; 50 }; 51 52 const CachedGlyphData* GetGlyphDataForChar(FT_Face aFace, uint32_t ch) { 53 CharGlyphMapEntryType* entry = mCharGlyphCache.PutEntry(ch); 54 55 if (!entry) return nullptr; 56 57 if (entry->GetData().glyphIndex == 0xffffffffU) { 58 // this is a new entry, fill it 59 FillGlyphDataForChar(aFace, ch, entry->GetModifiableData()); 60 } 61 62 return &entry->GetData(); 63 } 64 65 bool ShapeText(DrawTarget* aDrawTarget, const char16_t* aText, 66 uint32_t aOffset, uint32_t aLength, Script aScript, 67 nsAtom* aLanguage, bool aVertical, RoundingFlags aRounding, 68 gfxShapedText* aShapedText) override; 69 70 void FillGlyphDataForChar(FT_Face face, uint32_t ch, CachedGlyphData* gd); 71 72 void AddRange(const char16_t* aText, uint32_t aOffset, uint32_t aLength, 73 gfxShapedText* aShapedText); 74 75 typedef nsBaseHashtableET<nsUint32HashKey, CachedGlyphData> 76 CharGlyphMapEntryType; 77 typedef nsTHashtable<CharGlyphMapEntryType> CharGlyphMap; 78 CharGlyphMap mCharGlyphCache; 79 }; 80 81 #endif /* GFX_FT2FONTS_H */