зеркало из https://github.com/mozilla/gecko-dev.git
bug 229394 : add 'font.name-list' support to Xft build (r=bryner, sr=rbs)
This commit is contained in:
Родитель
4082e8f040
Коммит
fb17b19f9c
|
@ -1029,37 +1029,8 @@ nsFontMetricsXft::SetupFCPattern(void)
|
|||
// If there's a generic add a pref for the generic if there's one
|
||||
// set.
|
||||
if (mGenericFont && !mFont->systemFont) {
|
||||
nsCString name;
|
||||
name += "font.name.";
|
||||
name += mGenericFont->get();
|
||||
name += ".";
|
||||
|
||||
nsString langGroup;
|
||||
mLangGroup->ToString(langGroup);
|
||||
|
||||
name.AppendWithConversion(langGroup);
|
||||
|
||||
nsCOMPtr<nsIPref> pref;
|
||||
pref = do_GetService(NS_PREF_CONTRACTID);
|
||||
if (pref) {
|
||||
nsresult rv;
|
||||
nsXPIDLCString value;
|
||||
rv = pref->GetCharPref(name.get(), getter_Copies(value));
|
||||
|
||||
// we ignore prefs that have three hypens since they are X
|
||||
// style prefs.
|
||||
if (NS_FFRECountHyphens(value) < 3) {
|
||||
nsCString tmpstr;
|
||||
tmpstr.Append(value);
|
||||
|
||||
if (PR_LOG_TEST(gXftFontLoad, PR_LOG_DEBUG)) {
|
||||
printf("\tadding generic font from preferences: %s\n",
|
||||
tmpstr.get());
|
||||
}
|
||||
|
||||
NS_AddFFRE(mPattern, &tmpstr, PR_FALSE);
|
||||
}
|
||||
}
|
||||
NS_AddGenericFontFromPref(mGenericFont, mLangGroup, mPattern,
|
||||
gXftFontLoad);
|
||||
}
|
||||
|
||||
// Add the generic if there is one.
|
||||
|
|
|
@ -934,36 +934,8 @@ nsFontPSXft::FindFont(PRUnichar aChar, const nsFont& aFont,
|
|||
// If there's a generic add a pref for the generic if there's one
|
||||
// set.
|
||||
if (fpi.mGenericFont && !aFont.systemFont) {
|
||||
nsCAutoString name;
|
||||
name.AppendLiteral("font.name.");
|
||||
name += fpi.mGenericFont->get();
|
||||
name.AppendLiteral(".");
|
||||
|
||||
nsAutoString langGroupStr;
|
||||
langGroup->ToString(langGroupStr);
|
||||
|
||||
LossyAppendUTF16toASCII(langGroupStr, name);
|
||||
|
||||
nsCOMPtr<nsIPref> pref;
|
||||
pref = do_GetService(NS_PREF_CONTRACTID);
|
||||
if (pref) {
|
||||
nsresult rv;
|
||||
nsXPIDLCString value;
|
||||
rv = pref->GetCharPref(name.get(), getter_Copies(value));
|
||||
|
||||
// we ignore prefs that have three hypens since they are X
|
||||
// style prefs.
|
||||
if (NS_FFRECountHyphens(value) < 3) {
|
||||
nsCAutoString tmpstr(value);
|
||||
|
||||
if (PR_LOG_TEST(gFontMetricsPSM, PR_LOG_DEBUG)) {
|
||||
printf("\tadding generic font from preferences: %s\n",
|
||||
tmpstr.get());
|
||||
}
|
||||
|
||||
NS_AddFFRE(pattern, &tmpstr, PR_FALSE);
|
||||
}
|
||||
}
|
||||
NS_AddGenericFontFromPref(fpi.mGenericFont, langGroup, pattern,
|
||||
gFontMetricsPSM);
|
||||
}
|
||||
|
||||
// Add the generic if there is one.
|
||||
|
|
|
@ -73,6 +73,7 @@ LOCAL_INCLUDES = -I$(srcdir)/.. \
|
|||
$(NULL)
|
||||
|
||||
ifdef MOZ_ENABLE_XFT
|
||||
REQUIRES += pref
|
||||
CPPSRCS += nsFontConfigUtils.cpp
|
||||
LOCAL_INCLUDES += $(MOZ_XFT_CFLAGS)
|
||||
endif
|
||||
|
|
|
@ -34,6 +34,9 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsFontConfigUtils.h"
|
||||
|
||||
struct MozXftLangGroup {
|
||||
|
@ -208,3 +211,76 @@ NS_FFRECountHyphens (nsACString &aFFREName)
|
|||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
inline static void
|
||||
AddFFREandLog(FcPattern *aPattern, nsCString aFamily,
|
||||
const PRLogModuleInfo *aLogModule)
|
||||
{
|
||||
// we ignore prefs that have three hypens since they are X
|
||||
// style prefs.
|
||||
if (NS_FFRECountHyphens(aFamily) >= 3)
|
||||
return;
|
||||
|
||||
if (PR_LOG_TEST(aLogModule, PR_LOG_DEBUG)) {
|
||||
printf("\tadding generic font from preferences: %s\n",
|
||||
aFamily.get());
|
||||
}
|
||||
|
||||
NS_AddFFRE(aPattern, &aFamily, PR_FALSE);
|
||||
}
|
||||
|
||||
// Add prefs (font.name.[generic].[lang] and font.name-list.[generic].[lang])
|
||||
// for the generic if they're set.
|
||||
void
|
||||
NS_AddGenericFontFromPref(const nsCString *aGenericFont,
|
||||
nsIAtom *aLangGroup, FcPattern *aPattern,
|
||||
const PRLogModuleInfo *aLogModule)
|
||||
{
|
||||
nsCOMPtr<nsIPrefService> prefService;
|
||||
prefService = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
if (!prefService)
|
||||
return;
|
||||
nsCOMPtr<nsIPrefBranch> pref;
|
||||
if (NS_FAILED(prefService->GetBranch("font.", getter_AddRefs(pref))))
|
||||
return;
|
||||
|
||||
nsCAutoString genericDotLangGroup(aGenericFont->get());
|
||||
genericDotLangGroup.Append('.');
|
||||
nsAutoString langGroup;
|
||||
aLangGroup->ToString(langGroup);
|
||||
LossyAppendUTF16toASCII(langGroup, genericDotLangGroup);
|
||||
|
||||
nsCAutoString name("name.");
|
||||
name.Append(genericDotLangGroup);
|
||||
|
||||
// prefs file always uses (must use) UTF-8 and fontconfig
|
||||
// expects to get a UTF-8 string so that using |GetCharPref|
|
||||
// is fine.
|
||||
nsresult rv;
|
||||
nsXPIDLCString value;
|
||||
rv = pref->GetCharPref(name.get(), getter_Copies(value));
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
AddFFREandLog(aPattern, value, aLogModule);
|
||||
}
|
||||
|
||||
nsCAutoString nameList("name-list.");
|
||||
nameList.Append(genericDotLangGroup);
|
||||
rv = pref->GetCharPref(nameList.get(), getter_Copies(value));
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PRInt32 prevCommaPos = -1;
|
||||
PRInt32 commaPos;
|
||||
nsCAutoString family;
|
||||
|
||||
while ((commaPos = value.FindChar(',', prevCommaPos + 1)) > 0) {
|
||||
family = Substring(value, prevCommaPos + 1,
|
||||
commaPos - prevCommaPos - 1);
|
||||
prevCommaPos = commaPos;
|
||||
AddFFREandLog(aPattern, family, aLogModule);
|
||||
}
|
||||
|
||||
family = Substring(value, prevCommaPos + 1);
|
||||
AddFFREandLog(aPattern, family, aLogModule);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include "nsString.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsFont.h"
|
||||
#include "prlog.h"
|
||||
|
||||
#include <fontconfig/fontconfig.h>
|
||||
|
||||
|
@ -50,5 +51,9 @@ extern void NS_AddLangGroup (FcPattern *aPattern, nsIAtom *aLangGroup);
|
|||
extern void NS_AddFFRE (FcPattern *aPattern, nsCString *aFamily,
|
||||
PRBool aWeak);
|
||||
extern int NS_FFRECountHyphens (nsACString &aFFREName);
|
||||
extern void NS_AddGenericFontFromPref (const nsCString *aGenericFont,
|
||||
nsIAtom *aLangGroup,
|
||||
FcPattern *aPattern,
|
||||
const PRLogModuleInfo *aLogModule);
|
||||
#endif
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче