Commit 2d4285c3 authored by Jonathan Kew's avatar Jonathan Kew
Browse files

Bug 1363454 - Create a pref to list icon font families that should be used...

Bug 1363454 - Create a pref to list icon font families that should be used even when use_document_fonts=0, overriding the browser's font prefs. r=emilio,dholbert

Some widely-used icon fonts use ligature rules to replace icon names such as "volume_up"
or "down_arrow" with icon glyphs. If the site is designed to use such a font, but the user
disables document fonts and we use our default Latin font instead, the underlying text will
be rendered instead of the intended icon.

To enable such fonts to continue to work, we provide a list of known ligature-icon fonts
and allow them to be used even when the document-fonts setting is disabled.

Differential Revision: https://phabricator.services.mozilla.com/D167923
parent b6e561f1
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -1844,6 +1844,11 @@ bool gfxPlatform::IsFontFormatSupported(
  return true;
}

bool gfxPlatform::IsKnownIconFontFamily(const nsAtom* aFamilyName) const {
  return gfxPlatformFontList::PlatformFontList()->IsKnownIconFontFamily(
      aFamilyName);
}

gfxFontEntry* gfxPlatform::LookupLocalFont(nsPresContext* aPresContext,
                                           const nsACString& aFontName,
                                           WeightRange aWeightForEntry,
+2 −0
Original line number Diff line number Diff line
@@ -490,6 +490,8 @@ class gfxPlatform : public mozilla::layers::MemoryPressureListener {
      mozilla::StyleFontFaceSourceFormatKeyword aFormatHint,
      mozilla::StyleFontFaceSourceTechFlags aTechFlags);

  bool IsKnownIconFontFamily(const nsAtom* aFamilyName) const;

  virtual bool DidRenderingDeviceReset(
      DeviceResetReason* aResetReason = nullptr) {
    return false;
+31 −3
Original line number Diff line number Diff line
@@ -134,14 +134,20 @@ const gfxFontEntry::ScriptRange gfxPlatformFontList::sComplexScriptRanges[] = {
    {0, 0, 0, {0, 0, 0}}  // terminator
};

static const char* kObservedPrefs[] = {"font.", "font.name-list.",
                                       "intl.accept_languages",  // hmmmm...
                                       nullptr};
static const char* kObservedPrefs[] = {
    "font.", "font.name-list.", "intl.accept_languages",  // hmmmm...
    "browser.display.use_document_fonts.icon_font_allowlist", nullptr};

static const char kFontSystemWhitelistPref[] = "font.system.whitelist";

static const char kCJKFallbackOrderPref[] = "font.cjk_pref_fallback_order";

// Pref for the list of icon font families that still get to override the
// default font from prefs, even when use_document_fonts is disabled.
// (This is to enable ligature-based icon fonts to keep working.)
static const char kIconFontsPref[] =
    "browser.display.use_document_fonts.icon_font_allowlist";

// xxx - this can probably be eliminated by reworking pref font handling code
static const char* gPrefLangNames[] = {
#define FONT_PREF_LANG(enum_id_, str_, atom_id_) str_
@@ -164,6 +170,7 @@ static void FontListPrefChanged(const char* aPref, void* aData = nullptr) {
  // XXX this could be made to only clear out the cache for the prefs that were
  // changed but it probably isn't that big a deal.
  gfxPlatformFontList::PlatformFontList()->ClearLangGroupPrefFonts();
  gfxPlatformFontList::PlatformFontList()->LoadIconFontOverrideList();
  gfxFontCache::GetCache()->Flush();
}

@@ -275,6 +282,7 @@ gfxPlatformFontList::gfxPlatformFontList(bool aNeedFullnamePostscriptNames)
  mLangService = nsLanguageAtomService::GetService();

  LoadBadUnderlineList();
  LoadIconFontOverrideList();

  mFontPrefs = MakeUnique<FontPrefs>();

@@ -515,6 +523,7 @@ bool gfxPlatformFontList::InitFontList() {

    mAliasTable.Clear();
    mLocalNameTable.Clear();
    mIconFontsSet.Clear();

    CancelLoadCmapsTask();
    mStartedLoadingCmapsFrom = 0xffffffffu;
@@ -539,6 +548,8 @@ bool gfxPlatformFontList::InitFontList() {

    gfxFontUtils::GetPrefsFontList(kFontSystemWhitelistPref, mEnabledFontsList);
    mFontFamilyWhitelistActive = !mEnabledFontsList.IsEmpty();

    LoadIconFontOverrideList();
  }

  // From here, gfxPlatformFontList::IsInitialized will return true,
@@ -612,6 +623,16 @@ bool gfxPlatformFontList::InitFontList() {
  return true;
}

void gfxPlatformFontList::LoadIconFontOverrideList() {
  mIconFontsSet.Clear();
  AutoTArray<nsCString, 20> iconFontsList;
  gfxFontUtils::GetPrefsFontList(kIconFontsPref, iconFontsList);
  for (auto& name : iconFontsList) {
    ToLowerCase(name);
    mIconFontsSet.Insert(name);
  }
}

void gfxPlatformFontList::InitializeCodepointsWithNoFonts() {
  auto& first = mCodepointsWithNoFonts[FontVisibility(0)];
  for (auto& bitset : mCodepointsWithNoFonts) {
@@ -3080,5 +3101,12 @@ bool gfxPlatformFontList::FontPrefs::LookupNameList(const nsACString& aPref,
  return false;
}

bool gfxPlatformFontList::IsKnownIconFontFamily(
    const nsAtom* aFamilyName) const {
  nsAtomCString fam(aFamilyName);
  ToLowerCase(fam);
  return mIconFontsSet.Contains(fam);
}

#undef LOG
#undef LOG_ENABLED
+4 −0
Original line number Diff line number Diff line
@@ -636,6 +636,9 @@ class gfxPlatformFontList : public gfxFontInfoLoader {
    return PR_GetCurrentThread() == sInitFontListThread;
  }

  bool IsKnownIconFontFamily(const nsAtom* aFamilyName) const;
  void LoadIconFontOverrideList();

  void Lock() MOZ_CAPABILITY_ACQUIRE(mLock) { mLock.Lock(); }
  void Unlock() MOZ_CAPABILITY_RELEASE(mLock) { mLock.Unlock(); }

@@ -1032,6 +1035,7 @@ class gfxPlatformFontList : public gfxFontInfoLoader {
      MOZ_GUARDED_BY(mLock);

  nsTArray<nsCString> mEnabledFontsList;
  nsTHashSet<nsCString> mIconFontsSet;

  mozilla::UniquePtr<mozilla::fontlist::FontList> mSharedFontList;

+4 −0
Original line number Diff line number Diff line
@@ -1718,6 +1718,10 @@ bool Gecko_IsFontTechSupported(StyleFontFaceSourceTechFlags aFlag) {
      StyleFontFaceSourceFormatKeyword::None, aFlag);
}

bool Gecko_IsKnownIconFontFamily(const nsAtom* aFamilyName) {
  return gfxPlatform::GetPlatform()->IsKnownIconFontFamily(aFamilyName);
}

bool Gecko_IsInServoTraversal() { return ServoStyleSet::IsInServoTraversal(); }

bool Gecko_IsMainThread() { return NS_IsMainThread(); }
Loading