Bug 1170986 - patch 1.1 - Reformat the remains of gfxMacPlatformFontList.mm back to Obj-C++ style. r=gfx-reviewers,bradwerth

No functional change; just applying clang-format to what remains in the Obj-C++ file here,
after factoring out the common Core Text part to a separate .cpp source file.

Differential Revision: https://phabricator.services.mozilla.com/D180325
This commit is contained in:
Jonathan Kew 2023-08-31 15:59:18 +00:00
parent ee5b3515db
commit 4673c6cfa7

View file

@ -63,8 +63,7 @@ static void GetStringForNSString(const NSString* aSrc, nsAString& aDest) {
} }
static NSString* GetNSStringForString(const nsAString& aSrc) { static NSString* GetNSStringForString(const nsAString& aSrc) {
return [NSString return [NSString stringWithCharacters:reinterpret_cast<const unichar*>(aSrc.BeginReading())
stringWithCharacters:reinterpret_cast<const unichar*>(aSrc.BeginReading())
length:aSrc.Length()]; length:aSrc.Length()];
} }
@ -100,8 +99,7 @@ void gfxMacFontFamily::FindStyleVariationsLocked(FontInfoData* aFontInfoData) {
return; return;
} }
AUTO_PROFILER_LABEL_DYNAMIC_NSCSTRING("gfxMacFontFamily::FindStyleVariations", AUTO_PROFILER_LABEL_DYNAMIC_NSCSTRING("gfxMacFontFamily::FindStyleVariations", LAYOUT, mName);
LAYOUT, mName);
nsAutoreleasePool localPool; nsAutoreleasePool localPool;
@ -119,8 +117,7 @@ void gfxMacFontFamily::FindStyleVariationsLocked(FontInfoData* aFontInfoData) {
// Set the appropriate style, assuming it may not have a variation range. // Set the appropriate style, assuming it may not have a variation range.
fe->mStyleRange = SlantStyleRange( fe->mStyleRange = SlantStyleRange(
([[aNSFont fontDescriptor] symbolicTraits] & NSFontItalicTrait) ([[aNSFont fontDescriptor] symbolicTraits] & NSFontItalicTrait) ? FontSlantStyle::ITALIC
? FontSlantStyle::ITALIC
: FontSlantStyle::NORMAL); : FontSlantStyle::NORMAL);
// Set up weight (and width, if present) ranges. // Set up weight (and width, if present) ranges.
@ -131,8 +128,7 @@ void gfxMacFontFamily::FindStyleVariationsLocked(FontInfoData* aFontInfoData) {
addToFamily(mForSystemFont); addToFamily(mForSystemFont);
// See if there is a corresponding italic face, and add it to the family. // See if there is a corresponding italic face, and add it to the family.
NSFont* italicFont = NSFont* italicFont = [sFontManager convertFont:mForSystemFont toHaveTrait:NSItalicFontMask];
[sFontManager convertFont:mForSystemFont toHaveTrait:NSItalicFontMask];
if (italicFont != mForSystemFont) { if (italicFont != mForSystemFont) {
addToFamily(italicFont); addToFamily(italicFont);
} }
@ -151,8 +147,7 @@ void gfxMacFontFamily::FindStyleVariationsLocked(FontInfoData* aFontInfoData) {
class gfxSingleFaceMacFontFamily final : public gfxFontFamily { class gfxSingleFaceMacFontFamily final : public gfxFontFamily {
public: public:
gfxSingleFaceMacFontFamily(const nsACString& aName, gfxSingleFaceMacFontFamily(const nsACString& aName, FontVisibility aVisibility)
FontVisibility aVisibility)
: gfxFontFamily(aName, aVisibility) { : gfxFontFamily(aName, aVisibility) {
mFaceNamesInitialized = true; // omit from face name lists mFaceNamesInitialized = true; // omit from face name lists
} }
@ -180,8 +175,7 @@ void gfxSingleFaceMacFontFamily::LocalizedName(nsACString& aLocalizedName) {
} }
gfxFontEntry* fe = mAvailableFonts[0]; gfxFontEntry* fe = mAvailableFonts[0];
NSFont* font = [NSFont NSFont* font = [NSFont fontWithName:GetNSStringForString(NS_ConvertUTF8toUTF16(fe->Name()))
fontWithName:GetNSStringForString(NS_ConvertUTF8toUTF16(fe->Name()))
size:0.0]; size:0.0];
if (font) { if (font) {
NSString* localized = [font displayName]; NSString* localized = [font displayName];
@ -197,8 +191,7 @@ void gfxSingleFaceMacFontFamily::LocalizedName(nsACString& aLocalizedName) {
aLocalizedName = mName; aLocalizedName = mName;
} }
void gfxSingleFaceMacFontFamily::ReadOtherFamilyNames( void gfxSingleFaceMacFontFamily::ReadOtherFamilyNames(gfxPlatformFontList* aPlatformFontList) {
gfxPlatformFontList* aPlatformFontList) {
AutoWriteLock lock(mLock); AutoWriteLock lock(mLock);
if (mOtherFamilyNamesInitialized) { if (mOtherFamilyNamesInitialized) {
return; return;
@ -216,8 +209,7 @@ void gfxSingleFaceMacFontFamily::ReadOtherFamilyNames(
return; return;
} }
mHasOtherFamilyNames = mHasOtherFamilyNames = ReadOtherFamilyNamesForFace(aPlatformFontList, nameTable, true);
ReadOtherFamilyNamesForFace(aPlatformFontList, nameTable, true);
mOtherFamilyNamesInitialized = true; mOtherFamilyNamesInitialized = true;
} }
@ -237,8 +229,7 @@ gfxMacPlatformFontList::gfxMacPlatformFontList() : CoreTextFontList() {
gfxFontUtils::GetPrefsFontList("font.single-face-list", mSingleFaceFonts); gfxFontUtils::GetPrefsFontList("font.single-face-list", mSingleFaceFonts);
} }
FontVisibility gfxMacPlatformFontList::GetVisibilityForFamily( FontVisibility gfxMacPlatformFontList::GetVisibilityForFamily(const nsACString& aName) const {
const nsACString& aName) const {
if (aName[0] == '.' || aName.LowerCaseEqualsLiteral("lastresort")) { if (aName[0] == '.' || aName.LowerCaseEqualsLiteral("lastresort")) {
return FontVisibility::Hidden; return FontVisibility::Hidden;
} }
@ -373,8 +364,7 @@ void gfxMacPlatformFontList::InitSingleFaceList() {
// We found the correct face, so create the single-face family record. // We found the correct face, so create the single-face family record.
GenerateFontListKey(aliasName, key); GenerateFontListKey(aliasName, key);
LOG_FONTLIST(("(fontlist-singleface) family name: %s, key: %s\n", LOG_FONTLIST(("(fontlist-singleface) family name: %s, key: %s\n", aliasName.get(), key.get()));
aliasName.get(), key.get()));
// add only if doesn't exist already // add only if doesn't exist already
if (!mFontFamilies.GetWeak(key)) { if (!mFontFamilies.GetWeak(key)) {
@ -387,8 +377,8 @@ void gfxMacPlatformFontList::InitSingleFaceList() {
familyEntry->AddFontEntry(fontEntry); familyEntry->AddFontEntry(fontEntry);
familyEntry->SetHasStyles(true); familyEntry->SetHasStyles(true);
mFontFamilies.InsertOrUpdate(key, std::move(familyEntry)); mFontFamilies.InsertOrUpdate(key, std::move(familyEntry));
LOG_FONTLIST(("(fontlist-singleface) added new family: %s, key: %s\n", LOG_FONTLIST(
aliasName.get(), key.get())); ("(fontlist-singleface) added new family: %s, key: %s\n", aliasName.get(), key.get()));
} }
} }
} }
@ -414,14 +404,12 @@ static NSString* GetRealFamilyName(NSFont* aFont) {
// Eventually we should move to using CTFontUIFontType constants to identify // Eventually we should move to using CTFontUIFontType constants to identify
// system fonts, and eliminate the need to instantiate them (indirectly) from // system fonts, and eliminate the need to instantiate them (indirectly) from
// their postscript names. // their postscript names.
AutoCFRelease<CGFontRef> cgFont = AutoCFRelease<CGFontRef> cgFont = CGFontCreateWithFontName(CFStringRef(psName));
CGFontCreateWithFontName(CFStringRef(psName));
if (!cgFont) { if (!cgFont) {
return [aFont familyName]; return [aFont familyName];
} }
AutoCFRelease<CTFontRef> ctFont = AutoCFRelease<CTFontRef> ctFont = CTFontCreateWithGraphicsFont(cgFont, 0.0, nullptr, nullptr);
CTFontCreateWithGraphicsFont(cgFont, 0.0, nullptr, nullptr);
if (!ctFont) { if (!ctFont) {
return [aFont familyName]; return [aFont familyName];
} }
@ -455,8 +443,7 @@ void gfxMacPlatformFontList::InitSystemFontNames() {
// the hidden system fonts may be excluded from the font list altogether. // the hidden system fonts may be excluded from the font list altogether.
if (nsCocoaFeatures::OnCatalinaOrLater()) { if (nsCocoaFeatures::OnCatalinaOrLater()) {
// This family will be populated based on the given NSFont. // This family will be populated based on the given NSFont.
RefPtr<gfxFontFamily> fam = RefPtr<gfxFontFamily> fam = new gfxMacFontFamily(mSystemTextFontFamilyName, sys);
new gfxMacFontFamily(mSystemTextFontFamilyName, sys);
if (fam) { if (fam) {
nsAutoCString key; nsAutoCString key;
GenerateFontListKey(mSystemTextFontFamilyName, key); GenerateFontListKey(mSystemTextFontFamilyName, key);
@ -480,23 +467,19 @@ void gfxMacPlatformFontList::InitSystemFontNames() {
// different system font API's always map to the same family under OSX, so // different system font API's always map to the same family under OSX, so
// just assume that and emit a warning if that ever changes // just assume that and emit a warning if that ever changes
NSString* sysFamily = GetRealFamilyName([NSFont systemFontOfSize:0.0]); NSString* sysFamily = GetRealFamilyName([NSFont systemFontOfSize:0.0]);
if ([sysFamily compare:GetRealFamilyName([NSFont if ([sysFamily compare:GetRealFamilyName([NSFont boldSystemFontOfSize:0.0])] != NSOrderedSame ||
boldSystemFontOfSize:0.0])] != NSOrderedSame || [sysFamily compare:GetRealFamilyName([NSFont controlContentFontOfSize:0.0])] !=
[sysFamily compare:GetRealFamilyName([NSFont
controlContentFontOfSize:0.0])] != NSOrderedSame ||
[sysFamily compare:GetRealFamilyName([NSFont menuBarFontOfSize:0.0])] !=
NSOrderedSame || NSOrderedSame ||
[sysFamily compare:GetRealFamilyName([NSFont toolTipsFontOfSize:0.0])] != [sysFamily compare:GetRealFamilyName([NSFont menuBarFontOfSize:0.0])] != NSOrderedSame ||
NSOrderedSame) { [sysFamily compare:GetRealFamilyName([NSFont toolTipsFontOfSize:0.0])] != NSOrderedSame) {
NS_WARNING( NS_WARNING("system font types map to different font families"
"system font types map to different font families"
" -- please log a bug!!"); " -- please log a bug!!");
} }
#endif #endif
} }
FontFamily gfxMacPlatformFontList::GetDefaultFontForPlatform( FontFamily gfxMacPlatformFontList::GetDefaultFontForPlatform(nsPresContext* aPresContext,
nsPresContext* aPresContext, const gfxFontStyle* aStyle, const gfxFontStyle* aStyle,
nsAtom* aLanguage) { nsAtom* aLanguage) {
nsAutoreleasePool localPool; nsAutoreleasePool localPool;
@ -557,13 +540,10 @@ void gfxMacPlatformFontList::LookupSystemFont(LookAndFeel::FontID aSystemFontID,
} }
NSFontSymbolicTraits traits = [[font fontDescriptor] symbolicTraits]; NSFontSymbolicTraits traits = [[font fontDescriptor] symbolicTraits];
aFontStyle.style = (traits & NSFontItalicTrait) ? FontSlantStyle::ITALIC aFontStyle.style = (traits & NSFontItalicTrait) ? FontSlantStyle::ITALIC : FontSlantStyle::NORMAL;
: FontSlantStyle::NORMAL; aFontStyle.weight = (traits & NSFontBoldTrait) ? FontWeight::BOLD : FontWeight::NORMAL;
aFontStyle.weight =
(traits & NSFontBoldTrait) ? FontWeight::BOLD : FontWeight::NORMAL;
aFontStyle.stretch = (traits & NSFontExpandedTrait) ? FontStretch::EXPANDED aFontStyle.stretch = (traits & NSFontExpandedTrait) ? FontStretch::EXPANDED
: (traits & NSFontCondensedTrait) : (traits & NSFontCondensedTrait) ? FontStretch::CONDENSED
? FontStretch::CONDENSED
: FontStretch::NORMAL; : FontStretch::NORMAL;
aFontStyle.size = [font pointSize]; aFontStyle.size = [font pointSize];
aFontStyle.systemFont = true; aFontStyle.systemFont = true;