Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
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/. */
6 #ifndef GFX_FT2FONTLIST_H
7 #define GFX_FT2FONTLIST_H
9 #include "mozilla/MemoryReporting.h"
11 #ifdef XP_WIN
12 #include "gfxWindowsPlatform.h"
13 #include <windows.h>
14 #endif
15 #include "gfxPlatformFontList.h"
17 namespace mozilla {
18 namespace dom {
19 class FontListEntry;
20 };
21 };
22 using mozilla::dom::FontListEntry;
24 class FontNameCache;
25 typedef struct FT_FaceRec_* FT_Face;
26 class nsZipArchive;
28 class FT2FontEntry : public gfxFontEntry
29 {
30 public:
31 FT2FontEntry(const nsAString& aFaceName) :
32 gfxFontEntry(aFaceName),
33 mFTFace(nullptr),
34 mFontFace(nullptr),
35 mFTFontIndex(0)
36 {
37 }
39 ~FT2FontEntry();
41 const nsString& GetName() const {
42 return Name();
43 }
45 // create a font entry for a downloaded font
46 static FT2FontEntry*
47 CreateFontEntry(const gfxProxyFontEntry &aProxyEntry,
48 const uint8_t *aFontData, uint32_t aLength);
50 // create a font entry representing an installed font, identified by
51 // a FontListEntry; the freetype and cairo faces will not be instantiated
52 // until actually needed
53 static FT2FontEntry*
54 CreateFontEntry(const FontListEntry& aFLE);
56 // Create a font entry for a given freetype face; if it is an installed font,
57 // also record the filename and index.
58 // aFontData (if non-nullptr) is NS_Malloc'ed data that aFace depends on,
59 // to be freed after the face is destroyed
60 static FT2FontEntry*
61 CreateFontEntry(FT_Face aFace,
62 const char *aFilename, uint8_t aIndex,
63 const nsAString& aName,
64 const uint8_t *aFontData = nullptr);
66 virtual gfxFont *CreateFontInstance(const gfxFontStyle *aFontStyle,
67 bool aNeedsBold);
69 // Create (if necessary) and return the cairo_font_face for this font.
70 // This may fail and return null, so caller must be prepared to handle this.
71 cairo_font_face_t *CairoFontFace();
73 // Create a cairo_scaled_font for this face, with the given style.
74 // This may fail and return null, so caller must be prepared to handle this.
75 cairo_scaled_font_t *CreateScaledFont(const gfxFontStyle *aStyle);
77 nsresult ReadCMAP(FontInfoData *aFontInfoData = nullptr);
79 virtual hb_blob_t* GetFontTable(uint32_t aTableTag) MOZ_OVERRIDE;
81 virtual nsresult CopyFontTable(uint32_t aTableTag,
82 FallibleTArray<uint8_t>& aBuffer) MOZ_OVERRIDE;
84 // Check for various kinds of brokenness, and set flags on the entry
85 // accordingly so that we avoid using bad font tables
86 void CheckForBrokenFont(gfxFontFamily *aFamily);
88 virtual void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
89 FontListSizes* aSizes) const;
90 virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
91 FontListSizes* aSizes) const;
93 FT_Face mFTFace;
94 cairo_font_face_t *mFontFace;
96 nsCString mFilename;
97 uint8_t mFTFontIndex;
98 };
100 class FT2FontFamily : public gfxFontFamily
101 {
102 public:
103 FT2FontFamily(const nsAString& aName) :
104 gfxFontFamily(aName) { }
106 // Append this family's faces to the IPC fontlist
107 void AddFacesToFontList(InfallibleTArray<FontListEntry>* aFontList);
108 };
110 class gfxFT2FontList : public gfxPlatformFontList
111 {
112 public:
113 gfxFT2FontList();
115 virtual gfxFontFamily* GetDefaultFont(const gfxFontStyle* aStyle);
117 virtual gfxFontEntry* LookupLocalFont(const gfxProxyFontEntry *aProxyEntry,
118 const nsAString& aFontName);
120 virtual gfxFontEntry* MakePlatformFont(const gfxProxyFontEntry *aProxyEntry,
121 const uint8_t *aFontData,
122 uint32_t aLength);
124 void GetFontList(InfallibleTArray<FontListEntry>* retValue);
126 static gfxFT2FontList* PlatformFontList() {
127 return static_cast<gfxFT2FontList*>(gfxPlatformFontList::PlatformFontList());
128 }
130 protected:
131 virtual nsresult InitFontList();
133 void AppendFaceFromFontListEntry(const FontListEntry& aFLE,
134 bool isStdFile);
136 void AppendFacesFromFontFile(const nsCString& aFileName,
137 bool isStdFile = false,
138 FontNameCache *aCache = nullptr);
140 void AppendFacesFromOmnijarEntry(nsZipArchive *aReader,
141 const nsCString& aEntryName,
142 FontNameCache *aCache,
143 bool aJarChanged);
145 void AppendFacesFromCachedFaceList(const nsCString& aFileName,
146 bool isStdFile,
147 const nsCString& aFaceList);
149 void AddFaceToList(const nsCString& aEntryName, uint32_t aIndex,
150 bool aStdFile, FT_Face aFace, nsCString& aFaceList);
152 void FindFonts();
154 void FindFontsInOmnijar(FontNameCache *aCache);
156 #ifdef ANDROID
157 void FindFontsInDir(const nsCString& aDir, FontNameCache* aFNC);
158 #endif
160 nsTHashtable<nsStringHashKey> mSkipSpaceLookupCheckFamilies;
161 };
163 #endif /* GFX_FT2FONTLIST_H */