if (!aFont->GetXFont()) { aFont->LoadFont(); if (!aFont->GetXFont()) { mCCMap = mFontMetricsContext->mEmptyCCMap; return PR_FALSE;
PR_LOG(FontMetricsXlibLM, PR_LOG_DEBUG, ("# nsFontMetricsXlibContext new() for device=%p\n", aDevice));  NS_ENSURE_TRUE(aDevice != nsnull, NS_ERROR_NULL_POINTER);  #ifdef USE_XPRINT mPrinterMode = aPrintermode; #endif   mForceOutlineScaledFonts = PR_FALSE; mXlibRgbHandle = nsnull; mAllowDoubleByteSpecialChars = PR_TRUE;    mDevScale = 0.0f;  mScaleBitmapFontsWithDevScale = PR_FALSE;  mGlobalListInitalised = PR_FALSE;  mUserDefinedCCMap            = nsnull; mEmptyCCMap                  = nsnull; mDoubleByteSpecialCharsCCMap = nsnull;  mCharSetMap        = nsnull; mNoneCharSetMap    = nsnull; mSpecialCharSetMap = nsnull;    mOutlineScaleMinimum = 6; #ifdef USE_AASB  mAABitmapScaleEnabled = PR_TRUE; mAABitmapScaleAlways = PR_FALSE; mAABitmapScaleMinimum = 6; mAABitmapOversize = 1.1; mAABitmapUndersize = 0.9; #endif    mBitmapScaleMinimum = 10; mBitmapOversize = 1.2; mBitmapUndersize = 0.8;  #ifdef USE_AASB mAntiAliasMinimum = 8; #endif  mEmbeddedBitmapMaximumHeight = 1000000;  #ifdef USE_FREETYPE mEnableFreeType2 = PR_TRUE; mFreeType2Autohinted = PR_FALSE; mFreeType2Unhinted = PR_TRUE; #endif  #ifdef USE_AASB mAATTDarkTextMinValue = 64; mAATTDarkTextGain = 0.8; #endif   #ifdef ENABLE_X_FONT_BANNING mFontRejectRegEx = nsnull; mFontAcceptRegEx = nsnull; #endif   PR_LOG(FontMetricsXlibLM, PR_LOG_DEBUG, ("## CopyFontCharSetMapXlib start.\n"));  if (!CopyFontCharSetMapXlib(this)) { PR_LOG(FontMetricsXlibLM, PR_LOG_DEBUG, ("## CopyFontCharSetMapXlib FAILED.\n")); return NS_ERROR_OUT_OF_MEMORY; } PR_LOG(FontMetricsXlibLM, PR_LOG_DEBUG, ("## CopyFontCharSetMapXlib done.\n"));  #ifdef NS_FONT_DEBUG  const char *debug; #ifdef USE_XPRINT if (mPrinterMode) { debug = PR_GetEnv("NS_FONT_DEBUG_XPRINT"); } else #endif  { debug = PR_GetEnv("NS_FONT_DEBUG_XLIB"); }  if (!debug) { debug = PR_GetEnv("NS_FONT_DEBUG"); }  if (debug) { PR_sscanf(debug, "%lX", &gFontDebug); } #endif   NS_STATIC_CAST(nsDeviceContextX *, aDevice)->GetXlibRgbHandle(mXlibRgbHandle);  aDevice->GetCanonicalPixelScale(mDevScale);  mCharSetManager = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID); if (!mCharSetManager) { return NS_ERROR_FAILURE; }  mPref = do_GetService(NS_PREF_CONTRACTID); if (!mPref) { return NS_ERROR_FAILURE; }  nsCompressedCharMap empty_ccmapObj; mEmptyCCMap = empty_ccmapObj.NewCCMap(); if (!mEmptyCCMap) return NS_ERROR_OUT_OF_MEMORY;   PRBool val = PR_TRUE; nsresult rv = mPref->GetBoolPref("font.allow_double_byte_special_chars", &val); if (NS_SUCCEEDED(rv)) mAllowDoubleByteSpecialChars = val;   PRUint32 dbmapSize = sizeof(gDoubleByteSpecialCharsCCMapUnion); mDoubleByteSpecialCharsCCMap = (PRUint16*)PR_Malloc(dbmapSize); if (!mDoubleByteSpecialCharsCCMap) return NS_ERROR_OUT_OF_MEMORY; memcpy(mDoubleByteSpecialCharsCCMap, gDoubleByteSpecialCharsCCMap, dbmapSize);  PRInt32 scale_minimum = 0; rv = mPref->GetIntPref("font.scale.outline.min", &scale_minimum); if (NS_SUCCEEDED(rv)) { mOutlineScaleMinimum = scale_minimum; SIZE_FONT_PRINTF(("mOutlineScaleMinimum = %d", mOutlineScaleMinimum)); }  PRInt32 int_val = 0; PRInt32 percent = 0; #ifdef USE_AASB val = PR_TRUE; rv = mPref->GetBoolPref("font.scale.aa_bitmap.enable", &val); if (NS_SUCCEEDED(rv)) { mAABitmapScaleEnabled = val; SIZE_FONT_PRINTF(("mAABitmapScaleEnabled = %d", mAABitmapScaleEnabled)); }  val = PR_FALSE; rv = mPref->GetBoolPref("font.scale.aa_bitmap.always", &val); if (NS_SUCCEEDED(rv)) { mAABitmapScaleAlways = val; SIZE_FONT_PRINTF(("mAABitmapScaleAlways = %d", mAABitmapScaleAlways)); }  rv = mPref->GetIntPref("font.scale.aa_bitmap.min", &scale_minimum); if (NS_SUCCEEDED(rv)) { mAABitmapScaleMinimum = scale_minimum; SIZE_FONT_PRINTF(("mAABitmapScaleMinimum = %d", mAABitmapScaleMinimum)); }  percent = 0; rv = mPref->GetIntPref("font.scale.aa_bitmap.undersize", &percent); if ((NS_SUCCEEDED(rv)) && (percent)) { mAABitmapUndersize = percent/100.0; SIZE_FONT_PRINTF(("mAABitmapUndersize = %g", mAABitmapUndersize)); } percent = 0; rv = mPref->GetIntPref("font.scale.aa_bitmap.oversize", &percent); if ((NS_SUCCEEDED(rv)) && (percent)) { mAABitmapOversize = percent/100.0; SIZE_FONT_PRINTF(("mAABitmapOversize = %g", mAABitmapOversize)); } int_val = 0; rv = mPref->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 = mPref->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 = mPref->GetIntPref("font.scale.aa_bitmap.light_text.min", &int_val); if (NS_SUCCEEDED(rv)) { gAASBLightTextMinValue = int_val; SIZE_FONT_PRINTF(("gAASBLightTextMinValue = %d", gAASBLightTextMinValue)); } rv = mPref->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)); } #endif   rv = mPref->GetIntPref("font.scale.bitmap.min", &scale_minimum); if (NS_SUCCEEDED(rv)) { mBitmapScaleMinimum = scale_minimum; SIZE_FONT_PRINTF(("mBitmapScaleMinimum = %d", mBitmapScaleMinimum)); } percent = 0; mPref->GetIntPref("font.scale.bitmap.oversize", &percent); if (percent) { mBitmapOversize = percent/100.0; SIZE_FONT_PRINTF(("mBitmapOversize = %g", mBitmapOversize)); } percent = 0; mPref->GetIntPref("font.scale.bitmap.undersize", &percent); if (percent) { mBitmapUndersize = percent/100.0; SIZE_FONT_PRINTF(("mBitmapUndersize = %g", mBitmapUndersize)); }  #ifdef USE_XPRINT if (mPrinterMode) { mForceOutlineScaledFonts = PR_TRUE; } #endif   PRBool force_outline_scaled_fonts = mForceOutlineScaledFonts; #ifdef USE_XPRINT if (mPrinterMode) { rv = mPref->GetBoolPref("print.xprint.font.force_outline_scaled_fonts", &force_outline_scaled_fonts); } if (!mPrinterMode || NS_FAILED(rv)) { #endif  rv = mPref->GetBoolPref("font.x11.force_outline_scaled_fonts", &force_outline_scaled_fonts); #ifdef USE_XPRINT } #endif  if (NS_SUCCEEDED(rv)) { mForceOutlineScaledFonts = force_outline_scaled_fonts; }  #ifdef USE_FREETYPE PRBool enable_freetype2 = PR_TRUE; rv = mPref->GetBoolPref("font.FreeType2.enable", &enable_freetype2); if (NS_SUCCEEDED(rv)) { mEnableFreeType2 = enable_freetype2; FREETYPE_FONT_PRINTF(("mEnableFreeType2 = %d", mEnableFreeType2)); }  PRBool freetype2_autohinted = PR_FALSE; rv = mPref->GetBoolPref("font.FreeType2.autohinted", &freetype2_autohinted); if (NS_SUCCEEDED(rv)) { mFreeType2Autohinted = freetype2_autohinted; FREETYPE_FONT_PRINTF(("mFreeType2Autohinted = %d", mFreeType2Autohinted)); }  PRBool freetype2_unhinted = PR_TRUE; rv = mPref->GetBoolPref("font.FreeType2.unhinted", &freetype2_unhinted); if (NS_SUCCEEDED(rv)) { mFreeType2Unhinted = freetype2_unhinted; FREETYPE_FONT_PRINTF(("mFreeType2Unhinted = %d", mFreeType2Unhinted)); } #endif   #ifdef USE_AASB PRInt32 antialias_minimum = 8; rv = mPref->GetIntPref("font.antialias.min", &antialias_minimum); if (NS_SUCCEEDED(rv)) { mAntiAliasMinimum = antialias_minimum; FREETYPE_FONT_PRINTF(("mAntiAliasMinimum = %d", mAntiAliasMinimum)); } #endif   PRInt32 embedded_bitmaps_maximum = 1000000; rv = mPref->GetIntPref("font.embedded_bitmaps.max",&embedded_bitmaps_maximum); if (NS_SUCCEEDED(rv)) { mEmbeddedBitmapMaximumHeight = embedded_bitmaps_maximum; FREETYPE_FONT_PRINTF(("mEmbeddedBitmapMaximumHeight = %d", mEmbeddedBitmapMaximumHeight)); } int_val = 0; #ifdef USE_AASB rv = mPref->GetIntPref("font.scale.tt_bitmap.dark_text.min", &int_val); if (NS_SUCCEEDED(rv)) { mAATTDarkTextMinValue = int_val; SIZE_FONT_PRINTF(("mAATTDarkTextMinValue = %d", mAATTDarkTextMinValue)); } rv = mPref->GetCharPref("font.scale.tt_bitmap.dark_text.gain", getter_Copies(str)); if (NS_SUCCEEDED(rv)) { mAATTDarkTextGain = atof(str.get()); SIZE_FONT_PRINTF(("mAATTDarkTextGain = %g", mAATTDarkTextGain)); } #endif   #ifdef USE_XPRINT if (mPrinterMode) { mScaleBitmapFontsWithDevScale = PR_TRUE; } #endif   PRBool scale_bitmap_fonts_with_devscale = mScaleBitmapFontsWithDevScale; #ifdef USE_XPRINT if (mPrinterMode) { rv = mPref->GetBoolPref("print.xprint.font.scale_bitmap_fonts_with_devscale", &scale_bitmap_fonts_with_devscale); } if (!mPrinterMode || NS_FAILED(rv)) { #endif  rv = mPref->GetBoolPref("font.x11.scale_bitmap_fonts_with_devscale", &scale_bitmap_fonts_with_devscale); #ifdef USE_XPRINT } #endif  if (NS_SUCCEEDED(rv)) { mScaleBitmapFontsWithDevScale = scale_bitmap_fonts_with_devscale; }  const nsFontFamilyNameXlib* f = gFamilyNameTable; while (f->mName) { nsCStringKey key(f->mName); mAliases.Put(&key, (void *)f->mXName); f++; }  const nsFontPropertyNameXlib* p = gWeightNames; while (p->mName) { nsCStringKey key(p->mName); mWeights.Put(&key, (void*) p->mValue); p++; }  p = gStretchNames; while (p->mName) { nsCStringKey key(p->mName); mStretches.Put(&key, (void*) p->mValue); p++; }  const nsFontCharSetMapXlib* charSetMap = mCharSetMap; while (charSetMap->mName) { nsCStringKey key(charSetMap->mName); mCharSetMaps.Put(&key, (void *)charSetMap); charSetMap++; }  const nsFontCharSetMapXlib* specialCharSetMap = mSpecialCharSetMap; while (specialCharSetMap->mName) { nsCStringKey key(specialCharSetMap->mName); mSpecialCharSets.Put(&key, (void *)specialCharSetMap); specialCharSetMap++; }  mUnicode = NS_NewAtom("x-unicode"); if (!mUnicode) { return NS_ERROR_OUT_OF_MEMORY; } mUserDefined = NS_NewAtom(USER_DEFINED); if (!mUserDefined) { return NS_ERROR_OUT_OF_MEMORY; } mZHTW = NS_NewAtom("zh-TW"); if (!mZHTW) { return NS_ERROR_OUT_OF_MEMORY; } mZHHK = NS_NewAtom("zh-HK"); if (!mZHHK) { return NS_ERROR_OUT_OF_MEMORY; } mZHTWHK = NS_NewAtom("x-zh-TWHK"); if (!mZHTWHK) { return NS_ERROR_OUT_OF_MEMORY; }   nsCOMPtr<nsILanguageAtomService> langService; langService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID); if (langService) { nsIAtom *atom; langService->GetLocaleLanguageGroup(&atom); mUsersLocale = atom; } if (!mUsersLocale) { mUsersLocale = NS_NewAtom("x-western"); } mWesternLocale = NS_NewAtom("x-western"); if (!mUsersLocale) { return NS_ERROR_OUT_OF_MEMORY; }  #ifdef USE_AASB rv = nsX11AlphaBlendInitGlobals(xxlib_rgb_get_display(mXlibRgbHandle)); if (NS_FAILED(rv) || (!nsX11AlphaBlend::CanAntiAlias())) { mAABitmapScaleEnabled = PR_FALSE; }  if (mAABitmapScaleEnabled) { mAABitmapScaleEnabled = nsXFontAAScaledBitmap::InitGlobals(xxlib_rgb_get_display(mXlibRgbHandle), xxlib_rgb_get_screen(mXlibRgbHandle)); } #endif   #ifdef ENABLE_X_FONT_BANNING  nsXPIDLCString fbpattern; #ifdef USE_XPRINT if (mPrinterMode) { rv = mPref->GetCharPref("print.xprint.font.rejectfontpattern", getter_Copies(fbpattern)); } if (!mPrinterMode || NS_FAILED(rv)) { #endif  rv = mPref->GetCharPref("font.x11.rejectfontpattern", getter_Copies(fbpattern)); #ifdef USE_XPRINT } #endif  if (NS_SUCCEEDED(rv)) { mFontRejectRegEx = new regex_t; if (!mFontRejectRegEx) { return NS_ERROR_OUT_OF_MEMORY;
nsFontXlibUserDefined::Init(nsFontXlib* aFont){  if (!aFont->GetXFont()) {    aFont->LoadFont();    if (!aFont->GetXFont()) {      mCCMap = mFontMetricsContext->mEmptyCCMap;      return PR_FALSE;    }  }  mXFont = aFont->GetXFont();  mCCMap = mFontMetricsContext->mUserDefinedCCMap;  mName = aFont->mName;  return PR_TRUE;}