Pier Angelo Vendrame pushed to branch mullvad-browser-128.5.0esr-14.5-1 at The Tor Project / Applications / Mullvad Browser
Commits: 334a5ddd by Pier Angelo Vendrame at 2024-12-16T19:28:03+01:00 fixup! Bug 43140: Tighten up fonts on Linux.
Bug 43330: Move the previous fix earlier in the startup.
- - - - - 3b5a4ebe by Pier Angelo Vendrame at 2024-12-16T19:28:09+01:00 Bug 43322: Customize the font visibility lists.
Customize the lists of fonts to assign base visibility to in base browser and derivatives.
Also, rename the files with the upstream lists, to make sure we do not use them by mistake.
- - - - -
10 changed files:
- gfx/thebes/StandardFonts-linux.inc → gfx/thebes/StandardFonts-linux-upstream.inc - + gfx/thebes/StandardFonts-macos-bb.inc - gfx/thebes/StandardFonts-macos.inc → gfx/thebes/StandardFonts-macos-upstream.inc - + gfx/thebes/StandardFonts-win10-bb.inc - gfx/thebes/StandardFonts-win10.inc → gfx/thebes/StandardFonts-win10-upstream.inc - gfx/thebes/gfxDWriteFontList.cpp - gfx/thebes/gfxFcPlatformFontList.cpp - gfx/thebes/gfxGDIFontList.cpp - gfx/thebes/gfxMacPlatformFontList.mm - toolkit/xre/nsXREDirProvider.cpp
Changes:
===================================== gfx/thebes/StandardFonts-linux.inc → gfx/thebes/StandardFonts-linux-upstream.inc =====================================
===================================== gfx/thebes/StandardFonts-macos-bb.inc ===================================== @@ -0,0 +1,33 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +static const char* kBaseFonts[] = { + "Apple Color Emoji", + "AppleGothic", + "Arial", + "Arial Black", + "Arial Narrow", + "Courier", + "Courier New", + "Geneva", + "Georgia", + "Heiti TC", + "Helvetica", + "Helvetica Neue", + "Hiragino Kaku Gothic ProN", + "Kailasa", + "Lucida Grande", + "Menlo", + "Monaco", + "PingFang HK", + "PingFang SC", + "PingFang TC", + "Songti SC", + "Songti TC", + "Tahoma", + "Thonburi", + "Times", + "Times New Roman", + "Verdana", +};
===================================== gfx/thebes/StandardFonts-macos.inc → gfx/thebes/StandardFonts-macos-upstream.inc =====================================
===================================== gfx/thebes/StandardFonts-win10-bb.inc ===================================== @@ -0,0 +1,90 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +static const char* kBaseFonts[] = { + "Arial", + "Cambria Math", + "Consolas", + "Courier New", + "Georgia", + "Lucida Console", + "Malgun Gothic", + "Microsoft Himalaya", + "Microsoft JhengHei", + "Microsoft YaHei", + "MS Gothic", + "MS PGothic", + "MV Boli", + "Segoe UI", + "SimSun", + "Sylfaen", + "Tahoma", + "Times New Roman", + "Verdana", +}; + +struct FontSubstitute { + const char* substituteName; + const char* actualFontName; +}; + +static const FontSubstitute kFontSubstitutes[] = { + // Common substitutions + {"Arabic Transparent", "Arial"}, + {"Arabic Transparent Bold", "Arial Bold"}, + {"Arial Baltic", "Arial"}, + {"Arial CE", "Arial"}, + {"Arial CYR", "Arial"}, + {"Arial Greek", "Arial"}, + {"Arial TUR", "Arial"}, + {"Courier New Baltic", "Courier New"}, + {"Courier New CE", "Courier New"}, + {"Courier New CYR", "Courier New"}, + {"Courier New Greek", "Courier New"}, + {"Courier New TUR", "Courier New"}, + {"Helv", "MS Sans Serif"}, + {"Helvetica", "Arial"}, + {"MS Shell Dlg 2", "Tahoma"}, + {"Tahoma Armenian", "Tahoma"}, + {"Times", "Times New Roman"}, + {"Times New Roman Baltic", "Times New Roman"}, + {"Times New Roman CE", "Times New Roman"}, + {"Times New Roman CYR", "Times New Roman"}, + {"Times New Roman Greek", "Times New Roman"}, + {"Times New Roman TUR", "Times New Roman"}, + {"Tms Rmn", "MS Serif"}, + // Common, except Japanese (which uses MS UI Gothic, instead) + {"MS Shell Dlg", "Microsoft Sans Serif"}, + // Arabic + {"Arial (Arabic)", "Arial"}, + {"Courier New (Arabic)", "Courier New"}, + {"Times New Roman (Arabic)", "Times New Roman"}, + // Cyrillic + Greek + {"Courier", "Courier New"}, + // Greek + {"Fixedsys Greek", "Fixedsys"}, + {"MS Serif Greek", "MS Serif"}, + {"MS Sans Serif Greek", "MS Sans Serif"}, + {"Small Fonts Greek", "Small Fonts"}, + {"System Greek", "System"}, + // Hebrew + {"Arial (Hebrew)", "Arial"}, + {"Courier New (Hebrew)", "Courier New"}, + {"David Transparent", "David"}, + {"Fixed Miriam Transparent", "Miriam Fixed"}, + {"Miriam Transparent", "Miriam"}, + {"Rod Transparent", "Rod"}, + {"Times New Roman (Hebrew)", "Times New Roman"}, + // Japanese + {"標準明朝", "MS 明朝"}, + {"標準ゴシック", "MS ゴシック"}, + {"ゴシック", "MS ゴシック"}, + {"ゴシック", "MS ゴシック"}, + {"クーリエ", "Courier"}, + {"タイムズロマン", "Times New Roman"}, + {"ヘルベチカ", "Arial"}, + // Simplified Chinese + {"FangSong_GB2312", "FangSong"}, + {"KaiTi_GB2312", "KaiTi"}, +};
===================================== gfx/thebes/StandardFonts-win10.inc → gfx/thebes/StandardFonts-win10-upstream.inc ===================================== @@ -200,68 +200,3 @@ static const char* kLangPackFonts[] = { // "Rockwell Nova", // Pan-European Supplemental Fonts - EXCLUDED // "Verdana Pro", // Pan-European Supplemental Fonts - EXCLUDED }; - -struct FontSubstitute { - const char *substituteName; - const char *actualFontName; -}; - -static const FontSubstitute kFontSubstitutes[] = { - // Common substitutions - {"Arabic Transparent", "Arial"}, - {"Arabic Transparent Bold", "Arial Bold"}, - {"Arial Baltic", "Arial"}, - {"Arial CE", "Arial"}, - {"Arial CYR", "Arial"}, - {"Arial Greek", "Arial"}, - {"Arial TUR", "Arial"}, - {"Courier New Baltic", "Courier New"}, - {"Courier New CE", "Courier New"}, - {"Courier New CYR", "Courier New"}, - {"Courier New Greek", "Courier New"}, - {"Courier New TUR", "Courier New"}, - {"Helv", "MS Sans Serif"}, - {"Helvetica", "Arial"}, - {"MS Shell Dlg 2", "Tahoma"}, - {"Tahoma Armenian", "Tahoma"}, - {"Times", "Times New Roman"}, - {"Times New Roman Baltic", "Times New Roman"}, - {"Times New Roman CE", "Times New Roman"}, - {"Times New Roman CYR", "Times New Roman"}, - {"Times New Roman Greek", "Times New Roman"}, - {"Times New Roman TUR", "Times New Roman"}, - {"Tms Rmn", "MS Serif"}, - // Common, except Japanese (which uses MS UI Gothic, instead) - {"MS Shell Dlg", "Microsoft Sans Serif"}, - // Arabic - {"Arial (Arabic)", "Arial"}, - {"Courier New (Arabic)", "Courier New"}, - {"Times New Roman (Arabic)", "Times New Roman"}, - // Cyrillic + Greek - {"Courier", "Courier New"}, - // Greek - {"Fixedsys Greek", "Fixedsys"}, - {"MS Serif Greek", "MS Serif"}, - {"MS Sans Serif Greek", "MS Sans Serif"}, - {"Small Fonts Greek", "Small Fonts"}, - {"System Greek", "System"}, - // Hebrew - {"Arial (Hebrew)", "Arial"}, - {"Courier New (Hebrew)", "Courier New"}, - {"David Transparent", "David"}, - {"Fixed Miriam Transparent", "Miriam Fixed"}, - {"Miriam Transparent", "Miriam"}, - {"Rod Transparent", "Rod"}, - {"Times New Roman (Hebrew)", "Times New Roman"}, - // Japanese - {"標準明朝", "MS 明朝"}, - {"標準ゴシック", "MS ゴシック"}, - {"ゴシック", "MS ゴシック"}, - {"ゴシック", "MS ゴシック"}, - {"クーリエ", "Courier"}, - {"タイムズロマン", "Times New Roman"}, - {"ヘルベチカ", "Arial"}, - // Simplified Chinese - {"FangSong_GB2312", "FangSong"}, - {"KaiTi_GB2312", "KaiTi"}, -};
===================================== gfx/thebes/gfxDWriteFontList.cpp ===================================== @@ -32,7 +32,7 @@
#include "harfbuzz/hb.h"
-#include "StandardFonts-win10.inc" +#include "StandardFonts-win10-bb.inc"
using namespace mozilla; using namespace mozilla::gfx; @@ -910,7 +910,9 @@ void gfxDWriteFontEntry::AddSizeOfIncludingThis(MallocSizeOf aMallocSizeOf,
gfxDWriteFontList::gfxDWriteFontList() : mForceGDIClassicMaxFontSize(0.0) { CheckFamilyList(kBaseFonts); +#ifndef BASE_BROWSER_VERSION CheckFamilyList(kLangPackFonts); +#endif }
// bug 602792 - CJK systems default to large CJK fonts which cause excessive @@ -1153,9 +1155,11 @@ FontVisibility gfxDWriteFontList::GetVisibilityForFamily( if (FamilyInList(aName, kBaseFonts)) { return FontVisibility::Base; } +#ifndef BASE_BROWSER_VERSION if (FamilyInList(aName, kLangPackFonts)) { return FontVisibility::LangPack; } +#endif return FontVisibility::User; }
@@ -1164,8 +1168,10 @@ gfxDWriteFontList::GetFilteredPlatformFontLists() { nsTArray<std::pair<const char**, uint32_t>> fontLists;
fontLists.AppendElement(std::make_pair(kBaseFonts, ArrayLength(kBaseFonts))); +#ifndef BASE_BROWSER_VERSION fontLists.AppendElement( std::make_pair(kLangPackFonts, ArrayLength(kLangPackFonts))); +#endif
return fontLists; }
===================================== gfx/thebes/gfxFcPlatformFontList.cpp ===================================== @@ -32,7 +32,9 @@ #include "nsCharSeparatedTokenizer.h" #include "nsXULAppAPI.h" #include "SharedFontList-impl.h" -#include "StandardFonts-linux.inc" +#ifndef BASE_BROWSER_VERSION +# include "StandardFonts-linux.inc" +#endif #include "mozilla/intl/Locale.h"
#include "mozilla/gfx/HelpersCairo.h" @@ -1352,45 +1354,20 @@ bool gfxFontconfigFont::ShouldHintMetrics() const { return !GetStyle()->printerFont; }
-static nsresult SetFontconfigConfigFile() { - nsCOMPtr<nsIProperties> dirSvc( - do_GetService("@mozilla.org/file/directory_service;1")); - NS_ENSURE_TRUE(dirSvc, NS_ERROR_NOT_AVAILABLE); - nsCOMPtr<nsIFile> appFile, confDir; - nsresult rv = dirSvc->Get(XRE_EXECUTABLE_FILE, NS_GET_IID(nsIFile), - getter_AddRefs(appFile)); - NS_ENSURE_SUCCESS(rv, rv); - rv = appFile->GetParent(getter_AddRefs(confDir)); - NS_ENSURE_SUCCESS(rv, rv); - rv = confDir->AppendNative("fonts"_ns); - NS_ENSURE_SUCCESS(rv, rv); - - nsAutoCString confPath; - rv = confDir->GetNativePath(confPath); - NS_ENSURE_SUCCESS(rv, rv); - if (NS_WARN_IF(setenv("FONTCONFIG_PATH", confPath.BeginReading(), 1) != 0 || - setenv("FONTCONFIG_FILE", "fonts.conf", 1) != 0)) { - return NS_ERROR_FAILURE; - } - return NS_OK; -} - gfxFcPlatformFontList::gfxFcPlatformFontList() : mLocalNames(64), mGenericMappings(32), mFcSubstituteCache(64), mLastConfig(nullptr), mAlwaysUseFontconfigGenerics(true) { - if (NS_FAILED(SetFontconfigConfigFile())) { - NS_WARNING("Failed to set the fontconfig config file!"); - } - +#ifndef BASE_BROWSER_VERSION CheckFamilyList(kBaseFonts_Ubuntu_22_04); CheckFamilyList(kLangFonts_Ubuntu_22_04); CheckFamilyList(kBaseFonts_Ubuntu_20_04); CheckFamilyList(kLangFonts_Ubuntu_20_04); CheckFamilyList(kBaseFonts_Fedora_39); CheckFamilyList(kBaseFonts_Fedora_38); +#endif mLastConfig = FcConfigGetCurrent(); if (XRE_IsParentProcess()) { // if the rescan interval is set, start the timer @@ -1704,11 +1681,14 @@ using Device = nsIGfxInfo::FontVisibilityDeviceDetermination; static Device sFontVisibilityDevice = Device::Unassigned;
void AssignFontVisibilityDevice() { + sFontVisibilityDevice = Device::Linux_Unknown; +#ifndef BASE_BROWSER_VERSION if (sFontVisibilityDevice == Device::Unassigned) { nsCOMPtr<nsIGfxInfo> gfxInfo = components::GfxInfo::Service(); NS_ENSURE_SUCCESS_VOID( gfxInfo->GetFontVisibilityDetermination(&sFontVisibilityDevice)); } +#endif }
// Per family array of faces. @@ -2029,6 +2009,7 @@ FontVisibility gfxFcPlatformFontList::GetVisibilityForFamily( AssignFontVisibilityDevice();
switch (sFontVisibilityDevice) { +#ifndef BASE_BROWSER_VERSION case Device::Linux_Ubuntu_any: case Device::Linux_Ubuntu_22: if (FamilyInList(aName, kBaseFonts_Ubuntu_22_04)) { @@ -2068,7 +2049,7 @@ FontVisibility gfxFcPlatformFontList::GetVisibilityForFamily( return FontVisibility::Base; } return FontVisibility::User; - +#endif default: // We don't know how to categorize fonts on this system return FontVisibility::Unknown; @@ -2081,6 +2062,7 @@ gfxFcPlatformFontList::GetFilteredPlatformFontLists() {
nsTArray<std::pair<const char**, uint32_t>> fontLists;
+#ifndef BASE_BROWSER_VERSION switch (sFontVisibilityDevice) { case Device::Linux_Ubuntu_any: case Device::Linux_Ubuntu_22: @@ -2114,6 +2096,7 @@ gfxFcPlatformFontList::GetFilteredPlatformFontLists() { // We don't know how to categorize fonts on this system break; } +#endif
return fontLists; }
===================================== gfx/thebes/gfxGDIFontList.cpp ===================================== @@ -33,7 +33,7 @@
#include "nsContentUtils.h"
-#include "StandardFonts-win10.inc" +#include "StandardFonts-win10-bb.inc"
#include <usp10.h>
===================================== gfx/thebes/gfxMacPlatformFontList.mm ===================================== @@ -46,7 +46,7 @@ #include <time.h> #include <dlfcn.h>
-#include "StandardFonts-macos.inc" +#include "StandardFonts-macos-bb.inc"
using namespace mozilla; using namespace mozilla::gfx; @@ -153,7 +153,9 @@ void gfxSingleFaceMacFontFamily::ReadOtherFamilyNames(
gfxMacPlatformFontList::gfxMacPlatformFontList() : CoreTextFontList() { CheckFamilyList(kBaseFonts); +#ifndef BASE_BROWSER_VERSION CheckFamilyList(kBaseFonts_13_Higher); +#endif
// cache this in a static variable so that gfxMacFontFamily objects // don't have to repeatedly look it up @@ -188,10 +190,12 @@ FontVisibility gfxMacPlatformFontList::GetVisibilityForFamily( if (FamilyInList(aName, kBaseFonts)) { return FontVisibility::Base; } +#ifndef BASE_BROWSER_VERSION if (GetFontVisibilityDevice() == Device::MacOS_13_plus && FamilyInList(aName, kBaseFonts_13_Higher)) { return FontVisibility::Base; } +#endif #ifdef MOZ_BUNDLED_FONTS if (mBundledFamilies.Contains(aName)) { return FontVisibility::Base; @@ -206,10 +210,12 @@ gfxMacPlatformFontList::GetFilteredPlatformFontLists() {
fontLists.AppendElement(std::make_pair(kBaseFonts, std::size(kBaseFonts)));
+#ifndef BASE_BROWSER_VERSION if (GetFontVisibilityDevice() == Device::MacOS_13_plus) { fontLists.AppendElement( std::make_pair(kBaseFonts_13_Higher, std::size(kBaseFonts_13_Higher))); } +#endif
return fontLists; }
===================================== toolkit/xre/nsXREDirProvider.cpp ===================================== @@ -742,6 +742,25 @@ void nsXREDirProvider::FinishInitializingUserPrefs() { } }
+#ifdef MOZ_WIDGET_GTK +static nsresult SetFontconfigConfigFile(nsCOMPtr<nsIFile> appDir) { + NS_ENSURE_TRUE(appDir, NS_ERROR_NULL_POINTER); + nsCOMPtr<nsIFile> confDir; + nsresult rv = appDir->Clone(getter_AddRefs(confDir)); + NS_ENSURE_SUCCESS(rv, rv); + rv = confDir->AppendNative("fonts"_ns); + NS_ENSURE_SUCCESS(rv, rv); + nsAutoCString confPath; + rv = confDir->GetNativePath(confPath); + NS_ENSURE_SUCCESS(rv, rv); + if (NS_WARN_IF(setenv("FONTCONFIG_PATH", confPath.BeginReading(), 1) != 0 || + setenv("FONTCONFIG_FILE", "fonts.conf", 1) != 0)) { + return NS_ERROR_FAILURE; + } + return NS_OK; +} +#endif + NS_IMETHODIMP nsXREDirProvider::DoStartup() { nsresult rv; @@ -760,6 +779,13 @@ nsXREDirProvider::DoStartup() { */ MOZ_ASSERT(mPrefsInitialized);
+#ifdef MOZ_WIDGET_GTK + // FontConfig might be initialized by GTK/Pango, so we need to define its + // config variables before doing anything. + rv = SetFontconfigConfigFile(mGREDir); + NS_ENSURE_SUCCESS(rv, rv); +#endif + bool safeModeNecessary = false; nsCOMPtr<nsIAppStartup> appStartup( mozilla::components::AppStartup::Service());
View it on GitLab: https://gitlab.torproject.org/tpo/applications/mullvad-browser/-/compare/bd3...
tor-commits@lists.torproject.org