diff --git a/gfx/thebes/gfxFcPlatformFontList.cpp b/gfx/thebes/gfxFcPlatformFontList.cpp index 201e469e0c67b..f64c8e5bd01a6 100644 --- a/gfx/thebes/gfxFcPlatformFontList.cpp +++ b/gfx/thebes/gfxFcPlatformFontList.cpp @@ -21,6 +21,8 @@ #include "mozilla/TimeStamp.h" #include "nsGkAtoms.h" #include "nsIConsoleService.h" +#include "nsIGfxInfo.h" +#include "mozilla/Components.h" #include "nsString.h" #include "nsStringFwd.h" #include "nsUnicodeProperties.h" @@ -1671,6 +1673,18 @@ void gfxFcPlatformFontList::ReadSystemFontList(dom::SystemFontList* retValue) { } } +static nsIGfxInfo::FontVisibilityDeviceDetermination sFontVisibilityDevice = + nsIGfxInfo::FontVisibilityDeviceDetermination::Unassigned; + +void AssignFontVisibilityDevice() { + if (sFontVisibilityDevice == + nsIGfxInfo::FontVisibilityDeviceDetermination::Unassigned) { + nsCOMPtr gfxInfo = components::GfxInfo::Service(); + NS_ENSURE_SUCCESS_VOID( + gfxInfo->GetFontVisibilityDetermination(&sFontVisibilityDevice)); + } +} + // Per family array of faces. class FacesData { using FaceInitArray = AutoTArray; @@ -1957,7 +1971,10 @@ void gfxFcPlatformFontList::InitSharedFontListForPlatform() { FcFontSet* systemFonts = FcConfigGetFonts(nullptr, FcSetSystem); auto numBaseFamilies = addFontSetFamilies(systemFonts, policy.get(), /* aAppFonts = */ false); - if (GetDistroID() != DistroID::Unknown && numBaseFamilies < 3) { + AssignFontVisibilityDevice(); + if (numBaseFamilies < 3 && + sFontVisibilityDevice != + nsIGfxInfo::FontVisibilityDeviceDetermination::Linux_Unknown) { // If we found fewer than 3 known FontVisibility::Base families in the // system (ignoring app-bundled fonts), we must be dealing with a very // non-standard configuration; disable the distro-specific font @@ -1983,72 +2000,27 @@ void gfxFcPlatformFontList::InitSharedFontListForPlatform() { } } -gfxFcPlatformFontList::DistroID gfxFcPlatformFontList::GetDistroID() const { - // Helper called to initialize sResult the first time this is used. - auto getDistroID = []() { - DistroID result = DistroID::Unknown; - int versionMajor = 0; - FILE* fp = fopen("/etc/os-release", "r"); - if (fp) { - char buf[512]; - while (fgets(buf, sizeof(buf), fp)) { - if (strncmp(buf, "VERSION_ID=\"", 12) == 0) { - versionMajor = strtol(buf + 12, nullptr, 10); - if (result != DistroID::Unknown) { - break; - } - } - if (strncmp(buf, "ID=", 3) == 0) { - if (strncmp(buf + 3, "ubuntu", 6) == 0) { - result = DistroID::Ubuntu_any; - } else if (strncmp(buf + 3, "fedora", 6) == 0) { - result = DistroID::Fedora_any; - } - if (versionMajor) { - break; - } - } - } - fclose(fp); - } - if (result == DistroID::Ubuntu_any) { - if (versionMajor == 20) { - result = DistroID::Ubuntu_20; - } else if (versionMajor == 22) { - result = DistroID::Ubuntu_22; - } - } else if (result == DistroID::Fedora_any) { - if (versionMajor == 38) { - result = DistroID::Fedora_38; - } else if (versionMajor == 39) { - result = DistroID::Fedora_39; - } - } - return result; - }; - static DistroID sResult = getDistroID(); - return sResult; -} - FontVisibility gfxFcPlatformFontList::GetVisibilityForFamily( const nsACString& aName) const { - auto distro = GetDistroID(); - switch (distro) { - case DistroID::Ubuntu_any: - case DistroID::Ubuntu_22: + AssignFontVisibilityDevice(); + + switch (sFontVisibilityDevice) { + case nsIGfxInfo::FontVisibilityDeviceDetermination::Linux_Ubuntu_any: + case nsIGfxInfo::FontVisibilityDeviceDetermination::Linux_Ubuntu_22: if (FamilyInList(aName, kBaseFonts_Ubuntu_22_04)) { return FontVisibility::Base; } if (FamilyInList(aName, kLangFonts_Ubuntu_22_04)) { return FontVisibility::LangPack; } - if (distro == DistroID::Ubuntu_22) { + if (sFontVisibilityDevice == + nsIGfxInfo::FontVisibilityDeviceDetermination::Linux_Ubuntu_22) { return FontVisibility::User; } // For Ubuntu_any, we fall through to also check the 20_04 lists. [[fallthrough]]; - case DistroID::Ubuntu_20: + case nsIGfxInfo::FontVisibilityDeviceDetermination::Linux_Ubuntu_20: if (FamilyInList(aName, kBaseFonts_Ubuntu_20_04)) { return FontVisibility::Base; } @@ -2057,18 +2029,19 @@ FontVisibility gfxFcPlatformFontList::GetVisibilityForFamily( } return FontVisibility::User; - case DistroID::Fedora_any: - case DistroID::Fedora_39: + case nsIGfxInfo::FontVisibilityDeviceDetermination::Linux_Fedora_any: + case nsIGfxInfo::FontVisibilityDeviceDetermination::Linux_Fedora_39: if (FamilyInList(aName, kBaseFonts_Fedora_39)) { return FontVisibility::Base; } - if (distro == DistroID::Fedora_39) { + if (sFontVisibilityDevice == + nsIGfxInfo::FontVisibilityDeviceDetermination::Linux_Fedora_39) { return FontVisibility::User; } // For Fedora_any, fall through to also check Fedora 38 list. [[fallthrough]]; - case DistroID::Fedora_38: + case nsIGfxInfo::FontVisibilityDeviceDetermination::Linux_Fedora_38: if (FamilyInList(aName, kBaseFonts_Fedora_38)) { return FontVisibility::Base; } diff --git a/gfx/thebes/gfxFcPlatformFontList.h b/gfx/thebes/gfxFcPlatformFontList.h index 93ea34d52053a..54070d141051a 100644 --- a/gfx/thebes/gfxFcPlatformFontList.h +++ b/gfx/thebes/gfxFcPlatformFontList.h @@ -351,19 +351,6 @@ class gfxFcPlatformFontList final : public gfxPlatformFontList { nsAtom* aLanguage = nullptr) MOZ_REQUIRES(mLock) override; - enum class DistroID : int8_t { - Unknown, - Ubuntu_any, - Ubuntu_20, - Ubuntu_22, - Fedora_any, - Fedora_38, - Fedora_39, - // To be extended with any distros that ship a useful base set of fonts - // that we want to explicitly support. - }; - DistroID GetDistroID() const; // -> DistroID::Unknown if we can't tell - FontVisibility GetVisibilityForFamily(const nsACString& aName) const; gfxFontFamily* CreateFontFamily(const nsACString& aName, diff --git a/widget/GfxInfoBase.cpp b/widget/GfxInfoBase.cpp index 90ded426bc2b0..148b3bd00fb4c 100644 --- a/widget/GfxInfoBase.cpp +++ b/widget/GfxInfoBase.cpp @@ -2009,6 +2009,59 @@ std::pair GfxInfoBase::GetFontVisibilityDeterminationPair() { androidProduct.get(), androidProductIsChromebook ? "yes" : "no"); #elif defined(XP_LINUX) + ret.first = Device::Linux_Unknown; + + long versionMajor = 0; + FILE* fp = fopen("/etc/os-release", "r"); + if (fp) { + char buf[512]; + while (fgets(buf, sizeof(buf), fp)) { + if (strncmp(buf, "VERSION_ID=\"", 12) == 0) { + ret.second.AppendPrintf("VERSION_ID=%.11s", buf + 11); + versionMajor = strtol(buf + 12, nullptr, 10); + if (ret.first != Device::Linux_Unknown) { + break; + } + } + + if (strncmp(buf, "ID=", 3) == 0) { + ret.second.AppendPrintf("ID=%.6s", buf + 3); + if (strncmp(buf + 3, "ubuntu", 6) == 0) { + ret.first = Device::Linux_Ubuntu_any; + } else if (strncmp(buf + 3, "fedora", 6) == 0) { + ret.first = Device::Linux_Fedora_any; + } + + if (versionMajor) { + break; + } + } + } + fclose(fp); + } + if (ret.first == Device::Linux_Ubuntu_any) { + if (versionMajor == 20) { + ret.first = Device::Linux_Ubuntu_20; + ret.second.Insert(u"Ubuntu 20 - ", 0); + } else if (versionMajor == 22) { + ret.first = Device::Linux_Ubuntu_22; + ret.second.Insert(u"Ubuntu 22 - ", 0); + } else { + ret.second.Insert(u"Ubuntu Unknown - ", 0); + } + } else if (ret.first == Device::Linux_Fedora_any) { + if (versionMajor == 38) { + ret.first = Device::Linux_Fedora_38; + ret.second.Insert(u"Fedora 38 - ", 0); + } else if (versionMajor == 39) { + ret.first = Device::Linux_Fedora_39; + ret.second.Insert(u"Fedora 39 - ", 0); + } else { + ret.second.Insert(u"Fedora Unknown - ", 0); + } + } else { + ret.second.Insert(u"Linux Unknown - ", 0); + } #elif defined(XP_MACOSX) ret.first = Device::MacOS_Platform;