PRInt32 error = 0; key.Cut(0, 23); PRUnichar uchar = key.ToInteger(&error, 16); if (error) continue; key.Cut(0, 4);
InitGlobals(nsIPresContext* aPresContext){  NS_ASSERTION(!gInitialized, "Error -- already initialized");  gInitialized = PR_TRUE;  PRUint32 count = nsMathMLOperators::CountStretchyOperator();  if (!count) {    // nothing to stretch, so why bother...    return NS_OK;  }  // Allocate the placeholders for the preferred parts and variants  nsresult rv = NS_ERROR_OUT_OF_MEMORY;  gGlyphTableList = new nsGlyphTableList();  if (gGlyphTableList) {    nsGlyphTableList::gParts = new PRInt32[count];    nsGlyphTableList::gVariants = new PRInt32[count];    if (nsGlyphTableList::gParts && nsGlyphTableList::gVariants) {      rv = gGlyphTableList->Initialize();    }  }  if (NS_FAILED(rv) ||      !gGlyphTableList ||      !nsGlyphTableList::gParts ||      !nsGlyphTableList::gVariants) {    delete gGlyphTableList;    delete nsGlyphTableList::gParts;    delete nsGlyphTableList::gVariants;    gGlyphTableList = nsnull;    nsGlyphTableList::gParts = nsnull;    nsGlyphTableList::gVariants = nsnull;    return rv;  }  /*  else    The gGlyphTableList has been successfully registered as a shutdown observer.    It will be deleted at shutdown, even if a failure happens below.  */  PRUint32 i;  for (i = 0; i < count; i++) {    nsGlyphTableList::gParts[i] = kNotFound; // i.e., -1    nsGlyphTableList::gVariants[i] = kNotFound; // i.e., -1  }  nsGlyphTableList::gBaseFonts.Init(5);  nsCAutoString key;  nsAutoString value;  nsCOMPtr<nsIPersistentProperties> mathfontProp;  nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));  // Add the math fonts in the gGlyphTableList in order of preference ...  // Note: we only load font-names at this stage. The actual glyph tables will  // be loaded lazily (see nsGlyphTable::ElementAt()).  // Load the "mathfont.properties" file  value.Truncate();  rv = LoadProperties(value, mathfontProp);  if (NS_FAILED(rv)) return rv;  // Load the "mathfontPUA.properties" file  value.Assign(NS_LITERAL_STRING("PUA"));  rv = LoadProperties(value, gPUAProperties);  if (NS_FAILED(rv)) return rv;  // Get the default list of mathfonts to be used for stretchy characters  nsFont font(nsnull, 0, 0, 0, 0, 0);  NS_NAMED_LITERAL_CSTRING(defaultKey, "font.mathfont-family");  if (!GetPrefValue(prefBranch, defaultKey.get(), font.name)) {    // fallback to the internal default list    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;  MathFontEnumContext context = {aPresContext, &missingFamilyList};  font.EnumerateFamilies(MathFontEnumCallback, &context);  // Append a null separator  gGlyphTableList->AppendTable(nsnull);  // alert the user if some of the expected fonts are missing  if (!missingFamilyList.IsEmpty()) {    AlertMissingFonts(missingFamilyList);  }  // Let the particular characters have their preferred fonts  // First, look the prefs of the user  char **allKey = nsnull;  prefBranch->GetChildList("font.mathfont-family.", &count, &allKey);      for (i = 0; i < count; ++i) {#ifdef DEBUG_rbs    char str[50];    GetPrefValue(prefBranch, allKey[i], value);    value.ToCString(str, sizeof(str));    printf("Found user pref %s: %s\n", allKey[i], str);#endif    if ((30 < strlen(allKey[i])) &&         GetPrefValue(prefBranch, allKey[i], value)) {      // expected key:      // "font.mathfont-family.\uNNNN.base"     -- fonts for the base size      // "font.mathfont-family.\uNNNN.parts"    -- fonts for partial glyphs      // "font.mathfont-family.\uNNNN.variants" -- fonts for larger glyphs      PRInt32 error = 0;      // 22 is to skip "font.mathfont-family.\\u";      PRUnichar uchar = nsCAutoString(allKey[i]+22).ToInteger(&error, 16);      if (error) continue;      // 27 is to skip "font.mathfont-family.\\uNNNN"      SetPreferredFonts(uchar, allKey[i]+27, value);    }  }  NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(count, allKey);  // Next, look our internal settings  nsCOMPtr<nsISimpleEnumerator> iterator;  if (NS_SUCCEEDED(mathfontProp->Enumerate(getter_AddRefs(iterator)))) {    PRBool more;    while ((NS_SUCCEEDED(iterator->HasMoreElements(&more))) && more) {      nsCOMPtr<nsIPropertyElement> element;      if (NS_SUCCEEDED(iterator->GetNext(getter_AddRefs(element)))) {        if (NS_SUCCEEDED(element->GetKey(key))) {          // expected key:          // "font.mathfont-family.\uNNNN.base"     -- fonts for the base size          // "font.mathfont-family.\uNNNN.parts"    -- fonts for partial glyphs          // "font.mathfont-family.\uNNNN.variants" -- fonts for larger glyphs          if ((30 < key.Length()) &&               (0 == key.Find("font.mathfont-family.\\u")) &&              !GetPrefValue(prefBranch, key.get(), value) && // priority to user              NS_SUCCEEDED(element->GetValue(value))) {            PRInt32 error = 0;            key.Cut(0, 23); // 23 is the length of "font.mathfont-family.\\u";            PRUnichar uchar = key.ToInteger(&error, 16);            if (error) continue;            key.Cut(0, 4); // the digits of the unicode point ("NNNN")            Clean(value);            SetPreferredFonts(uchar, key.get(), value);          }        }      }    }  }  return rv;}