зеркало из https://github.com/mozilla/gecko-dev.git
Changed to use lang instead of font-family for message display,
contributed by jshin@pantheon.yale.edu, bug 102623, r=ducarroz, nhotta, sr=bienvenu.
This commit is contained in:
Родитель
834182b3ba
Коммит
e03414fa6b
|
@ -1992,12 +1992,12 @@ ResetChannelCharset(MimeObject *obj)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Function to get up mail/news font
|
||||
// Function to get up mail/news fontlang
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
nsresult GetMailNewsFont(MimeObject *obj, PRBool styleFixed, char *fontName, PRUint32 nameBuffSize,
|
||||
PRInt32 *fontPixelSize, PRInt32 *fontSizePercentage)
|
||||
nsresult GetMailNewsFont(MimeObject *obj, PRBool styleFixed, PRInt32 *fontPixelSize,
|
||||
PRInt32 *fontSizePercentage, nsCString& fontLang)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
|
@ -2005,9 +2005,6 @@ nsresult GetMailNewsFont(MimeObject *obj, PRBool styleFixed, char *fontName, PRU
|
|||
if (aPrefs) {
|
||||
MimeInlineText *text = (MimeInlineText *) obj;
|
||||
nsCAutoString aCharset;
|
||||
PRUnichar *unicode = nsnull;
|
||||
nsCAutoString convertedStr;
|
||||
nsCAutoString variableFontType; // serif, sans-serif
|
||||
|
||||
// get a charset
|
||||
if (!text->initializeCharset)
|
||||
|
@ -2018,118 +2015,47 @@ nsresult GetMailNewsFont(MimeObject *obj, PRBool styleFixed, char *fontName, PRU
|
|||
else
|
||||
aCharset.Assign(text->charset);
|
||||
|
||||
// get variable font type
|
||||
char* variable_font_type = nsnull;
|
||||
rv = aPrefs->CopyCharPref("font.default", &variable_font_type);
|
||||
nsCOMPtr<nsICharsetConverterManager2> aCharSetConverterManager2;
|
||||
nsCOMPtr <nsIAtom> charsetAtom;
|
||||
nsCOMPtr<nsIAtom> aLangGroup;
|
||||
const PRUnichar* langGroup = nsnull;
|
||||
nsCAutoString aPrefStr;
|
||||
|
||||
ToLowerCase(aCharset);
|
||||
|
||||
aCharSetConverterManager2 = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
|
||||
if ( NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
// get a language, e.g. x-western, ja
|
||||
rv = aCharSetConverterManager2->GetCharsetAtom2(PromiseFlatCString(aCharset).get(),getter_AddRefs(charsetAtom));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = aCharSetConverterManager2->GetCharsetLangGroup(charsetAtom,getter_AddRefs(aLangGroup));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = aLangGroup->GetUnicode(&langGroup);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
if (!variable_font_type)
|
||||
return NS_ERROR_FAILURE;
|
||||
variableFontType.Assign(variable_font_type);
|
||||
PR_FREEIF(variable_font_type);
|
||||
|
||||
// if indicated by the pref, do language sensitive font selection
|
||||
PRBool languageSensitiveFont = PR_FALSE;
|
||||
rv = aPrefs->GetBoolPref("mailnews.language_sensitive_font", &languageSensitiveFont);
|
||||
if (NS_SUCCEEDED(rv) && languageSensitiveFont) {
|
||||
nsCOMPtr<nsICharsetConverterManager> aCharSets;
|
||||
nsCOMPtr<nsIAtom> aLangGroup;
|
||||
const PRUnichar* langGroup = nsnull;
|
||||
nsCAutoString aPrefStr;
|
||||
|
||||
if (styleFixed) {
|
||||
aPrefStr.Assign("font.name.monospace.");
|
||||
}
|
||||
else {
|
||||
aPrefStr.Assign("font.name.");
|
||||
aPrefStr.Append(variableFontType);
|
||||
aPrefStr.Append(".");
|
||||
}
|
||||
fontLang.AssignWithConversion(langGroup);
|
||||
|
||||
ToLowerCase(aCharset);
|
||||
// get a font size from pref
|
||||
aPrefStr.Assign(!styleFixed ? "font.size.variable." : "font.size.fixed.");
|
||||
aPrefStr.AppendWithConversion(langGroup);
|
||||
rv = aPrefs->GetIntPref(aPrefStr.get(), fontPixelSize);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
aCharSets = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID);
|
||||
if (!aCharSets)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// get a language, e.g. x-western, ja
|
||||
nsAutoString u;
|
||||
u.AssignWithConversion(aCharset.get());
|
||||
rv = aCharSets->GetCharsetLangGroup(&u, getter_AddRefs(aLangGroup));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = aLangGroup->GetUnicode(&langGroup);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
// append the language to the pref string
|
||||
aPrefStr.AppendWithConversion(langGroup);
|
||||
// get original font size
|
||||
PRInt32 originalSize;
|
||||
rv = aPrefs->GetDefaultIntPref(aPrefStr.get(), &originalSize);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
// get a font name from pref, could be non ascii (need charset conversion)
|
||||
// this is not necessary if we insert this tag after the message is converted to UTF-8
|
||||
rv = aPrefs->CopyUnicharPref(aPrefStr.get(), &unicode);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
// calculate percentage
|
||||
*fontSizePercentage = (PRInt32)((float)*fontPixelSize / (float)originalSize * 100);
|
||||
|
||||
nsAutoString familyname(unicode);
|
||||
#if defined(XP_UNIX)
|
||||
// extract "courier" from "adobe-courier-iso8859-1"
|
||||
nsAutoString tmp;
|
||||
familyname.Right(tmp, familyname.Length()-familyname.FindChar(PRUnichar('-'))-1);
|
||||
tmp.Left(familyname, tmp.FindChar(PRUnichar('-')));
|
||||
#endif
|
||||
rv = nsMsgI18NConvertFromUnicode(nsCAutoString("UTF-8"), familyname, convertedStr);
|
||||
PR_FREEIF(unicode);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (convertedStr.Length() >= nameBuffSize)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
PL_strcpy(fontName, convertedStr.get());
|
||||
|
||||
// get a font size from pref
|
||||
aPrefStr.Assign(!styleFixed ? "font.size.variable." : "font.size.fixed.");
|
||||
aPrefStr.AppendWithConversion(langGroup);
|
||||
rv = aPrefs->GetIntPref(aPrefStr.get(), fontPixelSize);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
// get original font size
|
||||
PRInt32 originalSize;
|
||||
rv = aPrefs->GetDefaultIntPref(aPrefStr.get(), &originalSize);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
// calculate percentage
|
||||
*fontSizePercentage = (PRInt32)((float)*fontPixelSize / (float)originalSize * 100);
|
||||
|
||||
}
|
||||
// otherwise, use the mailnews font setting from pref
|
||||
else {
|
||||
|
||||
// get a font name from pref, could be non ascii (need charset conversion)
|
||||
// this is not necessary if we insert this tag after the message is converted to UTF-8
|
||||
rv = aPrefs->CopyUnicharPref(!styleFixed ? "mailnews.font.name.html" : "mailnews.font.name.plain", &unicode);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = nsMsgI18NConvertFromUnicode(nsCAutoString("UTF-8"), nsAutoString(unicode), convertedStr);
|
||||
PR_FREEIF(unicode);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (convertedStr.Length() >= nameBuffSize)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
PL_strcpy(fontName, convertedStr.get());
|
||||
|
||||
// get a font size from pref
|
||||
rv = aPrefs->GetIntPref(!styleFixed ? "mailnews.font.size.html" : "mailnews.font.size.plain", fontPixelSize);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
@ -201,7 +201,8 @@ extern "C" nsresult nsMimeNewURI(nsIURI** aInstancePtrResult, const char
|
|||
|
||||
extern "C" nsresult SetMailCharacterSetToMsgWindow(MimeObject *obj, const PRUnichar *aCharacterSet);
|
||||
|
||||
extern "C" nsresult GetMailNewsFont(MimeObject *obj, PRBool styleFixed, char *fontName, PRUint32 nameBuffSize, PRInt32 *fontPixelSize, PRInt32 *fontSizePercentage);
|
||||
extern "C" nsresult GetMailNewsFont(MimeObject *obj, PRBool styleFixed, PRInt32 *fontPixelSize, PRInt32 *fontSizePercentage, nsCString& fontLang);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -76,13 +76,13 @@ MimeInlineTextHTML_parse_begin (MimeObject *obj)
|
|||
nsMimeOutput::nsMimeMessagePrintOutput == obj->options->format_out)
|
||||
{
|
||||
char buf[256]; // local buffer for html tag
|
||||
char fontName[128]; // default font name
|
||||
PRInt32 fontSize; // default font size
|
||||
PRInt32 fontSizePercentage; // size percentage
|
||||
if (NS_SUCCEEDED(GetMailNewsFont(obj, PR_FALSE, fontName, sizeof(fontName), &fontSize, &fontSizePercentage)))
|
||||
nsCAutoString fontLang; // langgroup of the font.
|
||||
if (NS_SUCCEEDED(GetMailNewsFont(obj, PR_FALSE, &fontSize, &fontSizePercentage,fontLang)))
|
||||
{
|
||||
PR_snprintf(buf, 256, "<div class=\"moz-text-html\" style=\"font-family: %s;\">",
|
||||
(const char *) fontName);
|
||||
PR_snprintf(buf, 256, "<div class=\"moz-text-html\" lang=\"%s\">",
|
||||
PromiseFlatCString(fontLang).get());
|
||||
status = MimeObject_write(obj, buf, nsCRT::strlen(buf), PR_FALSE);
|
||||
}
|
||||
else
|
||||
|
|
|
@ -150,34 +150,31 @@ MimeInlineTextPlainFlowed_parse_begin (MimeObject *obj)
|
|||
// Get font
|
||||
// only used for viewing (!plainHTML)
|
||||
nsCAutoString fontstyle;
|
||||
nsCAutoString fontLang; // langgroup of the font
|
||||
|
||||
|
||||
// generic font-family name ( -moz-fixed for fixed font and NULL for
|
||||
// variable font ) is sufficient now that bug 105199 has been fixed.
|
||||
|
||||
if (exdata->fixedwidthfont)
|
||||
fontstyle = "font-family: -moz-fixed";
|
||||
|
||||
if (nsMimeOutput::nsMimeMessageBodyDisplay == obj->options->format_out ||
|
||||
nsMimeOutput::nsMimeMessagePrintOutput == obj->options->format_out)
|
||||
{
|
||||
/* Use a langugage sensitive default font
|
||||
(otherwise unicode font will be used since the data is UTF-8). */
|
||||
char fontName[128]; // default font name
|
||||
PRInt32 fontSize; // default font size
|
||||
PRInt32 fontSizePercentage; // size percentage
|
||||
nsresult rv = GetMailNewsFont(obj, exdata->fixedwidthfont,
|
||||
fontName, 128, &fontSize, &fontSizePercentage);
|
||||
&fontSize, &fontSizePercentage, fontLang);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
fontstyle = "font-family: ";
|
||||
fontstyle += fontName;
|
||||
fontstyle += "; font-size: ";
|
||||
if ( ! fontstyle.IsEmpty() ) {
|
||||
fontstyle += "; ";
|
||||
}
|
||||
fontstyle += "font-size: ";
|
||||
fontstyle.AppendInt(fontSize);
|
||||
fontstyle += "px;";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (exdata->fixedwidthfont)
|
||||
fontstyle = "font-family: -moz-fixed";
|
||||
}
|
||||
}
|
||||
else // DELETEME: makes sense?
|
||||
{
|
||||
if (exdata->fixedwidthfont)
|
||||
fontstyle = "font-family: -moz-fixed";
|
||||
}
|
||||
|
||||
// Opening <div>.
|
||||
|
@ -193,6 +190,12 @@ MimeInlineTextPlainFlowed_parse_begin (MimeObject *obj)
|
|||
openingDiv += fontstyle;
|
||||
openingDiv += '"';
|
||||
}
|
||||
if (!plainHTML && !fontLang.IsEmpty())
|
||||
{
|
||||
openingDiv += " lang=\"";
|
||||
openingDiv += fontLang;
|
||||
openingDiv += '\"';
|
||||
}
|
||||
openingDiv += ">";
|
||||
status = MimeObject_write(obj, NS_CONST_CAST(char*, openingDiv.get()), openingDiv.Length(), PR_FALSE);
|
||||
if (status < 0) return status;
|
||||
|
|
|
@ -169,35 +169,31 @@ MimeInlineTextPlain_parse_begin (MimeObject *obj)
|
|||
// Get font
|
||||
// only used for viewing (!plainHTML)
|
||||
nsCAutoString fontstyle;
|
||||
nsCAutoString fontLang; // langgroup of the font
|
||||
|
||||
// generic font-family name ( -moz-fixed for fixed font and NULL for
|
||||
// variable font ) is sufficient now that bug 105199 has been fixed.
|
||||
|
||||
if (!obj->options->variable_width_plaintext_p)
|
||||
fontstyle = "font-family: -moz-fixed";
|
||||
|
||||
if (nsMimeOutput::nsMimeMessageBodyDisplay == obj->options->format_out ||
|
||||
nsMimeOutput::nsMimeMessagePrintOutput == obj->options->format_out)
|
||||
{
|
||||
/* Use a langugage sensitive default font
|
||||
(otherwise unicode font will be used since the data is UTF-8). */
|
||||
char fontName[128]; // default font name
|
||||
PRInt32 fontSize; // default font size
|
||||
PRInt32 fontSizePercentage; // size percentage
|
||||
nsresult rv = GetMailNewsFont(obj,
|
||||
!obj->options->variable_width_plaintext_p,
|
||||
fontName, 128, &fontSize, &fontSizePercentage);
|
||||
&fontSize, &fontSizePercentage, fontLang);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
fontstyle = "font-family: ";
|
||||
fontstyle += fontName;
|
||||
fontstyle += "; font-size: ";
|
||||
if ( ! fontstyle.IsEmpty() ) {
|
||||
fontstyle += "; ";
|
||||
}
|
||||
fontstyle += "font-size: ";
|
||||
fontstyle.AppendInt(fontSize);
|
||||
fontstyle += "px;";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!obj->options->variable_width_plaintext_p)
|
||||
fontstyle = "font-family: -moz-fixed";
|
||||
}
|
||||
}
|
||||
else // DELETEME: makes sense?
|
||||
{
|
||||
if (!obj->options->variable_width_plaintext_p)
|
||||
fontstyle = "font-family: -moz-fixed";
|
||||
}
|
||||
|
||||
// Opening <div>. We currently have to add formatting here. :-(
|
||||
|
@ -225,6 +221,12 @@ MimeInlineTextPlain_parse_begin (MimeObject *obj)
|
|||
openingDiv += fontstyle;
|
||||
openingDiv += '\"';
|
||||
}
|
||||
if (!fontLang.IsEmpty())
|
||||
{
|
||||
openingDiv += " lang=\"";
|
||||
openingDiv += fontLang;
|
||||
openingDiv += '\"';
|
||||
}
|
||||
}
|
||||
openingDiv += "><pre wrap>";
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче