|
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 gfxMacPlatformFontList_H_ |
|
7 #define gfxMacPlatformFontList_H_ |
|
8 |
|
9 #include <CoreFoundation/CoreFoundation.h> |
|
10 |
|
11 #include "mozilla/MemoryReporting.h" |
|
12 #include "nsDataHashtable.h" |
|
13 #include "nsRefPtrHashtable.h" |
|
14 |
|
15 #include "gfxPlatformFontList.h" |
|
16 #include "gfxPlatform.h" |
|
17 #include "gfxPlatformMac.h" |
|
18 |
|
19 #include "nsUnicharUtils.h" |
|
20 #include "nsTArray.h" |
|
21 |
|
22 class gfxMacPlatformFontList; |
|
23 |
|
24 // a single member of a font family (i.e. a single face, such as Times Italic) |
|
25 class MacOSFontEntry : public gfxFontEntry |
|
26 { |
|
27 public: |
|
28 friend class gfxMacPlatformFontList; |
|
29 |
|
30 MacOSFontEntry(const nsAString& aPostscriptName, int32_t aWeight, |
|
31 bool aIsStandardFace = false); |
|
32 |
|
33 // for use with data fonts |
|
34 MacOSFontEntry(const nsAString& aPostscriptName, CGFontRef aFontRef, |
|
35 uint16_t aWeight, uint16_t aStretch, uint32_t aItalicStyle, |
|
36 bool aIsUserFont, bool aIsLocal); |
|
37 |
|
38 virtual ~MacOSFontEntry() { |
|
39 ::CGFontRelease(mFontRef); |
|
40 } |
|
41 |
|
42 virtual CGFontRef GetFontRef(); |
|
43 |
|
44 // override gfxFontEntry table access function to bypass table cache, |
|
45 // use CGFontRef API to get direct access to system font data |
|
46 virtual hb_blob_t *GetFontTable(uint32_t aTag) MOZ_OVERRIDE; |
|
47 |
|
48 virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf, |
|
49 FontListSizes* aSizes) const; |
|
50 |
|
51 nsresult ReadCMAP(FontInfoData *aFontInfoData = nullptr); |
|
52 |
|
53 bool RequiresAATLayout() const { return mRequiresAAT; } |
|
54 |
|
55 bool IsCFF(); |
|
56 |
|
57 protected: |
|
58 virtual gfxFont* CreateFontInstance(const gfxFontStyle *aFontStyle, bool aNeedsBold); |
|
59 |
|
60 virtual bool HasFontTable(uint32_t aTableTag); |
|
61 |
|
62 static void DestroyBlobFunc(void* aUserData); |
|
63 |
|
64 CGFontRef mFontRef; // owning reference to the CGFont, released on destruction |
|
65 |
|
66 bool mFontRefInitialized; |
|
67 bool mRequiresAAT; |
|
68 bool mIsCFF; |
|
69 bool mIsCFFInitialized; |
|
70 }; |
|
71 |
|
72 class gfxMacPlatformFontList : public gfxPlatformFontList { |
|
73 public: |
|
74 static gfxMacPlatformFontList* PlatformFontList() { |
|
75 return static_cast<gfxMacPlatformFontList*>(sPlatformFontList); |
|
76 } |
|
77 |
|
78 static int32_t AppleWeightToCSSWeight(int32_t aAppleWeight); |
|
79 |
|
80 virtual gfxFontFamily* GetDefaultFont(const gfxFontStyle* aStyle); |
|
81 |
|
82 virtual bool GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName); |
|
83 |
|
84 virtual gfxFontEntry* LookupLocalFont(const gfxProxyFontEntry *aProxyEntry, |
|
85 const nsAString& aFontName); |
|
86 |
|
87 virtual gfxFontEntry* MakePlatformFont(const gfxProxyFontEntry *aProxyEntry, |
|
88 const uint8_t *aFontData, uint32_t aLength); |
|
89 |
|
90 void ClearPrefFonts() { mPrefFonts.Clear(); } |
|
91 |
|
92 private: |
|
93 friend class gfxPlatformMac; |
|
94 |
|
95 gfxMacPlatformFontList(); |
|
96 virtual ~gfxMacPlatformFontList(); |
|
97 |
|
98 // initialize font lists |
|
99 virtual nsresult InitFontList(); |
|
100 |
|
101 // special case font faces treated as font families (set via prefs) |
|
102 void InitSingleFaceList(); |
|
103 |
|
104 static void RegisteredFontsChangedNotificationCallback(CFNotificationCenterRef center, |
|
105 void *observer, |
|
106 CFStringRef name, |
|
107 const void *object, |
|
108 CFDictionaryRef userInfo); |
|
109 |
|
110 // search fonts system-wide for a given character, null otherwise |
|
111 virtual gfxFontEntry* GlobalFontFallback(const uint32_t aCh, |
|
112 int32_t aRunScript, |
|
113 const gfxFontStyle* aMatchStyle, |
|
114 uint32_t& aCmapCount, |
|
115 gfxFontFamily** aMatchedFamily); |
|
116 |
|
117 virtual bool UsesSystemFallback() { return true; } |
|
118 |
|
119 virtual already_AddRefed<FontInfoData> CreateFontInfoData(); |
|
120 |
|
121 enum { |
|
122 kATSGenerationInitial = -1 |
|
123 }; |
|
124 |
|
125 // default font for use with system-wide font fallback |
|
126 CTFontRef mDefaultFont; |
|
127 }; |
|
128 |
|
129 #endif /* gfxMacPlatformFontList_H_ */ |