1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/thebes/gfxFT2FontList.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,163 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef GFX_FT2FONTLIST_H 1.10 +#define GFX_FT2FONTLIST_H 1.11 + 1.12 +#include "mozilla/MemoryReporting.h" 1.13 + 1.14 +#ifdef XP_WIN 1.15 +#include "gfxWindowsPlatform.h" 1.16 +#include <windows.h> 1.17 +#endif 1.18 +#include "gfxPlatformFontList.h" 1.19 + 1.20 +namespace mozilla { 1.21 + namespace dom { 1.22 + class FontListEntry; 1.23 + }; 1.24 +}; 1.25 +using mozilla::dom::FontListEntry; 1.26 + 1.27 +class FontNameCache; 1.28 +typedef struct FT_FaceRec_* FT_Face; 1.29 +class nsZipArchive; 1.30 + 1.31 +class FT2FontEntry : public gfxFontEntry 1.32 +{ 1.33 +public: 1.34 + FT2FontEntry(const nsAString& aFaceName) : 1.35 + gfxFontEntry(aFaceName), 1.36 + mFTFace(nullptr), 1.37 + mFontFace(nullptr), 1.38 + mFTFontIndex(0) 1.39 + { 1.40 + } 1.41 + 1.42 + ~FT2FontEntry(); 1.43 + 1.44 + const nsString& GetName() const { 1.45 + return Name(); 1.46 + } 1.47 + 1.48 + // create a font entry for a downloaded font 1.49 + static FT2FontEntry* 1.50 + CreateFontEntry(const gfxProxyFontEntry &aProxyEntry, 1.51 + const uint8_t *aFontData, uint32_t aLength); 1.52 + 1.53 + // create a font entry representing an installed font, identified by 1.54 + // a FontListEntry; the freetype and cairo faces will not be instantiated 1.55 + // until actually needed 1.56 + static FT2FontEntry* 1.57 + CreateFontEntry(const FontListEntry& aFLE); 1.58 + 1.59 + // Create a font entry for a given freetype face; if it is an installed font, 1.60 + // also record the filename and index. 1.61 + // aFontData (if non-nullptr) is NS_Malloc'ed data that aFace depends on, 1.62 + // to be freed after the face is destroyed 1.63 + static FT2FontEntry* 1.64 + CreateFontEntry(FT_Face aFace, 1.65 + const char *aFilename, uint8_t aIndex, 1.66 + const nsAString& aName, 1.67 + const uint8_t *aFontData = nullptr); 1.68 + 1.69 + virtual gfxFont *CreateFontInstance(const gfxFontStyle *aFontStyle, 1.70 + bool aNeedsBold); 1.71 + 1.72 + // Create (if necessary) and return the cairo_font_face for this font. 1.73 + // This may fail and return null, so caller must be prepared to handle this. 1.74 + cairo_font_face_t *CairoFontFace(); 1.75 + 1.76 + // Create a cairo_scaled_font for this face, with the given style. 1.77 + // This may fail and return null, so caller must be prepared to handle this. 1.78 + cairo_scaled_font_t *CreateScaledFont(const gfxFontStyle *aStyle); 1.79 + 1.80 + nsresult ReadCMAP(FontInfoData *aFontInfoData = nullptr); 1.81 + 1.82 + virtual hb_blob_t* GetFontTable(uint32_t aTableTag) MOZ_OVERRIDE; 1.83 + 1.84 + virtual nsresult CopyFontTable(uint32_t aTableTag, 1.85 + FallibleTArray<uint8_t>& aBuffer) MOZ_OVERRIDE; 1.86 + 1.87 + // Check for various kinds of brokenness, and set flags on the entry 1.88 + // accordingly so that we avoid using bad font tables 1.89 + void CheckForBrokenFont(gfxFontFamily *aFamily); 1.90 + 1.91 + virtual void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf, 1.92 + FontListSizes* aSizes) const; 1.93 + virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf, 1.94 + FontListSizes* aSizes) const; 1.95 + 1.96 + FT_Face mFTFace; 1.97 + cairo_font_face_t *mFontFace; 1.98 + 1.99 + nsCString mFilename; 1.100 + uint8_t mFTFontIndex; 1.101 +}; 1.102 + 1.103 +class FT2FontFamily : public gfxFontFamily 1.104 +{ 1.105 +public: 1.106 + FT2FontFamily(const nsAString& aName) : 1.107 + gfxFontFamily(aName) { } 1.108 + 1.109 + // Append this family's faces to the IPC fontlist 1.110 + void AddFacesToFontList(InfallibleTArray<FontListEntry>* aFontList); 1.111 +}; 1.112 + 1.113 +class gfxFT2FontList : public gfxPlatformFontList 1.114 +{ 1.115 +public: 1.116 + gfxFT2FontList(); 1.117 + 1.118 + virtual gfxFontFamily* GetDefaultFont(const gfxFontStyle* aStyle); 1.119 + 1.120 + virtual gfxFontEntry* LookupLocalFont(const gfxProxyFontEntry *aProxyEntry, 1.121 + const nsAString& aFontName); 1.122 + 1.123 + virtual gfxFontEntry* MakePlatformFont(const gfxProxyFontEntry *aProxyEntry, 1.124 + const uint8_t *aFontData, 1.125 + uint32_t aLength); 1.126 + 1.127 + void GetFontList(InfallibleTArray<FontListEntry>* retValue); 1.128 + 1.129 + static gfxFT2FontList* PlatformFontList() { 1.130 + return static_cast<gfxFT2FontList*>(gfxPlatformFontList::PlatformFontList()); 1.131 + } 1.132 + 1.133 +protected: 1.134 + virtual nsresult InitFontList(); 1.135 + 1.136 + void AppendFaceFromFontListEntry(const FontListEntry& aFLE, 1.137 + bool isStdFile); 1.138 + 1.139 + void AppendFacesFromFontFile(const nsCString& aFileName, 1.140 + bool isStdFile = false, 1.141 + FontNameCache *aCache = nullptr); 1.142 + 1.143 + void AppendFacesFromOmnijarEntry(nsZipArchive *aReader, 1.144 + const nsCString& aEntryName, 1.145 + FontNameCache *aCache, 1.146 + bool aJarChanged); 1.147 + 1.148 + void AppendFacesFromCachedFaceList(const nsCString& aFileName, 1.149 + bool isStdFile, 1.150 + const nsCString& aFaceList); 1.151 + 1.152 + void AddFaceToList(const nsCString& aEntryName, uint32_t aIndex, 1.153 + bool aStdFile, FT_Face aFace, nsCString& aFaceList); 1.154 + 1.155 + void FindFonts(); 1.156 + 1.157 + void FindFontsInOmnijar(FontNameCache *aCache); 1.158 + 1.159 +#ifdef ANDROID 1.160 + void FindFontsInDir(const nsCString& aDir, FontNameCache* aFNC); 1.161 +#endif 1.162 + 1.163 + nsTHashtable<nsStringHashKey> mSkipSpaceLookupCheckFamilies; 1.164 +}; 1.165 + 1.166 +#endif /* GFX_FT2FONTLIST_H */