Ticket #4797: use_only_generic_fonts.patch

File use_only_generic_fonts.patch, 7.1 KB (added by mikeperry, 7 years ago)

Camilo's generic-font limiting patch

  • layout/base/nsPresContext.cpp

    diff --git a/layout/base/nsPresContext.cpp b/layout/base/nsPresContext.cpp
    a b nsPresContext::nsPresContext(nsIDocument 
    221221
    222222  SetBackgroundImageDraw(true);         // always draw the background
    223223  SetBackgroundColorDraw(true);
    224224
    225225  mBackgroundColor = NS_RGB(0xFF, 0xFF, 0xFF);
    226226 
    227227  mUseDocumentColors = true;
    228228  mUseDocumentFonts = true;
     229  mUseOnlyGenericFonts = false;
    229230
    230231  // the minimum font-size is unconstrained by default
    231232
    232233  mLinkColor = NS_RGB(0x00, 0x00, 0xEE);
    233234  mActiveLinkColor = NS_RGB(0xEE, 0x00, 0x00);
    234235  mVisitedLinkColor = NS_RGB(0x55, 0x1A, 0x8B);
    235236  mUnderlineLinks = true;
    236237  mSendAfterPaintToContent = false;
    nsPresContext::GetUserPreferences() 
    745746    Preferences::GetInt("browser.display.focus_ring_style", mFocusRingStyle);
    746747
    747748  mBodyTextColor = mDefaultColor;
    748749 
    749750  // * use fonts?
    750751  mUseDocumentFonts =
    751752    Preferences::GetInt("browser.display.use_document_fonts") != 0;
    752753
     754  // *use only generic fonts?
     755  mUseOnlyGenericFonts =
     756    Preferences::GetInt("browser.display.use_only_generic_fonts") != 0;
     757
    753758  // * replace backslashes with Yen signs? (bug 245770)
    754759  mEnableJapaneseTransform =
    755760    Preferences::GetBool("layout.enable_japanese_specific_transform");
    756761
    757762  mPrefScrollbarSide = Preferences::GetInt("layout.scrollbar.side");
    758763
    759764  ResetCachedFontPrefs();
    760765
  • layout/base/nsPresContext.h

    diff --git a/layout/base/nsPresContext.h b/layout/base/nsPresContext.h
    a b class nsIDOMMediaQueryList; 
    109109#ifdef MOZ_REFLOW_PERF
    110110class nsRenderingContext;
    111111#endif
    112112
    113113// supported values for cached bool types
    114114enum nsPresContext_CachedBoolPrefType {
    115115  kPresContext_UseDocumentColors = 1,
    116116  kPresContext_UseDocumentFonts,
    117   kPresContext_UnderlineLinks
     117  kPresContext_UnderlineLinks,
     118  kPresContext_UseOnlyGenericFonts
    118119};
    119120
    120121// supported values for cached integer pref types
    121122enum nsPresContext_CachedIntPrefType {
    122123  kPresContext_ScrollbarSide = 1,
    123124  kPresContext_BidiDirection
    124125};
    125126
    public: 
    332333    // this switch statement away.
    333334    switch (aPrefType) {
    334335    case kPresContext_UseDocumentFonts:
    335336      return mUseDocumentFonts;
    336337    case kPresContext_UseDocumentColors:
    337338      return mUseDocumentColors;
    338339    case kPresContext_UnderlineLinks:
    339340      return mUnderlineLinks;
     341    case kPresContext_UseOnlyGenericFonts:
     342      return mUseOnlyGenericFonts;
    340343    default:
    341344      NS_ERROR("Invalid arg passed to GetCachedBoolPref");
    342345    }
    343346
    344347    return false;
    345348  }
    346349
    347350  /** Get a cached integer pref, by its type */
    protected: 
    11861189  PRUint32              mInterruptChecksToSkip;
    11871190
    11881191  mozilla::TimeStamp    mReflowStartTime;
    11891192
    11901193  unsigned              mHasPendingInterrupt : 1;
    11911194  unsigned              mInterruptsEnabled : 1;
    11921195  unsigned              mUseDocumentFonts : 1;
    11931196  unsigned              mUseDocumentColors : 1;
     1197  unsigned              mUseOnlyGenericFonts : 1;
    11941198  unsigned              mUnderlineLinks : 1;
    11951199  unsigned              mSendAfterPaintToContent : 1;
    11961200  unsigned              mUseFocusColors : 1;
    11971201  unsigned              mFocusRingOnAnything : 1;
    11981202  unsigned              mFocusRingStyle : 1;
    11991203  unsigned              mDrawImageBackground : 1;
    12001204  unsigned              mDrawColorBackground : 1;
    12011205  unsigned              mNeverAnimate : 1;
  • layout/style/nsRuleNode.cpp

    diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp
    a b nsRuleNode::ComputeFontData(void* aStart 
    31123112  // -moz-system-font), we won't cache in the rule tree even though we
    31133113  // could.  However, it's pretty unlikely authors will do that
    31143114  // (although there is a pretty good chance they'll fully specify it
    31153115  // using the 'font' shorthand).
    31163116
    31173117  bool useDocumentFonts =
    31183118    mPresContext->GetCachedBoolPref(kPresContext_UseDocumentFonts);
    31193119
     3120  bool useOnlyGenericFonts =
     3121    mPresContext->GetCachedBoolPref(kPresContext_UseOnlyGenericFonts);
     3122
     3123
    31203124  // See if we are in the chrome
    31213125  // We only need to know this to determine if we have to use the
    31223126  // document fonts (overriding the useDocumentFonts flag).
    31233127  if (!useDocumentFonts && mPresContext->IsChrome()) {
    31243128    // if we are not using document fonts, but this is a XUL document,
    31253129    // then we use the document fonts anyway
    31263130    useDocumentFonts = true;
     3131    useOnlyGenericFonts = false;
    31273132  }
    31283133
    31293134  // Figure out if we are a generic font
    31303135  PRUint8 generic = kGenericFont_NONE;
    31313136  // XXXldb What if we would have had a string if we hadn't been doing
    31323137  // the optimization with a non-null aStartStruct?
    31333138  const nsCSSValue* familyValue = aRuleData->ValueForFontFamily();
    31343139  if (eCSSUnit_Families == familyValue->GetUnit()) {
    31353140    familyValue->GetStringValue(font->mFont.name);
    31363141    // XXXldb Do we want to extract the generic for this if it's not only a
    31373142    // generic?
    31383143    nsFont::GetGenericID(font->mFont.name, &generic);
    31393144
    31403145    // If we aren't allowed to use document fonts, then we are only entitled
    31413146    // to use the user's default variable-width font and fixed-width font
    3142     if (!useDocumentFonts) {
     3147    if (!useDocumentFonts || useOnlyGenericFonts ) {
    31433148      // Extract the generic from the specified font family...
    31443149      nsAutoString genericName;
    31453150      if (!font->mFont.EnumerateFamilies(ExtractGeneric, &genericName)) {
    31463151        // The specified font had a generic family.
    31473152        font->mFont.name = genericName;
    31483153        nsFont::GetGenericID(genericName, &generic);
    31493154
    31503155        // ... and only use it if it's -moz-fixed or monospace
     3156        //     and we are are not using documentfonts
    31513157        if (generic != kGenericFont_moz_fixed &&
    3152             generic != kGenericFont_monospace) {
     3158            generic != kGenericFont_monospace &&
     3159            !useDocumentFonts) {
    31533160          font->mFont.name.Truncate();
    31543161          generic = kGenericFont_NONE;
    31553162        }
    31563163      } else {
    31573164        // The specified font did not have a generic family.
    31583165        font->mFont.name.Truncate();
    31593166        generic = kGenericFont_NONE;
    31603167      }
  • modules/libpref/src/init/all.js

    diff --git a/modules/libpref/src/init/all.js b/modules/libpref/src/init/all.js
    a b pref("dom.enable_performance", true); 
    114114
    115115// Fastback caching - if this pref is negative, then we calculate the number
    116116// of content viewers to cache based on the amount of available memory.
    117117pref("browser.sessionhistory.max_total_viewers", -1);
    118118
    119119pref("ui.use_native_colors", true);
    120120pref("ui.click_hold_context_menus", false);
    121121pref("browser.display.use_document_fonts",  1);  // 0 = never, 1 = quick, 2 = always
     122pref("browser.display.use_only_generic_fonts", 0);
    122123pref("browser.display.use_document_colors", true);
    123124pref("browser.display.use_system_colors",   false);
    124125pref("browser.display.foreground_color",    "#000000");
    125126pref("browser.display.background_color",    "#FFFFFF");
    126127pref("browser.display.force_inline_alttext", false); // true = force ALT text for missing images to be layed out inline
    127128// 0 = no external leading,
    128129// 1 = use external leading only when font provides,
    129130// 2 = add extra leading both internal leading and external leading are zero