2009-08-16 06:52:12 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2009-08-16 06:52:12 -07:00
|
|
|
|
|
|
|
#ifndef gfxMacPlatformFontList_H_
|
|
|
|
#define gfxMacPlatformFontList_H_
|
|
|
|
|
|
|
|
#include "nsDataHashtable.h"
|
|
|
|
#include "nsRefPtrHashtable.h"
|
|
|
|
|
|
|
|
#include "gfxPlatformFontList.h"
|
|
|
|
#include "gfxPlatform.h"
|
2011-06-24 10:55:27 -07:00
|
|
|
#include "gfxPlatformMac.h"
|
2009-08-16 06:52:12 -07:00
|
|
|
|
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
|
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
|
|
|
|
class gfxMacPlatformFontList;
|
|
|
|
|
|
|
|
// a single member of a font family (i.e. a single face, such as Times Italic)
|
|
|
|
class MacOSFontEntry : public gfxFontEntry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
friend class gfxMacPlatformFontList;
|
|
|
|
|
2011-06-24 10:55:27 -07:00
|
|
|
virtual ~MacOSFontEntry() {
|
|
|
|
::CGFontRelease(mFontRef);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual CGFontRef GetFontRef() = 0;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual nsresult GetFontTable(uint32_t aTableTag,
|
|
|
|
FallibleTArray<uint8_t>& aBuffer) = 0;
|
2009-08-16 06:52:12 -07:00
|
|
|
|
|
|
|
nsresult ReadCMAP();
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool RequiresAATLayout() const { return mRequiresAAT; }
|
2010-07-22 02:25:21 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsCFF();
|
2010-10-07 00:59:16 -07:00
|
|
|
|
2009-08-16 06:52:12 -07:00
|
|
|
protected:
|
2012-08-22 08:56:38 -07:00
|
|
|
MacOSFontEntry(const nsAString& aPostscriptName, int32_t aWeight,
|
2011-09-28 23:19:26 -07:00
|
|
|
gfxFontFamily *aFamily, bool aIsStandardFace = false);
|
2009-08-16 06:52:12 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual gfxFont* CreateFontInstance(const gfxFontStyle *aFontStyle, bool aNeedsBold);
|
2009-10-07 08:26:58 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual bool HasFontTable(uint32_t aTableTag) = 0;
|
2011-06-24 10:55:27 -07:00
|
|
|
|
|
|
|
CGFontRef mFontRef; // owning reference to the CGFont, released on destruction
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mFontRefInitialized;
|
|
|
|
bool mRequiresAAT;
|
|
|
|
bool mIsCFF;
|
|
|
|
bool mIsCFFInitialized;
|
2009-08-16 06:52:12 -07:00
|
|
|
};
|
|
|
|
|
2011-06-24 10:55:27 -07:00
|
|
|
// concrete subclasses of MacOSFontEntry: ATSFontEntry for 10.5, CGFontEntry for 10.6+
|
|
|
|
class ATSFontEntry : public MacOSFontEntry
|
|
|
|
{
|
|
|
|
public:
|
2012-08-22 08:56:38 -07:00
|
|
|
ATSFontEntry(const nsAString& aPostscriptName, int32_t aWeight,
|
2011-09-28 23:19:26 -07:00
|
|
|
gfxFontFamily *aFamily, bool aIsStandardFace = false);
|
2011-06-24 10:55:27 -07:00
|
|
|
|
|
|
|
// for use with data fonts
|
|
|
|
ATSFontEntry(const nsAString& aPostscriptName, ATSFontRef aFontRef,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t aWeight, uint16_t aStretch, uint32_t aItalicStyle,
|
2011-09-28 23:19:26 -07:00
|
|
|
gfxUserFontData *aUserFontData, bool aIsLocal);
|
2011-06-24 10:55:27 -07:00
|
|
|
|
|
|
|
ATSFontRef GetATSFontRef();
|
|
|
|
|
|
|
|
virtual CGFontRef GetFontRef();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual nsresult GetFontTable(uint32_t aTableTag,
|
|
|
|
FallibleTArray<uint8_t>& aBuffer);
|
2011-06-24 10:55:27 -07:00
|
|
|
|
2012-03-27 14:38:39 -07:00
|
|
|
virtual void SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf,
|
|
|
|
FontListSizes* aSizes) const;
|
|
|
|
|
2011-06-24 10:55:27 -07:00
|
|
|
protected:
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual bool HasFontTable(uint32_t aTableTag);
|
2011-06-24 10:55:27 -07:00
|
|
|
|
|
|
|
ATSFontRef mATSFontRef;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mATSFontRefInitialized;
|
2011-06-24 10:55:27 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class CGFontEntry : public MacOSFontEntry
|
|
|
|
{
|
|
|
|
public:
|
2012-08-22 08:56:38 -07:00
|
|
|
CGFontEntry(const nsAString& aPostscriptName, int32_t aWeight,
|
2011-09-28 23:19:26 -07:00
|
|
|
gfxFontFamily *aFamily, bool aIsStandardFace = false);
|
2011-06-24 10:55:27 -07:00
|
|
|
|
|
|
|
// for use with data fonts
|
|
|
|
CGFontEntry(const nsAString& aPostscriptName, CGFontRef aFontRef,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t aWeight, uint16_t aStretch, uint32_t aItalicStyle,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aIsUserFont, bool aIsLocal);
|
2011-06-24 10:55:27 -07:00
|
|
|
|
|
|
|
virtual CGFontRef GetFontRef();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual nsresult GetFontTable(uint32_t aTableTag,
|
|
|
|
FallibleTArray<uint8_t>& aBuffer);
|
2011-06-24 10:55:27 -07:00
|
|
|
|
2012-03-27 14:38:39 -07:00
|
|
|
virtual void SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf,
|
|
|
|
FontListSizes* aSizes) const;
|
|
|
|
|
2011-06-24 10:55:27 -07:00
|
|
|
protected:
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual bool HasFontTable(uint32_t aTableTag);
|
2011-06-24 10:55:27 -07:00
|
|
|
};
|
|
|
|
|
2009-08-16 06:52:12 -07:00
|
|
|
class gfxMacPlatformFontList : public gfxPlatformFontList {
|
|
|
|
public:
|
|
|
|
static gfxMacPlatformFontList* PlatformFontList() {
|
2009-10-07 07:13:40 -07:00
|
|
|
return static_cast<gfxMacPlatformFontList*>(sPlatformFontList);
|
2009-08-16 06:52:12 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t AppleWeightToCSSWeight(int32_t aAppleWeight);
|
2009-08-16 06:52:12 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual gfxFontEntry* GetDefaultFont(const gfxFontStyle* aStyle, bool& aNeedsBold);
|
2009-08-16 06:52:12 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual bool GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName);
|
2009-08-16 06:52:12 -07:00
|
|
|
|
|
|
|
virtual gfxFontEntry* LookupLocalFont(const gfxProxyFontEntry *aProxyEntry,
|
|
|
|
const nsAString& aFontName);
|
|
|
|
|
2009-10-07 07:13:40 -07:00
|
|
|
virtual gfxFontEntry* MakePlatformFont(const gfxProxyFontEntry *aProxyEntry,
|
2012-08-22 08:56:38 -07:00
|
|
|
const uint8_t *aFontData, uint32_t aLength);
|
2009-08-16 06:52:12 -07:00
|
|
|
|
|
|
|
void ClearPrefFonts() { mPrefFonts.Clear(); }
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool UseATSFontEntry() {
|
2011-06-24 10:55:27 -07:00
|
|
|
return gfxPlatformMac::GetPlatform()->OSXVersion() < MAC_OS_X_VERSION_10_6_HEX;
|
|
|
|
}
|
|
|
|
|
2009-08-16 06:52:12 -07:00
|
|
|
private:
|
|
|
|
friend class gfxPlatformMac;
|
|
|
|
|
|
|
|
gfxMacPlatformFontList();
|
2012-03-08 18:05:47 -08:00
|
|
|
virtual ~gfxMacPlatformFontList();
|
2009-08-16 06:52:12 -07:00
|
|
|
|
|
|
|
// initialize font lists
|
2010-11-08 03:02:27 -08:00
|
|
|
virtual nsresult InitFontList();
|
2009-08-16 06:52:12 -07:00
|
|
|
|
|
|
|
// special case font faces treated as font families (set via prefs)
|
|
|
|
void InitSingleFaceList();
|
|
|
|
|
2011-06-24 10:55:27 -07:00
|
|
|
gfxFontEntry* MakePlatformFontCG(const gfxProxyFontEntry *aProxyEntry,
|
2012-08-22 08:56:38 -07:00
|
|
|
const uint8_t *aFontData, uint32_t aLength);
|
2011-06-24 10:55:27 -07:00
|
|
|
|
|
|
|
gfxFontEntry* MakePlatformFontATS(const gfxProxyFontEntry *aProxyEntry,
|
2012-08-22 08:56:38 -07:00
|
|
|
const uint8_t *aFontData, uint32_t aLength);
|
2009-08-16 06:52:12 -07:00
|
|
|
|
|
|
|
static void ATSNotification(ATSFontNotificationInfoRef aInfo, void* aUserArg);
|
|
|
|
|
2012-03-08 18:05:47 -08:00
|
|
|
// search fonts system-wide for a given character, null otherwise
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual gfxFontEntry* GlobalFontFallback(const uint32_t aCh,
|
|
|
|
int32_t aRunScript,
|
2012-03-08 18:05:47 -08:00
|
|
|
const gfxFontStyle* aMatchStyle,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t& aCmapCount);
|
2012-03-08 18:05:47 -08:00
|
|
|
|
|
|
|
virtual bool UsesSystemFallback() { return true; }
|
|
|
|
|
2009-08-16 06:52:12 -07:00
|
|
|
// keep track of ATS generation to prevent unneeded updates when loading downloaded fonts
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mATSGeneration;
|
2009-08-16 06:52:12 -07:00
|
|
|
|
|
|
|
enum {
|
|
|
|
kATSGenerationInitial = -1
|
|
|
|
};
|
2012-03-08 18:05:47 -08:00
|
|
|
|
|
|
|
// default font for use with system-wide font fallback
|
|
|
|
CTFontRef mDefaultFont;
|
2009-08-16 06:52:12 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* gfxMacPlatformFontList_H_ */
|