Bug 1166161 - Display available font from font.name-list.{family}.{lang} as fallback default font, instead of empty string.

This commit is contained in:
Hector Zhao 2015-05-19 13:41:48 +08:00
parent c31804eaca
commit 1aac993fcc
7 changed files with 39 additions and 44 deletions

View File

@ -10,8 +10,7 @@ var gContentPane = {
this._rebuildFonts();
var menulist = document.getElementById("defaultFont");
if (menulist.selectedIndex == -1) {
menulist.insertItemAt(0, "", "", "");
menulist.selectedIndex = 0;
menulist.value = FontBuilder.readFontSelection(menulist);
}
// Show translation preferences if we may:

View File

@ -63,41 +63,6 @@ var gFontsDialog = {
return undefined;
},
readFontSelection: function (aElement)
{
// Determine the appropriate value to select, for the following cases:
// - there is no setting
// - the font selected by the user is no longer present (e.g. deleted from
// fonts folder)
var preference = document.getElementById(aElement.getAttribute("preference"));
if (preference.value) {
var fontItems = aElement.getElementsByAttribute("value", preference.value);
// There is a setting that actually is in the list. Respect it.
if (fontItems.length > 0)
return undefined;
}
var defaultValue = aElement.firstChild.firstChild.getAttribute("value");
var languagePref = document.getElementById("font.language.group");
preference = document.getElementById("font.name-list." + aElement.id + "." + languagePref.value);
if (!preference || !preference.hasUserValue)
return defaultValue;
var fontNames = preference.value.split(",");
var stripWhitespace = /^\s*(.*)\s*$/;
for (var i = 0; i < fontNames.length; ++i) {
var fontName = fontNames[i].replace(stripWhitespace, "$1");
fontItems = aElement.getElementsByAttribute("value", fontName);
if (fontItems.length)
break;
}
if (fontItems.length)
return fontItems[0].getAttribute("value");
return defaultValue;
},
readUseDocumentFonts: function ()
{
var preference = document.getElementById("browser.display.use_document_fonts");

View File

@ -142,7 +142,7 @@
<label accesskey="&serif.accesskey;" control="serif">&serif.label;</label>
</hbox>
<menulist id="serif" flex="1" style="width: 0px;" delayprefsave="true"
onsyncfrompreference="return gFontsDialog.readFontSelection(document.getElementById('serif'));"/>
onsyncfrompreference="return FontBuilder.readFontSelection(this);"/>
<spacer/>
</row>
<row align="center">
@ -150,7 +150,7 @@
<label accesskey="&sans-serif.accesskey;" control="sans-serif">&sans-serif.label;</label>
</hbox>
<menulist id="sans-serif" flex="1" style="width: 0px;" delayprefsave="true"
onsyncfrompreference="return gFontsDialog.readFontSelection(document.getElementById('sans-serif'));"/>
onsyncfrompreference="return FontBuilder.readFontSelection(this);"/>
<spacer/>
</row>
<row align="center">
@ -158,7 +158,7 @@
<label accesskey="&monospace.accesskey;" control="monospace">&monospace.label;</label>
</hbox>
<menulist id="monospace" flex="1" style="width: 0px;" crop="right" delayprefsave="true"
onsyncfrompreference="return gFontsDialog.readFontSelection(document.getElementById('monospace'));"/>
onsyncfrompreference="return FontBuilder.readFontSelection(this);"/>
<hbox align="center" pack="end">
<label value="&size.label;"
accesskey="&sizeMonospace.accesskey;"

View File

@ -15,8 +15,7 @@ var gContentPane = {
this._rebuildFonts();
var menulist = document.getElementById("defaultFont");
if (menulist.selectedIndex == -1) {
menulist.insertItemAt(0, "", "", "");
menulist.selectedIndex = 0;
menulist.value = FontBuilder.readFontSelection(menulist);
}
// Show translation preferences if we may:

View File

@ -1142,7 +1142,7 @@ gfxFcPlatformFontList::GetFontList(nsIAtom *aLangGroup,
NS_NOTREACHED("unexpected CSS generic font family");
// The first in the list becomes the default in
// gFontsDialog.readFontSelection() if the preference-selected font is not
// FontBuilder.readFontSelection() if the preference-selected font is not
// available, so put system configured defaults first.
if (monospace)
aListOfFonts.InsertElementAt(0, NS_LITERAL_STRING("monospace"));

View File

@ -361,7 +361,7 @@ gfxFontconfigUtils::GetFontList(nsIAtom *aLangGroup,
NS_NOTREACHED("unexpected CSS generic font family");
// The first in the list becomes the default in
// gFontsDialog.readFontSelection() if the preference-selected font is not
// FontBuilder.readFontSelection() if the preference-selected font is not
// available, so put system configured defaults first.
if (monospace)
aListOfFonts.InsertElementAt(0, NS_LITERAL_STRING("monospace"));

View File

@ -85,5 +85,37 @@ var FontBuilder = {
}
}
aMenuList.appendChild(popup);
},
readFontSelection(aElement)
{
// Determine the appropriate value to select, for the following cases:
// - there is no setting
// - the font selected by the user is no longer present (e.g. deleted from
// fonts folder)
let preference = document.getElementById(aElement.getAttribute("preference"));
if (preference.value) {
let fontItems = aElement.getElementsByAttribute("value", preference.value);
// There is a setting that actually is in the list. Respect it.
if (fontItems.length)
return undefined;
}
let defaultValue = aElement.firstChild.firstChild.getAttribute("value");
let fontNameList = preference.name.replace(".name.", ".name-list.");
let prefFontNameList = document.getElementById(fontNameList);
if (!prefFontNameList || !prefFontNameList.value)
return defaultValue;
let fontNames = prefFontNameList.value.split(",");
for (let i = 0; i < fontNames.length; ++i) {
let fontName = this.enumerator.getStandardFamilyName(fontNames[i].trim());
let fontItems = aElement.getElementsByAttribute("value", fontName);
if (fontItems.length)
return fontItems[0].getAttribute("value");
}
return defaultValue;
}
};