/src/mozilla-central/gfx/thebes/gfxPlatformFontList.h
Line | Count | Source (jump to first uncovered line) |
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 GFXPLATFORMFONTLIST_H_ |
7 | | #define GFXPLATFORMFONTLIST_H_ |
8 | | |
9 | | #include "nsDataHashtable.h" |
10 | | #include "nsRefPtrHashtable.h" |
11 | | #include "nsTHashtable.h" |
12 | | |
13 | | #include "gfxFontUtils.h" |
14 | | #include "gfxFontInfoLoader.h" |
15 | | #include "gfxFont.h" |
16 | | #include "gfxFontConstants.h" |
17 | | #include "gfxPlatform.h" |
18 | | #include "gfxFontFamilyList.h" |
19 | | |
20 | | #include "nsIMemoryReporter.h" |
21 | | #include "mozilla/Attributes.h" |
22 | | #include "mozilla/FontPropertyTypes.h" |
23 | | #include "mozilla/MemoryReporting.h" |
24 | | #include "mozilla/Mutex.h" |
25 | | #include "mozilla/RangedArray.h" |
26 | | #include "nsLanguageAtomService.h" |
27 | | |
28 | | class CharMapHashKey : public PLDHashEntryHdr |
29 | | { |
30 | | public: |
31 | | typedef gfxCharacterMap* KeyType; |
32 | | typedef const gfxCharacterMap* KeyTypePointer; |
33 | | |
34 | | explicit CharMapHashKey(const gfxCharacterMap *aCharMap) : |
35 | | mCharMap(const_cast<gfxCharacterMap*>(aCharMap)) |
36 | 0 | { |
37 | 0 | MOZ_COUNT_CTOR(CharMapHashKey); |
38 | 0 | } |
39 | | CharMapHashKey(const CharMapHashKey& toCopy) : |
40 | | mCharMap(toCopy.mCharMap) |
41 | 0 | { |
42 | 0 | MOZ_COUNT_CTOR(CharMapHashKey); |
43 | 0 | } |
44 | | ~CharMapHashKey() |
45 | 0 | { |
46 | 0 | MOZ_COUNT_DTOR(CharMapHashKey); |
47 | 0 | } |
48 | | |
49 | 0 | gfxCharacterMap* GetKey() const { return mCharMap; } |
50 | | |
51 | 0 | bool KeyEquals(const gfxCharacterMap *aCharMap) const { |
52 | 0 | NS_ASSERTION(!aCharMap->mBuildOnTheFly && !mCharMap->mBuildOnTheFly, |
53 | 0 | "custom cmap used in shared cmap hashtable"); |
54 | 0 | // cmaps built on the fly never match |
55 | 0 | if (aCharMap->mHash != mCharMap->mHash) |
56 | 0 | { |
57 | 0 | return false; |
58 | 0 | } |
59 | 0 | return mCharMap->Equals(aCharMap); |
60 | 0 | } |
61 | | |
62 | 0 | static const gfxCharacterMap* KeyToPointer(gfxCharacterMap *aCharMap) { |
63 | 0 | return aCharMap; |
64 | 0 | } |
65 | 0 | static PLDHashNumber HashKey(const gfxCharacterMap *aCharMap) { |
66 | 0 | return aCharMap->mHash; |
67 | 0 | } |
68 | | |
69 | | enum { ALLOW_MEMMOVE = true }; |
70 | | |
71 | | protected: |
72 | | // charMaps are not owned by the shared cmap cache, but it will be notified |
73 | | // by gfxCharacterMap::Release() when an entry is about to be deleted |
74 | | gfxCharacterMap* MOZ_NON_OWNING_REF mCharMap; |
75 | | }; |
76 | | |
77 | | // gfxPlatformFontList is an abstract class for the global font list on the system; |
78 | | // concrete subclasses for each platform implement the actual interface to the system fonts. |
79 | | // This class exists because we cannot rely on the platform font-finding APIs to behave |
80 | | // in sensible/similar ways, particularly with rich, complex OpenType families, |
81 | | // so we do our own font family/style management here instead. |
82 | | |
83 | | // Much of this is based on the old gfxQuartzFontCache, but adapted for use on all platforms. |
84 | | |
85 | | struct FontListSizes { |
86 | | uint32_t mFontListSize; // size of the font list and dependent objects |
87 | | // (font family and face names, etc), but NOT |
88 | | // including the font table cache and the cmaps |
89 | | uint32_t mFontTableCacheSize; // memory used for the gfxFontEntry table caches |
90 | | uint32_t mCharMapsSize; // memory used for cmap coverage info |
91 | | uint32_t mLoaderSize; // memory used for (platform-specific) loader |
92 | | }; |
93 | | |
94 | | class gfxUserFontSet; |
95 | | |
96 | | class gfxPlatformFontList : public gfxFontInfoLoader |
97 | | { |
98 | | friend class InitOtherFamilyNamesRunnable; |
99 | | |
100 | | public: |
101 | | typedef mozilla::StretchRange StretchRange; |
102 | | typedef mozilla::SlantStyleRange SlantStyleRange; |
103 | | typedef mozilla::WeightRange WeightRange; |
104 | | typedef mozilla::unicode::Script Script; |
105 | | |
106 | 0 | static gfxPlatformFontList* PlatformFontList() { |
107 | 0 | return sPlatformFontList; |
108 | 0 | } |
109 | | |
110 | 0 | static nsresult Init() { |
111 | 0 | NS_ASSERTION(!sPlatformFontList, "What's this doing here?"); |
112 | 0 | gfxPlatform::GetPlatform()->CreatePlatformFontList(); |
113 | 0 | if (!sPlatformFontList) { |
114 | 0 | return NS_ERROR_OUT_OF_MEMORY; |
115 | 0 | } |
116 | 0 | return NS_OK; |
117 | 0 | } |
118 | | |
119 | 0 | static void Shutdown() { |
120 | 0 | delete sPlatformFontList; |
121 | 0 | sPlatformFontList = nullptr; |
122 | 0 | } |
123 | | |
124 | | virtual ~gfxPlatformFontList(); |
125 | | |
126 | | // initialize font lists |
127 | | nsresult InitFontList(); |
128 | | |
129 | | virtual void GetFontList(nsAtom *aLangGroup, |
130 | | const nsACString& aGenericFamily, |
131 | | nsTArray<nsString>& aListOfFonts); |
132 | | |
133 | | void UpdateFontList(); |
134 | | |
135 | | virtual void ClearLangGroupPrefFonts(); |
136 | | |
137 | | virtual void GetFontFamilyList(nsTArray<RefPtr<gfxFontFamily> >& aFamilyArray); |
138 | | |
139 | | gfxFontEntry* |
140 | | SystemFindFontForChar(uint32_t aCh, uint32_t aNextCh, |
141 | | Script aRunScript, |
142 | | const gfxFontStyle* aStyle); |
143 | | |
144 | | // Flags to control optional behaviors in FindAndAddFamilies. The sense |
145 | | // of the bit flags have been chosen such that the default parameter of |
146 | | // FindFamiliesFlags(0) in FindFamily will give the most commonly-desired |
147 | | // behavior, and only a few callsites need to explicitly pass other values. |
148 | | enum class FindFamiliesFlags { |
149 | | // If set, "other" (e.g. localized) family names should be loaded |
150 | | // immediately; if clear, InitOtherFamilyNames is allowed to defer |
151 | | // loading to avoid blocking. |
152 | | eForceOtherFamilyNamesLoading = 1 << 0, |
153 | | |
154 | | // If set, FindAndAddFamilies should not check for legacy "styled |
155 | | // family" names to add to the font list. This is used to avoid |
156 | | // a recursive search when using FindFamily to find a potential base |
157 | | // family name for a styled variant. |
158 | | eNoSearchForLegacyFamilyNames = 1 << 1, |
159 | | |
160 | | // If set, FindAndAddFamilies will not add a missing entry to mOtherNamesMissed |
161 | | eNoAddToNamesMissedWhenSearching = 1 << 2 |
162 | | }; |
163 | | |
164 | | // Find family(ies) matching aFamily and append to the aOutput array |
165 | | // (there may be multiple results in the case of fontconfig aliases, etc). |
166 | | // Return true if any match was found and appended, false if none. |
167 | | virtual bool |
168 | | FindAndAddFamilies(const nsACString& aFamily, |
169 | | nsTArray<FamilyAndGeneric>* aOutput, |
170 | | FindFamiliesFlags aFlags, |
171 | | gfxFontStyle* aStyle = nullptr, |
172 | | gfxFloat aDevToCssSize = 1.0); |
173 | | |
174 | | gfxFontEntry* FindFontForFamily(const nsACString& aFamily, |
175 | | const gfxFontStyle* aStyle); |
176 | | |
177 | | // name lookup table methods |
178 | | |
179 | | void AddOtherFamilyName(gfxFontFamily *aFamilyEntry, nsCString& aOtherFamilyName); |
180 | | |
181 | | void AddFullname(gfxFontEntry *aFontEntry, const nsCString& aFullname); |
182 | | |
183 | | void AddPostscriptName(gfxFontEntry *aFontEntry, const nsCString& aPostscriptName); |
184 | | |
185 | 0 | bool NeedFullnamePostscriptNames() { return mExtraNames != nullptr; } |
186 | | |
187 | | // pure virtual functions, to be provided by concrete subclasses |
188 | | |
189 | | // get the system default font family |
190 | | gfxFontFamily* GetDefaultFont(const gfxFontStyle* aStyle); |
191 | | |
192 | | /** |
193 | | * Look up a font by name on the host platform. |
194 | | * |
195 | | * Note that the style attributes (weight, stretch, style) are NOT used in |
196 | | * selecting the platform font, which is looked up by name only; these are |
197 | | * values to be recorded in the new font entry. |
198 | | */ |
199 | | virtual gfxFontEntry* LookupLocalFont(const nsACString& aFontName, |
200 | | WeightRange aWeightForEntry, |
201 | | StretchRange aStretchForEntry, |
202 | | SlantStyleRange aStyleForEntry) = 0; |
203 | | |
204 | | /** |
205 | | * Create a new platform font from downloaded data (@font-face). |
206 | | * |
207 | | * Note that the style attributes (weight, stretch, style) are NOT related |
208 | | * (necessarily) to any values within the font resource itself; these are |
209 | | * values to be recorded in the new font entry and used for face selection, |
210 | | * in place of whatever inherent style attributes the resource may have. |
211 | | * |
212 | | * This method takes ownership of the data block passed in as aFontData, |
213 | | * and must ensure it is free()'d when no longer required. |
214 | | */ |
215 | | virtual gfxFontEntry* MakePlatformFont(const nsACString& aFontName, |
216 | | WeightRange aWeightForEntry, |
217 | | StretchRange aStretchForEntry, |
218 | | SlantStyleRange aStyleForEntry, |
219 | | const uint8_t* aFontData, |
220 | | uint32_t aLength) = 0; |
221 | | |
222 | | // get the standard family name on the platform for a given font name |
223 | | // (platforms may override, eg Mac) |
224 | | virtual bool GetStandardFamilyName(const nsCString& aFontName, nsACString& aFamilyName); |
225 | | |
226 | | // get the default font name which is available on the system from |
227 | | // font.name-list.*. if there are no available fonts in the pref, |
228 | | // returns nullptr. |
229 | | gfxFontFamily* GetDefaultFontFamily(const nsACString& aLangGroup, |
230 | | const nsACString& aGenericFamily); |
231 | | |
232 | | virtual void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf, |
233 | | FontListSizes* aSizes) const; |
234 | | virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf, |
235 | | FontListSizes* aSizes) const; |
236 | | |
237 | | // search for existing cmap that matches the input |
238 | | // return the input if no match is found |
239 | | gfxCharacterMap* FindCharMap(gfxCharacterMap *aCmap); |
240 | | |
241 | | // add a cmap to the shared cmap set |
242 | | gfxCharacterMap* AddCmap(const gfxCharacterMap *aCharMap); |
243 | | |
244 | | // remove the cmap from the shared cmap set |
245 | | void RemoveCmap(const gfxCharacterMap *aCharMap); |
246 | | |
247 | | // keep track of userfont sets to notify when global fontlist changes occur |
248 | 0 | void AddUserFontSet(gfxUserFontSet *aUserFontSet) { |
249 | 0 | mUserFontSetList.PutEntry(aUserFontSet); |
250 | 0 | } |
251 | | |
252 | 0 | void RemoveUserFontSet(gfxUserFontSet *aUserFontSet) { |
253 | 0 | mUserFontSetList.RemoveEntry(aUserFontSet); |
254 | 0 | } |
255 | | |
256 | | static const gfxFontEntry::ScriptRange sComplexScriptRanges[]; |
257 | | |
258 | 0 | void GetFontlistInitInfo(uint32_t& aNumInits, uint32_t& aLoaderState) { |
259 | 0 | aNumInits = mFontlistInitCount; |
260 | 0 | aLoaderState = (uint32_t) mState; |
261 | 0 | } |
262 | | |
263 | | virtual void |
264 | | AddGenericFonts(mozilla::FontFamilyType aGenericType, |
265 | | nsAtom* aLanguage, |
266 | | nsTArray<FamilyAndGeneric>& aFamilyList); |
267 | | |
268 | | nsTArray<RefPtr<gfxFontFamily>>* |
269 | | GetPrefFontsLangGroup(mozilla::FontFamilyType aGenericType, |
270 | | eFontPrefLang aPrefLang); |
271 | | |
272 | | // in some situations, need to make decisions about ambiguous characters, may need to look at multiple pref langs |
273 | | void GetLangPrefs(eFontPrefLang aPrefLangs[], uint32_t &aLen, eFontPrefLang aCharLang, eFontPrefLang aPageLang); |
274 | | |
275 | | // convert a lang group to enum constant (i.e. "zh-TW" ==> eFontPrefLang_ChineseTW) |
276 | | static eFontPrefLang GetFontPrefLangFor(const char* aLang); |
277 | | |
278 | | // convert a lang group atom to enum constant |
279 | | static eFontPrefLang GetFontPrefLangFor(nsAtom *aLang); |
280 | | |
281 | | // convert an enum constant to a lang group atom |
282 | | static nsAtom* GetLangGroupForPrefLang(eFontPrefLang aLang); |
283 | | |
284 | | // convert a enum constant to lang group string (i.e. eFontPrefLang_ChineseTW ==> "zh-TW") |
285 | | static const char* GetPrefLangName(eFontPrefLang aLang); |
286 | | |
287 | | // map a Unicode range (based on char code) to a font language for Preferences |
288 | | static eFontPrefLang GetFontPrefLangFor(uint8_t aUnicodeRange); |
289 | | |
290 | | // returns true if a pref lang is CJK |
291 | | static bool IsLangCJK(eFontPrefLang aLang); |
292 | | |
293 | | // helper method to add a pref lang to an array, if not already in array |
294 | | static void AppendPrefLang(eFontPrefLang aPrefLangs[], uint32_t& aLen, eFontPrefLang aAddLang); |
295 | | |
296 | | // default serif/sans-serif choice based on font.default.xxx prefs |
297 | | mozilla::FontFamilyType |
298 | | GetDefaultGeneric(eFontPrefLang aLang); |
299 | | |
300 | | // Returns true if the font family whitelist is not empty. |
301 | | bool IsFontFamilyWhitelistActive(); |
302 | | |
303 | | static void FontWhitelistPrefChanged(const char *aPref, void *aClosure); |
304 | | |
305 | | bool AddWithLegacyFamilyName(const nsACString& aLegacyName, |
306 | | gfxFontEntry* aFontEntry); |
307 | | |
308 | | static const char* GetGenericName(mozilla::FontFamilyType aGenericType); |
309 | | |
310 | | protected: |
311 | | class InitOtherFamilyNamesRunnable : public mozilla::CancelableRunnable |
312 | | { |
313 | | public: |
314 | | InitOtherFamilyNamesRunnable() |
315 | | : CancelableRunnable("gfxPlatformFontList::InitOtherFamilyNamesRunnable") |
316 | | , mIsCanceled(false) |
317 | 0 | { |
318 | 0 | } |
319 | | |
320 | | NS_IMETHOD Run() override |
321 | 0 | { |
322 | 0 | if (mIsCanceled) { |
323 | 0 | return NS_OK; |
324 | 0 | } |
325 | 0 | |
326 | 0 | gfxPlatformFontList* fontList = gfxPlatformFontList::PlatformFontList(); |
327 | 0 | if (!fontList) { |
328 | 0 | return NS_OK; |
329 | 0 | } |
330 | 0 | |
331 | 0 | fontList->InitOtherFamilyNamesInternal(true); |
332 | 0 |
|
333 | 0 | return NS_OK; |
334 | 0 | } |
335 | | |
336 | | virtual nsresult Cancel() override |
337 | 0 | { |
338 | 0 | mIsCanceled = true; |
339 | 0 |
|
340 | 0 | return NS_OK; |
341 | 0 | } |
342 | | |
343 | | private: |
344 | | bool mIsCanceled; |
345 | | }; |
346 | | |
347 | | class MemoryReporter final : public nsIMemoryReporter |
348 | | { |
349 | 0 | ~MemoryReporter() {} |
350 | | public: |
351 | | NS_DECL_ISUPPORTS |
352 | | NS_DECL_NSIMEMORYREPORTER |
353 | | }; |
354 | | |
355 | | template<bool ForNameList> |
356 | | class PrefNameMaker final : public nsAutoCString |
357 | | { |
358 | | void Init(const nsACString& aGeneric, const nsACString& aLangGroup) |
359 | 0 | { |
360 | 0 | if (ForNameList) { |
361 | 0 | AssignLiteral("font.name-list."); |
362 | 0 | } else { |
363 | 0 | AssignLiteral("font.name."); |
364 | 0 | } |
365 | 0 | Append(aGeneric); |
366 | 0 | if (!aLangGroup.IsEmpty()) { |
367 | 0 | Append('.'); |
368 | 0 | Append(aLangGroup); |
369 | 0 | } |
370 | 0 | } Unexecuted instantiation: gfxPlatformFontList::PrefNameMaker<false>::Init(nsTSubstring<char> const&, nsTSubstring<char> const&) Unexecuted instantiation: gfxPlatformFontList::PrefNameMaker<true>::Init(nsTSubstring<char> const&, nsTSubstring<char> const&) |
371 | | |
372 | | public: |
373 | | PrefNameMaker(const nsACString& aGeneric, |
374 | | const nsACString& aLangGroup) |
375 | 0 | { |
376 | 0 | Init(aGeneric, aLangGroup); |
377 | 0 | } |
378 | | |
379 | | PrefNameMaker(const char* aGeneric, |
380 | | const char* aLangGroup) |
381 | 0 | { |
382 | 0 | Init(nsDependentCString(aGeneric), nsDependentCString(aLangGroup)); |
383 | 0 | } Unexecuted instantiation: gfxPlatformFontList::PrefNameMaker<false>::PrefNameMaker(char const*, char const*) Unexecuted instantiation: gfxPlatformFontList::PrefNameMaker<true>::PrefNameMaker(char const*, char const*) |
384 | | |
385 | | PrefNameMaker(const char* aGeneric, |
386 | | nsAtom* aLangGroup) |
387 | 0 | { |
388 | 0 | if (aLangGroup) { |
389 | 0 | Init(nsDependentCString(aGeneric), nsAtomCString(aLangGroup)); |
390 | 0 | } else { |
391 | 0 | Init(nsDependentCString(aGeneric), nsAutoCString()); |
392 | 0 | } |
393 | 0 | } Unexecuted instantiation: gfxPlatformFontList::PrefNameMaker<false>::PrefNameMaker(char const*, nsAtom*) Unexecuted instantiation: gfxPlatformFontList::PrefNameMaker<true>::PrefNameMaker(char const*, nsAtom*) |
394 | | }; |
395 | | |
396 | | typedef PrefNameMaker<false> NamePref; |
397 | | typedef PrefNameMaker<true> NameListPref; |
398 | | |
399 | | explicit gfxPlatformFontList(bool aNeedFullnamePostscriptNames = true); |
400 | | |
401 | | static gfxPlatformFontList *sPlatformFontList; |
402 | | |
403 | | // Convenience method to return the first matching family (if any) as found |
404 | | // by FindAndAddFamilies(). |
405 | | gfxFontFamily* |
406 | | FindFamily(const nsACString& aFamily, |
407 | | FindFamiliesFlags aFlags = FindFamiliesFlags(0), |
408 | | gfxFontStyle* aStyle = nullptr, |
409 | | gfxFloat aDevToCssSize = 1.0) |
410 | 0 | { |
411 | 0 | AutoTArray<FamilyAndGeneric,1> families; |
412 | 0 | return FindAndAddFamilies(aFamily, |
413 | 0 | &families, |
414 | 0 | aFlags, |
415 | 0 | aStyle, |
416 | 0 | aDevToCssSize) |
417 | 0 | ? families[0].mFamily : nullptr; |
418 | 0 | } |
419 | | |
420 | | // Lookup family name in global family list without substitutions or |
421 | | // localized family name lookup. Used for common font fallback families. |
422 | 0 | gfxFontFamily* FindFamilyByCanonicalName(const nsACString& aFamily) { |
423 | 0 | nsAutoCString key; |
424 | 0 | gfxFontFamily *familyEntry; |
425 | 0 | GenerateFontListKey(aFamily, key); |
426 | 0 | if ((familyEntry = mFontFamilies.GetWeak(key))) { |
427 | 0 | return CheckFamily(familyEntry); |
428 | 0 | } |
429 | 0 | return nullptr; |
430 | 0 | } |
431 | | |
432 | | // returns default font for a given character, null otherwise |
433 | | gfxFontEntry* CommonFontFallback(uint32_t aCh, uint32_t aNextCh, |
434 | | Script aRunScript, |
435 | | const gfxFontStyle* aMatchStyle, |
436 | | gfxFontFamily** aMatchedFamily); |
437 | | |
438 | | // Search fonts system-wide for a given character, null if not found. |
439 | | gfxFontEntry* GlobalFontFallback(const uint32_t aCh, |
440 | | Script aRunScript, |
441 | | const gfxFontStyle* aMatchStyle, |
442 | | uint32_t& aCmapCount, |
443 | | gfxFontFamily** aMatchedFamily); |
444 | | |
445 | | // Platform-specific implementation of global font fallback, if any; |
446 | | // this may return nullptr in which case the default cmap-based fallback |
447 | | // will be performed. |
448 | | virtual gfxFontEntry* |
449 | | PlatformGlobalFontFallback(const uint32_t aCh, |
450 | | Script aRunScript, |
451 | | const gfxFontStyle* aMatchStyle, |
452 | | gfxFontFamily** aMatchedFamily) |
453 | 0 | { |
454 | 0 | return nullptr; |
455 | 0 | } |
456 | | |
457 | | // whether system-based font fallback is used or not |
458 | | // if system fallback is used, no need to load all cmaps |
459 | 0 | virtual bool UsesSystemFallback() { return false; } |
460 | | |
461 | | void AppendCJKPrefLangs(eFontPrefLang aPrefLangs[], uint32_t &aLen, |
462 | | eFontPrefLang aCharLang, eFontPrefLang aPageLang); |
463 | | |
464 | | // verifies that a family contains a non-zero font count |
465 | | gfxFontFamily* CheckFamily(gfxFontFamily *aFamily); |
466 | | |
467 | | // initialize localized family names |
468 | | void InitOtherFamilyNames(bool aDeferOtherFamilyNamesLoading); |
469 | | void InitOtherFamilyNamesInternal(bool aDeferOtherFamilyNamesLoading); |
470 | | void CancelInitOtherFamilyNamesTask(); |
471 | | |
472 | | // search through font families, looking for a given name, initializing |
473 | | // facename lists along the way. first checks all families with names |
474 | | // close to face name, then searchs all families if not found. |
475 | | gfxFontEntry* SearchFamiliesForFaceName(const nsACString& aFaceName); |
476 | | |
477 | | // helper method for finding fullname/postscript names in facename lists |
478 | | gfxFontEntry* FindFaceName(const nsACString& aFaceName); |
479 | | |
480 | | // look up a font by name, for cases where platform font list |
481 | | // maintains explicit mappings of fullname/psname ==> font |
482 | | virtual gfxFontEntry* LookupInFaceNameLists(const nsACString& aFontName); |
483 | | |
484 | | // commonly used fonts for which the name table should be loaded at startup |
485 | | virtual void PreloadNamesList(); |
486 | | |
487 | | // load the bad underline blacklist from pref. |
488 | | void LoadBadUnderlineList(); |
489 | | |
490 | | void GenerateFontListKey(const nsACString& aKeyName, nsACString& aResult); |
491 | | |
492 | | virtual void GetFontFamilyNames(nsTArray<nsCString>& aFontFamilyNames); |
493 | | |
494 | | // helper function to map lang to lang group |
495 | | nsAtom* GetLangGroup(nsAtom* aLanguage); |
496 | | |
497 | | // gfxFontInfoLoader overrides, used to load in font cmaps |
498 | | virtual void InitLoader() override; |
499 | | virtual bool LoadFontInfo() override; |
500 | | virtual void CleanupLoader() override; |
501 | | |
502 | | // read the loader initialization prefs, and start it |
503 | | void GetPrefsAndStartLoader(); |
504 | | |
505 | | // for font list changes that affect all documents |
506 | 0 | void ForceGlobalReflow() { |
507 | 0 | gfxPlatform::ForceGlobalReflow(); |
508 | 0 | } |
509 | | |
510 | | void RebuildLocalFonts(); |
511 | | |
512 | | void |
513 | | ResolveGenericFontNames(mozilla::FontFamilyType aGenericType, |
514 | | eFontPrefLang aPrefLang, |
515 | | nsTArray<RefPtr<gfxFontFamily>>* aGenericFamilies); |
516 | | |
517 | | void |
518 | | ResolveEmojiFontNames(nsTArray<RefPtr<gfxFontFamily>>* aGenericFamilies); |
519 | | |
520 | | void |
521 | | GetFontFamiliesFromGenericFamilies( |
522 | | nsTArray<nsCString>& aGenericFamilies, |
523 | | nsAtom* aLangGroup, |
524 | | nsTArray<RefPtr<gfxFontFamily>>* aFontFamilies); |
525 | | |
526 | | virtual nsresult InitFontListForPlatform() = 0; |
527 | | |
528 | | void ApplyWhitelist(); |
529 | | |
530 | | // Create a new gfxFontFamily of the appropriate subclass for the platform, |
531 | | // used when AddWithLegacyFamilyName needs to create a new family. |
532 | | virtual gfxFontFamily* CreateFontFamily(const nsACString& aName) const = 0; |
533 | | |
534 | | typedef nsRefPtrHashtable<nsCStringHashKey, gfxFontFamily> FontFamilyTable; |
535 | | typedef nsRefPtrHashtable<nsCStringHashKey, gfxFontEntry> FontEntryTable; |
536 | | |
537 | | // used by memory reporter to accumulate sizes of family names in the table |
538 | | static size_t |
539 | | SizeOfFontFamilyTableExcludingThis(const FontFamilyTable& aTable, |
540 | | mozilla::MallocSizeOf aMallocSizeOf); |
541 | | static size_t |
542 | | SizeOfFontEntryTableExcludingThis(const FontEntryTable& aTable, |
543 | | mozilla::MallocSizeOf aMallocSizeOf); |
544 | | |
545 | | // Platform-specific helper for GetDefaultFont(...). |
546 | | virtual gfxFontFamily* |
547 | | GetDefaultFontForPlatform(const gfxFontStyle* aStyle) = 0; |
548 | | |
549 | | // Protects mFontFamilies. |
550 | | mozilla::Mutex mFontFamiliesMutex; |
551 | | |
552 | | // canonical family name ==> family entry (unique, one name per family entry) |
553 | | FontFamilyTable mFontFamilies; |
554 | | |
555 | | // other family name ==> family entry (not unique, can have multiple names per |
556 | | // family entry, only names *other* than the canonical names are stored here) |
557 | | FontFamilyTable mOtherFamilyNames; |
558 | | |
559 | | // flag set after InitOtherFamilyNames is called upon first name lookup miss |
560 | | bool mOtherFamilyNamesInitialized; |
561 | | |
562 | | // The pending InitOtherFamilyNames() task. |
563 | | RefPtr<mozilla::CancelableRunnable> mPendingOtherFamilyNameTask; |
564 | | |
565 | | // flag set after fullname and Postcript name lists are populated |
566 | | bool mFaceNameListsInitialized; |
567 | | |
568 | | struct ExtraNames { |
569 | 0 | ExtraNames() : mFullnames(64), mPostscriptNames(64) {} |
570 | | |
571 | | // fullname ==> font entry (unique, one name per font entry) |
572 | | FontEntryTable mFullnames; |
573 | | // Postscript name ==> font entry (unique, one name per font entry) |
574 | | FontEntryTable mPostscriptNames; |
575 | | }; |
576 | | mozilla::UniquePtr<ExtraNames> mExtraNames; |
577 | | |
578 | | // face names missed when face name loading takes a long time |
579 | | mozilla::UniquePtr<nsTHashtable<nsCStringHashKey> > mFaceNamesMissed; |
580 | | |
581 | | // localized family names missed when face name loading takes a long time |
582 | | mozilla::UniquePtr<nsTHashtable<nsCStringHashKey> > mOtherNamesMissed; |
583 | | |
584 | | typedef nsTArray<RefPtr<gfxFontFamily>> PrefFontList; |
585 | | typedef mozilla::RangedArray<mozilla::UniquePtr<PrefFontList>, |
586 | | mozilla::eFamily_generic_first, |
587 | | mozilla::eFamily_generic_count> PrefFontsForLangGroup; |
588 | | mozilla::RangedArray<PrefFontsForLangGroup, |
589 | | eFontPrefLang_First, |
590 | | eFontPrefLang_Count> mLangGroupPrefFonts; |
591 | | mozilla::UniquePtr<PrefFontList> mEmojiPrefFont; |
592 | | |
593 | | // when system-wide font lookup fails for a character, cache it to skip future searches |
594 | | gfxSparseBitSet mCodepointsWithNoFonts; |
595 | | |
596 | | // the family to use for U+FFFD fallback, to avoid expensive search every time |
597 | | // on pages with lots of problems |
598 | | RefPtr<gfxFontFamily> mReplacementCharFallbackFamily; |
599 | | |
600 | | nsTHashtable<nsCStringHashKey> mBadUnderlineFamilyNames; |
601 | | |
602 | | // character map data shared across families |
603 | | // contains weak ptrs to cmaps shared by font entry objects |
604 | | nsTHashtable<CharMapHashKey> mSharedCmaps; |
605 | | |
606 | | // data used as part of the font cmap loading process |
607 | | nsTArray<RefPtr<gfxFontFamily> > mFontFamiliesToLoad; |
608 | | uint32_t mStartIndex; |
609 | | uint32_t mNumFamilies; |
610 | | |
611 | | // xxx - info for diagnosing no default font aborts |
612 | | // see bugs 636957, 1070983, 1189129 |
613 | | uint32_t mFontlistInitCount; // num times InitFontList called |
614 | | |
615 | | nsTHashtable<nsPtrHashKey<gfxUserFontSet> > mUserFontSetList; |
616 | | |
617 | | nsLanguageAtomService* mLangService; |
618 | | |
619 | | nsTArray<uint32_t> mCJKPrefLangs; |
620 | | nsTArray<mozilla::FontFamilyType> mDefaultGenericsLangGroup; |
621 | | |
622 | | bool mFontFamilyWhitelistActive; |
623 | | }; |
624 | | |
625 | | MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(gfxPlatformFontList::FindFamiliesFlags) |
626 | | |
627 | | #endif /* GFXPLATFORMFONTLIST_H_ */ |