Commit 2c1a8f52 authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame 🎃
Browse files

fixup! Bug 41116: Normalize system fonts.

Bug 42529: Fix the breakage of this patch on Android.

Also, improve the patch hoping I can finally uplift it.
parent df3f350e
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/ContentProcessMessageManager.h"
#include "mozilla/dom/Document.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/ipc/FileDescriptorUtils.h"
#include "mozilla/ResultExtensions.h"
@@ -1964,20 +1965,27 @@ void gfxPlatformFontList::MaybeRemoveCmap(gfxCharacterMap* aCharMap) {
  }
}

static void GetSystemUIFontFamilies([[maybe_unused]] nsAtom* aLangGroup,
static void GetSystemUIFontFamilies(const nsPresContext* aPresContext,
                                    [[maybe_unused]] nsAtom* aLangGroup,
                                    nsTArray<nsCString>& aFamilies) {
  // TODO: On macOS, use CTCreateUIFontForLanguage or such thing (though the
  // code below ends up using [NSFont systemFontOfSize: 0.0].
  nsFont systemFont;
  gfxFontStyle fontStyle;
  nsAutoString systemFontName;
  if (nsContentUtils::ShouldResistFingerprinting()) {
  if (aPresContext && aPresContext->Document()
                 ? aPresContext->Document()->ShouldResistFingerprinting(
                       RFPTarget::Unknown)
                 : nsContentUtils::ShouldResistFingerprinting(
                       "aPresContext not available", RFPTarget::Unknown)) {
#ifdef XP_MACOSX
    *aFamilies.AppendElement() = "-apple-system"_ns;
#else
    return;
#elif !defined(MOZ_WIDGET_ANDROID)
    *aFamilies.AppendElement() = "sans-serif"_ns;
#endif
    return;
#endif
    // Android uses already fixed fonts.
  }
  if (!LookAndFeel::GetFont(StyleSystemFont::Menu, systemFontName, fontStyle)) {
    return;
@@ -2014,7 +2022,7 @@ void gfxPlatformFontList::ResolveGenericFontNames(
  MOZ_ASSERT(langGroup, "null lang group for pref lang");

  if (aGenericType == StyleGenericFontFamily::SystemUi) {
    GetSystemUIFontFamilies(langGroup, genericFamilies);
    GetSystemUIFontFamilies(aPresContext, langGroup, genericFamilies);
  }

  GetFontFamiliesFromGenericFamilies(
+4 −2
Original line number Diff line number Diff line
@@ -9708,7 +9708,10 @@ static void GetSpoofedSystemFontForRFP(LookAndFeel::FontID aFontID,
  // does.
  aName = u"sans-serif"_ns;
  aStyle.size = 12;
#elif !defined(MOZ_WIDGET_ANDROID)
#elif defined(MOZ_WIDGET_ANDROID)
  aName = u"Roboto"_ns;
  aStyle.size = 12;
#else
  // On Linux, there is not a default. For example, GNOME on Debian uses
  // Cantarell, 14.667px. Ubuntu Mate uses the Ubuntu font, but also 14.667px.
  // Fedora with KDE uses Noto Sans, 13.3333px, but it uses Noto Sans on
@@ -9719,7 +9722,6 @@ static void GetSpoofedSystemFontForRFP(LookAndFeel::FontID aFontID,
  aName = u"sans-serif"_ns;
  aStyle.size = 15;
#endif
  // No need to do anything on Android, as font and sizes are already fixed.
}

/* static */