Skip to content

Commit

Permalink
#417: remove 10.7+ font handling and tune up gfx/thebes/ etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
classilla committed Jul 21, 2017
1 parent 07656db commit e45c857
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 25 deletions.
3 changes: 3 additions & 0 deletions gfx/thebes/gfxFontEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,8 @@ gfxFontFamily::ReadFaceNames(gfxPlatformFontList *aPlatformFontList,
}
#endif

#ifdef __LP64__
// Can't run on 10.4-10.6.
if (!mOtherFamilyNamesInitialized &&
aFontInfoData &&
aFontInfoData->mLoadOtherNames &&
Expand All @@ -1742,6 +1744,7 @@ gfxFontFamily::ReadFaceNames(gfxPlatformFontList *aPlatformFontList,
(mFaceNamesInitialized || !aNeedFullnamePostscriptNames)) {
return;
}
#endif

FindStyleVariations(aFontInfoData);

Expand Down
28 changes: 14 additions & 14 deletions gfx/thebes/gfxMacFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,18 +223,18 @@ gfxMacFont::InitMetrics()

{
ByteCount tableSize;
if (::ATSFontGetTable(myATSFont,
if (MOZ_UNLIKELY(::ATSFontGetTable(myATSFont,
TRUETYPE_TAG('h','e','a','d'),
0, 0, NULL, &tableSize) != noErr)
0, 0, NULL, &tableSize) != noErr))
return;
CFMutableDataRef data = ::CFDataCreateMutable(kCFAllocatorDefault,
tableSize);
if (!data) return;
if (MOZ_UNLIKELY(!data)) return;
::CFDataIncreaseLength(data, tableSize);
if (::ATSFontGetTable(myATSFont,
if (MOZ_UNLIKELY(::ATSFontGetTable(myATSFont,
TRUETYPE_TAG('h','e','a','d'),
0, tableSize, ::CFDataGetMutableBytePtr(data),
&tableSize) != noErr) {
&tableSize) != noErr)) {
::CFRelease(data);
return;
}
Expand All @@ -253,7 +253,7 @@ gfxMacFont::InitMetrics()
upem = ::CGFontGetUnitsPerEm(mCGFont);
}

if (upem < 16 || upem > 16384) {
if (MOZ_UNLIKELY(upem < 16 || upem > 16384)) {
// See http://www.microsoft.com/typography/otspec/head.htm
#ifdef DEBUG
char warnBuf[1024];
Expand Down Expand Up @@ -294,7 +294,7 @@ gfxMacFont::InitMetrics()

err = ::ATSFontGetHorizontalMetrics(myATSFont, kATSOptionFlagsDefault,
&atsMetrics);
if (err != noErr) {
if (MOZ_UNLIKELY(err != noErr)) {
NS_WARNING("could not get CGFontGetXHeight, no ATS fallback");
return; // just fail -- Cameron Kludge
}
Expand Down Expand Up @@ -330,7 +330,7 @@ gfxMacFont::InitMetrics()
err = ::ATSFontGetHorizontalMetrics(myATSFont,
kATSOptionFlagsDefault,
&atsMetrics);
if (err != noErr) {
if (MOZ_UNLIKELY(err != noErr)) {
NS_WARNING("could not get CGFontGetXHeight again, no ATS fallback");
return; // just fail -- Cameron Kludge
}
Expand All @@ -353,15 +353,15 @@ gfxMacFont::InitMetrics()
CFDataRef cmap;
{
ByteCount tableSize;
if (::ATSFontGetTable(myATSFont, TRUETYPE_TAG('c','m','a','p'), 0, 0, NULL,
&tableSize) != noErr) return;
if (MOZ_UNLIKELY(::ATSFontGetTable(myATSFont, TRUETYPE_TAG('c','m','a','p'), 0, 0, NULL,
&tableSize) != noErr)) return;
CFMutableDataRef data = ::CFDataCreateMutable(kCFAllocatorDefault,
tableSize);
if (!data) return;
if (MOZ_UNLIKELY(!data)) return;
::CFDataIncreaseLength(data, tableSize);
if (::ATSFontGetTable(myATSFont, TRUETYPE_TAG('c','m','a','p'),
if (MOZ_UNLIKELY(::ATSFontGetTable(myATSFont, TRUETYPE_TAG('c','m','a','p'),
0, tableSize,
::CFDataGetMutableBytePtr(data), &tableSize) != noErr)
::CFDataGetMutableBytePtr(data), &tableSize) != noErr))
{ ::CFRelease(data); return; }
cmap = data;
}
Expand Down Expand Up @@ -512,7 +512,7 @@ static_cast<MacOSFontEntry*>(GetFontEntry())->GetATSFontRef();

err = ::ATSFontGetHorizontalMetrics(aFontRef, kATSOptionFlagsDefault,
&atsMetrics);
if (err != noErr) {
if (MOZ_UNLIKELY(err != noErr)) {
#ifdef DEBUG
char warnBuf[1024];
sprintf(warnBuf, "Bad font metrics for: %s err: %8.8x",
Expand Down
37 changes: 26 additions & 11 deletions gfx/thebes/gfxMacPlatformFontList.mm
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ new FontTableRec(dataRef),
#endif
OSStatus status = ::ATSFontGetTable(fontRef, aTag, 0, 0, 0,
&dataLength);
if (status != noErr) return nullptr;
if (MOZ_UNLIKELY(status != noErr)) return nullptr;
}

// Taking advantage of bridging CFMutableDataRef to CFDataRef.
Expand All @@ -521,9 +521,9 @@ new FontTableRec(dataRef),
if (!dataRef) return nullptr;

::CFDataIncreaseLength(dataRef, dataLength); // paranoia
if(::ATSFontGetTable(fontRef, aTag, 0, dataLength,
if(MOZ_UNLIKELY(::ATSFontGetTable(fontRef, aTag, 0, dataLength,
::CFDataGetMutableBytePtr(dataRef),
&dataLength) != noErr) {
&dataLength) != noErr)) {
::CFRelease(dataRef);
return nullptr;
}
Expand Down Expand Up @@ -612,10 +612,10 @@ static bool FindTagInTableDir(FallibleTArray<uint8_t>& table,

ByteCount sizer;

if(::ATSFontGetTableDirectory(fontRef, 0, NULL, &sizer) == noErr) {
if(MOZ_LIKELY(::ATSFontGetTableDirectory(fontRef, 0, NULL, &sizer) == noErr)) {
// If the header is abnormal, try the old, slower way in case this
// is a gap in our algorithm.
if (sizer <= 12 || ((sizer-12) % 16) || sizer >= 1024) {
if (MOZ_UNLIKELY(sizer <= 12 || ((sizer-12) % 16) || sizer >= 1024)) {
fprintf(stderr, "Warning: TenFourFox found "
"abnormal font table dir in %s (%i).\n",
NS_ConvertUTF16toUTF8(mName).get(), sizer);
Expand All @@ -631,8 +631,8 @@ static bool FindTagInTableDir(FallibleTArray<uint8_t>& table,
fprintf(stderr, "Size of %s font table directory: %i\nTables: ",
NS_ConvertUTF16toUTF8(mName).get(), mFontTableDir.Length());
#endif
if (::ATSFontGetTableDirectory(fontRef, mFontTableDirSize,
reinterpret_cast<void *>(mFontTableDir.Elements()), &sizer) == noErr) {
if (MOZ_LIKELY(::ATSFontGetTableDirectory(fontRef, mFontTableDirSize,
reinterpret_cast<void *>(mFontTableDir.Elements()), &sizer) == noErr)) {

// Push to platform.
if (!mIsDataUserFont || mIsLocalUserFont)
Expand Down Expand Up @@ -1175,6 +1175,7 @@ explicit gfxSingleFaceMacFontFamily(nsAString& aName) :
void
gfxMacPlatformFontList::InitSystemFonts()
{
#ifdef __LP64__
// system font under 10.11 are two distinct families for text/display sizes
if (nsCocoaFeatures::OnElCapitanOrLater()) {
mUseSizeSensitiveSystemFont = true;
Expand Down Expand Up @@ -1209,6 +1210,16 @@ explicit gfxSingleFaceMacFontFamily(nsAString& aName) :
"system text/display font size switch point is not as expected!");
#endif
}
#else // LP64
// Simplified version for 10.4-10.6

NSFont* sys = [NSFont systemFontOfSize: 0.0];
NSString* textFamilyName = GetRealFamilyName(sys);
nsAutoString familyName;
nsCocoaUtils::GetStringForNSString(textFamilyName, familyName);
mSystemTextFontFamily = FindSystemFontFamily(familyName);
NS_ASSERTION(mSystemTextFontFamily, "null system display font family");
#endif // LP64

#ifdef DEBUG
// different system font API's always map to the same family under OSX, so
Expand Down Expand Up @@ -1583,7 +1594,7 @@ static void ReleaseData(void *info, const void *data, size_t size)
&containerRef);
mATSGeneration = ::ATSGetGeneration();

if (err != noErr) {
if (MOZ_UNLIKELY(err != noErr)) {
#if DEBUG
char warnBuf[1024];
sprintf(warnBuf, "downloaded font error, ATSFontActivateFromMemory err: %d",
Expand All @@ -1596,7 +1607,7 @@ static void ReleaseData(void *info, const void *data, size_t size)
// ignoring containers with multiple fonts, use the first face only for now
err = ::ATSFontFindFromContainer(containerRef, kATSOptionFlagsDefault, 1,
&fontRef, NULL);
if (err != noErr) {
if (MOZ_UNLIKELY(err != noErr)) {
#if DEBUG
char warnBuf[1024];
sprintf(warnBuf, "downloaded font error, ATSFontFindFromContainer err: %d",
Expand All @@ -1611,7 +1622,7 @@ static void ReleaseData(void *info, const void *data, size_t size)
OSStatus err;
NSString *psname = NULL;
err = ::ATSFontGetPostScriptName(fontRef, kATSOptionFlagsDefault, (CFStringRef*) (&psname));
if (err == noErr) {
if (MOZ_LIKELY(err == noErr)) {
#if(0)
fprintf(stderr, "Trying: %s.\n", [psname UTF8String]);
#endif
Expand Down Expand Up @@ -1679,7 +1690,7 @@ new MacOSFontEntry(uniqueName,
containerRef, true, false);

// if succeeded and font cmap is good, return the new font
if (newFontEntry->mIsValid && NS_SUCCEEDED(newFontEntry->ReadCMAP())) {
if (MOZ_LIKELY(newFontEntry->mIsValid && NS_SUCCEEDED(newFontEntry->ReadCMAP()))) {
return newFontEntry;
}

Expand Down Expand Up @@ -1753,10 +1764,12 @@ new MacOSFontEntry(uniqueName,
{
// search for special system font name, -apple-system
if (aFamily.EqualsLiteral(kSystemFont_system)) {
#ifdef __LP64__
if (mUseSizeSensitiveSystemFont &&
aStyle && (aStyle->size * aDevToCssSize) >= kTextDisplayCrossover) {
return mSystemDisplayFontFamily;
}
#endif
return mSystemTextFontFamily;
}

Expand Down Expand Up @@ -1847,11 +1860,13 @@ new MacOSFontEntry(uniqueName,
virtual ~MacFontInfo() {}

virtual void Load() {
#ifdef __LP64__
nsAutoreleasePool localPool;
// bug 975460 - async font loader crashes sometimes under 10.6, disable
if (nsCocoaFeatures::OnLionOrLater()) {
FontInfoData::Load();
}
#endif
}

// loads font data for all members of a given family
Expand Down

0 comments on commit e45c857

Please sign in to comment.