|
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/. */ |
|
5 |
|
6 #ifndef GFX_FT2FONTLIST_H |
|
7 #define GFX_FT2FONTLIST_H |
|
8 |
|
9 #include "mozilla/MemoryReporting.h" |
|
10 |
|
11 #ifdef XP_WIN |
|
12 #include "gfxWindowsPlatform.h" |
|
13 #include <windows.h> |
|
14 #endif |
|
15 #include "gfxPlatformFontList.h" |
|
16 |
|
17 namespace mozilla { |
|
18 namespace dom { |
|
19 class FontListEntry; |
|
20 }; |
|
21 }; |
|
22 using mozilla::dom::FontListEntry; |
|
23 |
|
24 class FontNameCache; |
|
25 typedef struct FT_FaceRec_* FT_Face; |
|
26 class nsZipArchive; |
|
27 |
|
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 } |
|
38 |
|
39 ~FT2FontEntry(); |
|
40 |
|
41 const nsString& GetName() const { |
|
42 return Name(); |
|
43 } |
|
44 |
|
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); |
|
49 |
|
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); |
|
55 |
|
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); |
|
65 |
|
66 virtual gfxFont *CreateFontInstance(const gfxFontStyle *aFontStyle, |
|
67 bool aNeedsBold); |
|
68 |
|
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(); |
|
72 |
|
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); |
|
76 |
|
77 nsresult ReadCMAP(FontInfoData *aFontInfoData = nullptr); |
|
78 |
|
79 virtual hb_blob_t* GetFontTable(uint32_t aTableTag) MOZ_OVERRIDE; |
|
80 |
|
81 virtual nsresult CopyFontTable(uint32_t aTableTag, |
|
82 FallibleTArray<uint8_t>& aBuffer) MOZ_OVERRIDE; |
|
83 |
|
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); |
|
87 |
|
88 virtual void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf, |
|
89 FontListSizes* aSizes) const; |
|
90 virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf, |
|
91 FontListSizes* aSizes) const; |
|
92 |
|
93 FT_Face mFTFace; |
|
94 cairo_font_face_t *mFontFace; |
|
95 |
|
96 nsCString mFilename; |
|
97 uint8_t mFTFontIndex; |
|
98 }; |
|
99 |
|
100 class FT2FontFamily : public gfxFontFamily |
|
101 { |
|
102 public: |
|
103 FT2FontFamily(const nsAString& aName) : |
|
104 gfxFontFamily(aName) { } |
|
105 |
|
106 // Append this family's faces to the IPC fontlist |
|
107 void AddFacesToFontList(InfallibleTArray<FontListEntry>* aFontList); |
|
108 }; |
|
109 |
|
110 class gfxFT2FontList : public gfxPlatformFontList |
|
111 { |
|
112 public: |
|
113 gfxFT2FontList(); |
|
114 |
|
115 virtual gfxFontFamily* GetDefaultFont(const gfxFontStyle* aStyle); |
|
116 |
|
117 virtual gfxFontEntry* LookupLocalFont(const gfxProxyFontEntry *aProxyEntry, |
|
118 const nsAString& aFontName); |
|
119 |
|
120 virtual gfxFontEntry* MakePlatformFont(const gfxProxyFontEntry *aProxyEntry, |
|
121 const uint8_t *aFontData, |
|
122 uint32_t aLength); |
|
123 |
|
124 void GetFontList(InfallibleTArray<FontListEntry>* retValue); |
|
125 |
|
126 static gfxFT2FontList* PlatformFontList() { |
|
127 return static_cast<gfxFT2FontList*>(gfxPlatformFontList::PlatformFontList()); |
|
128 } |
|
129 |
|
130 protected: |
|
131 virtual nsresult InitFontList(); |
|
132 |
|
133 void AppendFaceFromFontListEntry(const FontListEntry& aFLE, |
|
134 bool isStdFile); |
|
135 |
|
136 void AppendFacesFromFontFile(const nsCString& aFileName, |
|
137 bool isStdFile = false, |
|
138 FontNameCache *aCache = nullptr); |
|
139 |
|
140 void AppendFacesFromOmnijarEntry(nsZipArchive *aReader, |
|
141 const nsCString& aEntryName, |
|
142 FontNameCache *aCache, |
|
143 bool aJarChanged); |
|
144 |
|
145 void AppendFacesFromCachedFaceList(const nsCString& aFileName, |
|
146 bool isStdFile, |
|
147 const nsCString& aFaceList); |
|
148 |
|
149 void AddFaceToList(const nsCString& aEntryName, uint32_t aIndex, |
|
150 bool aStdFile, FT_Face aFace, nsCString& aFaceList); |
|
151 |
|
152 void FindFonts(); |
|
153 |
|
154 void FindFontsInOmnijar(FontNameCache *aCache); |
|
155 |
|
156 #ifdef ANDROID |
|
157 void FindFontsInDir(const nsCString& aDir, FontNameCache* aFNC); |
|
158 #endif |
|
159 |
|
160 nsTHashtable<nsStringHashKey> mSkipSpaceLookupCheckFamilies; |
|
161 }; |
|
162 |
|
163 #endif /* GFX_FT2FONTLIST_H */ |