nsComponentManager::CreateInstance(NS_SAVEASCHARSET_CONTRACTID, nsnull, NS_GET_IID(nsISaveAsCharset), (void**)&gFontSubstituteConverter);
CallCreateInstance(NS_SAVEASCHARSET_CONTRACTID, &gFontSubstituteConverter);
SubstituteChars(const PRUnichar*    aString,                 PRUint32            aLength,                nsAutoChar16Buffer& aResult,                PRUint32*           aCount){  nsresult res;  if (!gFontSubstituteConverter) {    nsComponentManager::CreateInstance(NS_SAVEASCHARSET_CONTRACTID, nsnull,                                       NS_GET_IID(nsISaveAsCharset),                                       (void**)&gFontSubstituteConverter);    if (gFontSubstituteConverter) {      res = gFontSubstituteConverter->Init("ISO-8859-1",                              nsISaveAsCharset::attr_EntityAfterCharsetConv +                              nsISaveAsCharset::attr_FallbackQuestionMark +                              nsISaveAsCharset::attr_IgnoreIgnorables,                              nsIEntityConverter::transliterate);      if (NS_FAILED(res)) {        NS_RELEASE(gFontSubstituteConverter);      }    }  }  // do the transliteration if we have a converter  PRUnichar* result;   if (gFontSubstituteConverter) {    nsXPIDLCString conv;    nsAutoString tmp(aString, aLength); // we need to pass a null-terminated string    res = gFontSubstituteConverter->Convert(tmp.get(), getter_Copies(conv));    if (NS_SUCCEEDED(res)) {      *aCount = conv.Length();      if (*aCount > 0) {        if (!aResult.EnsureElemCapacity(*aCount)) {          return NS_ERROR_OUT_OF_MEMORY;        }        result = aResult.get();        PRUnichar* u = result;        const char* c = conv.get();        for (; *c; ++c, ++u) {          *u = *c;        }      }      return NS_OK;    }  }  // we reach here if we couldn't transliterate, so fallback to question marks   if (!aResult.EnsureElemCapacity(aLength)) return NS_ERROR_OUT_OF_MEMORY;  result = aResult.get();  for (PRUint32 i = 0; i < aLength; i++) {    result[i] = NS_REPLACEMENT_CHAR;  }  *aCount = aLength;  return NS_OK;}