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_FT2FONTLIST_H michael@0: #define GFX_FT2FONTLIST_H michael@0: michael@0: #include "mozilla/MemoryReporting.h" michael@0: michael@0: #ifdef XP_WIN michael@0: #include "gfxWindowsPlatform.h" michael@0: #include michael@0: #endif michael@0: #include "gfxPlatformFontList.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: class FontListEntry; michael@0: }; michael@0: }; michael@0: using mozilla::dom::FontListEntry; michael@0: michael@0: class FontNameCache; michael@0: typedef struct FT_FaceRec_* FT_Face; michael@0: class nsZipArchive; michael@0: michael@0: class FT2FontEntry : public gfxFontEntry michael@0: { michael@0: public: michael@0: FT2FontEntry(const nsAString& aFaceName) : michael@0: gfxFontEntry(aFaceName), michael@0: mFTFace(nullptr), michael@0: mFontFace(nullptr), michael@0: mFTFontIndex(0) michael@0: { michael@0: } michael@0: michael@0: ~FT2FontEntry(); michael@0: michael@0: const nsString& GetName() const { michael@0: return Name(); michael@0: } michael@0: michael@0: // create a font entry for a downloaded font michael@0: static FT2FontEntry* michael@0: CreateFontEntry(const gfxProxyFontEntry &aProxyEntry, michael@0: const uint8_t *aFontData, uint32_t aLength); michael@0: michael@0: // create a font entry representing an installed font, identified by michael@0: // a FontListEntry; the freetype and cairo faces will not be instantiated michael@0: // until actually needed michael@0: static FT2FontEntry* michael@0: CreateFontEntry(const FontListEntry& aFLE); michael@0: michael@0: // Create a font entry for a given freetype face; if it is an installed font, michael@0: // also record the filename and index. michael@0: // aFontData (if non-nullptr) is NS_Malloc'ed data that aFace depends on, michael@0: // to be freed after the face is destroyed michael@0: static FT2FontEntry* michael@0: CreateFontEntry(FT_Face aFace, michael@0: const char *aFilename, uint8_t aIndex, michael@0: const nsAString& aName, michael@0: const uint8_t *aFontData = nullptr); michael@0: michael@0: virtual gfxFont *CreateFontInstance(const gfxFontStyle *aFontStyle, michael@0: bool aNeedsBold); michael@0: michael@0: // Create (if necessary) and return the cairo_font_face for this font. michael@0: // This may fail and return null, so caller must be prepared to handle this. michael@0: cairo_font_face_t *CairoFontFace(); michael@0: michael@0: // Create a cairo_scaled_font for this face, with the given style. michael@0: // This may fail and return null, so caller must be prepared to handle this. michael@0: cairo_scaled_font_t *CreateScaledFont(const gfxFontStyle *aStyle); michael@0: michael@0: nsresult ReadCMAP(FontInfoData *aFontInfoData = nullptr); michael@0: michael@0: virtual hb_blob_t* GetFontTable(uint32_t aTableTag) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult CopyFontTable(uint32_t aTableTag, michael@0: FallibleTArray& aBuffer) MOZ_OVERRIDE; michael@0: michael@0: // Check for various kinds of brokenness, and set flags on the entry michael@0: // accordingly so that we avoid using bad font tables michael@0: void CheckForBrokenFont(gfxFontFamily *aFamily); michael@0: michael@0: virtual void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf, michael@0: FontListSizes* aSizes) const; michael@0: virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf, michael@0: FontListSizes* aSizes) const; michael@0: michael@0: FT_Face mFTFace; michael@0: cairo_font_face_t *mFontFace; michael@0: michael@0: nsCString mFilename; michael@0: uint8_t mFTFontIndex; michael@0: }; michael@0: michael@0: class FT2FontFamily : public gfxFontFamily michael@0: { michael@0: public: michael@0: FT2FontFamily(const nsAString& aName) : michael@0: gfxFontFamily(aName) { } michael@0: michael@0: // Append this family's faces to the IPC fontlist michael@0: void AddFacesToFontList(InfallibleTArray* aFontList); michael@0: }; michael@0: michael@0: class gfxFT2FontList : public gfxPlatformFontList michael@0: { michael@0: public: michael@0: gfxFT2FontList(); michael@0: michael@0: virtual gfxFontFamily* GetDefaultFont(const gfxFontStyle* aStyle); michael@0: michael@0: virtual gfxFontEntry* LookupLocalFont(const gfxProxyFontEntry *aProxyEntry, michael@0: const nsAString& aFontName); michael@0: michael@0: virtual gfxFontEntry* MakePlatformFont(const gfxProxyFontEntry *aProxyEntry, michael@0: const uint8_t *aFontData, michael@0: uint32_t aLength); michael@0: michael@0: void GetFontList(InfallibleTArray* retValue); michael@0: michael@0: static gfxFT2FontList* PlatformFontList() { michael@0: return static_cast(gfxPlatformFontList::PlatformFontList()); michael@0: } michael@0: michael@0: protected: michael@0: virtual nsresult InitFontList(); michael@0: michael@0: void AppendFaceFromFontListEntry(const FontListEntry& aFLE, michael@0: bool isStdFile); michael@0: michael@0: void AppendFacesFromFontFile(const nsCString& aFileName, michael@0: bool isStdFile = false, michael@0: FontNameCache *aCache = nullptr); michael@0: michael@0: void AppendFacesFromOmnijarEntry(nsZipArchive *aReader, michael@0: const nsCString& aEntryName, michael@0: FontNameCache *aCache, michael@0: bool aJarChanged); michael@0: michael@0: void AppendFacesFromCachedFaceList(const nsCString& aFileName, michael@0: bool isStdFile, michael@0: const nsCString& aFaceList); michael@0: michael@0: void AddFaceToList(const nsCString& aEntryName, uint32_t aIndex, michael@0: bool aStdFile, FT_Face aFace, nsCString& aFaceList); michael@0: michael@0: void FindFonts(); michael@0: michael@0: void FindFontsInOmnijar(FontNameCache *aCache); michael@0: michael@0: #ifdef ANDROID michael@0: void FindFontsInDir(const nsCString& aDir, FontNameCache* aFNC); michael@0: #endif michael@0: michael@0: nsTHashtable mSkipSpaceLookupCheckFamilies; michael@0: }; michael@0: michael@0: #endif /* GFX_FT2FONTLIST_H */