зеркало из https://github.com/mozilla/pjs.git
Bug 705594. Use CoreText for system font fallback on OSX. r=jfkthame
This commit is contained in:
Родитель
6306e71cf0
Коммит
f395d7b96f
|
@ -166,6 +166,7 @@ private:
|
|||
friend class gfxPlatformMac;
|
||||
|
||||
gfxMacPlatformFontList();
|
||||
virtual ~gfxMacPlatformFontList();
|
||||
|
||||
// initialize font lists
|
||||
virtual nsresult InitFontList();
|
||||
|
@ -181,12 +182,23 @@ private:
|
|||
|
||||
static void ATSNotification(ATSFontNotificationInfoRef aInfo, void* aUserArg);
|
||||
|
||||
// search fonts system-wide for a given character, null otherwise
|
||||
virtual gfxFontEntry* GlobalFontFallback(const PRUint32 aCh,
|
||||
PRInt32 aRunScript,
|
||||
const gfxFontStyle* aMatchStyle,
|
||||
PRUint32& aCmapCount);
|
||||
|
||||
virtual bool UsesSystemFallback() { return true; }
|
||||
|
||||
// keep track of ATS generation to prevent unneeded updates when loading downloaded fonts
|
||||
PRUint32 mATSGeneration;
|
||||
|
||||
enum {
|
||||
kATSGenerationInitial = -1
|
||||
};
|
||||
|
||||
// default font for use with system-wide font fallback
|
||||
CTFontRef mDefaultFont;
|
||||
};
|
||||
|
||||
#endif /* gfxMacPlatformFontList_H_ */
|
||||
|
|
|
@ -58,6 +58,7 @@
|
|||
#include "nsDirectoryServiceUtils.h"
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
#include "nsISimpleEnumerator.h"
|
||||
#include "nsCharTraits.h"
|
||||
|
||||
#include "mozilla/Telemetry.h"
|
||||
|
||||
|
@ -704,7 +705,8 @@ gfxSingleFaceMacFontFamily::ReadOtherFamilyNames(gfxPlatformFontList *aPlatformF
|
|||
#pragma mark-
|
||||
|
||||
gfxMacPlatformFontList::gfxMacPlatformFontList() :
|
||||
gfxPlatformFontList(false), mATSGeneration(PRUint32(kATSGenerationInitial))
|
||||
gfxPlatformFontList(false), mATSGeneration(PRUint32(kATSGenerationInitial)),
|
||||
mDefaultFont(nsnull)
|
||||
{
|
||||
::ATSFontNotificationSubscribe(ATSNotification,
|
||||
kATSFontNotifyOptionDefault,
|
||||
|
@ -719,6 +721,13 @@ gfxMacPlatformFontList::gfxMacPlatformFontList() :
|
|||
sFontManager = [NSFontManager sharedFontManager];
|
||||
}
|
||||
|
||||
gfxMacPlatformFontList::~gfxMacPlatformFontList()
|
||||
{
|
||||
if (mDefaultFont) {
|
||||
::CFRelease(mDefaultFont);
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
gfxMacPlatformFontList::InitFontList()
|
||||
{
|
||||
|
@ -875,6 +884,93 @@ gfxMacPlatformFontList::ATSNotification(ATSFontNotificationInfoRef aInfo,
|
|||
qfc->UpdateFontList();
|
||||
}
|
||||
|
||||
gfxFontEntry*
|
||||
gfxMacPlatformFontList::GlobalFontFallback(const PRUint32 aCh,
|
||||
PRInt32 aRunScript,
|
||||
const gfxFontStyle* aMatchStyle,
|
||||
PRUint32& aCmapCount)
|
||||
{
|
||||
bool useCmaps = gfxPlatform::GetPlatform()->UseCmapsDuringSystemFallback();
|
||||
|
||||
if (useCmaps) {
|
||||
return gfxPlatformFontList::GlobalFontFallback(aCh,
|
||||
aRunScript,
|
||||
aMatchStyle,
|
||||
aCmapCount);
|
||||
}
|
||||
|
||||
CFStringRef str;
|
||||
UniChar ch[2];
|
||||
CFIndex len = 1;
|
||||
|
||||
if (IS_IN_BMP(aCh)) {
|
||||
ch[0] = aCh;
|
||||
str = ::CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, ch, 1,
|
||||
kCFAllocatorNull);
|
||||
} else {
|
||||
ch[0] = H_SURROGATE(aCh);
|
||||
ch[1] = L_SURROGATE(aCh);
|
||||
str = ::CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, ch, 2,
|
||||
kCFAllocatorNull);
|
||||
if (!str) {
|
||||
return nsnull;
|
||||
}
|
||||
len = 2;
|
||||
}
|
||||
|
||||
// use CoreText to find the fallback family
|
||||
|
||||
gfxFontEntry *fontEntry = nsnull;
|
||||
CTFontRef fallback;
|
||||
bool cantUseFallbackFont = false;
|
||||
|
||||
if (!mDefaultFont) {
|
||||
mDefaultFont = ::CTFontCreateWithName(CFSTR("Lucida Grande"), 12.f,
|
||||
NULL);
|
||||
}
|
||||
|
||||
fallback = ::CTFontCreateForString(mDefaultFont, str,
|
||||
::CFRangeMake(0, len));
|
||||
|
||||
if (fallback) {
|
||||
CFStringRef familyName = ::CTFontCopyFamilyName(fallback);
|
||||
::CFRelease(fallback);
|
||||
|
||||
if (familyName &&
|
||||
::CFStringCompare(familyName, CFSTR("LastResort"),
|
||||
kCFCompareCaseInsensitive) != kCFCompareEqualTo)
|
||||
{
|
||||
nsAutoTArray<UniChar, 1024> buffer;
|
||||
CFIndex len = ::CFStringGetLength(familyName);
|
||||
buffer.SetLength(len+1);
|
||||
::CFStringGetCharacters(familyName, ::CFRangeMake(0, len),
|
||||
buffer.Elements());
|
||||
buffer[len] = 0;
|
||||
nsDependentString family(buffer.Elements(), len);
|
||||
|
||||
bool needsBold; // ignored in the system fallback case
|
||||
|
||||
fontEntry = FindFontForFamily(family, aMatchStyle, needsBold);
|
||||
if (fontEntry && !fontEntry->TestCharacterMap(aCh)) {
|
||||
fontEntry = nsnull;
|
||||
cantUseFallbackFont = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (familyName) {
|
||||
::CFRelease(familyName);
|
||||
}
|
||||
}
|
||||
|
||||
if (cantUseFallbackFont) {
|
||||
Telemetry::Accumulate(Telemetry::BAD_FALLBACK_FONT, cantUseFallbackFont);
|
||||
}
|
||||
|
||||
::CFRelease(str);
|
||||
|
||||
return fontEntry;
|
||||
}
|
||||
|
||||
gfxFontEntry*
|
||||
gfxMacPlatformFontList::GetDefaultFont(const gfxFontStyle* aStyle, bool& aNeedsBold)
|
||||
{
|
||||
|
|
|
@ -147,6 +147,7 @@ HISTOGRAM(WORD_CACHE_LOOKUP_SCRIPT, 1, 110, 111, LINEAR, "Word cache lookup (scr
|
|||
HISTOGRAM(WORD_CACHE_HIT_SCRIPT, 1, 110, 111, LINEAR, "Word cache hit (script)")
|
||||
|
||||
HISTOGRAM_BOOLEAN(FONT_CACHE_HIT, "font cache hit")
|
||||
HISTOGRAM_BOOLEAN(BAD_FALLBACK_FONT, "system fallback font can't be used")
|
||||
|
||||
HISTOGRAM_BOOLEAN(SHUTDOWN_OK, "Did the browser start after a successful shutdown")
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче