[tbb-commits] [Git][tpo/applications/mullvad-browser][mullvad-browser-128.4.0esr-14.5-1] amend! Bug 41043: Hardcode the UI font on Linux

Pier Angelo Vendrame (@pierov) git at gitlab.torproject.org
Tue Oct 29 13:56:48 UTC 2024



Pier Angelo Vendrame pushed to branch mullvad-browser-128.4.0esr-14.5-1 at The Tor Project / Applications / Mullvad Browser


Commits:
4e14cbf3 by Pier Angelo Vendrame at 2024-10-29T14:56:34+01:00
amend! Bug 41043: Hardcode the UI font on Linux

Bug 43140: Tighten up fonts on Linux.

We ship a fontconfig configuration to esnure all Linux users have the
same defaults and reduce the chances of fingerprinting.
We used to add this file in tor-browser-build, but some users might
skip it by using the browser executable without the wrapper script.
Therefore, we decided to activate the file with the FontConfig API
instead of the environment variables.

Bug 41043: Hardcode the UI font on Linux

The mechanism to choose the UI font does not play well with our
fontconfig configuration. As a result, the final criterion to choose
the font for the UI was its version.

Since we hardcode Arimo as a default sans-serif on preferences, we use
it also for the UI. FontConfig will fall back to some other font for
scripts Arimo does not cover as expected (we tested with Japanese).

Bug 43141: Hardcode system-ui to Arimo.

- - - - -


3 changed files:

- + browser/fonts/fonts.conf
- browser/fonts/moz.build
- gfx/thebes/gfxFcPlatformFontList.cpp


Changes:

=====================================
browser/fonts/fonts.conf
=====================================
@@ -0,0 +1,183 @@
+<?xml version="1.0"?>
+<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
+<!--
+**DO NOT EDIT THIS FILE!**
+This file sets Tor Browser's bundled fonts as the only available system fonts
+and standardizes rendering settings.
+Any changes might deanonymize you, or expose you to fingerprinting vectors.
+-->
+<!--
+Derived from fonts.conf.in of Fontconfig.
+
+Copyright © 2000,2001,2002,2003,2004,2006,2007 Keith Packard
+Copyright © 2005 Patrick Lam
+Copyright © 2009 Roozbeh Pournader
+Copyright © 2008,2009 Red Hat, Inc.
+Copyright © 2008 Danilo Šegan
+Copyright © 2012 Google, Inc.
+
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation, and that the name of the author(s) not be used in
+advertising or publicity pertaining to distribution of the software without
+specific, written prior permission.  The authors make no
+representations about the suitability of this software for any purpose.  It
+is provided "as is" without express or implied warranty.
+
+THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+-->
+<fontconfig>
+
+<!-- Font directory list -->
+
+	<dir prefix="cwd">fonts</dir>
+
+<!--
+  Accept deprecated 'mono' alias, replacing it with 'monospace'
+-->
+	<match target="pattern">
+		<test qual="any" name="family">
+			<string>mono</string>
+		</test>
+		<edit name="family" mode="assign" binding="same">
+			<string>monospace</string>
+		</edit>
+	</match>
+
+<!--
+  Accept alternate 'sans serif' spelling, replacing it with 'sans-serif'
+-->
+	<match target="pattern">
+		<test qual="any" name="family">
+			<string>sans serif</string>
+		</test>
+		<edit name="family" mode="assign" binding="same">
+			<string>sans-serif</string>
+		</edit>
+	</match>
+
+<!--
+  Accept deprecated 'sans' alias, replacing it with 'sans-serif'
+-->
+	<match target="pattern">
+		<test qual="any" name="family">
+			<string>sans</string>
+		</test>
+		<edit name="family" mode="assign" binding="same">
+			<string>sans-serif</string>
+		</edit>
+	</match>
+
+<!--
+  Set our default generic families.
+-->
+	<match target="pattern">
+		<test qual="any" name="family">
+			<string>sans-serif</string>
+		</test>
+		<edit name="family" mode="assign" binding="same">
+			<string>Arimo</string>
+		</edit>
+	</match>
+	<match target="pattern">
+		<test qual="any" name="family">
+			<string>serif</string>
+		</test>
+		<edit name="family" mode="assign" binding="same">
+			<string>Tinos</string>
+		</edit>
+	</match>
+	<match target="pattern">
+		<test qual="any" name="family">
+			<string>monospace</string>
+		</test>
+		<edit name="family" mode="assign" binding="same">
+			<string>Cousine</string>
+		</edit>
+	</match>
+
+<!--
+  tor-browser#41799, tor-browser-build#41237: Add some aliases for
+  compatibility.
+-->
+	<match target="pattern">
+		<test qual="any" name="family">
+			<string>Arial</string>
+		</test>
+		<edit name="family" mode="assign" binding="same">
+			<string>Arimo</string>
+		</edit>
+	</match>
+	<match target="pattern">
+		<test qual="any" name="family">
+			<string>Times New Roman</string>
+		</test>
+		<edit name="family" mode="assign" binding="same">
+			<string>Tinos</string>
+		</edit>
+	</match>
+	<match target="pattern">
+		<test qual="any" name="family">
+			<string>Courier New</string>
+		</test>
+		<edit name="family" mode="assign" binding="same">
+			<string>Cousine</string>
+		</edit>
+	</match>
+	<match target="pattern">
+		<test qual="any" name="family">
+			<string>Helvetica</string>
+		</test>
+		<edit name="family" mode="assign" binding="same">
+			<string>Arimo</string>
+		</edit>
+	</match>
+	<match target="pattern">
+		<test qual="any" name="family">
+			<string>Times</string>
+		</test>
+		<edit name="family" mode="assign" binding="same">
+			<string>Tinos</string>
+		</edit>
+	</match>
+	<match target="pattern">
+		<test qual="any" name="family">
+			<string>Courier</string>
+		</test>
+		<edit name="family" mode="assign" binding="same">
+			<string>Cousine</string>
+		</edit>
+	</match>
+
+<!-- Font cache directory list -->
+
+	<cachedir prefix="xdg">fontconfig</cachedir>
+
+	<config>
+<!--
+  Rescan configuration every 30 seconds when FcFontSetList is called
+ -->
+		<rescan>
+			<int>30</int>
+		</rescan>
+	</config>
+
+	<!-- Standardize rendering settings. -->
+	<match target="pattern">
+		<edit name="antialias" mode="assign"><bool>true</bool></edit>
+		<edit name="autohint" mode="assign"><bool>false</bool></edit>
+		<edit name="hinting" mode="assign"><bool>true</bool></edit>
+		<edit name="hintstyle" mode="assign"><const>hintfull</const></edit>
+		<edit name="lcdfilter" mode="assign"><const>lcddefault</const></edit>
+		<edit name="rgba" mode="assign"><const>none</const></edit>
+	</match>
+</fontconfig>


=====================================
browser/fonts/moz.build
=====================================
@@ -7,3 +7,6 @@
 if CONFIG["MOZ_WIDGET_TOOLKIT"] in ("windows", "gtk"):
     DIST_SUBDIR = ""
     FINAL_TARGET_FILES.fonts += ["TwemojiMozilla.ttf"]
+
+if CONFIG["MOZ_WIDGET_TOOLKIT"] == "gtk":
+    FINAL_TARGET_FILES.fonts += ["fonts.conf"]


=====================================
gfx/thebes/gfxFcPlatformFontList.cpp
=====================================
@@ -1352,12 +1352,39 @@ 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, confFile;
+  nsresult rv = dirSvc->Get(XRE_EXECUTABLE_FILE, NS_GET_IID(nsIFile),
+                            getter_AddRefs(appFile));
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = appFile->GetParent(getter_AddRefs(confFile));
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = confFile->AppendNative("fonts"_ns);
+  NS_ENSURE_SUCCESS(rv, rv);
+  rv = confFile->AppendNative("fonts.conf"_ns);
+  NS_ENSURE_SUCCESS(rv, rv);
+
+  nsAutoCString confPath;
+  rv = confFile->GetNativePath(confPath);
+  if (setenv("FONTCONFIG_FILE", confPath.BeginReading(), 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!");
+  }
+
   CheckFamilyList(kBaseFonts_Ubuntu_22_04);
   CheckFamilyList(kLangFonts_Ubuntu_22_04);
   CheckFamilyList(kBaseFonts_Ubuntu_20_04);



View it on GitLab: https://gitlab.torproject.org/tpo/applications/mullvad-browser/-/commit/4e14cbf3be3540e07ab85c958cd9f2dede2f274d

-- 
View it on GitLab: https://gitlab.torproject.org/tpo/applications/mullvad-browser/-/commit/4e14cbf3be3540e07ab85c958cd9f2dede2f274d
You're receiving this email because of your account on gitlab.torproject.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.torproject.org/pipermail/tbb-commits/attachments/20241029/7ffe2c0a/attachment-0001.htm>


More information about the tbb-commits mailing list