michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef GFX_FT2FONTS_H michael@0: #define GFX_FT2FONTS_H michael@0: michael@0: #include "mozilla/MemoryReporting.h" michael@0: #include "cairo.h" michael@0: #include "gfxTypes.h" michael@0: #include "gfxFont.h" michael@0: #include "gfxFT2FontBase.h" michael@0: #include "gfxContext.h" michael@0: #include "gfxFontUtils.h" michael@0: #include "gfxUserFontSet.h" michael@0: michael@0: class FT2FontEntry; michael@0: michael@0: class gfxFT2Font : public gfxFT2FontBase { michael@0: public: // new functions michael@0: gfxFT2Font(cairo_scaled_font_t *aCairoFont, michael@0: FT2FontEntry *aFontEntry, michael@0: const gfxFontStyle *aFontStyle, michael@0: bool aNeedsBold); michael@0: virtual ~gfxFT2Font (); michael@0: michael@0: FT2FontEntry *GetFontEntry(); michael@0: michael@0: static already_AddRefed michael@0: GetOrMakeFont(const nsAString& aName, const gfxFontStyle *aStyle, michael@0: bool aNeedsBold = false); michael@0: michael@0: static already_AddRefed michael@0: GetOrMakeFont(FT2FontEntry *aFontEntry, const gfxFontStyle *aStyle, michael@0: bool aNeedsBold = false); michael@0: michael@0: struct CachedGlyphData { michael@0: CachedGlyphData() michael@0: : glyphIndex(0xffffffffU) { } michael@0: michael@0: CachedGlyphData(uint32_t gid) michael@0: : glyphIndex(gid) { } michael@0: michael@0: uint32_t glyphIndex; michael@0: int32_t lsbDelta; michael@0: int32_t rsbDelta; michael@0: int32_t xAdvance; michael@0: }; michael@0: michael@0: const CachedGlyphData* GetGlyphDataForChar(uint32_t ch) { michael@0: CharGlyphMapEntryType *entry = mCharGlyphCache.PutEntry(ch); michael@0: michael@0: if (!entry) michael@0: return nullptr; michael@0: michael@0: if (entry->mData.glyphIndex == 0xffffffffU) { michael@0: // this is a new entry, fill it michael@0: FillGlyphDataForChar(ch, &entry->mData); michael@0: } michael@0: michael@0: return &entry->mData; michael@0: } michael@0: michael@0: virtual void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf, michael@0: FontCacheSizes* aSizes) const; michael@0: virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf, michael@0: FontCacheSizes* aSizes) const; michael@0: michael@0: #ifdef USE_SKIA michael@0: virtual mozilla::TemporaryRef GetGlyphRenderingOptions(); michael@0: #endif michael@0: michael@0: protected: michael@0: virtual bool ShapeText(gfxContext *aContext, michael@0: const char16_t *aText, michael@0: uint32_t aOffset, michael@0: uint32_t aLength, michael@0: int32_t aScript, michael@0: gfxShapedText *aShapedText, michael@0: bool aPreferPlatformShaping); michael@0: michael@0: void FillGlyphDataForChar(uint32_t ch, CachedGlyphData *gd); michael@0: michael@0: void AddRange(const char16_t *aText, michael@0: uint32_t aOffset, michael@0: uint32_t aLength, michael@0: gfxShapedText *aShapedText); michael@0: michael@0: typedef nsBaseHashtableET CharGlyphMapEntryType; michael@0: typedef nsTHashtable CharGlyphMap; michael@0: CharGlyphMap mCharGlyphCache; michael@0: }; michael@0: michael@0: #ifndef ANDROID // not needed on Android, uses the standard gfxFontGroup directly michael@0: class gfxFT2FontGroup : public gfxFontGroup { michael@0: public: // new functions michael@0: gfxFT2FontGroup (const nsAString& families, michael@0: const gfxFontStyle *aStyle, michael@0: gfxUserFontSet *aUserFontSet); michael@0: virtual ~gfxFT2FontGroup (); michael@0: michael@0: protected: // from gfxFontGroup michael@0: michael@0: virtual gfxFontGroup *Copy(const gfxFontStyle *aStyle); michael@0: michael@0: michael@0: protected: // new functions michael@0: michael@0: static bool FontCallback (const nsAString & fontName, michael@0: const nsACString & genericName, michael@0: bool aUseFontSet, michael@0: void *closure); michael@0: bool mEnableKerning; michael@0: michael@0: void GetPrefFonts(nsIAtom *aLangGroup, michael@0: nsTArray >& aFontEntryList); michael@0: void GetCJKPrefFonts(nsTArray >& aFontEntryList); michael@0: void FamilyListToArrayList(const nsString& aFamilies, michael@0: nsIAtom *aLangGroup, michael@0: nsTArray > *aFontEntryList); michael@0: already_AddRefed WhichFontSupportsChar(const nsTArray >& aFontEntryList, michael@0: uint32_t aCh); michael@0: already_AddRefed WhichPrefFontSupportsChar(uint32_t aCh); michael@0: already_AddRefed michael@0: WhichSystemFontSupportsChar(uint32_t aCh, int32_t aRunScript); michael@0: michael@0: nsTArray mRanges; michael@0: nsString mString; michael@0: }; michael@0: #endif // !ANDROID michael@0: michael@0: #endif /* GFX_FT2FONTS_H */ michael@0: