Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
nsFontConfigUtils.cpp File Reference
#include "nsServiceManagerUtils.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsFontConfigUtils.h"

Go to the source code of this file.

Defines

#define NUM_GTK_LANG_GROUPS

Functions

static void FFREToFamily (nsACString &aFFREName, nsACString &oFamily)
const MozGtkLangGroupNS_FindFCLangGroup (nsACString &aLangGroup)
int NS_CalculateSlant (PRUint8 aStyle)
int NS_CalculateWeight (PRUint16 aWeight)
void NS_AddLangGroup (FcPattern *aPattern, nsIAtom *aLangGroup)
void NS_AddFFRE (FcPattern *aPattern, nsCString *aFamily, PRBool aWeak)
int NS_FFRECountHyphens (nsACString &aFFREName)
static void AddFFREandLog (FcPattern *aPattern, nsCString aFamily, const PRLogModuleInfo *aLogModule)
void NS_AddGenericFontFromPref (const nsCString *aGenericFont, nsIAtom *aLangGroup, FcPattern *aPattern, const PRLogModuleInfo *aLogModule)

Variables

const MozGtkLangGroup MozGtkLangGroups []

Define Documentation

Value:
(sizeof (MozGtkLangGroups) / \
                             sizeof (MozGtkLangGroups[0]))

Definition at line 62 of file nsFontConfigUtils.cpp.


Function Documentation

static void AddFFREandLog ( FcPattern *  aPattern,
nsCString  aFamily,
const PRLogModuleInfo aLogModule 
) [inline, static]

Definition at line 218 of file nsFontConfigUtils.cpp.

{
    // we ignore prefs that have three hypens since they are X
    // style prefs.
    if (NS_FFRECountHyphens(aFamily) >= 3)
        return;

    if (aLogModule && PR_LOG_TEST(aLogModule, PR_LOG_DEBUG)) {
        printf("\tadding generic font from preferences: %s\n",
               aFamily.get());
    }

    NS_AddFFRE(aPattern, &aFamily, PR_FALSE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void FFREToFamily ( nsACString &  aFFREName,
nsACString &  oFamily 
) [static]

Definition at line 192 of file nsFontConfigUtils.cpp.

{
  if (NS_FFRECountHyphens(aFFREName) == 3) {
      PRInt32 familyHyphen = aFFREName.FindChar('-') + 1;
      PRInt32 registryHyphen = aFFREName.FindChar('-',familyHyphen);
      oFamily.Append(Substring(aFFREName, familyHyphen,
                               registryHyphen-familyHyphen));
  }
  else {
      oFamily.Append(aFFREName);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void NS_AddFFRE ( FcPattern *  aPattern,
nsCString aFamily,
PRBool  aWeak 
)

Definition at line 174 of file nsFontConfigUtils.cpp.

{
    nsCAutoString family;
    FFREToFamily(*aFamily, family);

    FcValue v;
    v.type = FcTypeString;
    // casting away the const here, should be safe
    v.u.s = (FcChar8 *)family.get();

    if (aWeak)
        FcPatternAddWeak(aPattern, FC_FAMILY, v, FcTrue);
    else
        FcPatternAdd(aPattern, FC_FAMILY, v, FcTrue);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void NS_AddGenericFontFromPref ( const nsCString aGenericFont,
nsIAtom aLangGroup,
FcPattern *  aPattern,
const PRLogModuleInfo aLogModule 
)

Definition at line 237 of file nsFontConfigUtils.cpp.

{
    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);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void NS_AddLangGroup ( FcPattern *  aPattern,
nsIAtom aLangGroup 
)

Definition at line 151 of file nsFontConfigUtils.cpp.

{
    // Find the FC lang group for this lang group
    nsCAutoString cname;
    aLangGroup->ToUTF8String(cname);

    // see if the lang group needs to be translated from mozilla's
    // internal mapping into fontconfig's
    const struct MozGtkLangGroup *langGroup;
    langGroup = NS_FindFCLangGroup(cname);

    // if there's no lang group, just use the lang group as it was
    // passed to us
    //
    // we're casting away the const here for the strings - should be
    // safe.
    if (!langGroup)
        FcPatternAddString(aPattern, FC_LANG, (FcChar8 *)cname.get());
    else if (langGroup->Lang)
        FcPatternAddString(aPattern, FC_LANG, (FcChar8 *)langGroup->Lang);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 82 of file nsFontConfigUtils.cpp.

{
    int fcSlant;

    switch(aStyle) {
    case NS_FONT_STYLE_ITALIC:
        fcSlant = FC_SLANT_ITALIC;
        break;
    case NS_FONT_STYLE_OBLIQUE:
        fcSlant = FC_SLANT_OBLIQUE;
        break;
    default:
        fcSlant = FC_SLANT_ROMAN;
        break;
    }

    return fcSlant;
}

Here is the caller graph for this function:

Definition at line 102 of file nsFontConfigUtils.cpp.

{
    /*
     * weights come in two parts crammed into one
     * integer -- the "base" weight is weight / 100,
     * the rest of the value is the "offset" from that
     * weight -- the number of steps to move to adjust
     * the weight in the list of supported font weights,
     * this value can be negative or positive.
     */
    PRInt32 baseWeight = (aWeight + 50) / 100;
    PRInt32 offset = aWeight - baseWeight * 100;

    /* clip weights to range 0 to 9 */
    if (baseWeight < 0)
        baseWeight = 0;
    if (baseWeight > 9)
        baseWeight = 9;

    /* Map from weight value to fcWeights index */
    static int fcWeightLookup[10] = {
        0, 0, 0, 0, 1, 1, 2, 3, 3, 4,
    };

    PRInt32 fcWeight = fcWeightLookup[baseWeight];

    /*
     * adjust by the offset value, make sure we stay inside the
     * fcWeights table
     */
    fcWeight += offset;
    if (fcWeight < 0)
        fcWeight = 0;
    if (fcWeight > 4)
        fcWeight = 4;

    /* Map to final FC_WEIGHT value */
    static int fcWeights[5] = {
        FC_WEIGHT_LIGHT,      /* 0 */
        FC_WEIGHT_MEDIUM,     /* 1 */
        FC_WEIGHT_DEMIBOLD,   /* 2 */
        FC_WEIGHT_BOLD,       /* 3 */
        FC_WEIGHT_BLACK,      /* 4 */
    };

    return fcWeights[fcWeight];
}

Here is the caller graph for this function:

int NS_FFRECountHyphens ( nsACString &  aFFREName)

Definition at line 206 of file nsFontConfigUtils.cpp.

{
    int h = 0;
    PRInt32 hyphen = 0;
    while ((hyphen = aFFREName.FindChar('-', hyphen)) >= 0) {
        ++h;
        ++hyphen;
    }
    return h;
}

Here is the caller graph for this function:

const MozGtkLangGroup* NS_FindFCLangGroup ( nsACString &  aLangGroup)

Definition at line 69 of file nsFontConfigUtils.cpp.

{
    for (unsigned int i=0; i < NUM_GTK_LANG_GROUPS; ++i) {
        if (aLangGroup.Equals(MozGtkLangGroups[i].mozLangGroup,
                              nsCaseInsensitiveCStringComparator())) {
            return &MozGtkLangGroups[i];
        }
    }

    return nsnull;
}

Here is the caller graph for this function:


Variable Documentation

Initial value:
 {
    { "x-western",      (const FcChar8 *)"en" },
    { "x-central-euro", (const FcChar8 *)"pl" },
    { "x-cyrillic",     (const FcChar8 *)"ru" },
    { "x-baltic",       (const FcChar8 *)"lv" },
    { "x-devanagari",   (const FcChar8 *)"hi" },
    { "x-tamil",        (const FcChar8 *)"ta" },
    { "x-armn",         (const FcChar8 *)"hy" },
    { "x-beng",         (const FcChar8 *)"bn" },
    { "x-cans",         (const FcChar8 *)"iu" },
    { "x-ethi",         (const FcChar8 *)"am" },
    { "x-geor",         (const FcChar8 *)"ka" },
    { "x-gujr",         (const FcChar8 *)"gu" },
    { "x-guru",         (const FcChar8 *)"pa" },
    { "x-khmr",         (const FcChar8 *)"km" },
    { "x-mlym",         (const FcChar8 *)"ml" },
    { "x-unicode",                       0    },
    { "x-user-def",                      0    },
}

Definition at line 42 of file nsFontConfigUtils.cpp.