mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 08:15:31 +00:00
Bug 1694151 - Make more use of AutoCFRelease in gfxMacPlatformFontList. r=lsalzman
Depends on D105973 Differential Revision: https://phabricator.services.mozilla.com/D105974
This commit is contained in:
parent
6f248773b6
commit
fdbe0843a3
@ -435,13 +435,12 @@ class FontTableRec {
|
||||
}
|
||||
|
||||
hb_blob_t* MacOSFontEntry::GetFontTable(uint32_t aTag) {
|
||||
CGFontRef fontRef = CreateOrCopyFontRef();
|
||||
AutoCFRelease<CGFontRef> fontRef = CreateOrCopyFontRef();
|
||||
if (!fontRef) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CFDataRef dataRef = ::CGFontCopyTableForTag(fontRef, aTag);
|
||||
::CGFontRelease(fontRef);
|
||||
if (dataRef) {
|
||||
return hb_blob_create((const char*)::CFDataGetBytePtr(dataRef), ::CFDataGetLength(dataRef),
|
||||
HB_MEMORY_MODE_READONLY,
|
||||
@ -460,12 +459,11 @@ bool MacOSFontEntry::HasFontTable(uint32_t aTableTag) {
|
||||
if (mAvailableTables.Count() == 0) {
|
||||
nsAutoreleasePool localPool;
|
||||
|
||||
CGFontRef fontRef = CreateOrCopyFontRef();
|
||||
AutoCFRelease<CGFontRef> fontRef = CreateOrCopyFontRef();
|
||||
if (!fontRef) {
|
||||
return false;
|
||||
}
|
||||
CFArrayRef tags = ::CGFontCopyTableTags(fontRef);
|
||||
::CGFontRelease(fontRef);
|
||||
AutoCFRelease<CFArrayRef> tags = ::CGFontCopyTableTags(fontRef);
|
||||
if (!tags) {
|
||||
return false;
|
||||
}
|
||||
@ -474,7 +472,6 @@ bool MacOSFontEntry::HasFontTable(uint32_t aTableTag) {
|
||||
uint32_t tag = (uint32_t)(uintptr_t)::CFArrayGetValueAtIndex(tags, t);
|
||||
mAvailableTables.PutEntry(tag);
|
||||
}
|
||||
::CFRelease(tags);
|
||||
}
|
||||
|
||||
return mAvailableTables.GetEntry(aTableTag);
|
||||
@ -551,13 +548,11 @@ bool MacOSFontEntry::SupportsOpenTypeFeature(Script aScript, uint32_t aFeatureTa
|
||||
if (!cgFont) {
|
||||
return mHasAATSmallCaps;
|
||||
}
|
||||
CTFontRef ctFont = CTFontCreateWithGraphicsFont(cgFont, 0.0, nullptr, nullptr);
|
||||
AutoCFRelease<CTFontRef> ctFont = CTFontCreateWithGraphicsFont(cgFont, 0.0, nullptr, nullptr);
|
||||
if (ctFont) {
|
||||
CFArrayRef features = CTFontCopyFeatures(ctFont);
|
||||
CFRelease(ctFont);
|
||||
AutoCFRelease<CFArrayRef> features = CTFontCopyFeatures(ctFont);
|
||||
if (features) {
|
||||
mHasAATSmallCaps = CheckForAATSmallCaps(features);
|
||||
CFRelease(features);
|
||||
}
|
||||
}
|
||||
return mHasAATSmallCaps;
|
||||
@ -980,11 +975,10 @@ nsresult gfxMacPlatformFontList::InitFontListForPlatform() {
|
||||
} else {
|
||||
// We're not a content process, so get the available fonts directly
|
||||
// from Core Text.
|
||||
CFArrayRef familyNames = CTFontManagerCopyAvailableFontFamilyNames();
|
||||
for (NSString* familyName in (NSArray*)familyNames) {
|
||||
AutoCFRelease<CFArrayRef> familyNames = CTFontManagerCopyAvailableFontFamilyNames();
|
||||
for (NSString* familyName in (NSArray*)(CFArrayRef)familyNames) {
|
||||
AddFamily((CFStringRef)familyName);
|
||||
}
|
||||
CFRelease(familyNames);
|
||||
}
|
||||
|
||||
InitSingleFaceList();
|
||||
@ -1006,9 +1000,9 @@ void gfxMacPlatformFontList::InitSharedFontListForPlatform() {
|
||||
|
||||
InitSystemFontNames();
|
||||
if (XRE_IsParentProcess()) {
|
||||
CFArrayRef familyNames = CTFontManagerCopyAvailableFontFamilyNames();
|
||||
AutoCFRelease<CFArrayRef> familyNames = CTFontManagerCopyAvailableFontFamilyNames();
|
||||
nsTArray<fontlist::Family::InitData> families;
|
||||
for (NSString* familyName in (NSArray*)familyNames) {
|
||||
for (NSString* familyName in (NSArray*)(CFArrayRef)familyNames) {
|
||||
nsAutoString name16;
|
||||
GetStringForNSString(familyName, name16);
|
||||
NS_ConvertUTF16toUTF8 name(name16);
|
||||
@ -1017,7 +1011,6 @@ void gfxMacPlatformFontList::InitSharedFontListForPlatform() {
|
||||
families.AppendElement(fontlist::Family::InitData(key, name, fontlist::Family::kNoIndex,
|
||||
GetVisibilityForFamily(name)));
|
||||
}
|
||||
CFRelease(familyNames);
|
||||
SharedFontList()->SetFamilyNames(families);
|
||||
InitAliasesForSingleFaceList();
|
||||
GetPrefsAndStartLoader();
|
||||
@ -1176,18 +1169,16 @@ static NSString* GetRealFamilyName(NSFont* aFont) {
|
||||
// Eventually we should move to using CTFontUIFontType constants to identify
|
||||
// system fonts, and eliminate the need to instantiate them (indirectly) from
|
||||
// their postscript names.
|
||||
CGFontRef cgFont = CGFontCreateWithFontName(CFStringRef(psName));
|
||||
AutoCFRelease<CGFontRef> cgFont = CGFontCreateWithFontName(CFStringRef(psName));
|
||||
if (!cgFont) {
|
||||
return [aFont familyName];
|
||||
}
|
||||
|
||||
CTFontRef ctFont = CTFontCreateWithGraphicsFont(cgFont, 0.0, nullptr, nullptr);
|
||||
CFRelease(cgFont);
|
||||
AutoCFRelease<CTFontRef> ctFont = CTFontCreateWithGraphicsFont(cgFont, 0.0, nullptr, nullptr);
|
||||
if (!ctFont) {
|
||||
return [aFont familyName];
|
||||
}
|
||||
NSString* familyName = (NSString*)CTFontCopyFamilyName(ctFont);
|
||||
CFRelease(ctFont);
|
||||
|
||||
return [familyName autorelease];
|
||||
}
|
||||
@ -1328,18 +1319,17 @@ gfxFontEntry* gfxMacPlatformFontList::PlatformGlobalFontFallback(const uint32_t
|
||||
// use CoreText to find the fallback family
|
||||
|
||||
gfxFontEntry* fontEntry = nullptr;
|
||||
CTFontRef fallback;
|
||||
bool cantUseFallbackFont = false;
|
||||
|
||||
if (!mDefaultFont) {
|
||||
mDefaultFont = ::CTFontCreateWithName(CFSTR("LucidaGrande"), 12.f, NULL);
|
||||
}
|
||||
|
||||
fallback = ::CTFontCreateForString(mDefaultFont, str, ::CFRangeMake(0, length));
|
||||
AutoCFRelease<CTFontRef> fallback =
|
||||
::CTFontCreateForString(mDefaultFont, str, ::CFRangeMake(0, length));
|
||||
|
||||
if (fallback) {
|
||||
CFStringRef familyNameRef = ::CTFontCopyFamilyName(fallback);
|
||||
::CFRelease(fallback);
|
||||
AutoCFRelease<CFStringRef> familyNameRef = ::CTFontCopyFamilyName(fallback);
|
||||
|
||||
if (familyNameRef &&
|
||||
::CFStringCompare(familyNameRef, CFSTR("LastResort"), kCFCompareCaseInsensitive) !=
|
||||
@ -1385,10 +1375,6 @@ gfxFontEntry* gfxMacPlatformFontList::PlatformGlobalFontFallback(const uint32_t
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (familyNameRef) {
|
||||
::CFRelease(familyNameRef);
|
||||
}
|
||||
}
|
||||
|
||||
if (cantUseFallbackFont) {
|
||||
@ -1494,11 +1480,9 @@ gfxFontEntry* gfxMacPlatformFontList::MakePlatformFont(const nsACString& aFontNa
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CGDataProviderRef provider =
|
||||
AutoCFRelease<CGDataProviderRef> provider =
|
||||
::CGDataProviderCreateWithData(nullptr, aFontData, aLength, &ReleaseData);
|
||||
CGFontRef fontRef = ::CGFontCreateWithDataProvider(provider);
|
||||
::CGDataProviderRelease(provider);
|
||||
|
||||
AutoCFRelease<CGFontRef> fontRef = ::CGFontCreateWithDataProvider(provider);
|
||||
if (!fontRef) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -1506,7 +1490,6 @@ gfxFontEntry* gfxMacPlatformFontList::MakePlatformFont(const nsACString& aFontNa
|
||||
auto newFontEntry =
|
||||
MakeUnique<MacOSFontEntry>(NS_ConvertUTF16toUTF8(uniqueName), fontRef, aWeightForEntry,
|
||||
aStretchForEntry, aStyleForEntry, true, false);
|
||||
::CFRelease(fontRef);
|
||||
return newFontEntry.release();
|
||||
}
|
||||
|
||||
@ -1637,13 +1620,11 @@ void MacFontInfo::LoadFontFamilyData(const nsACString& aFamilyName) {
|
||||
NSString* famName = GetNSStringForString(NS_ConvertUTF8toUTF16(aFamilyName));
|
||||
CFStringRef family = CFStringRef(famName);
|
||||
|
||||
CFMutableDictionaryRef attr = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks,
|
||||
&kCFTypeDictionaryValueCallBacks);
|
||||
AutoCFRelease<CFMutableDictionaryRef> attr = CFDictionaryCreateMutable(
|
||||
NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
|
||||
CFDictionaryAddValue(attr, kCTFontFamilyNameAttribute, family);
|
||||
CTFontDescriptorRef fd = CTFontDescriptorCreateWithAttributes(attr);
|
||||
CFRelease(attr);
|
||||
CFArrayRef matchingFonts = CTFontDescriptorCreateMatchingFontDescriptors(fd, NULL);
|
||||
CFRelease(fd);
|
||||
AutoCFRelease<CTFontDescriptorRef> fd = CTFontDescriptorCreateWithAttributes(attr);
|
||||
AutoCFRelease<CFArrayRef> matchingFonts = CTFontDescriptorCreateMatchingFontDescriptors(fd, NULL);
|
||||
if (!matchingFonts) {
|
||||
return;
|
||||
}
|
||||
@ -1660,7 +1641,7 @@ void MacFontInfo::LoadFontFamilyData(const nsACString& aFamilyName) {
|
||||
if (!faceDesc) {
|
||||
continue;
|
||||
}
|
||||
CTFontRef fontRef = CTFontCreateWithFontDescriptor(faceDesc, 0.0, nullptr);
|
||||
AutoCFRelease<CTFontRef> fontRef = CTFontCreateWithFontDescriptor(faceDesc, 0.0, nullptr);
|
||||
if (!fontRef) {
|
||||
NS_WARNING("failed to create a CTFontRef");
|
||||
continue;
|
||||
@ -1668,7 +1649,7 @@ void MacFontInfo::LoadFontFamilyData(const nsACString& aFamilyName) {
|
||||
|
||||
if (mLoadCmaps) {
|
||||
// face name
|
||||
CFStringRef faceName =
|
||||
AutoCFRelease<CFStringRef> faceName =
|
||||
(CFStringRef)CTFontDescriptorCopyAttribute(faceDesc, kCTFontNameAttribute);
|
||||
|
||||
AutoTArray<UniChar, 1024> buffer;
|
||||
@ -1680,7 +1661,8 @@ void MacFontInfo::LoadFontFamilyData(const nsACString& aFamilyName) {
|
||||
|
||||
// load the cmap data
|
||||
FontFaceData fontData;
|
||||
CFDataRef cmapTable = CTFontCopyTable(fontRef, kCTFontTableCmap, kCTFontTableOptionNoOptions);
|
||||
AutoCFRelease<CFDataRef> cmapTable =
|
||||
CTFontCopyTable(fontRef, kCTFontTableCmap, kCTFontTableOptionNoOptions);
|
||||
|
||||
if (cmapTable) {
|
||||
const uint8_t* cmapData = (const uint8_t*)CFDataGetBytePtr(cmapTable);
|
||||
@ -1695,15 +1677,14 @@ void MacFontInfo::LoadFontFamilyData(const nsACString& aFamilyName) {
|
||||
fontData.mUVSOffset = offset;
|
||||
mLoadStats.cmaps++;
|
||||
}
|
||||
CFRelease(cmapTable);
|
||||
}
|
||||
|
||||
mFontFaceData.Put(fontName, fontData);
|
||||
CFRelease(faceName);
|
||||
}
|
||||
|
||||
if (mLoadOtherNames && hasOtherFamilyNames) {
|
||||
CFDataRef nameTable = CTFontCopyTable(fontRef, kCTFontTableName, kCTFontTableOptionNoOptions);
|
||||
AutoCFRelease<CFDataRef> nameTable =
|
||||
CTFontCopyTable(fontRef, kCTFontTableName, kCTFontTableOptionNoOptions);
|
||||
|
||||
if (nameTable) {
|
||||
const char* nameData = (const char*)CFDataGetBytePtr(nameTable);
|
||||
@ -1711,13 +1692,9 @@ void MacFontInfo::LoadFontFamilyData(const nsACString& aFamilyName) {
|
||||
gfxFontUtils::ReadOtherFamilyNamesForFace(aFamilyName, nameData, nameLen, otherFamilyNames,
|
||||
false);
|
||||
hasOtherFamilyNames = otherFamilyNames.Length() != 0;
|
||||
CFRelease(nameTable);
|
||||
}
|
||||
}
|
||||
|
||||
CFRelease(fontRef);
|
||||
}
|
||||
CFRelease(matchingFonts);
|
||||
|
||||
// if found other names, insert them in the hash table
|
||||
if (otherFamilyNames.Length() != 0) {
|
||||
@ -1759,7 +1736,8 @@ void gfxMacPlatformFontList::ActivateFontsFromDir(nsIFile* aDir) {
|
||||
return;
|
||||
}
|
||||
|
||||
CFMutableArrayRef urls = ::CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
|
||||
AutoCFRelease<CFMutableArrayRef> urls =
|
||||
::CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);
|
||||
|
||||
bool hasMore;
|
||||
while (NS_SUCCEEDED(e->HasMoreElements(&hasMore)) && hasMore) {
|
||||
@ -1775,16 +1753,14 @@ void gfxMacPlatformFontList::ActivateFontsFromDir(nsIFile* aDir) {
|
||||
if (NS_FAILED(file->GetNativePath(path))) {
|
||||
continue;
|
||||
}
|
||||
CFURLRef fontURL = ::CFURLCreateFromFileSystemRepresentation(
|
||||
AutoCFRelease<CFURLRef> fontURL = ::CFURLCreateFromFileSystemRepresentation(
|
||||
kCFAllocatorDefault, (uint8_t*)path.get(), path.Length(), false);
|
||||
if (fontURL) {
|
||||
::CFArrayAppendValue(urls, fontURL);
|
||||
::CFRelease(fontURL);
|
||||
}
|
||||
}
|
||||
|
||||
::CTFontManagerRegisterFontsForURLs(urls, kCTFontManagerScopeProcess, nullptr);
|
||||
::CFRelease(urls);
|
||||
}
|
||||
|
||||
void gfxMacPlatformFontList::GetFacesInitDataForFamily(const fontlist::Family* aFamily,
|
||||
@ -1852,17 +1828,15 @@ void gfxMacPlatformFontList::GetFacesInitDataForFamily(const fontlist::Family* a
|
||||
|
||||
RefPtr<gfxCharacterMap> charmap;
|
||||
if (aLoadCmaps) {
|
||||
CGFontRef font = CGFontCreateWithFontName(CFStringRef(psname));
|
||||
AutoCFRelease<CGFontRef> font = CGFontCreateWithFontName(CFStringRef(psname));
|
||||
if (font) {
|
||||
uint32_t kCMAP = TRUETYPE_TAG('c', 'm', 'a', 'p');
|
||||
CFDataRef data = CGFontCopyTableForTag(font, kCMAP);
|
||||
AutoCFRelease<CFDataRef> data = CGFontCopyTableForTag(font, kCMAP);
|
||||
if (data) {
|
||||
uint32_t offset;
|
||||
charmap = new gfxCharacterMap();
|
||||
gfxFontUtils::ReadCMAP(CFDataGetBytePtr(data), CFDataGetLength(data), *charmap, offset);
|
||||
CFRelease(data);
|
||||
}
|
||||
CGFontRelease(font);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user