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 gfxMacPlatformFontList_H_
7 #define gfxMacPlatformFontList_H_
9 #include <CoreFoundation/CoreFoundation.h>
11 #include "mozilla/MemoryReporting.h"
12 #include "nsDataHashtable.h"
13 #include "nsRefPtrHashtable.h"
15 #include "gfxPlatformFontList.h"
16 #include "gfxPlatform.h"
17 #include "gfxPlatformMac.h"
19 #include "nsUnicharUtils.h"
20 #include "nsTArray.h"
22 class gfxMacPlatformFontList;
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;
30 MacOSFontEntry(const nsAString& aPostscriptName, int32_t aWeight,
31 bool aIsStandardFace = false);
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);
38 virtual ~MacOSFontEntry() {
39 ::CGFontRelease(mFontRef);
40 }
42 virtual CGFontRef GetFontRef();
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;
48 virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
49 FontListSizes* aSizes) const;
51 nsresult ReadCMAP(FontInfoData *aFontInfoData = nullptr);
53 bool RequiresAATLayout() const { return mRequiresAAT; }
55 bool IsCFF();
57 protected:
58 virtual gfxFont* CreateFontInstance(const gfxFontStyle *aFontStyle, bool aNeedsBold);
60 virtual bool HasFontTable(uint32_t aTableTag);
62 static void DestroyBlobFunc(void* aUserData);
64 CGFontRef mFontRef; // owning reference to the CGFont, released on destruction
66 bool mFontRefInitialized;
67 bool mRequiresAAT;
68 bool mIsCFF;
69 bool mIsCFFInitialized;
70 };
72 class gfxMacPlatformFontList : public gfxPlatformFontList {
73 public:
74 static gfxMacPlatformFontList* PlatformFontList() {
75 return static_cast<gfxMacPlatformFontList*>(sPlatformFontList);
76 }
78 static int32_t AppleWeightToCSSWeight(int32_t aAppleWeight);
80 virtual gfxFontFamily* GetDefaultFont(const gfxFontStyle* aStyle);
82 virtual bool GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName);
84 virtual gfxFontEntry* LookupLocalFont(const gfxProxyFontEntry *aProxyEntry,
85 const nsAString& aFontName);
87 virtual gfxFontEntry* MakePlatformFont(const gfxProxyFontEntry *aProxyEntry,
88 const uint8_t *aFontData, uint32_t aLength);
90 void ClearPrefFonts() { mPrefFonts.Clear(); }
92 private:
93 friend class gfxPlatformMac;
95 gfxMacPlatformFontList();
96 virtual ~gfxMacPlatformFontList();
98 // initialize font lists
99 virtual nsresult InitFontList();
101 // special case font faces treated as font families (set via prefs)
102 void InitSingleFaceList();
104 static void RegisteredFontsChangedNotificationCallback(CFNotificationCenterRef center,
105 void *observer,
106 CFStringRef name,
107 const void *object,
108 CFDictionaryRef userInfo);
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);
117 virtual bool UsesSystemFallback() { return true; }
119 virtual already_AddRefed<FontInfoData> CreateFontInfoData();
121 enum {
122 kATSGenerationInitial = -1
123 };
125 // default font for use with system-wide font fallback
126 CTFontRef mDefaultFont;
127 };
129 #endif /* gfxMacPlatformFontList_H_ */