psnativefont = nsnull; psnativecode = nsnull;
psnativefont.Adopt(0); psnativecode.Adopt(0);
static void PrefEnumCallback(const char *aName, void *aClosure){  nsPostScriptObj *psObj = (nsPostScriptObj*)aClosure;  XP_File f = psObj->GetPrintFile();  nsAutoString lang; lang.AssignWithConversion(aName);  if (strstr(aName, "print.psnativefont.")) {    lang.Cut(0, 19);  } else if (strstr(aName, "print.psunicodefont.")) {    lang.Cut(0, 20);  }  nsStringKey key(lang);  PS_LangGroupInfo *linfo = (PS_LangGroupInfo *) gLangGroups->Get(&key);  if (linfo) {    /* already exist */    return;  }  /* define new language group */  nsXPIDLCString psnativefont;  nsXPIDLCString psnativecode;  nsXPIDLCString psunicodefont;  int psfontorder = 0;  PRBool use_prefsfile = PR_FALSE;  PRBool use_vendorfile = PR_FALSE;  //  // Try to get the info from the user's prefs file  //  nsCAutoString namepsnativefont("print.psnativefont.");  namepsnativefont.AppendWithConversion(lang);  gPrefs->CopyCharPref(namepsnativefont.get(), getter_Copies(psnativefont));  nsCAutoString namepsnativecode("print.psnativecode.");  namepsnativecode.AppendWithConversion(lang);  gPrefs->CopyCharPref(namepsnativecode.get(), getter_Copies(psnativecode));  if (((psnativefont)&&(*psnativefont)) && ((psnativecode)&&(*psnativecode))) {    use_prefsfile = PR_TRUE;  } else {    psnativefont = nsnull;    psnativecode = nsnull;  }  //  // if not found look for info from the printer vendor  //  if (use_prefsfile != PR_TRUE) {    psObj->GetUnixPrinterSetting(namepsnativefont, getter_Copies(psnativefont));    psObj->GetUnixPrinterSetting(namepsnativecode, getter_Copies(psnativecode));    if ((psnativefont) && (psnativecode)) {      use_vendorfile = PR_TRUE;    } else {      psnativefont = nsnull;      psnativecode = nsnull;    }  }  if (!use_prefsfile && !use_vendorfile) {    GetUnixPrinterFallbackSetting(namepsnativefont, getter_Copies(psnativefont));    GetUnixPrinterFallbackSetting(namepsnativecode, getter_Copies(psnativecode));  }  /* psnativefont and psnativecode both should be set */  if (!psnativefont || !psnativecode) {    psnativefont = nsnull;    psnativecode = nsnull;  } else {    nsCAutoString namepsfontorder("print.psfontorder.");    namepsfontorder.AppendWithConversion(lang);    if (use_prefsfile) {      gPrefs->GetIntPref(namepsfontorder.get(), &psfontorder);    }    else if (use_vendorfile) {      nsXPIDLCString psfontorder_str;      psObj->GetUnixPrinterSetting(namepsfontorder, getter_Copies(psfontorder_str));      if (psfontorder_str) {        psfontorder = atoi(psfontorder_str);      }    }  }  /* check UCS fonts */  nsCAutoString namepsunicodefont("print.psunicodefont.");  namepsunicodefont.AppendWithConversion(lang);  if (use_prefsfile) {    gPrefs->CopyCharPref(namepsunicodefont.get(), getter_Copies(psunicodefont));  } else if (use_vendorfile) {    psObj->GetUnixPrinterSetting(namepsunicodefont, getter_Copies(psunicodefont));  }  nsresult res = NS_OK;  if (psnativefont || psunicodefont) {    linfo = new PS_LangGroupInfo;    linfo->mEncoder = nsnull;    linfo->mU2Ntable = nsnull;    if (psnativecode) {      nsAutoString str;      nsICharsetConverterManager *ccMain = nsnull;      nsICharsetAlias *aliasmgr = nsnull;      res = nsServiceManager::GetService(kCharsetConverterManagerCID,	   kICharsetConverterManagerIID, (nsISupports **) & ccMain);      if (NS_SUCCEEDED(res) && ccMain) {        res = nsServiceManager::GetService(NS_CHARSETALIAS_CONTRACTID,	  NS_GET_IID(nsICharsetAlias), (nsISupports **) & aliasmgr);	if (NS_SUCCEEDED(res) && aliasmgr) {	  res = aliasmgr->GetPreferred(NS_ConvertASCIItoUCS2(psnativecode), str);	  if (NS_SUCCEEDED(res)) {	    res = ccMain->GetUnicodeEncoder(&str, &linfo->mEncoder);	  }          nsServiceManager::ReleaseService(NS_CHARSETALIAS_CONTRACTID, aliasmgr);	}        nsServiceManager::ReleaseService(kCharsetConverterManagerCID, ccMain);      }    }    gLangGroups->Put(&key, (void *) linfo);    nsCAutoString langstrC; langstrC.AssignWithConversion(lang);    if (psnativefont && linfo->mEncoder) {      XP_FilePrintf(f, "/Unicode2NativeDict%s 0 dict def\n", (const char *) langstrC);    }    XP_FilePrintf(f, "/%s_ls {\n", (const char *) langstrC);    XP_FilePrintf(f, "  /NativeFont /%s def\n",      (psnativefont && linfo->mEncoder) ? psnativefont.get() : "Courier");    XP_FilePrintf(f, "  /UCS2Font /%s def\n",		  psunicodefont ? psunicodefont.get() : "Courier");    if (psnativefont && linfo->mEncoder) {      XP_FilePrintf(f, "  /Unicode2NativeDict Unicode2NativeDict%s def\n",		    (const char *) langstrC);    }    if (psfontorder) {      XP_FilePrintf(f, "  /unicodeshow1 { real_unicodeshow_native } bind def\n");      XP_FilePrintf(f, "  /unicodeshow2 { real_unicodeshow } bind def\n");    } else {      XP_FilePrintf(f, "  /unicodeshow1 { real_unicodeshow } bind def\n");      XP_FilePrintf(f, "  /unicodeshow2 { real_unicodeshow_native } bind def\n");    }    XP_FilePrintf(f, "} bind def\n");    if (linfo->mEncoder) {      linfo->mEncoder->SetOutputErrorBehavior(		    linfo->mEncoder->kOnError_Replace, nsnull, '?');      linfo->mU2Ntable = new nsHashtable();    }  }}