if (gGlyphTableList) delete gGlyphTableList;
InitGlobals(nsIPresContext* aPresContext){  NS_ASSERTION(!gInitialized, "Error -- already initialized");  gInitialized = PR_TRUE;  PRInt32 count = nsMathMLOperators::CountStretchyOperator();  if (!count) {    // nothing to stretch, so why bother...    return NS_OK;  }  // Allocate the placeholders for the preferred parts and variants  nsGlyphTableList::gParts = new PRInt32[count];  if (!nsGlyphTableList::gParts)    return NS_ERROR_OUT_OF_MEMORY;  nsGlyphTableList::gVariants = new PRInt32[count];  if (!nsGlyphTableList::gVariants) {    delete nsGlyphTableList::gParts;    return NS_ERROR_OUT_OF_MEMORY;  }  PRInt32 i;  for (i = 0; i < count; i++) {    nsGlyphTableList::gParts[i] = kNotFound; // i.e., -1    nsGlyphTableList::gVariants[i] = kNotFound; // i.e., -1  }  // Allocate gGlyphTableList  nsresult rv = NS_ERROR_OUT_OF_MEMORY;  gGlyphTableList = new nsGlyphTableList();  if (gGlyphTableList) {    rv = gGlyphTableList->Initialize();  }  if (NS_FAILED(rv)) {    delete nsGlyphTableList::gParts;    delete nsGlyphTableList::gVariants;    if (gGlyphTableList) delete gGlyphTableList;    gGlyphTableList = 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.  */  nsCAutoString key;  nsAutoString value;  nsCOMPtr<nsIPersistentProperties> mathfontProp;  // 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);  nsAutoString familyList;  nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));  if (prefBranch) {    // first, try to see if the user has a value in the pref    nsCOMPtr<nsISupportsString> prefString;    prefBranch->GetComplexValue("font.mathfont-family",                                NS_GET_IID(nsISupportsString),                                getter_AddRefs(prefString));    if (prefString) {      prefString->GetData(familyList);    }  }  if (familyList.IsEmpty()) {    // fallback to the default list    rv = mathfontProp->GetStringProperty(NS_LITERAL_CSTRING("mathfont-family"),                                         value);    if (NS_FAILED(rv)) return rv;    font.name.Assign(value);  }  else {    font.name.Assign(familyList);  }  // 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 extension tables  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)) &&            NS_SUCCEEDED(element->GetValue(value))) {          // expected key: "mathfont-family.\uNNNN.parts" or          // "mathfont-family.\uNNNN.variants"          if ((22 <= key.Length()) && (0 == key.Find("mathfont-family.\\u"))) {            PRInt32 error = 0;            key.Cut(0, 18); // 18 is the length of "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);            SetPreferredTableList(uchar, key, value);          }        }      }    }  }  return rv;}