Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions
nsFontConfigUtils.h File Reference
#include "nspr.h"
#include "nsString.h"
#include "nsIAtom.h"
#include "nsFont.h"
#include "prlog.h"
#include <fontconfig/fontconfig.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  MozGtkLangGroup

Functions

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)
void NS_AddGenericFontFromPref (const nsCString *aGenericFont, nsIAtom *aLangGroup, FcPattern *aPattern, const PRLogModuleInfo *aLogModule)
const MozGtkLangGroupNS_FindFCLangGroup (nsACString &aLangGroup)

Class Documentation

struct MozGtkLangGroup

Definition at line 48 of file nsFontConfigUtils.h.

Class Members
const FcChar8 * Lang
const char * mozLangGroup

Function Documentation

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: