rv = nsFreeTypeInitGlobals(); if (NS_FAILED(rv)) { FreeGlobals(); return NS_ERROR_OUT_OF_MEMORY; }
InitGlobals(void){#ifdef NS_FONT_DEBUG  char* debug = PR_GetEnv("NS_FONT_DEBUG");  if (debug) {    PR_sscanf(debug, "%lX", &gDebug);  }#endif  nsServiceManager::GetService(kCharSetManagerCID,    NS_GET_IID(nsICharsetConverterManager2), (nsISupports**) &gCharSetManager);  if (!gCharSetManager) {    FreeGlobals();    return NS_ERROR_FAILURE;  }  nsServiceManager::GetService(kPrefCID, NS_GET_IID(nsIPref),    (nsISupports**) &gPref);  if (!gPref) {    FreeGlobals();    return NS_ERROR_FAILURE;  }  nsCompressedCharMap empty_ccmapObj;  gEmptyCCMap = empty_ccmapObj.NewCCMap();  if (!gEmptyCCMap)    return NS_ERROR_OUT_OF_MEMORY;  // get the "disable double byte font special chars" setting  PRBool val = PR_TRUE;  nsresult rv = gPref->GetBoolPref("font.allow_double_byte_special_chars", &val);  if (NS_SUCCEEDED(rv))    gAllowDoubleByteSpecialChars = val;  // setup the double byte font special chars glyph map  nsCompressedCharMap specialchars_ccmapObj;  for (int i=0; gDoubleByteSpecialChars[i]; i++) {    specialchars_ccmapObj.SetChar(gDoubleByteSpecialChars[i]);  }  gDoubleByteSpecialCharsCCMap = specialchars_ccmapObj.NewCCMap();  if (!gDoubleByteSpecialCharsCCMap)    return NS_ERROR_OUT_OF_MEMORY;  PRInt32 scale_minimum = 0;  rv = gPref->GetIntPref("font.scale.outline.min", &scale_minimum);  if (NS_SUCCEEDED(rv)) {    gOutlineScaleMinimum = scale_minimum;    SIZE_FONT_PRINTF(("gOutlineScaleMinimum = %d", gOutlineScaleMinimum));  }  val = PR_TRUE;  rv = gPref->GetBoolPref("font.scale.aa_bitmap.enable", &val);  if (NS_SUCCEEDED(rv)) {    gAABitmapScaleEnabled = val;    SIZE_FONT_PRINTF(("gAABitmapScaleEnabled = %d", gAABitmapScaleEnabled));  }  val = PR_FALSE;  rv = gPref->GetBoolPref("font.scale.aa_bitmap.always", &val);  if (NS_SUCCEEDED(rv)) {    gAABitmapScaleAlways = val;    SIZE_FONT_PRINTF(("gAABitmapScaleAlways = %d", gAABitmapScaleAlways));  }  rv = gPref->GetIntPref("font.scale.aa_bitmap.min", &scale_minimum);  if (NS_SUCCEEDED(rv)) {    gAABitmapScaleMinimum = scale_minimum;    SIZE_FONT_PRINTF(("gAABitmapScaleMinimum = %d", gAABitmapScaleMinimum));  }  PRInt32 percent = 0;  rv = gPref->GetIntPref("font.scale.aa_bitmap.undersize", &percent);  if ((NS_SUCCEEDED(rv)) && (percent)) {    gAABitmapUndersize = percent/100.0;    SIZE_FONT_PRINTF(("gAABitmapUndersize = %g", gAABitmapUndersize));  }  percent = 0;  rv = gPref->GetIntPref("font.scale.aa_bitmap.oversize", &percent);  if ((NS_SUCCEEDED(rv)) && (percent)) {    gAABitmapOversize = percent/100.0;    SIZE_FONT_PRINTF(("gAABitmapOversize = %g", gAABitmapOversize));  }  PRInt32 int_val = 0;  rv = gPref->GetIntPref("font.scale.aa_bitmap.dark_text.min", &int_val);  if (NS_SUCCEEDED(rv)) {    gAASBDarkTextMinValue = int_val;    SIZE_FONT_PRINTF(("gAASBDarkTextMinValue = %d", gAASBDarkTextMinValue));  }  nsXPIDLCString str;  rv = gPref->GetCharPref("font.scale.aa_bitmap.dark_text.gain",                           getter_Copies(str));  if (NS_SUCCEEDED(rv)) {    gAASBDarkTextGain = atof(str.get());    SIZE_FONT_PRINTF(("gAASBDarkTextGain = %g", gAASBDarkTextGain));  }  int_val = 0;  rv = gPref->GetIntPref("font.scale.aa_bitmap.light_text.min", &int_val);  if (NS_SUCCEEDED(rv)) {    gAASBLightTextMinValue = int_val;    SIZE_FONT_PRINTF(("gAASBLightTextMinValue = %d", gAASBLightTextMinValue));  }  rv = gPref->GetCharPref("font.scale.aa_bitmap.light_text.gain",                           getter_Copies(str));  if (NS_SUCCEEDED(rv)) {    gAASBLightTextGain = atof(str.get());    SIZE_FONT_PRINTF(("gAASBLightTextGain = %g", gAASBLightTextGain));  }  rv = gPref->GetIntPref("font.scale.bitmap.min", &scale_minimum);  if (NS_SUCCEEDED(rv)) {    gBitmapScaleMinimum = scale_minimum;    SIZE_FONT_PRINTF(("gBitmapScaleMinimum = %d", gBitmapScaleMinimum));  }  percent = 0;  gPref->GetIntPref("font.scale.bitmap.oversize", &percent);  if (percent) {    gBitmapOversize = percent/100.0;    SIZE_FONT_PRINTF(("gBitmapOversize = %g", gBitmapOversize));  }  percent = 0;  gPref->GetIntPref("font.scale.bitmap.undersize", &percent);  if (percent) {    gBitmapUndersize = percent/100.0;    SIZE_FONT_PRINTF(("gBitmapUndersize = %g", gBitmapUndersize));  }  gFFRENodes = new nsHashtable();  if (!gFFRENodes) {    FreeGlobals();    return NS_ERROR_OUT_OF_MEMORY;  }  gAFRENodes = new nsHashtable();  if (!gAFRENodes) {    FreeGlobals();    return NS_ERROR_OUT_OF_MEMORY;  }  gCachedFFRESearches = new nsHashtable();  if (!gCachedFFRESearches) {    FreeGlobals();    return NS_ERROR_OUT_OF_MEMORY;  }  gFamilies = new nsHashtable();  if (!gFamilies) {    FreeGlobals();    return NS_ERROR_OUT_OF_MEMORY;  }  gAliases = new nsHashtable();  if (!gAliases) {    FreeGlobals();    return NS_ERROR_OUT_OF_MEMORY;  }  nsFontFamilyName* f = gFamilyNameTable;  while (f->mName) {    nsCStringKey key(f->mName);    gAliases->Put(&key, f->mXName);    f++;  }  gWeights = new nsHashtable();  if (!gWeights) {    FreeGlobals();    return NS_ERROR_OUT_OF_MEMORY;  }  nsFontPropertyName* p = gWeightNames;  while (p->mName) {    nsCStringKey key(p->mName);    gWeights->Put(&key, (void*) p->mValue);    p++;  }  gStretches = new nsHashtable();  if (!gStretches) {    FreeGlobals();    return NS_ERROR_OUT_OF_MEMORY;  }  p = gStretchNames;  while (p->mName) {    nsCStringKey key(p->mName);    gStretches->Put(&key, (void*) p->mValue);    p++;  }  gCharSetMaps = new nsHashtable();  if (!gCharSetMaps) {    FreeGlobals();    return NS_ERROR_OUT_OF_MEMORY;  }  nsFontCharSetMap* charSetMap = gCharSetMap;  while (charSetMap->mName) {    nsCStringKey key(charSetMap->mName);    gCharSetMaps->Put(&key, charSetMap);    charSetMap++;  }  gSpecialCharSets = new nsHashtable();  if (!gSpecialCharSets) {    FreeGlobals();    return NS_ERROR_OUT_OF_MEMORY;  }  nsFontCharSetMap* specialCharSetMap = gSpecialCharSetMap;  while (specialCharSetMap->mName) {    nsCStringKey key(specialCharSetMap->mName);    gSpecialCharSets->Put(&key, specialCharSetMap);    specialCharSetMap++;  }  gUnicode = NS_NewAtom("x-unicode");  if (!gUnicode) {    FreeGlobals();    return NS_ERROR_OUT_OF_MEMORY;  }  gUserDefined = NS_NewAtom(USER_DEFINED);  if (!gUserDefined) {    FreeGlobals();    return NS_ERROR_OUT_OF_MEMORY;  }  // the user's locale  nsCOMPtr<nsILanguageAtomService> langService;  langService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID);  if (langService) {    langService->GetLocaleLanguageGroup(&gUsersLocale);  }  if (!gUsersLocale) {    gUsersLocale = NS_NewAtom("x-western");  }  gWesternLocale = NS_NewAtom("x-western");  if (!gUsersLocale) {    FreeGlobals();    return NS_ERROR_OUT_OF_MEMORY;  }  if (gAABitmapScaleEnabled) {    rv = nsX11AlphaBlendInitGlobals(GDK_DISPLAY());    if (NS_SUCCEEDED(rv)) {      // disable Anti-Aliased Scaled Bitmaps if the      // hardware does not support it      gAABitmapScaleEnabled = nsX11AlphaBlend::CanAntiAlias();    }    else      gAABitmapScaleEnabled = PR_FALSE;  }  if (gAABitmapScaleEnabled) {      gAABitmapScaleEnabled = nsXFontAAScaledBitmap::InitGlobals(GDK_DISPLAY(),                                     DefaultScreen(GDK_DISPLAY()));  }  #ifdef ENABLE_X_FONT_BANNING  /* get the font banning pattern */  nsXPIDLCString fbpattern;  rv = gPref->GetCharPref("font.x11.rejectfontpattern", getter_Copies(fbpattern));  if (NS_SUCCEEDED(rv)) {    gFontRejectRegEx = new regex_t;    if (!gFontRejectRegEx) {      FreeGlobals();      return NS_ERROR_OUT_OF_MEMORY;    }        /* Compile the pattern - and return an error if we get an invalid pattern... */    if (regcomp(gFontRejectRegEx, fbpattern.get(), REG_EXTENDED|REG_NOSUB) != REG_OK) {      PR_LOG(FontMetricsGTKLM, PR_LOG_DEBUG, ("Invalid rejectfontpattern '%s'\n", fbpattern.get()));      BANNED_FONT_PRINTF(("Invalid font.x11.rejectfontpattern '%s'", fbpattern.get()));      delete gFontRejectRegEx;      gFontRejectRegEx = nsnull;            FreeGlobals();      return NS_ERROR_INVALID_ARG;    }      }  rv = gPref->GetCharPref("font.x11.acceptfontpattern", getter_Copies(fbpattern));  if (NS_SUCCEEDED(rv)) {    gFontAcceptRegEx = new regex_t;    if (!gFontAcceptRegEx) {      FreeGlobals();      return NS_ERROR_OUT_OF_MEMORY;    }        /* Compile the pattern - and return an error if we get an invalid pattern... */    if (regcomp(gFontAcceptRegEx, fbpattern.get(), REG_EXTENDED|REG_NOSUB) != REG_OK) {      PR_LOG(FontMetricsGTKLM, PR_LOG_DEBUG, ("Invalid acceptfontpattern '%s'\n", fbpattern.get()));      BANNED_FONT_PRINTF(("Invalid font.x11.acceptfontpattern '%s'", fbpattern.get()));      delete gFontAcceptRegEx;      gFontAcceptRegEx = nsnull;            FreeGlobals();      return NS_ERROR_INVALID_ARG;    }      }#endif /* ENABLE_X_FONT_BANNING */  gInitialized = 1;  return NS_OK;}