PR_LOG(FontMetricsXlibLM, PR_LOG_DEBUG, ("# nsFontMetricsXlibContext new() for device=%p\n", aDevice));
if (!aFont->GetXFont()) { aFont->LoadFont(); if (!aFont->GetXFont()) { mCCMap = mFontMetricsContext->mEmptyCCMap; return PR_FALSE; } } mXFont = aFont->GetXFont(); mCCMap = mFontMetricsContext->mUserDefinedCCMap; mName = aFont->mName;
nsFontMetricsXlibContext::Init(nsIDeviceContext *aDevice, PRBool aPrintermode){  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 /* USE_XPRINT */  mForceOutlineScaledFonts = PR_FALSE;  mXlibRgbHandle = nsnull;  mAllowDoubleByteSpecialChars = PR_TRUE;  // XXX many of these statics need to be freed at shutdown time  mDevScale = 0.0f; /* Scaler value from |GetCanonicalPixelScale()| */  mScaleBitmapFontsWithDevScale = PR_FALSE;  mGlobalListInitalised = PR_FALSE;  mUserDefinedCCMap            = nsnull;  mEmptyCCMap                  = nsnull;  mDoubleByteSpecialCharsCCMap = nsnull;  mCharSetMap        = nsnull;  mNoneCharSetMap    = nsnull;  mSpecialCharSetMap = nsnull;    // Controls for Outline Scaled Fonts (okay looking)  mOutlineScaleMinimum = 6;#ifdef USE_AASB// Controls for Anti-Aliased Scaled Bitmaps (okay looking)  mAABitmapScaleEnabled = PR_TRUE;  mAABitmapScaleAlways = PR_FALSE;  mAABitmapScaleMinimum = 6;  mAABitmapOversize = 1.1;  mAABitmapUndersize = 0.9;#endif /* USE_AASB */// Controls for (regular) Scaled Bitmaps (very ugly)  mBitmapScaleMinimum = 10;  mBitmapOversize = 1.2;  mBitmapUndersize = 0.8;#ifdef USE_AASB  mAntiAliasMinimum = 8;#endif /* USE_AASB */  mEmbeddedBitmapMaximumHeight = 1000000;#ifdef MOZ_ENABLE_FREETYPE2  mEnableFreeType2 = PR_TRUE;  mFreeType2Autohinted = PR_FALSE;  mFreeType2Unhinted = PR_TRUE;#endif /* MOZ_ENABLE_FREETYPE2 */#ifdef USE_AASB  mAATTDarkTextMinValue = 64;  mAATTDarkTextGain = 0.8;#endif /* USE_AASB */#ifdef ENABLE_X_FONT_BANNING  mFontRejectRegEx = nsnull;  mFontAcceptRegEx = nsnull;#endif /* ENABLE_X_FONT_BANNING */  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  /* First check gfx/src/xlib/-specific env var "NS_FONT_DEBUG_XLIB" (or  * "NS_FONT_DEBUG_XPRINT" if the device is a printer),   * then the more general "NS_FONT_DEBUG" if    * "NS_FONT_DEBUG_XLIB"/"NS_FONT_DEBUG_XPRINT" is not present */  const char *debug;#ifdef USE_XPRINT  if (mPrinterMode) {    debug = PR_GetEnv("NS_FONT_DEBUG_XPRINT");  }  else#endif /* USE_XPRINT */  {    debug = PR_GetEnv("NS_FONT_DEBUG_XLIB");  }  if (!debug) {    debug = PR_GetEnv("NS_FONT_DEBUG");  }    if (debug) {    PR_sscanf(debug, "%lX", &gFontDebug);  }#endif /* NS_FONT_DEBUG */  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;  // get the "disable double byte font special chars" setting  PRBool val = PR_TRUE;  nsresult rv = mPref->GetBoolPref("font.allow_double_byte_special_chars", &val);  if (NS_SUCCEEDED(rv))    mAllowDoubleByteSpecialChars = val;  /* Make sure we allocate/copy enough (see bug 235913, comment 12)*/  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 /* USE_AASB */  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 /* USE_XPRINT */ 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 /* USE_XPRINT */    rv = mPref->GetBoolPref("font.x11.force_outline_scaled_fonts", &force_outline_scaled_fonts);#ifdef USE_XPRINT  }#endif /* USE_XPRINT */  if (NS_SUCCEEDED(rv)) {    mForceOutlineScaledFonts = force_outline_scaled_fonts;  }#ifdef MOZ_ENABLE_FREETYPE2  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 /* MOZ_ENABLE_FREETYPE2 */#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 /* USE_AASB */  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 /* USE_AASB */#ifdef USE_XPRINT  if (mPrinterMode) {    mScaleBitmapFontsWithDevScale = PR_TRUE;  }#endif /* USE_XPRINT */ 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 /* USE_XPRINT */    rv = mPref->GetBoolPref("font.x11.scale_bitmap_fonts_with_devscale", &scale_bitmap_fonts_with_devscale);#ifdef USE_XPRINT  }#endif /* USE_XPRINT */  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 = do_GetAtom("x-unicode");  if (!mUnicode) {    return NS_ERROR_OUT_OF_MEMORY;  }  mUserDefined = do_GetAtom(USER_DEFINED);  if (!mUserDefined) {    return NS_ERROR_OUT_OF_MEMORY;  }  mZHTW = do_GetAtom("zh-TW");  if (!mZHTW) {    return NS_ERROR_OUT_OF_MEMORY;  }  mZHHK = do_GetAtom("zh-HK");  if (!mZHHK) {    return NS_ERROR_OUT_OF_MEMORY;  }  mZHTWHK = do_GetAtom("x-zh-TWHK");  if (!mZHTWHK) {    return NS_ERROR_OUT_OF_MEMORY;  }  // the user's locale  nsCOMPtr<nsILanguageAtomService> langService;  langService = do_GetService(NS_LANGUAGEATOMSERVICE_CONTRACTID);  if (langService) {    mUsersLocale = langService->GetLocaleLanguageGroup();  }  if (!mUsersLocale) {    mUsersLocale = do_GetAtom("x-western");  }  mWesternLocale = do_GetAtom("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 /* USE_AASB */  #ifdef ENABLE_X_FONT_BANNING  /* get the font banning pattern */  nsXPIDLCString fbpattern;#ifdef USE_XPRINT  if (mPrinterMode) {    rv = mPref->GetCharPref("print.xprint.font.rejectfontpattern", getter_Copies(fbpattern));  }    if (!mPrinterMode || NS_FAILED(rv)) {#endif /* USE_XPRINT */    rv = mPref->GetCharPref("font.x11.rejectfontpattern", getter_Copies(fbpattern));#ifdef USE_XPRINT  }#endif /* USE_XPRINT */  if (NS_SUCCEEDED(rv)) {    mFontRejectRegEx = new regex_t;    if (!mFontRejectRegEx) {      return NS_ERROR_OUT_OF_MEMORY;    }        /* Compile the pattern - and return an error if we get an invalid pattern... */    if (regcomp(mFontRejectRegEx, fbpattern.get(), REG_EXTENDED|REG_NOSUB) != REG_OK) {      PR_LOG(FontMetricsXlibLM, PR_LOG_DEBUG, ("Invalid rejectfontpattern '%s'\n", fbpattern.get()));      BANNED_FONT_PRINTF(("Invalid font.x11.rejectfontpattern '%s'", fbpattern.get()));      delete mFontRejectRegEx;      mFontRejectRegEx = nsnull;            return NS_ERROR_INVALID_ARG;    }      }#ifdef USE_XPRINT  if (mPrinterMode) {    rv = mPref->GetCharPref("print.xprint.font.acceptfontpattern", getter_Copies(fbpattern));  }    if (!mPrinterMode || NS_FAILED(rv)) {#endif /* USE_XPRINT */    rv = mPref->GetCharPref("font.x11.acceptfontpattern", getter_Copies(fbpattern));#ifdef USE_XPRINT  }#endif /* USE_XPRINT */  if (NS_SUCCEEDED(rv)) {    mFontAcceptRegEx = new regex_t;    if (!mFontAcceptRegEx) {      return NS_ERROR_OUT_OF_MEMORY;    }        /* Compile the pattern - and return an error if we get an invalid pattern... */    if (regcomp(mFontAcceptRegEx, fbpattern.get(), REG_EXTENDED|REG_NOSUB) != REG_OK) {      PR_LOG(FontMetricsXlibLM, PR_LOG_DEBUG, ("Invalid acceptfontpattern '%s'\n", fbpattern.get()));      BANNED_FONT_PRINTF(("Invalid font.x11.acceptfontpattern '%s'", fbpattern.get()));      delete mFontAcceptRegEx;      mFontAcceptRegEx = nsnull;            return NS_ERROR_INVALID_ARG;    }      }#endif /* ENABLE_X_FONT_BANNING */#ifdef MOZ_ENABLE_FREETYPE2  rv = nsFreeTypeInitGlobals();  if (NS_FAILED(rv)) {    return NS_ERROR_OUT_OF_MEMORY;  }#endif /* MOZ_ENABLE_FREETYPE2 */  return NS_OK;}