Bug 1000745 - Part 1: Remove obsolete font.mathfont-family* preferences. r=karlt
authorFrédéric Wang <fred.wang@free.fr>
Thu, 24 Apr 2014 02:33:00 -0400
changeset 180338 7564b6bb7720dd9f77cb341759a2cba97e39f821
parent 180337 82bec52d69158741b92fcfbaadacef6f0b07a0c6
child 180339 570a6e27b76ee5b9fc689ba1b53a1de522e952a9
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewerskarlt
bugs1000745
milestone31.0a1
Bug 1000745 - Part 1: Remove obsolete font.mathfont-family* preferences. r=karlt
layout/mathml/mathfont.properties
layout/mathml/nsMathMLChar.cpp
--- a/layout/mathml/mathfont.properties
+++ b/layout/mathml/mathfont.properties
@@ -16,29 +16,16 @@ font.mathfont-glyph-tables = MathJax_Mai
 font.mathfont-glyph-tables = MathJax_Main, STIXNonUnicode, STIXSizeOneSym, Standard Symbols L
 %endif
 
 # The ordered list of fonts with which to attempt to stretch MathML
 # characters is controlled by setting pref("font.mathfont-family",
 # "CMSY10, CMEX10, ...") for example, or by setting the font-family list in
 # :-moz-math-stretchy in mathml.css.
 #
-# Preferred fonts for particular stretchy characters may be specified in
-# preferences.  Each entry is specified using the Unicode format of the
-# character, and the comma-separated list of fonts like in the font-family
-# property of CSS.  A character can request different fonts for its variants
-# and for its parts.
-# e.g. pref("font.mathfont-family.\\u2264.base", "CMSY10, etc")
-# - A ".base" extension indicates the ordered list fonts to look for the glyph
-#   at its base size.
-# - The ".variants" extension indicates the ordered list of fonts where to
-#   look for glyphs of larger sizes.
-# - The ".parts" extension indicates the ordered list of fonts that should be
-#   used to look for the partial glyphs to be used to build up the character.
-#
 # Note: setting base fonts for non-stretchy characters only works
 # for operators that are ultimately handled by nsMathMLChar.
 # @see how |useMathMLChar| is set in nsMathMLmoFrame::Stretch() & Paint().
 
 # Operator Dictionary indexed on the "form" (i.e., infix, prefix, or suffix).
 # Each entry lists the attributes of the operator, using its Unicode format.
 
 operator.\u0021.postfix = lspace:1 rspace:0 # !
--- a/layout/mathml/nsMathMLChar.cpp
+++ b/layout/mathml/nsMathMLChar.cpp
@@ -34,18 +34,16 @@ using namespace mozilla;
 
 //#define NOISY_SEARCH 1
 
 static const float kLargeOpFactor = float(M_SQRT2);
 static const float kIntegralFactor = 2.0;
 
 // -----------------------------------------------------------------------------
 static const nsGlyphCode kNullGlyph = {{{0, 0}}, 0};
-typedef enum {eExtension_base, eExtension_variants, eExtension_parts}
-  nsMathfontPrefExtension;
 
 // -----------------------------------------------------------------------------
 // nsGlyphTable is a class that provides an interface for accessing glyphs
 // of stretchy chars. It acts like a table that stores the variants of bigger
 // sizes (if any) and the partial glyphs needed to build extensible symbols.
 //
 // Bigger sizes (if any) of the char can then be retrieved with BigOf(...).
 // Partial glyphs can be retrieved with ElementAt(...).
@@ -676,79 +674,16 @@ nsGlyphTableList::GetGlyphTableFor(const
     }
   }
   // Fall back to default Unicode table
   return &mUnicodeTable;
 }
 
 // -----------------------------------------------------------------------------
 
-// Lookup the preferences:
-// "font.mathfont-family.\uNNNN.base"     -- fonts for the base size
-// "font.mathfont-family.\uNNNN.variants" -- fonts for larger glyphs
-// "font.mathfont-family.\uNNNN.parts"    -- fonts for partial glyphs
-// Given the char code and mode of stretch, retrieve the preferred extension
-// font families.
-static bool
-GetFontExtensionPref(char16_t aChar,
-                     nsMathfontPrefExtension aExtension, nsString& aValue)
-{
-  // initialize OUT param
-  aValue.Truncate();
-
-  // We are going to try two keys because some users specify their pref as 
-  // user_pref("font.mathfont-family.\uNNNN.base", "...") rather than
-  // user_pref("font.mathfont-family.\\uNNNN.base", "...").
-  // The \uNNNN in the former is interpreted as an UTF16 escape sequence by
-  // JavaScript and is converted to the internal UTF8 string that JavaScript
-  // uses. 
-  // But clueless users who are not savvy of JavaScript have no idea as to what 
-  // is going on and are baffled as to why their pref setting is not working.
-  // So to save countless explanations, we are going to support both keys.
-
-  static const char* kMathFontPrefix = "font.mathfont-family.";
-
-  nsAutoCString extension;
-  switch (aExtension)
-  {
-    case eExtension_base:
-      extension.AssignLiteral(".base");
-      break;
-    case eExtension_variants:
-      extension.AssignLiteral(".variants");
-      break;
-    case eExtension_parts:
-      extension.AssignLiteral(".parts");
-      break;
-    default:
-      return false;
-  }
-
-  // .\\uNNNN key
-  nsAutoCString key;
-  key.AssignASCII(kMathFontPrefix);
-  char ustr[10];
-  PR_snprintf(ustr, sizeof(ustr), "\\u%04X", aChar);
-  key.Append(ustr);
-  key.Append(extension);
-  // .\uNNNN key
-  nsAutoCString alternateKey;
-  alternateKey.AssignASCII(kMathFontPrefix);
-  NS_ConvertUTF16toUTF8 tmp(&aChar, 1);
-  alternateKey.Append(tmp);
-  alternateKey.Append(extension);
-
-  aValue = Preferences::GetString(key.get());
-  if (aValue.IsEmpty()) {
-    aValue = Preferences::GetString(alternateKey.get());
-  }
-  return !aValue.IsEmpty();
-}
-
-
 static bool
 MathFontEnumCallback(const nsString& aFamily, bool aGeneric, void *aData)
 {
   if (!gGlyphTableList->AddGlyphTable(aFamily))
     return false; // stop in low-memory situations
   return true; // don't stop
 }
 
@@ -792,19 +727,16 @@ InitGlobals(nsPresContext* aPresContext)
   // stretchy characters.
   // We just want to iterate over the font-family list using the
   // callback mechanism that nsFont has...
   nsFont font("", 0, 0, 0, 0, 0, 0);
   NS_NAMED_LITERAL_CSTRING(defaultKey, "font.mathfont-glyph-tables");
   rv = mathfontProp->GetStringProperty(defaultKey, font.name);
   if (NS_FAILED(rv)) return rv;
 
-  // Parse the font list and append an entry for each family to gGlyphTableList
-  nsAutoString missingFamilyList;
-
   font.EnumerateFamilies(MathFontEnumCallback, nullptr);
   return rv;
 }
 
 // -----------------------------------------------------------------------------
 // And now the implementation of nsMathMLChar
 
 nsMathMLChar::~nsMathMLChar()
@@ -1584,40 +1516,32 @@ nsMathMLChar::StretchInternal(nsPresCont
   // So first set our direction back to its instrinsic value
   nsStretchDirection direction = nsMathMLOperators::GetStretchyDirection(mData);
 
   // Set default font and get the default bounding metrics
   // mStyleContext is a leaf context used only when stretching happens.
   // For the base size, the default font should come from the parent context
   nsFont font = mStyleContext->GetParent()->StyleFont()->mFont;
 
-  // Override with specific fonts if applicable for this character
-  nsAutoString families;
-  if (GetFontExtensionPref(mData[0], eExtension_base, families)) {
-    font.name = families;
-  }
-
-  // Don't modify this nsMathMLChar when doing GetMaxWidth()
-  bool maxWidth = (NS_STRETCH_MAXWIDTH & aStretchHint) != 0;
-
   nsRefPtr<nsFontMetrics> fm;
   aPresContext->DeviceContext()->
     GetMetricsFor(font,
                   mStyleContext->StyleFont()->mLanguage,
                   aPresContext->GetUserFontSet(),
                   aPresContext->GetTextPerfMetrics(),
                   *getter_AddRefs(fm));
   uint32_t len = uint32_t(mData.Length());
   nsAutoPtr<gfxTextRun> textRun;
   textRun = fm->GetThebesFontGroup()->
     MakeTextRun(static_cast<const char16_t*>(mData.get()), len, aThebesContext,
                 aPresContext->AppUnitsPerDevPixel(), 0);
   aDesiredStretchSize = MeasureTextRun(aThebesContext, textRun);
   mGlyphs[0] = textRun;
 
+  bool maxWidth = (NS_STRETCH_MAXWIDTH & aStretchHint) != 0;
   if (!maxWidth) {
     mUnscaledAscent = aDesiredStretchSize.ascent;
   }
 
   //////////////////////////////////////////////////////////////////////////////
   // 1. Check the common situations where stretching is not actually needed
   //////////////////////////////////////////////////////////////////////////////
 
@@ -1699,51 +1623,20 @@ nsMathMLChar::StretchInternal(nsPresCont
       done = true;
   }
 
   //////////////////////////////////////////////////////////////////////////////
   // 2/3. Search for a glyph or set of part glyphs of appropriate size
   //////////////////////////////////////////////////////////////////////////////
 
   bool glyphFound = false;
-  nsAutoString cssFamilies;
-
-  if (!done) {
-    font = mStyleContext->StyleFont()->mFont;
-    cssFamilies = font.name;
-  }
-
-  // See if there are preferred fonts for the variants of this char
-  if (!done && GetFontExtensionPref(mData[0], eExtension_variants, families)) {
-    font.name = families;
-
-    StretchEnumContext enumData(this, aPresContext, aThebesContext,
-                                aStretchDirection, targetSize, aStretchHint,
-                                aDesiredStretchSize, font.name, glyphFound);
-    enumData.mTryParts = false;
-
-    done = !font.EnumerateFamilies(StretchEnumContext::EnumCallback, &enumData);
-  }
-
-  // See if there are preferred fonts for the parts of this char
-  if (!done && !largeopOnly
-      && GetFontExtensionPref(mData[0], eExtension_parts, families)) {
-    font.name = families;
-
-    StretchEnumContext enumData(this, aPresContext, aThebesContext,
-                                aStretchDirection, targetSize, aStretchHint,
-                                aDesiredStretchSize, font.name, glyphFound);
-    enumData.mTryVariants = false;
-
-    done = !font.EnumerateFamilies(StretchEnumContext::EnumCallback, &enumData);
-  }
 
   if (!done) { // normal case
     // Use the css font-family but add preferred fallback fonts.
-    font.name = cssFamilies;
+    font = mStyleContext->StyleFont()->mFont;
     NS_NAMED_LITERAL_CSTRING(defaultKey, "font.mathfont-family");
     nsAdoptingString fallbackFonts = Preferences::GetString(defaultKey.get());
     if (!fallbackFonts.IsEmpty()) {
       AddFallbackFonts(font.name, fallbackFonts);
     }
 
 #ifdef NOISY_SEARCH
     printf("Searching in "%s" for a glyph of appropriate size for: 0x%04X:%c\n",