[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [torbrowser/master] Update font limiting patch to exempt @font-face.



commit 11c13307994168e97e95ac3a5d92cbd768cd12c6
Author: Mike Perry <mikeperry-git@xxxxxxxxxx>
Date:   Tue Feb 12 22:44:08 2013 -0800

    Update font limiting patch to exempt @font-face.
    
    This provides substantial rendering improvements, and probably will also make
    non-latin script users much happier.
---
 ...11-Limit-the-number-of-fonts-per-document.patch |   81 +++++++++++++++++---
 1 files changed, 71 insertions(+), 10 deletions(-)

diff --git a/src/current-patches/firefox/0011-Limit-the-number-of-fonts-per-document.patch b/src/current-patches/firefox/0011-Limit-the-number-of-fonts-per-document.patch
index 80660db..dbf34a9 100644
--- a/src/current-patches/firefox/0011-Limit-the-number-of-fonts-per-document.patch
+++ b/src/current-patches/firefox/0011-Limit-the-number-of-fonts-per-document.patch
@@ -1,4 +1,4 @@
-From 2786933e3a395e1058da8850a3710f01ca416463 Mon Sep 17 00:00:00 2001
+From 6b7306a50a304bcf12b04784115f21f34b71864a Mon Sep 17 00:00:00 2001
 From: Mike Perry <mikeperry-git@xxxxxxxxxxxxxx>
 Date: Wed, 5 Dec 2012 12:25:21 -0800
 Subject: [PATCH 11/26] Limit the number of fonts per document.
@@ -14,6 +14,11 @@ browser.display.use_document_fonts was set to 0 for subsequent font queries.
 
 If a pref is not set or is negative, that limit does not apply.
 
+The use of "User Fonts" (aka WebFonts, aka @font-face fonts) are exempt from
+both of these limits. The patch also makes such fonts take precedence over
+local fonts. This vastly improves typography on many sites that would
+otherwise hit these limits.
+
 This is done to address:
 https://www.torproject.org/projects/torbrowser/design/#fingerprinting-linkability
 ---
@@ -21,8 +26,8 @@ https://www.torproject.org/projects/torbrowser/design/#fingerprinting-linkabilit
  layout/base/nsPresContext.cpp |  100 +++++++++++++++++++++++++++++++++++++++++
  layout/base/nsPresContext.h   |    9 ++++
  layout/style/nsCSSParser.cpp  |    1 +
- layout/style/nsRuleNode.cpp   |   14 +++++-
- 5 files changed, 122 insertions(+), 3 deletions(-)
+ layout/style/nsRuleNode.cpp   |   56 ++++++++++++++++++++++-
+ 5 files changed, 164 insertions(+), 3 deletions(-)
 
 diff --git a/gfx/thebes/gfxPangoFonts.cpp b/gfx/thebes/gfxPangoFonts.cpp
 index c94a299..88c8b8e 100644
@@ -201,10 +206,18 @@ index 37a19c4..30fd021 100644
        // because it's only being used to call EnumerateFamilies
        nsFont font(family, 0, 0, 0, 0, 0, 0);
 diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp
-index 64504fb..33ce21e 100644
+index 64504fb..86eff1f 100644
 --- a/layout/style/nsRuleNode.cpp
 +++ b/layout/style/nsRuleNode.cpp
-@@ -2954,6 +2954,7 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext,
+@@ -42,6 +42,7 @@
+ #include "mozilla/dom/Element.h"
+ #include "mozilla/LookAndFeel.h"
+ #include "mozilla/Util.h"
++#include "gfxUserFontSet.h"
+ 
+ #if defined(_MSC_VER) || defined(__MINGW32__)
+ #include <malloc.h>
+@@ -2954,6 +2955,7 @@ nsRuleNode::SetFont(nsPresContext* aPresContext, nsStyleContext* aContext,
      aPresContext->GetDefaultFont(kPresContext_DefaultVariableFont_ID,
                                   aFont->mLanguage);
  
@@ -212,11 +225,44 @@ index 64504fb..33ce21e 100644
    // -moz-system-font: enum (never inherit!)
    MOZ_STATIC_ASSERT(
      NS_STYLE_FONT_CAPTION        == LookAndFeel::eFont_Caption &&
-@@ -3439,14 +3440,15 @@ nsRuleNode::ComputeFontData(void* aStartStruct,
+@@ -3416,6 +3418,31 @@ static bool ExtractGeneric(const nsString& aFamily, bool aGeneric,
+   return true;
+ }
+ 
++struct smugglerStruct {
++  nsStyleFont *font;
++  gfxUserFontSet *userFonts;
++};
++
++/* This function forces the use of the first @font-face font we find */
++static bool ForceFirstWebFont(const nsString& aFamily, bool aGeneric,
++                              void *smuggled)
++{
++  smugglerStruct *sm = static_cast<smugglerStruct*>(smuggled);
++    
++  if (aGeneric) {
++    return true;
++  }
++
++  if (sm->userFonts->HasFamily(aFamily)) {
++    // Force use of this exact @font-face font since we have it.
++    sm->font->mFont.name = aFamily;
++
++    return false; // Stop enumeration. 
++  }
++
++  return true;
++}
++
+ const void*
+ nsRuleNode::ComputeFontData(void* aStartStruct,
+                             const nsRuleData* aRuleData,
+@@ -3439,14 +3466,16 @@ nsRuleNode::ComputeFontData(void* aStartStruct,
  
    bool useDocumentFonts =
      mPresContext->GetCachedBoolPref(kPresContext_UseDocumentFonts);
 +  bool isXUL = PR_FALSE;
++  bool forcedWebFont = false;
  
    // See if we are in the chrome
    // We only need to know this to determine if we have to use the
@@ -230,11 +276,26 @@ index 64504fb..33ce21e 100644
    }
  
    // Figure out if we are a generic font
-@@ -3460,9 +3462,13 @@ nsRuleNode::ComputeFontData(void* aStartStruct,
+@@ -3460,9 +3489,28 @@ nsRuleNode::ComputeFontData(void* aStartStruct,
      // generic?
      nsFont::GetGenericID(font->mFont.name, &generic);
  
-+    mPresContext->AddFontAttempt(font->mFont);
++    if (!isXUL) {
++      gfxUserFontSet *userFonts = mPresContext->GetUserFontSet();
++      if (userFonts) {
++        smugglerStruct sm;
++        sm.userFonts = userFonts;
++        sm.font = font;
++
++        if (!sm.font->mFont.EnumerateFamilies(ForceFirstWebFont, &sm)) {
++          isXUL = true; // Always allow WebFont use.
++          forcedWebFont = true;
++        }
++      }
++    }
++
++    if (!forcedWebFont && generic == kGenericFont_NONE)
++      mPresContext->AddFontAttempt(font->mFont);
 +
      // If we aren't allowed to use document fonts, then we are only entitled
      // to use the user's default variable-width font and fixed-width font
@@ -245,11 +306,11 @@ index 64504fb..33ce21e 100644
        // Extract the generic from the specified font family...
        nsAutoString genericName;
        if (!font->mFont.EnumerateFamilies(ExtractGeneric, &genericName)) {
-@@ -3498,6 +3504,8 @@ nsRuleNode::ComputeFontData(void* aStartStruct,
+@@ -3498,6 +3546,8 @@ nsRuleNode::ComputeFontData(void* aStartStruct,
                                 font);
    }
  
-+  if (font->mGenericID == kGenericFont_NONE)
++  if (!forcedWebFont && font->mGenericID == kGenericFont_NONE)
 +    mPresContext->AddFontUse(font->mFont);
    COMPUTE_END_INHERITED(Font, font)
  }



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits