Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
nsFontMetricsPango.cpp File Reference
#include <strings.h>
#include "nsFont.h"
#include "nsIDeviceContext.h"
#include "nsICharsetConverterManager.h"
#include "nsIPref.h"
#include "nsServiceManagerUtils.h"
#include "nsFontMetricsPango.h"
#include "nsRenderingContextGTK.h"
#include "nsDeviceContextGTK.h"
#include "nsFontConfigUtils.h"
#include "nsUnicharUtils.h"
#include "nsQuickSort.h"
#include <fontconfig/fontconfig.h>
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include <freetype/tttables.h>
#include "mozilla-decoder.h"
#include "prlog.h"

Go to the source code of this file.

Defines

#define PANGO_ENABLE_BACKEND
#define PANGO_ENABLE_ENGINE
#define FORCE_PR_LOG
#define FONT_MAX_FONT_SCALE   2
#define MOZ_FT_ROUND(x)   (((x) + 32) & ~63)
#define MOZ_FT_TRUNC(x)   ((x) >> 6)
#define CONVERT_DESIGN_UNITS_TO_PIXELS(v, s)   MOZ_FT_TRUNC(MOZ_FT_ROUND(FT_MulFix((v) , (s))))

Functions

static NS_DEFINE_CID (kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID)
static PangoLanguage * GetPangoLanguage (nsIAtom *aLangGroup)
static void FreeGlobals (void)
static PangoStyle CalculateStyle (PRUint8 aStyle)
static PangoWeight CalculateWeight (PRUint16 aWeight)
static nsresult EnumFontsPango (nsIAtom *aLangGroup, const char *aGeneric, PRUint32 *aCount, PRUnichar ***aResult)
static int CompareFontNames (const void *aArg1, const void *aArg2, void *aClosure)

Variables

static PRLogModuleInfogPangoFontLog
static int gNumInstances

Define Documentation

Definition at line 95 of file nsFontMetricsPango.cpp.

Definition at line 79 of file nsFontMetricsPango.cpp.

Definition at line 65 of file nsFontMetricsPango.cpp.

#define MOZ_FT_ROUND (   x)    (((x) + 32) & ~63)

Definition at line 93 of file nsFontMetricsPango.cpp.

#define MOZ_FT_TRUNC (   x)    ((x) >> 6)

Definition at line 94 of file nsFontMetricsPango.cpp.

Definition at line 46 of file nsFontMetricsPango.cpp.

Definition at line 47 of file nsFontMetricsPango.cpp.


Function Documentation

PangoStyle CalculateStyle ( PRUint8  aStyle) [static]

Definition at line 1572 of file nsFontMetricsPango.cpp.

{
    switch(aStyle) {
    case NS_FONT_STYLE_ITALIC:
        return PANGO_STYLE_ITALIC;
        break;
    case NS_FONT_STYLE_OBLIQUE:
        return PANGO_STYLE_OBLIQUE;
        break;
    }

    return PANGO_STYLE_NORMAL;
}

Here is the caller graph for this function:

PangoWeight CalculateWeight ( PRUint16  aWeight) [static]

Definition at line 1588 of file nsFontMetricsPango.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 PANGO_WEIGHT value */
    static int fcWeights[5] = {
        349,
        499,
        649,
        749,
        999
    };

    return (PangoWeight)fcWeights[fcWeight];
}

Here is the caller graph for this function:

int CompareFontNames ( const void aArg1,
const void aArg2,
void aClosure 
) [static]

Definition at line 1766 of file nsFontMetricsPango.cpp.

{
    const PRUnichar* str1 = *((const PRUnichar**) aArg1);
    const PRUnichar* str2 = *((const PRUnichar**) aArg2);

    return nsCRT::strcmp(str1, str2);
}

Here is the caller graph for this function:

nsresult EnumFontsPango ( nsIAtom aLangGroup,
const char *  aGeneric,
PRUint32 aCount,
PRUnichar ***  aResult 
) [static]

Definition at line 1639 of file nsFontMetricsPango.cpp.

{
    FcPattern   *pat = NULL;
    FcObjectSet *os  = NULL;
    FcFontSet   *fs  = NULL;
    nsresult     rv  = NS_ERROR_FAILURE;

    PRUnichar **array = NULL;
    PRUint32    narray = 0;
    PRInt32     serif = 0, sansSerif = 0, monospace = 0, nGenerics;

    *aCount = 0;
    *aResult = nsnull;

    pat = FcPatternCreate();
    if (!pat)
        goto end;

    os = FcObjectSetBuild(FC_FAMILY, FC_FOUNDRY, NULL);
    if (!os)
        goto end;

    // take the pattern and add the lang group to it
    if (aLangGroup)
        NS_AddLangGroup(pat, aLangGroup);

    // get the font list
    fs = FcFontList(0, pat, os);

    if (!fs)
        goto end;

    if (!fs->nfont) {
        rv = NS_OK;
        goto end;
    }

    // Fontconfig supports 3 generic fonts, "serif", "sans-serif", and
    // "monospace", slightly different from CSS's 5.
    if (!aGeneric)
        serif = sansSerif = monospace = 1;
    else if (!strcmp(aGeneric, "serif"))
        serif = 1;
    else if (!strcmp(aGeneric, "sans-serif"))
        sansSerif = 1;
    else if (!strcmp(aGeneric, "monospace"))
        monospace = 1;
    else if (!strcmp(aGeneric, "cursive") || !strcmp(aGeneric, "fantasy"))
        serif = sansSerif =  1;
    else
        NS_NOTREACHED("unexpected generic family");
    nGenerics = serif + sansSerif + monospace;

    array = NS_STATIC_CAST(PRUnichar **,
               nsMemory::Alloc((fs->nfont + nGenerics) * sizeof(PRUnichar *)));
    if (!array)
        goto end;

    if (serif) {
        PRUnichar *name = ToNewUnicode(NS_LITERAL_STRING("serif"));
        if (!name)
            goto end;
        array[narray++] = name;
    }

    if (sansSerif) {
        PRUnichar *name = ToNewUnicode(NS_LITERAL_STRING("sans-serif"));
        if (!name)
            goto end;
        array[narray++] = name;
    }

    if (monospace) {
        PRUnichar *name = ToNewUnicode(NS_LITERAL_STRING("monospace"));
        if (!name)
            goto end;
        array[narray++] = name;
    }

    for (int i=0; i < fs->nfont; ++i) {
        char *family;

        // if there's no family, just move to the next iteration
        if (FcPatternGetString (fs->fonts[i], FC_FAMILY, 0,
                                (FcChar8 **) &family) != FcResultMatch) {
            continue;
        }

        // fontconfig always returns family names in UTF-8
        PRUnichar* name =  UTF8ToNewUnicode(nsDependentCString(family));

        if (!name)
            goto end;

        array[narray++] = name;
    }

    NS_QuickSort(array + nGenerics, narray - nGenerics, sizeof (PRUnichar*),
                 CompareFontNames, nsnull);

    *aCount = narray;
    if (narray)
        *aResult = array;
    else
        nsMemory::Free(array);

    rv = NS_OK;

 end:
    if (NS_FAILED(rv) && array) {
        while (narray)
            nsMemory::Free (array[--narray]);
        nsMemory::Free (array);
    }
    if (pat)
        FcPatternDestroy(pat);
    if (os)
        FcObjectSetDestroy(os);
    if (fs)
        FcFontSetDestroy(fs);

    return rv;
}

Here is the call graph for this function:

void FreeGlobals ( void  ) [static]

Definition at line 1566 of file nsFontMetricsPango.cpp.

{
}

Here is the caller graph for this function:

PangoLanguage * GetPangoLanguage ( nsIAtom aLangGroup) [static]

Definition at line 1540 of file nsFontMetricsPango.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 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)
        return pango_language_from_string(cname.get());
    else if (langGroup->Lang) 
        return pango_language_from_string((char *) langGroup->Lang);

    return pango_language_from_string("en");
}

Here is the call graph for this function:

Here is the caller graph for this function:

static NS_DEFINE_CID ( kCharsetConverterManagerCID  ,
NS_ICHARSETCONVERTERMANAGER_CID   
) [static]

Variable Documentation

int gNumInstances [static]

Definition at line 71 of file nsFontMetricsPango.cpp.

Definition at line 70 of file nsFontMetricsPango.cpp.