Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Protected Attributes | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes
nsFontMetricsXft Class Reference

#include <nsFontMetricsXft.h>

Inheritance diagram for nsFontMetricsXft:
Inheritance graph
[legend]
Collaboration diagram for nsFontMetricsXft:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsFontMetricsXft ()
virtual ~nsFontMetricsXft ()
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
NS_DECL_ISUPPORTS NS_IMETHOD 
Init (const nsFont &aFont, nsIAtom *aLangGroup, nsIDeviceContext *aContext)
 Initialize the font metrics.
NS_IMETHOD Destroy ()
 Destroy this font metrics.
NS_IMETHOD GetLangGroup (nsIAtom **aLangGroup)
 Returns the language group associated with these metrics.
NS_IMETHOD GetFontHandle (nsFontHandle &aHandle)
 Returns the font handle associated with these metrics.
NS_IMETHOD GetXHeight (nscoord &aResult)
 Return the font's xheight property, scaled into app-units.
NS_IMETHOD GetSuperscriptOffset (nscoord &aResult)
 Return the font's superscript offset (the distance from the baseline to where a superscript's baseline should be placed).
NS_IMETHOD GetSubscriptOffset (nscoord &aResult)
 Return the font's subscript offset (the distance from the baseline to where a subscript's baseline should be placed).
NS_IMETHOD GetStrikeout (nscoord &aOffset, nscoord &aSize)
 Return the font's strikeout offset (the distance from the baseline to where a strikeout should be placed) and size Positive values are above the baseline, negative below.
NS_IMETHOD GetUnderline (nscoord &aOffset, nscoord &aSize)
 Return the font's underline offset (the distance from the baseline to where a underline should be placed) and size.
NS_IMETHOD GetHeight (nscoord &aHeight)
 Returns the height (in app units) of the font.
NS_IMETHOD GetNormalLineHeight (nscoord &aHeight)
 Returns the normal line height (em height + leading).
NS_IMETHOD GetLeading (nscoord &aLeading)
 Returns the amount of internal leading (in app units) for the font.
NS_IMETHOD GetEmHeight (nscoord &aHeight)
 Returns the height (in app units) of the Western font's em square.
NS_IMETHOD GetEmAscent (nscoord &aAscent)
 Returns, in app units, the ascent part of the Western font's em square.
NS_IMETHOD GetEmDescent (nscoord &aDescent)
 Returns, in app units, the descent part of the Western font's em square.
NS_IMETHOD GetMaxHeight (nscoord &aHeight)
 Returns the height (in app units) of the Western font's bounding box.
NS_IMETHOD GetMaxAscent (nscoord &aAscent)
 Returns, in app units, the maximum distance characters in this font extend above the base line.
NS_IMETHOD GetMaxDescent (nscoord &aDescent)
 Returns, in app units, the maximum distance characters in this font extend below the base line.
NS_IMETHOD GetMaxAdvance (nscoord &aAdvance)
 Returns, in app units, the maximum character advance for the font.
NS_IMETHOD GetSpaceWidth (nscoord &aSpaceCharWidth)
 Returns the often needed width of the space character.
NS_IMETHOD GetAveCharWidth (nscoord &aAveCharWidth)
 Returns the average character width.
virtual nsresult GetWidth (const char *aString, PRUint32 aLength, nscoord &aWidth)
virtual nsresult GetWidth (const PRUnichar *aString, PRUint32 aLength, nscoord &aWidth, PRInt32 *aFontID)
virtual nsresult GetTextDimensions (const PRUnichar *aString, PRUint32 aLength, nsTextDimensions &aDimensions, PRInt32 *aFontID)
virtual nsresult GetTextDimensions (const char *aString, PRInt32 aLength, PRInt32 aAvailWidth, PRInt32 *aBreaks, PRInt32 aNumBreaks, nsTextDimensions &aDimensions, PRInt32 &aNumCharsFit, nsTextDimensions &aLastWordDimensions, PRInt32 *aFontID)
virtual nsresult GetTextDimensions (const PRUnichar *aString, PRInt32 aLength, PRInt32 aAvailWidth, PRInt32 *aBreaks, PRInt32 aNumBreaks, nsTextDimensions &aDimensions, PRInt32 &aNumCharsFit, nsTextDimensions &aLastWordDimensions, PRInt32 *aFontID)
virtual nsresult DrawString (const char *aString, PRUint32 aLength, nscoord aX, nscoord aY, const nscoord *aSpacing, nsCairoRenderingContext *aContext, nsCairoDrawingSurface *aSurface)
virtual nsresult DrawString (const PRUnichar *aString, PRUint32 aLength, nscoord aX, nscoord aY, PRInt32 aFontID, const nscoord *aSpacing, nsCairoRenderingContext *aContext, nsCairoDrawingSurface *aSurface)
virtual nsresult SetRightToLeftText (PRBool aIsRTL)
nsresult DrawStringCallback (const FcChar32 *aString, PRUint32 aLen, nsFontXft *aFont, void *aData)
nsresult TextDimensionsCallback (const FcChar32 *aString, PRUint32 aLen, nsFontXft *aFont, void *aData)
nsresult GetWidthCallback (const FcChar32 *aString, PRUint32 aLen, nsFontXft *aFont, void *aData)
 nsFontMetricsXft ()
virtual ~nsFontMetricsXft ()
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
NS_DECL_ISUPPORTS NS_IMETHOD 
Init (const nsFont &aFont, nsIAtom *aLangGroup, nsIDeviceContext *aContext)
 Initialize the font metrics.
NS_IMETHOD Destroy ()
 Destroy this font metrics.
NS_IMETHOD GetLangGroup (nsIAtom **aLangGroup)
 Returns the language group associated with these metrics.
NS_IMETHOD GetFontHandle (nsFontHandle &aHandle)
 Returns the font handle associated with these metrics.
NS_IMETHOD GetXHeight (nscoord &aResult)
 Return the font's xheight property, scaled into app-units.
NS_IMETHOD GetSuperscriptOffset (nscoord &aResult)
 Return the font's superscript offset (the distance from the baseline to where a superscript's baseline should be placed).
NS_IMETHOD GetSubscriptOffset (nscoord &aResult)
 Return the font's subscript offset (the distance from the baseline to where a subscript's baseline should be placed).
NS_IMETHOD GetStrikeout (nscoord &aOffset, nscoord &aSize)
 Return the font's strikeout offset (the distance from the baseline to where a strikeout should be placed) and size Positive values are above the baseline, negative below.
NS_IMETHOD GetUnderline (nscoord &aOffset, nscoord &aSize)
 Return the font's underline offset (the distance from the baseline to where a underline should be placed) and size.
NS_IMETHOD GetHeight (nscoord &aHeight)
 Returns the height (in app units) of the font.
NS_IMETHOD GetNormalLineHeight (nscoord &aHeight)
 Returns the normal line height (em height + leading).
NS_IMETHOD GetLeading (nscoord &aLeading)
 Returns the amount of internal leading (in app units) for the font.
NS_IMETHOD GetEmHeight (nscoord &aHeight)
 Returns the height (in app units) of the Western font's em square.
NS_IMETHOD GetEmAscent (nscoord &aAscent)
 Returns, in app units, the ascent part of the Western font's em square.
NS_IMETHOD GetEmDescent (nscoord &aDescent)
 Returns, in app units, the descent part of the Western font's em square.
NS_IMETHOD GetMaxHeight (nscoord &aHeight)
 Returns the height (in app units) of the Western font's bounding box.
NS_IMETHOD GetMaxAscent (nscoord &aAscent)
 Returns, in app units, the maximum distance characters in this font extend above the base line.
NS_IMETHOD GetMaxDescent (nscoord &aDescent)
 Returns, in app units, the maximum distance characters in this font extend below the base line.
NS_IMETHOD GetMaxAdvance (nscoord &aAdvance)
 Returns, in app units, the maximum character advance for the font.
NS_IMETHOD GetSpaceWidth (nscoord &aSpaceCharWidth)
 Returns the often needed width of the space character.
NS_IMETHOD GetAveCharWidth (nscoord &aAveCharWidth)
 Returns the average character width.
PRInt32 GetMaxStringLength ()
virtual nsresult GetWidth (const char *aString, PRUint32 aLength, nscoord &aWidth, nsRenderingContextGTK *aContext)
virtual nsresult GetWidth (const PRUnichar *aString, PRUint32 aLength, nscoord &aWidth, PRInt32 *aFontID, nsRenderingContextGTK *aContext)
virtual nsresult GetTextDimensions (const PRUnichar *aString, PRUint32 aLength, nsTextDimensions &aDimensions, PRInt32 *aFontID, nsRenderingContextGTK *aContext)
virtual nsresult GetTextDimensions (const char *aString, PRInt32 aLength, PRInt32 aAvailWidth, PRInt32 *aBreaks, PRInt32 aNumBreaks, nsTextDimensions &aDimensions, PRInt32 &aNumCharsFit, nsTextDimensions &aLastWordDimensions, PRInt32 *aFontID, nsRenderingContextGTK *aContext)
virtual nsresult GetTextDimensions (const PRUnichar *aString, PRInt32 aLength, PRInt32 aAvailWidth, PRInt32 *aBreaks, PRInt32 aNumBreaks, nsTextDimensions &aDimensions, PRInt32 &aNumCharsFit, nsTextDimensions &aLastWordDimensions, PRInt32 *aFontID, nsRenderingContextGTK *aContext)
virtual nsresult DrawString (const char *aString, PRUint32 aLength, nscoord aX, nscoord aY, const nscoord *aSpacing, nsRenderingContextGTK *aContext, nsDrawingSurfaceGTK *aSurface)
virtual nsresult DrawString (const PRUnichar *aString, PRUint32 aLength, nscoord aX, nscoord aY, PRInt32 aFontID, const nscoord *aSpacing, nsRenderingContextGTK *aContext, nsDrawingSurfaceGTK *aSurface)
virtual GdkFont * GetCurrentGDKFont (void)
virtual nsresult SetRightToLeftText (PRBool aIsRTL)
virtual PRBool GetRightToLeftText ()
virtual nsresult GetClusterInfo (const PRUnichar *aText, PRUint32 aLength, PRUint8 *aClusterStarts)
virtual PRInt32 GetPosition (const PRUnichar *aText, PRUint32 aLength, nsPoint aPt)
virtual nsresult GetRangeWidth (const PRUnichar *aText, PRUint32 aLength, PRUint32 aStart, PRUint32 aEnd, PRUint32 &aWidth)
virtual nsresult GetRangeWidth (const char *aText, PRUint32 aLength, PRUint32 aStart, PRUint32 aEnd, PRUint32 &aWidth)
nsresult DrawStringCallback (const FcChar32 *aString, PRUint32 aLen, nsFontXft *aFont, void *aData)
nsresult TextDimensionsCallback (const FcChar32 *aString, PRUint32 aLen, nsFontXft *aFont, void *aData)
nsresult GetWidthCallback (const FcChar32 *aString, PRUint32 aLen, nsFontXft *aFont, void *aData)
const nsFontFont ()
 Returns the font associated with these metrics.
const nsFontFont ()
 Returns the font associated with these metrics.

Static Public Member Functions

static PRUint32 GetHints (void)
static nsresult FamilyExists (nsIDeviceContext *aDevice, const nsString &aName)
static PRUint32 GetHints (void)
static nsresult FamilyExists (nsIDeviceContext *aDevice, const nsString &aName)

Protected Attributes

nsFont mFont
nsFont mFont

Private Types

enum  FontMatch {
  eNoMatch, eBestMatch, eAllMatching, eNoMatch,
  eBestMatch, eAllMatching
}
enum  FontMatch {
  eNoMatch, eBestMatch, eAllMatching, eNoMatch,
  eBestMatch, eAllMatching
}

Private Member Functions

nsresult RealizeFont (void)
nsresult CacheFontMetrics (void)
nsFontXftFindFont (PRUint32)
void SetupFCPattern (void)
void DoMatch (PRBool aMatchAll)
int RawGetWidth (const PRUnichar *aString, PRUint32 aLength)
nsresult SetupMiniFont (void)
nsresult DrawUnknownGlyph (FcChar32 aChar, nscoord aX, nscoord aY, XftColor *aColor, XftDraw *aDraw)
nsresult EnumerateXftGlyphs (const FcChar32 *aString, PRUint32 aLen, GlyphEnumeratorCallback aCallback, void *aCallbackData)
nsresult EnumerateGlyphs (const char *aString, PRUint32 aLen, GlyphEnumeratorCallback aCallback, void *aCallbackData)
nsresult EnumerateGlyphs (const PRUnichar *aString, PRUint32 aLen, GlyphEnumeratorCallback aCallback, void *aCallbackData)
void PrepareToDraw (nsCairoRenderingContext *aContext, nsCairoDrawingSurface *aSurface, XftDraw **aDraw, XftColor &aColor)
nsresult RealizeFont (void)
nsresult CacheFontMetrics (void)
nsFontXftFindFont (PRUint32)
void SetupFCPattern (void)
void DoMatch (PRBool aMatchAll)
gint RawGetWidth (const PRUnichar *aString, PRUint32 aLength)
nsresult SetupMiniFont (void)
nsresult DrawUnknownGlyph (FcChar32 aChar, nscoord aX, nscoord aY, XftColor *aColor, XftDraw *aDraw)
nsresult EnumerateXftGlyphs (const FcChar32 *aString, PRUint32 aLen, GlyphEnumeratorCallback aCallback, void *aCallbackData)
nsresult EnumerateGlyphs (const char *aString, PRUint32 aLen, GlyphEnumeratorCallback aCallback, void *aCallbackData)
nsresult EnumerateGlyphs (const PRUnichar *aString, PRUint32 aLen, GlyphEnumeratorCallback aCallback, void *aCallbackData)
void PrepareToDraw (nsRenderingContextGTK *aContext, nsDrawingSurfaceGTK *aSurface, XftDraw **aDraw, XftColor &aColor)

Static Private Member Functions

static PRBool EnumFontCallback (const nsString &aFamily, PRBool aIsGeneric, void *aData)
static PRBool EnumFontCallback (const nsString &aFamily, PRBool aIsGeneric, void *aData)

Private Attributes

nsCStringArray mFontList
nsAutoVoidArray mFontIsGeneric
nsIDeviceContextmDeviceContext
nsCOMPtr< nsIAtommLangGroup
nsCStringmGenericFont
float mPixelSize
nsCAutoString mDefaultFont
nsVoidArray mLoadedFonts
nsFontXftmWesternFont
FcPattern * mPattern
FontMatch mMatchType
XftFont * mMiniFont
nscoord mMiniFontWidth
nscoord mMiniFontHeight
nscoord mMiniFontPadding
nscoord mMiniFontYOffset
nscoord mMiniFontAscent
nscoord mMiniFontDescent
nscoord mXHeight
nscoord mSuperscriptOffset
nscoord mSubscriptOffset
nscoord mStrikeoutOffset
nscoord mStrikeoutSize
nscoord mUnderlineOffset
nscoord mUnderlineSize
nscoord mMaxHeight
nscoord mLeading
nscoord mEmHeight
nscoord mEmAscent
nscoord mEmDescent
nscoord mMaxAscent
nscoord mMaxDescent
nscoord mMaxAdvance
nscoord mSpaceWidth
nscoord mAveCharWidth
PRInt32 mMaxStringLength

Detailed Description

Definition at line 59 of file nsFontMetricsXft.h.


Member Enumeration Documentation

Enumerator:
eNoMatch 
eBestMatch 
eAllMatching 
eNoMatch 
eBestMatch 
eAllMatching 

Definition at line 219 of file nsFontMetricsXft.h.

Enumerator:
eNoMatch 
eBestMatch 
eAllMatching 
eNoMatch 
eBestMatch 
eAllMatching 

Definition at line 249 of file nsFontMetricsXft.h.


Constructor & Destructor Documentation

Definition at line 315 of file nsFontMetricsXft.cpp.

                                  : mMiniFont(nsnull)
{
    if (!gXftFontLoad)
        gXftFontLoad = PR_NewLogModule("XftFontLoad");

    ++gNumInstances;
}

Definition at line 323 of file nsFontMetricsXft.cpp.

{
    if (mDeviceContext)
        mDeviceContext->FontMetricsDeleted(this);

    if (mPattern)
        FcPatternDestroy(mPattern);

    for (PRInt32 i= mLoadedFonts.Count() - 1; i >= 0; --i) {
        nsFontXft *font = (nsFontXft *)mLoadedFonts.ElementAt(i);
        delete font;
    }

    if (mMiniFont)
        XftFontClose(GDK_DISPLAY(), mMiniFont);

    if (--gNumInstances == 0) {
        FreeGlobals();
#ifdef DEBUG_XFT_MEMORY
        XftMemReport();
        FcMemReport();
#endif
    }
}

Here is the call graph for this function:

virtual nsFontMetricsXft::~nsFontMetricsXft ( ) [virtual]

Member Function Documentation

Definition at line 754 of file nsFontMetricsXft.cpp.

{
    // Get our scale factor
    float f;
    float val;
    f = mDeviceContext->DevUnitsToAppUnits();
    
    // Get our font face
    FT_Face face;
    TT_OS2 *os2;
    XftFont *xftFont = mWesternFont->mXftFont;
    NS_ASSERTION(xftFont, "FindFont returned a bad font");

    face = XftLockFace(xftFont);
    os2 = (TT_OS2 *) FT_Get_Sfnt_Table(face, ft_sfnt_os2);

    // mEmHeight (size in pixels of EM height)
    int size;
    if (FcPatternGetInteger(mWesternFont->mPattern, FC_PIXEL_SIZE, 0, &size) !=
        FcResultMatch) {
        size = 12;
    }
    mEmHeight = PR_MAX(1, nscoord(size * f));

    // mMaxAscent
    mMaxAscent = nscoord(xftFont->ascent * f);

    // mMaxDescent
    mMaxDescent = nscoord(xftFont->descent * f);

    nscoord lineHeight = mMaxAscent + mMaxDescent;

    // mLeading (needs ascent and descent and EM height) 
    if (lineHeight > mEmHeight)
        mLeading = lineHeight - mEmHeight;
    else
        mLeading = 0;

    // mMaxHeight (needs ascent and descent)
    mMaxHeight = lineHeight;

    // mEmAscent (needs maxascent, EM height, ascent and descent)
    mEmAscent = nscoord(mMaxAscent * mEmHeight / lineHeight);

    // mEmDescent (needs EM height and EM ascent
    mEmDescent = mEmHeight - mEmAscent;

    // mMaxAdvance
    mMaxAdvance = nscoord(xftFont->max_advance_width * f);

    // mSpaceWidth (width of a space)
    gint rawWidth;
    PRUnichar unispace(' ');
    rawWidth = RawGetWidth(&unispace, 1);
    mSpaceWidth = NSToCoordRound(rawWidth * f);

    // mAveCharWidth (width of an 'average' char)
    PRUnichar xUnichar('x');
    rawWidth = RawGetWidth(&xUnichar, 1);
    mAveCharWidth = NSToCoordRound(rawWidth * f);

    // mXHeight (height of an 'x' character)
    if (FcCharSetHasChar(mWesternFont->mCharset, xUnichar)) {
        XGlyphInfo extents;
        XftTextExtents16(GDK_DISPLAY(), xftFont, &xUnichar, 1, &extents);
        mXHeight = extents.height;
    }
    else {
        // 56% of ascent, best guess for non-true type or asian fonts
        mXHeight = nscoord(((float)mMaxAscent) * 0.56);
    }
    mXHeight = nscoord(mXHeight * f);

    // mUnderlineOffset (offset for underlines)
    val = CONVERT_DESIGN_UNITS_TO_PIXELS(face->underline_position,
                                         face->size->metrics.y_scale);
    if (val) {
        mUnderlineOffset = NSToIntRound(val * f);
    }
    else {
        mUnderlineOffset =
            -NSToIntRound(PR_MAX(1, floor(0.1 * xftFont->height + 0.5)) * f);
    }

    // mUnderlineSize (thickness of an underline)
    val = CONVERT_DESIGN_UNITS_TO_PIXELS(face->underline_thickness,
                                         face->size->metrics.y_scale);
    if (val) {
        mUnderlineSize = nscoord(PR_MAX(f, NSToIntRound(val * f)));
    }
    else {
        mUnderlineSize =
            NSToIntRound(PR_MAX(1, floor(0.05 * xftFont->height + 0.5)) * f);
    }

    // mSuperscriptOffset
    if (os2 && os2->ySuperscriptYOffset) {
        val = CONVERT_DESIGN_UNITS_TO_PIXELS(os2->ySuperscriptYOffset,
                                             face->size->metrics.y_scale);
        mSuperscriptOffset = nscoord(PR_MAX(f, NSToIntRound(val * f)));
    }
    else {
        mSuperscriptOffset = mXHeight;
    }

    // mSubscriptOffset
    if (os2 && os2->ySubscriptYOffset) {
        val = CONVERT_DESIGN_UNITS_TO_PIXELS(os2->ySubscriptYOffset,
                                             face->size->metrics.y_scale);
        // some fonts have the incorrect sign. 
        val = (val < 0) ? -val : val;
        mSubscriptOffset = nscoord(PR_MAX(f, NSToIntRound(val * f)));
    }
    else {
        mSubscriptOffset = mXHeight;
    }

    // mStrikeoutOffset
    mStrikeoutOffset = NSToCoordRound(mXHeight / 2.0);

    // mStrikeoutSize
    mStrikeoutSize = mUnderlineSize;

    XftUnlockFace(xftFont);

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Destroy this font metrics.

This breaks the association between the font metrics and the device context.

Implements nsIFontMetrics.

Definition at line 452 of file nsFontMetricsXft.cpp.

{
    mDeviceContext = nsnull;

    return NS_OK;
}

Destroy this font metrics.

This breaks the association between the font metrics and the device context.

Implements nsIFontMetrics.

void nsFontMetricsXft::DoMatch ( PRBool  aMatchAll) [private]

Definition at line 1069 of file nsFontMetricsXft.cpp.

{
    FcFontSet *set = nsnull;
    // now that we have a pattern we can match
    FcResult   result;

    if (aMatchAll) {
        set = FcFontSort(0, mPattern, FcTrue, NULL, &result);
        if (!set || set->nfont == 1) {
            // There is a bug in older fontconfig versions that causes it to
            // bail if it hits a font it can't deal with.
            // If this has happened, try just the generic font-family by
            // removing everything else from the font list and rebuilding
            // the pattern.

            NS_WARNING("Detected buggy fontconfig, falling back to generic font");

            nsCAutoString genericFont;
            if (mGenericFont)
                genericFont.Assign(*mGenericFont);

            mFontList.Clear();
            mFontIsGeneric.Clear();

            mFontList.AppendCString(genericFont);
            mFontIsGeneric.AppendElement((void*) PR_TRUE);
            mGenericFont = mFontList.CStringAt(0);

            FcPatternDestroy(mPattern);
            SetupFCPattern();

            if (set)
                FcFontSetDestroy(set);

            set = FcFontSort(0, mPattern, FcTrue, NULL, &result);
        }
    }
    else {
        FcPattern* font = FcFontMatch(0, mPattern, &result);
        if (font) {
            set = FcFontSetCreate();
            FcFontSetAdd(set, font);
        }
    }

    // did we not match anything?
    if (!set) {
        goto loser;
    }

    if (PR_LOG_TEST(gXftFontLoad, PR_LOG_DEBUG)) {
        printf("matched the following (%d) fonts:\n", set->nfont);
    }

    // Create a list of new font objects based on the fonts returned
    // as part of the query. We start at mLoadedFonts.Count() so as to
    // not re-add the best match font we've already loaded.
    for (int i=mLoadedFonts.Count(); i < set->nfont; ++i) {
        if (PR_LOG_TEST(gXftFontLoad, PR_LOG_DEBUG)) {
            char *name;
            FcPatternGetString(set->fonts[i], FC_FAMILY, 0, (FcChar8 **)&name);
            printf("\t%s\n", name);
        }

        nsFontXft *font;
        nsFontXftInfo *info;
        nsCOMPtr<nsIUnicodeEncoder> converter = 0;

        info = GetFontXftInfo(set->fonts[i]);
        if (info) {
            if (info->mFontType == eFontTypeUnicode)
                font = new nsFontXftUnicode(mPattern, set->fonts[i]);
            else
                font = new nsFontXftCustom(mPattern, set->fonts[i], info);
        }
        else {  // if null is returned, treat it as Unicode font.
            font = new nsFontXftUnicode(mPattern, set->fonts[i]);
        }

        if (!font)
            goto loser;

        // append this font to our list of loaded fonts
        mLoadedFonts.AppendElement((void *)font);
    }

    // we're done with the set now
    FcFontSetDestroy(set);
    set = nsnull;

    // Done matching!
    if (aMatchAll)
        mMatchType = eAllMatching;
    else
        mMatchType = eBestMatch;
    return;

    // if we got this far, something went terribly wrong
 loser:
    NS_WARNING("nsFontMetricsXft::DoMatch failed to match anything");

    if (set)
        FcFontSetDestroy(set);

    for (PRInt32 i = mLoadedFonts.Count() - 1; i >= 0; --i) {
        nsFontXft *font = (nsFontXft *)mLoadedFonts.ElementAt(i);
        mLoadedFonts.RemoveElementAt(i);
        delete font;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsFontMetricsXft::DoMatch ( PRBool  aMatchAll) [private]
nsresult nsFontMetricsXft::DrawString ( const char *  aString,
PRUint32  aLength,
nscoord  aX,
nscoord  aY,
const nscoord aSpacing,
nsCairoRenderingContext aContext,
nsCairoDrawingSurface aSurface 
) [virtual]

Implements nsICairoFontMetrics.

Definition at line 583 of file nsFontMetricsXft.cpp.

{
    NS_TIMELINE_MARK_FUNCTION("DrawString");

    // The data we will carry through the function
    DrawStringData data;
    memset(&data, 0, sizeof(data));

    data.x = aX;
    data.y = aY;
    data.spacing = aSpacing;
    data.context = aContext;
    data.p2t = mDeviceContext->DevUnitsToAppUnits();

    PrepareToDraw(aContext, aSurface, &data.draw, data.color);

    nsAutoDrawSpecBuffer drawBuffer(data.draw, &data.color);
    data.drawBuffer = &drawBuffer;

    return EnumerateGlyphs(aString, aLength,
                           &nsFontMetricsXft::DrawStringCallback, &data);
}

Here is the call graph for this function:

nsresult nsFontMetricsXft::DrawString ( const PRUnichar aString,
PRUint32  aLength,
nscoord  aX,
nscoord  aY,
PRInt32  aFontID,
const nscoord aSpacing,
nsCairoRenderingContext aContext,
nsCairoDrawingSurface aSurface 
) [virtual]

Implements nsICairoFontMetrics.

Definition at line 611 of file nsFontMetricsXft.cpp.

{
    NS_TIMELINE_MARK_FUNCTION("DrawString");

    // The data we will carry through the function
    DrawStringData data;
    memset(&data, 0, sizeof(data));

    data.x = aX;
    data.y = aY;
    data.spacing = aSpacing;
    data.context = aContext;
    data.p2t = mDeviceContext->DevUnitsToAppUnits();

    // set up our colors and clip regions
    PrepareToDraw(aContext, aSurface, &data.draw, data.color);

    nsAutoDrawSpecBuffer drawBuffer(data.draw, &data.color);
    data.drawBuffer = &drawBuffer;

    return EnumerateGlyphs(aString, aLength,
                           &nsFontMetricsXft::DrawStringCallback, &data);
}

Here is the call graph for this function:

nsresult nsFontMetricsXft::DrawString ( const char *  aString,
PRUint32  aLength,
nscoord  aX,
nscoord  aY,
const nscoord aSpacing,
nsRenderingContextGTK aContext,
nsDrawingSurfaceGTK aSurface 
) [virtual]

Implements nsIFontMetricsGTK.

Definition at line 589 of file nsFontMetricsXft.cpp.

{
    NS_TIMELINE_MARK_FUNCTION("DrawString");

    // The data we will carry through the function
    DrawStringData data;
    memset(&data, 0, sizeof(data));

    data.x = aX;
    data.y = aY;
    data.spacing = aSpacing;
    data.context = aContext;
    data.p2t = mDeviceContext->DevUnitsToAppUnits();

    PrepareToDraw(aContext, aSurface, &data.draw, data.color);

    nsAutoDrawSpecBuffer drawBuffer(data.draw, &data.color);
    data.drawBuffer = &drawBuffer;

    return EnumerateGlyphs(aString, aLength,
                           &nsFontMetricsXft::DrawStringCallback, &data);
}

Here is the call graph for this function:

nsresult nsFontMetricsXft::DrawString ( const PRUnichar aString,
PRUint32  aLength,
nscoord  aX,
nscoord  aY,
PRInt32  aFontID,
const nscoord aSpacing,
nsRenderingContextGTK aContext,
nsDrawingSurfaceGTK aSurface 
) [virtual]

Implements nsIFontMetricsGTK.

Definition at line 617 of file nsFontMetricsXft.cpp.

{
    NS_TIMELINE_MARK_FUNCTION("DrawString");

    // The data we will carry through the function
    DrawStringData data;
    memset(&data, 0, sizeof(data));

    data.x = aX;
    data.y = aY;
    data.spacing = aSpacing;
    data.context = aContext;
    data.p2t = mDeviceContext->DevUnitsToAppUnits();

    // set up our colors and clip regions
    PrepareToDraw(aContext, aSurface, &data.draw, data.color);

    nsAutoDrawSpecBuffer drawBuffer(data.draw, &data.color);
    data.drawBuffer = &drawBuffer;

    return EnumerateGlyphs(aString, aLength,
                           &nsFontMetricsXft::DrawStringCallback, &data);
}

Here is the call graph for this function:

nsresult nsFontMetricsXft::DrawStringCallback ( const FcChar32 *  aString,
PRUint32  aLen,
nsFontXft aFont,
void aData 
)

Definition at line 1497 of file nsFontMetricsXft.cpp.

{
    DrawStringData *data = (DrawStringData *)aData;

    // If there was no font found for this character, just draw the
    // unknown glyph character
    if (!aFont) {
        SetupMiniFont();

        for (PRUint32 i = 0; i<aLen; i++) {
            // position in X is the location offset in the string plus
            // whatever offset is required for the spacing argument
            const FcChar32 ch = aString[i];
            nscoord x = data->x + data->xOffset;
            nscoord y = data->y;

            // convert this into device coordinates
            data->context->TransformCoord(&x, &y);

            DrawUnknownGlyph(ch, x, y + mMiniFontYOffset, &data->color,
                             data->draw);

            if (data->spacing) {
                data->xOffset += *data->spacing;
                data->spacing += IS_NON_BMP(ch) ? 2 : 1;
            }
            else {
                data->xOffset +=
                    NSToCoordRound((mMiniFontWidth*(IS_NON_BMP(ch) ? 3 : 2) +
                                mMiniFontPadding*(IS_NON_BMP(ch) ? 6:5)) *
                            data->p2t);
            }
        }

        // We're done.
        return NS_OK;
    }

    // actually process the specbuffer converting the input string
    // to custom font code if necessary.
    return aFont->DrawStringSpec(NS_CONST_CAST(FcChar32 *, aString), 
                                 aLen, data);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsFontMetricsXft::DrawStringCallback ( const FcChar32 *  aString,
PRUint32  aLen,
nsFontXft aFont,
void aData 
)
nsresult nsFontMetricsXft::DrawUnknownGlyph ( FcChar32  aChar,
nscoord  aX,
nscoord  aY,
XftColor *  aColor,
XftDraw *  aDraw 
) [private]

Definition at line 1281 of file nsFontMetricsXft.cpp.

{
    int width,height;
    int ndigit = (IS_NON_BMP(aChar)) ? 3 : 2;

    // ndigit characters + padding around the fonts.  From left to
    // right it would be one padding for the glyph box, one for the
    // padding in between the box and the left most digit, ndigit
    // padding following each of ndigit letters and one for the
    // rightmost part of the box.  This pattern is used throughout the
    // rest of this function.
    width = mMiniFontWidth * ndigit + mMiniFontPadding * (ndigit + 3);
    height = mMiniFontHeight * 2 + mMiniFontPadding * 5;

    // Draw an outline of a box.  We do with this with four calls
    // since with one call it would fill in the box.
    
    // horizontal lines
    XftDrawRect(aDraw, aColor,
                aX, aY - height,
                width, mMiniFontPadding);
    XftDrawRect(aDraw, aColor,
                aX, aY - mMiniFontPadding,
                width, mMiniFontPadding);

    // vertical lines
    XftDrawRect(aDraw, aColor,
                aX,
                aY - height + mMiniFontPadding,
                mMiniFontPadding, height - mMiniFontPadding * 2);
    XftDrawRect(aDraw, aColor,
                aX + width - mMiniFontPadding,
                aY - height + mMiniFontPadding,
                mMiniFontPadding, height - mMiniFontPadding * 2);

    // If for some reason the mini font couldn't be loaded, just
    // return - the box is enough.
    if (!mMiniFont)
        return NS_OK;

    // now draw the characters
    char buf[7];
    PR_snprintf (buf, sizeof(buf), "%0*X", ndigit * 2, aChar);

    // Draw the 'ndigit * 2' characters
    XftDrawString8(aDraw, aColor, mMiniFont,
                   aX + mMiniFontPadding * 2,
                   aY - mMiniFontHeight - mMiniFontPadding * 3,
                   (FcChar8 *)&buf[0], 1);
    XftDrawString8(aDraw, aColor, mMiniFont,
                   aX + mMiniFontWidth + mMiniFontPadding * 3,
                   aY - mMiniFontHeight - mMiniFontPadding * 3,
                   (FcChar8 *)&buf[1], 1);

    if (ndigit == 2) {
        XftDrawString8(aDraw, aColor, mMiniFont,
                       aX + mMiniFontPadding * 2,
                       aY - mMiniFontPadding * 2,
                       (FcChar8 *)&buf[2], 1);
        XftDrawString8(aDraw, aColor, mMiniFont,
                       aX + mMiniFontWidth + mMiniFontPadding * 3,
                       aY - mMiniFontPadding * 2,
                       (FcChar8 *)&buf[3], 1);

        return NS_OK;
    }

    XftDrawString8(aDraw, aColor, mMiniFont,
                   aX + mMiniFontWidth * 2 + mMiniFontPadding * 4,
                   aY - mMiniFontHeight - mMiniFontPadding * 3,
                   (FcChar8 *)&buf[2], 1);
    XftDrawString8(aDraw, aColor, mMiniFont,
                   aX + mMiniFontPadding * 2,
                   aY - mMiniFontPadding * 2,
                   (FcChar8 *)&buf[3], 1);
    XftDrawString8(aDraw, aColor, mMiniFont,
                   aX + mMiniFontWidth + mMiniFontPadding * 3,
                   aY - mMiniFontPadding * 2,
                   (FcChar8 *)&buf[4], 1);
    XftDrawString8(aDraw, aColor, mMiniFont,
                   aX + mMiniFontWidth * 2 + mMiniFontPadding * 4,
                   aY - mMiniFontPadding * 2,
                   (FcChar8 *)&buf[5], 1);

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsFontMetricsXft::DrawUnknownGlyph ( FcChar32  aChar,
nscoord  aX,
nscoord  aY,
XftColor *  aColor,
XftDraw *  aDraw 
) [private]
nsresult nsFontMetricsXft::EnumerateGlyphs ( const char *  aString,
PRUint32  aLen,
GlyphEnumeratorCallback  aCallback,
void aCallbackData 
) [private]

Definition at line 1428 of file nsFontMetricsXft.cpp.

{
    PRUint32 len;
    nsAutoFcChar32Buffer charBuffer;

    NS_ENSURE_TRUE(aLen, NS_OK); 

    // Convert the incoming string into an array of UCS4 chars
    ConvertCharToUCS4(aString, aLen, charBuffer, &len);
    if (!len)
        return NS_ERROR_OUT_OF_MEMORY;

    return EnumerateXftGlyphs(charBuffer.get(), len, aCallback, aCallbackData);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsFontMetricsXft::EnumerateGlyphs ( const PRUnichar aString,
PRUint32  aLen,
GlyphEnumeratorCallback  aCallback,
void aCallbackData 
) [private]

Definition at line 1410 of file nsFontMetricsXft.cpp.

{
    PRUint32 len;
    nsAutoFcChar32Buffer charBuffer;

    NS_ENSURE_TRUE(aLen, NS_OK); 

    ConvertUnicharToUCS4(aString, aLen, charBuffer, &len);
    if (!len)
        return NS_ERROR_OUT_OF_MEMORY;

    return EnumerateXftGlyphs(charBuffer.get(), len, aCallback, aCallbackData);
}

Here is the call graph for this function:

nsresult nsFontMetricsXft::EnumerateGlyphs ( const char *  aString,
PRUint32  aLen,
GlyphEnumeratorCallback  aCallback,
void aCallbackData 
) [private]
nsresult nsFontMetricsXft::EnumerateGlyphs ( const PRUnichar aString,
PRUint32  aLen,
GlyphEnumeratorCallback  aCallback,
void aCallbackData 
) [private]
nsresult nsFontMetricsXft::EnumerateXftGlyphs ( const FcChar32 *  aString,
PRUint32  aLen,
GlyphEnumeratorCallback  aCallback,
void aCallbackData 
) [private]

Definition at line 1373 of file nsFontMetricsXft.cpp.

{
    nsFontXft* prevFont = nsnull;
    PRUint32 start = 0;
    nsresult rv = NS_OK;
    PRUint32 i = 0;

    for ( ; i < aLen; i ++) {
        nsFontXft *currFont = FindFont(aString[i]);

        // Don't try to handle more than 512 characters at once, since
        // Xft text measurement can't deal with anything with a width of
        // more than 2^15 (32768) pixels.  This is a hack, and it could
        // break things like combining characters, but that's not nearly
        // as bad as not displaying anything, and it's also very rare to
        // draw strings this long without any breaks.
        if (currFont != prevFont || i - start > 512) {
            if (i > start) {
                rv = (this->*aCallback)(&aString[start], i - start, prevFont,
                                        aCallbackData);
                NS_ENSURE_SUCCESS(rv, rv);
            }
            prevFont = currFont;
            start = i;
        }
    }

    if (i > start)
        rv = (this->*aCallback)(&aString[start], i - start, prevFont,
                                aCallbackData);

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsFontMetricsXft::EnumerateXftGlyphs ( const FcChar32 *  aString,
PRUint32  aLen,
GlyphEnumeratorCallback  aCallback,
void aCallbackData 
) [private]
PRBool nsFontMetricsXft::EnumFontCallback ( const nsString aFamily,
PRBool  aIsGeneric,
void aData 
) [static, private]

Definition at line 1697 of file nsFontMetricsXft.cpp.

{
    NS_ConvertUTF16toUTF8 name(aFamily);

    // The newest fontconfig does the full Unicode case folding so that 
    // we're being lazy here by calling |ToLowerCase| after converting
    // to UTF-8  assuming that in virtually all cases, we just have to
    // fold [A-Z].  (bug 223653). 
    ToLowerCase(name);
    nsFontMetricsXft *metrics = (nsFontMetricsXft *)aData;
    metrics->mFontList.AppendCString(name);
    metrics->mFontIsGeneric.AppendElement((void *)aIsGeneric);
    if (aIsGeneric) {
        metrics->mGenericFont = 
            metrics->mFontList.CStringAt(metrics->mFontList.Count() - 1);
        return PR_FALSE; // stop processing
    }

    return PR_TRUE; // keep processing
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool nsFontMetricsXft::EnumFontCallback ( const nsString aFamily,
PRBool  aIsGeneric,
void aData 
) [static, private]

Definition at line 1643 of file nsFontMetricsXft.cpp.

{
    // fontconfig family name is always in UTF-8
    NS_ConvertUTF16toUTF8 name(aName);

    FcFontSet *set = nsnull;
    FcObjectSet *os = nsnull;

    FcPattern *pat = FcPatternCreate();
    if (!pat)
        return NS_ERROR_FAILURE;

    nsresult rv = NS_ERROR_FAILURE;
    
    // Build a list of familes and walk the list looking to see if we
    // have it.
    os = FcObjectSetBuild(FC_FAMILY, 0);
    if (!os)
        goto end;

    set = FcFontList(0, pat, os);

    if (!set || !set->nfont)
        goto end;

    for (int i = 0; i < set->nfont; ++i) {
        const char *tmpname = NULL;
        if (FcPatternGetString(set->fonts[i], FC_FAMILY, 0,
                               (FcChar8 **)&tmpname) != FcResultMatch) {
            continue;
        }

        // do they match?
        if (!Compare(nsDependentCString(tmpname), name,
                     nsCaseInsensitiveCStringComparator())) {
            rv = NS_OK;
            break;
        }
    }

 end:
    if (set)
        FcFontSetDestroy(set);
    if (os)
        FcObjectSetDestroy(os);

    FcPatternDestroy(pat);

    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult nsFontMetricsXft::FamilyExists ( nsIDeviceContext aDevice,
const nsString aName 
) [static]

Definition at line 883 of file nsFontMetricsXft.cpp.

{

    // If mPattern is null, set up the base bits of it so we can
    // match.  If we need to match later we don't have to set it up
    // again.
    if (!mPattern) {
        SetupFCPattern();
        // did we fail to set it up?
        if (!mPattern)
            return nsnull;
    }

    // go forth and find us some fonts
    if (mMatchType == eNoMatch) {
        // Optimistically just look for the best match font.
        // This can be completed in linear time, which is ideal if all
        // of the characters we're asked for can be found in this font.
        DoMatch(PR_FALSE);
    }

    // Now that we have the fonts loaded and ready to run, return the
    // font in our loaded list that supports the character

    if (mLoadedFonts.Count() == 0) {
        // No fonts were matched at all.  This probably means out-of-memory
        // or some equally bad condition.
        return nsnull;
    }

    PRBool removeFirstFont = PR_FALSE;
    nsFontXft *font = (nsFontXft *)mLoadedFonts.ElementAt(0);
    if (font->HasChar(aChar)) {
        if (font->GetXftFont())
            return font;
        removeFirstFont = PR_TRUE;
    }

    // We failed to find the character in the best-match font, so load
    // _all_ matching fonts if we haven't already done so.

    if (mMatchType == eBestMatch)
        DoMatch(PR_TRUE);

    PRInt32 i = 1;
    if (removeFirstFont) {
        // The first font was bad, so remove it (see below).  But do this
        // after |DoMatch| since otherwise it will get re-added.
        mLoadedFonts.RemoveElementAt(0);
        i = 0;
    }

    // Now check the remaining fonts
    for (; i < mLoadedFonts.Count(); ++i) {
        nsFontXft *font = (nsFontXft *)mLoadedFonts.ElementAt(i);
        if (font->HasChar(aChar)) {
            if (font->GetXftFont())
                return font;
            // This is a bad font, so remove it from mLoadedFonts.  This
            // could happen if it's in fc.cache-1 but the font doesn't exist
            // (https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=111973)
            // or isn't readable.
            mLoadedFonts.RemoveElementAt(i--);
        }
    }

    // If we got this far, none of the fonts support this character.
    // Return nothing.
    return nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const nsFont& nsIFontMetrics::Font ( ) [inline, inherited]

Returns the font associated with these metrics.

The return value is only defined after Init() has been called.

Definition at line 214 of file nsIFontMetrics.h.

{ return mFont; }

Here is the caller graph for this function:

const nsFont& nsIFontMetrics::Font ( ) [inline, inherited]

Returns the font associated with these metrics.

The return value is only defined after Init() has been called.

Definition at line 214 of file nsIFontMetrics.h.

{ return mFont; }

Here is the caller graph for this function:

NS_IMETHOD nsFontMetricsXft::GetAveCharWidth ( nscoord aAveCharWidth) [inline, virtual]

Returns the average character width.

Implements nsIFontMetrics.

Definition at line 142 of file nsFontMetricsXft.h.

                                     { aAveCharWidth = mAveCharWidth;
                                       return NS_OK; };
NS_IMETHOD nsFontMetricsXft::GetAveCharWidth ( nscoord aAveCharWidth) [inline, virtual]

Returns the average character width.

Implements nsIFontMetrics.

Definition at line 142 of file nsFontMetricsXft.h.

                                     { aAveCharWidth = mAveCharWidth;
                                       return NS_OK; };
nsresult nsFontMetricsXft::GetClusterInfo ( const PRUnichar aText,
PRUint32  aLength,
PRUint8 aClusterStarts 
) [virtual]

Implements nsIFontMetricsGTK.

Definition at line 746 of file nsFontMetricsXft.cpp.

GdkFont * nsFontMetricsXft::GetCurrentGDKFont ( void  ) [virtual]

Implements nsIFontMetricsGTK.

Definition at line 728 of file nsFontMetricsXft.cpp.

{
    return nsnull;
}
NS_IMETHOD nsFontMetricsXft::GetEmAscent ( nscoord aAscent) [inline, virtual]

Returns, in app units, the ascent part of the Western font's em square.

Implements nsIFontMetrics.

Definition at line 114 of file nsFontMetricsXft.h.

                                     { aAscent = mEmAscent;
                                       return NS_OK; };
NS_IMETHOD nsFontMetricsXft::GetEmAscent ( nscoord aAscent) [inline, virtual]

Returns, in app units, the ascent part of the Western font's em square.

Implements nsIFontMetrics.

Definition at line 114 of file nsFontMetricsXft.h.

                                     { aAscent = mEmAscent;
                                       return NS_OK; };
NS_IMETHOD nsFontMetricsXft::GetEmDescent ( nscoord aDescent) [inline, virtual]

Returns, in app units, the descent part of the Western font's em square.

Implements nsIFontMetrics.

Definition at line 118 of file nsFontMetricsXft.h.

                                     { aDescent = mEmDescent;
                                       return NS_OK; };
NS_IMETHOD nsFontMetricsXft::GetEmDescent ( nscoord aDescent) [inline, virtual]

Returns, in app units, the descent part of the Western font's em square.

Implements nsIFontMetrics.

Definition at line 118 of file nsFontMetricsXft.h.

                                     { aDescent = mEmDescent;
                                       return NS_OK; };
NS_IMETHOD nsFontMetricsXft::GetEmHeight ( nscoord aHeight) [inline, virtual]

Returns the height (in app units) of the Western font's em square.

This is em ascent plus em descent.

Implements nsIFontMetrics.

Definition at line 110 of file nsFontMetricsXft.h.

                                     { aHeight = mEmHeight; 
                                       return NS_OK; };
NS_IMETHOD nsFontMetricsXft::GetEmHeight ( nscoord aHeight) [inline, virtual]

Returns the height (in app units) of the Western font's em square.

This is em ascent plus em descent.

Implements nsIFontMetrics.

Definition at line 110 of file nsFontMetricsXft.h.

                                     { aHeight = mEmHeight; 
                                       return NS_OK; };

Returns the font handle associated with these metrics.

Implements nsIFontMetrics.

Definition at line 469 of file nsFontMetricsXft.cpp.

Returns the font handle associated with these metrics.

Implements nsIFontMetrics.

NS_IMETHOD nsFontMetricsXft::GetHeight ( nscoord aHeight) [inline, virtual]

Returns the height (in app units) of the font.

This is ascent plus descent plus any internal leading

This method will be removed once the callers have been moved over to the new GetEmHeight (and possibly GetMaxHeight).

Implements nsIFontMetrics.

Definition at line 98 of file nsFontMetricsXft.h.

                                     { aHeight = mMaxHeight; 
                                       return NS_OK; };
NS_IMETHOD nsFontMetricsXft::GetHeight ( nscoord aHeight) [inline, virtual]

Returns the height (in app units) of the font.

This is ascent plus descent plus any internal leading

This method will be removed once the callers have been moved over to the new GetEmHeight (and possibly GetMaxHeight).

Implements nsIFontMetrics.

Definition at line 98 of file nsFontMetricsXft.h.

                                     { aHeight = mMaxHeight; 
                                       return NS_OK; };

Definition at line 728 of file nsFontMetricsXft.cpp.

{
    return 0;
}

Here is the caller graph for this function:

static PRUint32 nsFontMetricsXft::GetHints ( void  ) [static]
NS_IMETHOD nsFontMetricsXft::GetLangGroup ( nsIAtom **  aLangGroup) [virtual]

Returns the language group associated with these metrics.

Implements nsIFontMetrics.

Returns the language group associated with these metrics.

Implements nsIFontMetrics.

Definition at line 460 of file nsFontMetricsXft.cpp.

{
    *aLangGroup = mLangGroup;
    NS_IF_ADDREF(*aLangGroup);

    return NS_OK;
}
NS_IMETHOD nsFontMetricsXft::GetLeading ( nscoord aLeading) [inline, virtual]

Returns the amount of internal leading (in app units) for the font.

This is computed as the "height - (ascent + descent)"

Implements nsIFontMetrics.

Definition at line 106 of file nsFontMetricsXft.h.

                                     { aLeading = mLeading; 
                                       return NS_OK; };
NS_IMETHOD nsFontMetricsXft::GetLeading ( nscoord aLeading) [inline, virtual]

Returns the amount of internal leading (in app units) for the font.

This is computed as the "height - (ascent + descent)"

Implements nsIFontMetrics.

Definition at line 106 of file nsFontMetricsXft.h.

                                     { aLeading = mLeading; 
                                       return NS_OK; };
NS_IMETHOD nsFontMetricsXft::GetMaxAdvance ( nscoord aAdvance) [inline, virtual]

Returns, in app units, the maximum character advance for the font.

Implements nsIFontMetrics.

Definition at line 134 of file nsFontMetricsXft.h.

                                     { aAdvance = mMaxAdvance;
                                       return NS_OK; };
NS_IMETHOD nsFontMetricsXft::GetMaxAdvance ( nscoord aAdvance) [inline, virtual]

Returns, in app units, the maximum character advance for the font.

Implements nsIFontMetrics.

Definition at line 134 of file nsFontMetricsXft.h.

                                     { aAdvance = mMaxAdvance;
                                       return NS_OK; };
NS_IMETHOD nsFontMetricsXft::GetMaxAscent ( nscoord aAscent) [inline, virtual]

Returns, in app units, the maximum distance characters in this font extend above the base line.

Implements nsIFontMetrics.

Definition at line 126 of file nsFontMetricsXft.h.

                                     { aAscent = mMaxAscent;
                                       return NS_OK; };
NS_IMETHOD nsFontMetricsXft::GetMaxAscent ( nscoord aAscent) [inline, virtual]

Returns, in app units, the maximum distance characters in this font extend above the base line.

Implements nsIFontMetrics.

Definition at line 126 of file nsFontMetricsXft.h.

                                     { aAscent = mMaxAscent;
                                       return NS_OK; };
NS_IMETHOD nsFontMetricsXft::GetMaxDescent ( nscoord aDescent) [inline, virtual]

Returns, in app units, the maximum distance characters in this font extend below the base line.

Implements nsIFontMetrics.

Definition at line 130 of file nsFontMetricsXft.h.

                                     { aDescent = mMaxDescent;
                                       return NS_OK; };
NS_IMETHOD nsFontMetricsXft::GetMaxDescent ( nscoord aDescent) [inline, virtual]

Returns, in app units, the maximum distance characters in this font extend below the base line.

Implements nsIFontMetrics.

Definition at line 130 of file nsFontMetricsXft.h.

                                     { aDescent = mMaxDescent;
                                       return NS_OK; };
NS_IMETHOD nsFontMetricsXft::GetMaxHeight ( nscoord aHeight) [inline, virtual]

Returns the height (in app units) of the Western font's bounding box.

This is max ascent plus max descent.

Implements nsIFontMetrics.

Definition at line 122 of file nsFontMetricsXft.h.

                                     { aHeight = mMaxHeight;
                                       return NS_OK; };
NS_IMETHOD nsFontMetricsXft::GetMaxHeight ( nscoord aHeight) [inline, virtual]

Returns the height (in app units) of the Western font's bounding box.

This is max ascent plus max descent.

Implements nsIFontMetrics.

Definition at line 122 of file nsFontMetricsXft.h.

                                     { aHeight = mMaxHeight;
                                       return NS_OK; };

Implements nsIFontMetricsGTK.

Definition at line 146 of file nsFontMetricsXft.h.

{ return mMaxStringLength; }
NS_IMETHOD nsFontMetricsXft::GetNormalLineHeight ( nscoord aHeight) [inline, virtual]

Returns the normal line height (em height + leading).

Implements nsIFontMetrics.

Definition at line 102 of file nsFontMetricsXft.h.

                                     { aHeight = mEmHeight + mLeading;
                                       return NS_OK; };
NS_IMETHOD nsFontMetricsXft::GetNormalLineHeight ( nscoord aHeight) [inline, virtual]

Returns the normal line height (em height + leading).

Implements nsIFontMetrics.

Definition at line 102 of file nsFontMetricsXft.h.

                                     { aHeight = mEmHeight + mLeading;
                                       return NS_OK; };
PRInt32 nsFontMetricsXft::GetPosition ( const PRUnichar aText,
PRUint32  aLength,
nsPoint  aPt 
) [virtual]

Implements nsIFontMetricsGTK.

Definition at line 754 of file nsFontMetricsXft.cpp.

{
    return -1;
}
nsresult nsFontMetricsXft::GetRangeWidth ( const PRUnichar aText,
PRUint32  aLength,
PRUint32  aStart,
PRUint32  aEnd,
PRUint32 aWidth 
) [virtual]

Implements nsIFontMetricsGTK.

Definition at line 762 of file nsFontMetricsXft.cpp.

nsresult nsFontMetricsXft::GetRangeWidth ( const char *  aText,
PRUint32  aLength,
PRUint32  aStart,
PRUint32  aEnd,
PRUint32 aWidth 
) [virtual]

Implements nsIFontMetricsGTK.

Definition at line 772 of file nsFontMetricsXft.cpp.

Implements nsIFontMetricsGTK.

Definition at line 740 of file nsFontMetricsXft.cpp.

{
    return PR_FALSE;
}
NS_IMETHOD nsFontMetricsXft::GetSpaceWidth ( nscoord aSpaceCharWidth) [inline, virtual]

Returns the often needed width of the space character.

Implements nsIFontMetrics.

Definition at line 138 of file nsFontMetricsXft.h.

                                     { aSpaceCharWidth = mSpaceWidth;
                                       return NS_OK; };
NS_IMETHOD nsFontMetricsXft::GetSpaceWidth ( nscoord aSpaceCharWidth) [inline, virtual]

Returns the often needed width of the space character.

Implements nsIFontMetrics.

Definition at line 138 of file nsFontMetricsXft.h.

                                     { aSpaceCharWidth = mSpaceWidth;
                                       return NS_OK; };
NS_IMETHOD nsFontMetricsXft::GetStrikeout ( nscoord aOffset,
nscoord aSize 
) [inline, virtual]

Return the font's strikeout offset (the distance from the baseline to where a strikeout should be placed) and size Positive values are above the baseline, negative below.

Implements nsIFontMetrics.

Definition at line 88 of file nsFontMetricsXft.h.

                                     { aOffset = mStrikeoutOffset;
                                       aSize = mStrikeoutSize; 
                                       return NS_OK; };
NS_IMETHOD nsFontMetricsXft::GetStrikeout ( nscoord aOffset,
nscoord aSize 
) [inline, virtual]

Return the font's strikeout offset (the distance from the baseline to where a strikeout should be placed) and size Positive values are above the baseline, negative below.

Implements nsIFontMetrics.

Definition at line 88 of file nsFontMetricsXft.h.

                                     { aOffset = mStrikeoutOffset;
                                       aSize = mStrikeoutSize; 
                                       return NS_OK; };
NS_IMETHOD nsFontMetricsXft::GetSubscriptOffset ( nscoord aResult) [inline, virtual]

Return the font's subscript offset (the distance from the baseline to where a subscript's baseline should be placed).

The value returned will be a positive value.

Implements nsIFontMetrics.

Definition at line 84 of file nsFontMetricsXft.h.

                                     { aResult = mSubscriptOffset;
                                       return NS_OK; };
NS_IMETHOD nsFontMetricsXft::GetSubscriptOffset ( nscoord aResult) [inline, virtual]

Return the font's subscript offset (the distance from the baseline to where a subscript's baseline should be placed).

The value returned will be a positive value.

Implements nsIFontMetrics.

Definition at line 84 of file nsFontMetricsXft.h.

                                     { aResult = mSubscriptOffset;
                                       return NS_OK; };
NS_IMETHOD nsFontMetricsXft::GetSuperscriptOffset ( nscoord aResult) [inline, virtual]

Return the font's superscript offset (the distance from the baseline to where a superscript's baseline should be placed).

The value returned will be a positive value.

Implements nsIFontMetrics.

Definition at line 80 of file nsFontMetricsXft.h.

                                     { aResult = mSuperscriptOffset;
                                       return NS_OK; };
NS_IMETHOD nsFontMetricsXft::GetSuperscriptOffset ( nscoord aResult) [inline, virtual]

Return the font's superscript offset (the distance from the baseline to where a superscript's baseline should be placed).

The value returned will be a positive value.

Implements nsIFontMetrics.

Definition at line 80 of file nsFontMetricsXft.h.

                                     { aResult = mSuperscriptOffset;
                                       return NS_OK; };
nsresult nsFontMetricsXft::GetTextDimensions ( const PRUnichar aString,
PRUint32  aLength,
nsTextDimensions aDimensions,
PRInt32 aFontID 
) [virtual]

Implements nsICairoFontMetrics.

Definition at line 521 of file nsFontMetricsXft.cpp.

{
    NS_TIMELINE_MARK_FUNCTION("GetTextDimensions");
    aDimensions.Clear();

    if (!aLength)
        return NS_OK;

    nsresult rv;
    rv = EnumerateGlyphs(aString, aLength,
                         &nsFontMetricsXft::TextDimensionsCallback,
                         &aDimensions);

    NS_ENSURE_SUCCESS(rv, rv);

    float P2T;
    P2T = mDeviceContext->DevUnitsToAppUnits();

    aDimensions.width = NSToCoordRound(aDimensions.width * P2T);
    aDimensions.ascent = NSToCoordRound(aDimensions.ascent * P2T);
    aDimensions.descent = NSToCoordRound(aDimensions.descent * P2T);

    if (nsnull != aFontID)
        *aFontID = 0;

    return NS_OK;
}

Here is the call graph for this function:

nsresult nsFontMetricsXft::GetTextDimensions ( const PRUnichar aString,
PRUint32  aLength,
nsTextDimensions aDimensions,
PRInt32 aFontID,
nsRenderingContextGTK aContext 
) [virtual]

Implements nsIFontMetricsGTK.

Definition at line 524 of file nsFontMetricsXft.cpp.

{
    NS_TIMELINE_MARK_FUNCTION("GetTextDimensions");
    aDimensions.Clear();

    if (!aLength)
        return NS_OK;

    nsresult rv;
    rv = EnumerateGlyphs(aString, aLength,
                         &nsFontMetricsXft::TextDimensionsCallback,
                         &aDimensions);

    NS_ENSURE_SUCCESS(rv, rv);

    float P2T;
    P2T = mDeviceContext->DevUnitsToAppUnits();

    aDimensions.width = NSToCoordRound(aDimensions.width * P2T);
    aDimensions.ascent = NSToCoordRound(aDimensions.ascent * P2T);
    aDimensions.descent = NSToCoordRound(aDimensions.descent * P2T);

    if (nsnull != aFontID)
        *aFontID = 0;

    return NS_OK;
}

Here is the call graph for this function:

nsresult nsFontMetricsXft::GetTextDimensions ( const char *  aString,
PRInt32  aLength,
PRInt32  aAvailWidth,
PRInt32 aBreaks,
PRInt32  aNumBreaks,
nsTextDimensions aDimensions,
PRInt32 aNumCharsFit,
nsTextDimensions aLastWordDimensions,
PRInt32 aFontID 
) [virtual]

Implements nsICairoFontMetrics.

Definition at line 553 of file nsFontMetricsXft.cpp.

{
    NS_NOTREACHED("GetTextDimensions");
    return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsFontMetricsXft::GetTextDimensions ( const char *  aString,
PRInt32  aLength,
PRInt32  aAvailWidth,
PRInt32 aBreaks,
PRInt32  aNumBreaks,
nsTextDimensions aDimensions,
PRInt32 aNumCharsFit,
nsTextDimensions aLastWordDimensions,
PRInt32 aFontID,
nsRenderingContextGTK aContext 
) [virtual]

Implements nsIFontMetricsGTK.

Definition at line 557 of file nsFontMetricsXft.cpp.

{
    NS_NOTREACHED("GetTextDimensions");
    return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsFontMetricsXft::GetTextDimensions ( const PRUnichar aString,
PRInt32  aLength,
PRInt32  aAvailWidth,
PRInt32 aBreaks,
PRInt32  aNumBreaks,
nsTextDimensions aDimensions,
PRInt32 aNumCharsFit,
nsTextDimensions aLastWordDimensions,
PRInt32 aFontID 
) [virtual]

Implements nsICairoFontMetrics.

Definition at line 568 of file nsFontMetricsXft.cpp.

{
    NS_NOTREACHED("GetTextDimensions");
    return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult nsFontMetricsXft::GetTextDimensions ( const PRUnichar aString,
PRInt32  aLength,
PRInt32  aAvailWidth,
PRInt32 aBreaks,
PRInt32  aNumBreaks,
nsTextDimensions aDimensions,
PRInt32 aNumCharsFit,
nsTextDimensions aLastWordDimensions,
PRInt32 aFontID,
nsRenderingContextGTK aContext 
) [virtual]

Implements nsIFontMetricsGTK.

Definition at line 573 of file nsFontMetricsXft.cpp.

{
    NS_NOTREACHED("GetTextDimensions");
    return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHOD nsFontMetricsXft::GetUnderline ( nscoord aOffset,
nscoord aSize 
) [inline, virtual]

Return the font's underline offset (the distance from the baseline to where a underline should be placed) and size.

Positive values are above the baseline, negative below.

Implements nsIFontMetrics.

Definition at line 93 of file nsFontMetricsXft.h.

                                     { aOffset = mUnderlineOffset;
                                       aSize = mUnderlineSize; 
                                       return NS_OK; };
NS_IMETHOD nsFontMetricsXft::GetUnderline ( nscoord aOffset,
nscoord aSize 
) [inline, virtual]

Return the font's underline offset (the distance from the baseline to where a underline should be placed) and size.

Positive values are above the baseline, negative below.

Implements nsIFontMetrics.

Definition at line 93 of file nsFontMetricsXft.h.

                                     { aOffset = mUnderlineOffset;
                                       aSize = mUnderlineSize; 
                                       return NS_OK; };
nsresult nsFontMetricsXft::GetWidth ( const char *  aString,
PRUint32  aLength,
nscoord aWidth 
) [virtual]

Implements nsICairoFontMetrics.

Definition at line 477 of file nsFontMetricsXft.cpp.

{
    NS_TIMELINE_MARK_FUNCTION("GetWidth");

    XftFont *font = mWesternFont->mXftFont;
    NS_ASSERTION(font, "FindFont returned a bad font");

    XGlyphInfo glyphInfo;

    // casting away const for aString but it  should be safe
    XftTextExtents8(GDK_DISPLAY(), font, (FcChar8 *)aString,
                    aLength, &glyphInfo);

    float f;
    f = mDeviceContext->DevUnitsToAppUnits();
    aWidth = NSToCoordRound(glyphInfo.xOff * f);

    return NS_OK;
}

Here is the call graph for this function:

nsresult nsFontMetricsXft::GetWidth ( const PRUnichar aString,
PRUint32  aLength,
nscoord aWidth,
PRInt32 aFontID 
) [virtual]

Implements nsICairoFontMetrics.

Definition at line 499 of file nsFontMetricsXft.cpp.

{
    NS_TIMELINE_MARK_FUNCTION("GetWidth");
    if (!aLength) {
        aWidth = 0;
        return NS_OK;
    }

    gint rawWidth = RawGetWidth(aString, aLength);

    float f;
    f = mDeviceContext->DevUnitsToAppUnits();
    aWidth = NSToCoordRound(rawWidth * f);

    if (aFontID)
        *aFontID = 0;

    return NS_OK;
}

Here is the call graph for this function:

nsresult nsFontMetricsXft::GetWidth ( const char *  aString,
PRUint32  aLength,
nscoord aWidth,
nsRenderingContextGTK aContext 
) [virtual]

Implements nsIFontMetricsGTK.

Definition at line 478 of file nsFontMetricsXft.cpp.

{
    NS_TIMELINE_MARK_FUNCTION("GetWidth");

    XftFont *font = mWesternFont->mXftFont;
    NS_ASSERTION(font, "FindFont returned a bad font");

    XGlyphInfo glyphInfo;

    // casting away const for aString but it  should be safe
    XftTextExtents8(GDK_DISPLAY(), font, (FcChar8 *)aString,
                    aLength, &glyphInfo);

    float f;
    f = mDeviceContext->DevUnitsToAppUnits();
    aWidth = NSToCoordRound(glyphInfo.xOff * f);

    return NS_OK;
}

Here is the call graph for this function:

nsresult nsFontMetricsXft::GetWidth ( const PRUnichar aString,
PRUint32  aLength,
nscoord aWidth,
PRInt32 aFontID,
nsRenderingContextGTK aContext 
) [virtual]

Implements nsIFontMetricsGTK.

Definition at line 501 of file nsFontMetricsXft.cpp.

{
    NS_TIMELINE_MARK_FUNCTION("GetWidth");
    if (!aLength) {
        aWidth = 0;
        return NS_OK;
    }

    gint rawWidth = RawGetWidth(aString, aLength);

    float f;
    f = mDeviceContext->DevUnitsToAppUnits();
    aWidth = NSToCoordRound(rawWidth * f);

    if (aFontID)
        *aFontID = 0;

    return NS_OK;
}

Here is the call graph for this function:

nsresult nsFontMetricsXft::GetWidthCallback ( const FcChar32 *  aString,
PRUint32  aLen,
nsFontXft aFont,
void aData 
)

Definition at line 1584 of file nsFontMetricsXft.cpp.

{
    nscoord *width = (nscoord*)aData;

    if (!aFont) {
        SetupMiniFont();
        for (PRUint32 i = 0; i < aLen; i++) {
            *width += mMiniFontWidth * (IS_NON_BMP(aString[i]) ? 3 : 2) + 
                      mMiniFontPadding * (IS_NON_BMP(aString[i]) ? 6 : 5);
        }
        return NS_OK;
    }

    *width += aFont->GetWidth32(aString, aLen);
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsFontMetricsXft::GetWidthCallback ( const FcChar32 *  aString,
PRUint32  aLen,
nsFontXft aFont,
void aData 
)
NS_IMETHOD nsFontMetricsXft::GetXHeight ( nscoord aResult) [inline, virtual]

Return the font's xheight property, scaled into app-units.

Implements nsIFontMetrics.

Definition at line 77 of file nsFontMetricsXft.h.

                                     { aResult = mXHeight; return NS_OK; };
NS_IMETHOD nsFontMetricsXft::GetXHeight ( nscoord aResult) [inline, virtual]

Return the font's xheight property, scaled into app-units.

Implements nsIFontMetrics.

Definition at line 77 of file nsFontMetricsXft.h.

                                     { aResult = mXHeight; return NS_OK; };

Initialize the font metrics.

Call this after creating the font metrics. Font metrics you get from the font cache do NOT need to be initialized

See also:
nsIDeviceContext::GetMetricsFor()

Implements nsIFontMetrics.

NS_IMETHODIMP nsFontMetricsXft::Init ( const nsFont aFont,
nsIAtom aLangGroup,
nsIDeviceContext aContext 
) [virtual]

Initialize the font metrics.

Call this after creating the font metrics. Font metrics you get from the font cache do NOT need to be initialized

See also:
nsIDeviceContext::GetMetricsFor()

Implements nsIFontMetrics.

Definition at line 353 of file nsFontMetricsXft.cpp.

{
    mFont = aFont;
    mLangGroup = aLangGroup;

    // Hang onto the device context
    mDeviceContext = aContext;

    float app2dev = mDeviceContext->AppUnitsToDevUnits();
    mPixelSize = NSTwipsToFloatPixels(mFont.size, app2dev);

    // Make sure to clamp the pixel size to something reasonable so we
    // don't make the X server blow up.
    nscoord screenPixels = 1200;//XXX pavlov gdk_screen_height();
    mPixelSize = PR_MIN(screenPixels * FONT_MAX_FONT_SCALE, mPixelSize);

    // enumerate over the font names passed in
    mFont.EnumerateFamilies(nsFontMetricsXft::EnumFontCallback, this);

    nsCOMPtr<nsIPref> prefService;
    prefService = do_GetService(NS_PREF_CONTRACTID);
    if (!prefService)
        return NS_ERROR_FAILURE;
        
    nsXPIDLCString value;
    const char* langGroup;
    mLangGroup->GetUTF8String(&langGroup);

    // Set up the default font name if it's not set
    if (!mGenericFont) {
        nsCAutoString name("font.default.");
        name.Append(langGroup);
        prefService->CopyCharPref(name.get(), getter_Copies(value));

        if (value.get())
            mDefaultFont = value.get();
        else
            mDefaultFont = "serif";
        
        mGenericFont = &mDefaultFont;
    }

    // set up the minimum sizes for fonts
    if (mLangGroup) {
        nsCAutoString name("font.min-size.");

        if (mGenericFont->Equals("monospace"))
            name.Append("fixed");
        else
            name.Append("variable");

        name.Append(char('.'));
        name.Append(langGroup);

        PRInt32 minimum = 0;
        nsresult res;
        res = prefService->GetIntPref(name.get(), &minimum);
        if (NS_FAILED(res))
            prefService->GetDefaultIntPref(name.get(), &minimum);

        if (minimum < 0)
            minimum = 0;

        if (mPixelSize < minimum)
            mPixelSize = minimum;
    }

    // Make sure that the pixel size is at least greater than zero
    if (mPixelSize < 1) {
#ifdef DEBUG
        printf("*** Warning: nsFontMetricsXft was passed a pixel size of %f\n",
               mPixelSize);
#endif
        mPixelSize = 1;
    }
    if (!gInitialized) {
        CallGetService(kCharsetConverterManagerCID, &gCharsetManager);
        if (!gCharsetManager) {
            FreeGlobals();
            return NS_ERROR_FAILURE;
        }

        if (!gFontXftMaps.IsInitialized() && 
            !gFontXftMaps.Init(INITIAL_FONT_MAP_SIZE)) {
            FreeGlobals();
            return NS_ERROR_OUT_OF_MEMORY;
        }

        gInitialized = PR_TRUE;
    }

    if (NS_FAILED(RealizeFont()))
        return NS_ERROR_FAILURE;

    return NS_OK;
}

Here is the call graph for this function:

void nsFontMetricsXft::PrepareToDraw ( nsCairoRenderingContext aContext,
nsCairoDrawingSurface aSurface,
XftDraw **  aDraw,
XftColor &  aColor 
) [private]

Definition at line 1447 of file nsFontMetricsXft.cpp.

{
    // Set our color
    nscolor rccolor;

    aContext->GetColor(rccolor);
#define NS_TO_GDK_RGB(ns) \
  ((ns & 0xff) << 16 | (ns & 0xff00) | ((ns >> 16) & 0xff))
#define GDK_COLOR_TO_NS_RGB(c) \
  ((nscolor) NS_RGB(c.red, c.green, c.blue))

    aColor.pixel = gdk_rgb_xpixel_from_rgb(NS_TO_GDK_RGB(rccolor));
    aColor.color.red = (NS_GET_R(rccolor) << 8) | NS_GET_R(rccolor);
    aColor.color.green = (NS_GET_G(rccolor) << 8) | NS_GET_G(rccolor);
    aColor.color.blue = (NS_GET_B(rccolor) << 8) | NS_GET_B(rccolor);
    aColor.color.alpha = 0xffff;

    *aDraw = aSurface->GetXftDraw();

//    fprintf (stderr, "+++ PrepareToDraw: %p\n", *aDraw);

    nsCOMPtr<nsIRegion> lastRegion;
    nsCOMPtr<nsIRegion> clipRegion;

    aSurface->GetLastXftClip(getter_AddRefs(lastRegion));
    aContext->GetClipRegion(getter_AddRefs(clipRegion));

    // avoid setting the clip, if possible
    if (!lastRegion || !clipRegion || !lastRegion->IsEqual(*clipRegion)) {
#if 0 // XXX pavlov ugh...
        aSurface->SetLastXftClip(clipRegion);

        GdkRegion *rgn = nsnull;
        clipRegion->GetNativeRegion((void *&)rgn);

#ifdef MOZ_WIDGET_GTK
        GdkRegionPrivate  *priv = (GdkRegionPrivate *)rgn;
        XftDrawSetClip(*aDraw, priv->xregion);
#endif

#ifdef MOZ_WIDGET_GTK2
        GdkRegionSetXftClip(rgn, *aDraw);
#endif
#endif
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsFontMetricsXft::PrepareToDraw ( nsRenderingContextGTK aContext,
nsDrawingSurfaceGTK aSurface,
XftDraw **  aDraw,
XftColor &  aColor 
) [private]

Definition at line 1506 of file nsFontMetricsXft.cpp.

{
    // Set our color
    nscolor rccolor;

    aContext->GetColor(rccolor);

    aColor.pixel = gdk_rgb_xpixel_from_rgb(NS_TO_GDK_RGB(rccolor));
    aColor.color.red = (NS_GET_R(rccolor) << 8) | NS_GET_R(rccolor);
    aColor.color.green = (NS_GET_G(rccolor) << 8) | NS_GET_G(rccolor);
    aColor.color.blue = (NS_GET_B(rccolor) << 8) | NS_GET_B(rccolor);
    aColor.color.alpha = 0xffff;

    *aDraw = aSurface->GetXftDraw();

    nsCOMPtr<nsIRegion> lastRegion;
    nsCOMPtr<nsIRegion> clipRegion;

    aSurface->GetLastXftClip(getter_AddRefs(lastRegion));
    aContext->GetClipRegion(getter_AddRefs(clipRegion));

    // avoid setting the clip, if possible
    if (!lastRegion || !clipRegion || !lastRegion->IsEqual(*clipRegion)) {
        aSurface->SetLastXftClip(clipRegion);

        GdkRegion *rgn = nsnull;
        clipRegion->GetNativeRegion((void *&)rgn);

#ifdef MOZ_WIDGET_GTK
        GdkRegionPrivate  *priv = (GdkRegionPrivate *)rgn;
        XftDrawSetClip(*aDraw, priv->xregion);
#endif

#ifdef MOZ_WIDGET_GTK2
        GdkRegionSetXftClip(rgn, *aDraw);
#endif
    }
}

Here is the call graph for this function:

gint nsFontMetricsXft::RawGetWidth ( const PRUnichar aString,
PRUint32  aLength 
) [private]

Definition at line 1181 of file nsFontMetricsXft.cpp.

{
    nscoord width = 0;
    nsresult rv;

    rv = EnumerateGlyphs(aString, aLength,
                         &nsFontMetricsXft::GetWidthCallback, &width);

    if (NS_FAILED(rv))
        width = 0;

    return width;
}

Here is the call graph for this function:

Here is the caller graph for this function:

gint nsFontMetricsXft::RawGetWidth ( const PRUnichar aString,
PRUint32  aLength 
) [private]

Definition at line 734 of file nsFontMetricsXft.cpp.

{
    // make sure that the western font is loaded since we need that to
    // get the font metrics
    mWesternFont = FindFont('a');
    if (!mWesternFont)
        return NS_ERROR_FAILURE;

    return CacheFontMetrics();
}

Here is the call graph for this function:

Implements nsICairoFontMetrics.

Definition at line 722 of file nsFontMetricsXft.cpp.

{
    return NS_OK;
}
virtual nsresult nsFontMetricsXft::SetRightToLeftText ( PRBool  aIsRTL) [virtual]

Implements nsICairoFontMetrics.

Definition at line 955 of file nsFontMetricsXft.cpp.

{
    if (PR_LOG_TEST(gXftFontLoad, PR_LOG_DEBUG)) {
        printf("[%p] setting up pattern with the following specification:\n",
               (void *)this);

        // non-generic families
        if (mFontList.Count() && !mFontIsGeneric[0]) {
            printf("\tadding non-generic families: ");
            for (int i=0; i < mFontList.Count(); ++i) {
                if (mFontIsGeneric[i])
                    break;

                nsCString *familyName = mFontList.CStringAt(i);
                printf("%s, ", familyName->get());
            }
            printf("\n");
        }

        // language group
        const char *name;
        mLangGroup->GetUTF8String(&name);
        printf("\tlang group: %s\n", name);


    }

    mPattern = FcPatternCreate();
    if (!mPattern)
        return;

    if (gdk_rgb_get_cmap() != gdk_colormap_get_system())
        XftPatternAddBool(mPattern, XFT_RENDER, False);

    // XXX need to add user defined family

    // Add CSS names - walk the list of fonts, adding the generic as
    // the last font
    for (int i=0; i < mFontList.Count(); ++i) {
        // if this was a generic name, break out of the loop since we
        // don't want to add it to the pattern yet
        if (mFontIsGeneric[i])
            break;;

        nsCString *familyName = mFontList.CStringAt(i);
        NS_AddFFRE(mPattern, familyName, PR_FALSE);
    }

    // Add the language group.  Note that we do this before adding any
    // generics.  That's because the language is more important than
    // any generic font.
    NS_AddLangGroup (mPattern, mLangGroup);

    // If there's a generic add a pref for the generic if there's one
    // set.
    if (mGenericFont && !mFont.systemFont) {
        NS_AddGenericFontFromPref(mGenericFont, mLangGroup, mPattern,
                                  gXftFontLoad);
    }

    // Add the generic if there is one.
    if (mGenericFont && !mFont.systemFont)
        NS_AddFFRE(mPattern, mGenericFont, PR_FALSE);

    if (PR_LOG_TEST(gXftFontLoad, PR_LOG_DEBUG)) {
        // generic font
        if (mGenericFont && !mFont.systemFont) {
            printf("\tadding generic family: %s\n", mGenericFont->get());
        }

        // pixel size
        printf("\tpixel,twip size: %f,%d\n", mPixelSize, mFont.size);

        // slant type
        printf("\tslant: ");
        switch(mFont.style) {
        case NS_FONT_STYLE_ITALIC:
            printf("italic\n");
            break;
        case NS_FONT_STYLE_OBLIQUE:
            printf("oblique\n");
            break;
        default:
            printf("roman\n");
            break;
        }

        // weight
        printf("\tweight: (orig,calc) %d,%d\n",
               mFont.weight, NS_CalculateWeight(mFont.weight));

    }        

    // add the point size
    // We've done some round-tripping of floating point numbers so they
    // might not be quite right.  Since Xft rounds down, add a little,
    // so we don't go from 9.00000 to 8.99999 to 8.
    FcPatternAddDouble(mPattern, FC_PIXEL_SIZE, mPixelSize + 0.000001);

    // Add the slant type
    FcPatternAddInteger(mPattern, FC_SLANT,
                        NS_CalculateSlant(mFont.style));

    // Add the weight
    FcPatternAddInteger(mPattern, FC_WEIGHT,
                        NS_CalculateWeight(mFont.weight));

    // Set up the default substitutions for this font
    FcConfigSubstitute(0, mPattern, FcMatchPattern);
    XftDefaultSubstitute(GDK_DISPLAY(), DefaultScreen(GDK_DISPLAY()),
                         mPattern);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1196 of file nsFontMetricsXft.cpp.

{
    // The minifont is initialized lazily.
    if (mMiniFont)
        return NS_OK;

    FcPattern *pattern = nsnull;
    XftFont *font = nsnull;
    XftFont *xftFont = mWesternFont->mXftFont;
    NS_ASSERTION(xftFont, "FindFont returned a bad font");

    mMiniFontAscent = xftFont->ascent;
    mMiniFontDescent = xftFont->descent;

    pattern = FcPatternCreate();
    if (!pattern)
        return NS_ERROR_FAILURE;

    if (gdk_rgb_get_cmap() != gdk_colormap_get_system())
        XftPatternAddBool(mPattern, XFT_RENDER, False);

    FcPatternAddString(pattern, FC_FAMILY, (FcChar8 *)"monospace");

    FcPatternAddInteger(pattern, FC_PIXEL_SIZE, int(0.5 * mPixelSize));

    FcPatternAddInteger(pattern, FC_WEIGHT,
                        NS_CalculateWeight(mFont.weight));

    FcConfigSubstitute(0, pattern, FcMatchPattern);
    XftDefaultSubstitute(GDK_DISPLAY(), DefaultScreen(GDK_DISPLAY()),
                         pattern);

    FcResult res;
    
    FcPattern *pat = FcFontMatch(0, pattern, &res);

    if (pat) {
        font = XftFontOpenPattern(GDK_DISPLAY(), pat);

        if (font) {
            mMiniFont = font;
            pat = nsnull; // the font owns the pattern now
        }
        else {
            font = xftFont;
        }
    }

    // now that the font has been loaded, measure the fonts to find
    // the bounds
    for (int i=0; i < 16; ++i) {
        // create a little mini-string that contains what we want to
        // measure.
        char c = i < 10 ? '0' + i : 'A' + i - 10;
        char str[2];
        str[0] = c;
        str[1] = '\0';

        XGlyphInfo extents;
        XftTextExtents8(GDK_DISPLAY(), font,
                        (FcChar8 *)str, 1, &extents);

        mMiniFontWidth = PR_MAX (mMiniFontWidth, extents.width);
        mMiniFontHeight = PR_MAX (mMiniFontHeight, extents.height);
    }

    if (!mMiniFont) {
        mMiniFontWidth /= 2;
        mMiniFontHeight /= 2;
    }

    mMiniFontPadding = PR_MAX(mMiniFontHeight / 10, 1);
    mMiniFontYOffset = ((mMiniFontAscent + mMiniFontDescent) -
                        (mMiniFontHeight * 2 + mMiniFontPadding * 5)) / 2;


    if (pat)
        FcPatternDestroy(pat);
    if (pattern)
        FcPatternDestroy(pattern);

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsFontMetricsXft::TextDimensionsCallback ( const FcChar32 *  aString,
PRUint32  aLen,
nsFontXft aFont,
void aData 
)

Definition at line 1543 of file nsFontMetricsXft.cpp.

{
    nsTextDimensions *dimensions = (nsTextDimensions *)aData;

    if (!aFont) {
        SetupMiniFont();
        for (PRUint32 i = 0; i<aLen; i++) {
            dimensions->width += 
                mMiniFontWidth * (IS_NON_BMP(aString[i]) ? 3 : 2) +
                mMiniFontPadding * (IS_NON_BMP(aString[i]) ? 6 : 5);
        }

        if (dimensions->ascent < mMiniFontAscent)
            dimensions->ascent = mMiniFontAscent;
        if (dimensions->descent < mMiniFontDescent)
            dimensions->descent = mMiniFontDescent;

        return NS_OK;
    }

    // get the metric after converting the input string to
    // custom font code if necessary.
    XGlyphInfo glyphInfo;
    nsresult rv = aFont->GetTextExtents32(aString, aLen, glyphInfo);
    NS_ENSURE_SUCCESS(rv, rv);

    dimensions->width += glyphInfo.xOff;

    nscoord tmpMaxAscent = aFont->GetMaxAscent();
    nscoord tmpMaxDescent = aFont->GetMaxDescent();

    if (dimensions->ascent < tmpMaxAscent)
        dimensions->ascent = tmpMaxAscent;
    if (dimensions->descent < tmpMaxDescent)
        dimensions->descent = tmpMaxDescent;

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsFontMetricsXft::TextDimensionsCallback ( const FcChar32 *  aString,
PRUint32  aLen,
nsFontXft aFont,
void aData 
)

Member Data Documentation

Definition at line 308 of file nsFontMetricsXft.h.

Definition at line 270 of file nsFontMetricsXft.h.

Definition at line 265 of file nsFontMetricsXft.h.

Definition at line 302 of file nsFontMetricsXft.h.

Definition at line 303 of file nsFontMetricsXft.h.

Definition at line 301 of file nsFontMetricsXft.h.

nsFont nsIFontMetrics::mFont [protected, inherited]

Definition at line 238 of file nsIFontMetrics.h.

nsFont nsIFontMetrics::mFont [protected, inherited]

Definition at line 238 of file nsIFontMetrics.h.

nsAutoVoidArray nsFontMetricsXft::mFontIsGeneric [private]

Definition at line 263 of file nsFontMetricsXft.h.

nsCStringArray nsFontMetricsXft::mFontList [private]

Definition at line 262 of file nsFontMetricsXft.h.

Definition at line 267 of file nsFontMetricsXft.h.

Definition at line 266 of file nsFontMetricsXft.h.

Definition at line 300 of file nsFontMetricsXft.h.

Definition at line 275 of file nsFontMetricsXft.h.

Definition at line 280 of file nsFontMetricsXft.h.

Definition at line 306 of file nsFontMetricsXft.h.

Definition at line 304 of file nsFontMetricsXft.h.

Definition at line 305 of file nsFontMetricsXft.h.

Definition at line 299 of file nsFontMetricsXft.h.

Definition at line 341 of file nsFontMetricsXft.h.

XftFont * nsFontMetricsXft::mMiniFont [private]

Definition at line 283 of file nsFontMetricsXft.h.

Definition at line 288 of file nsFontMetricsXft.h.

Definition at line 289 of file nsFontMetricsXft.h.

Definition at line 285 of file nsFontMetricsXft.h.

Definition at line 286 of file nsFontMetricsXft.h.

Definition at line 284 of file nsFontMetricsXft.h.

Definition at line 287 of file nsFontMetricsXft.h.

FcPattern * nsFontMetricsXft::mPattern [private]

Definition at line 279 of file nsFontMetricsXft.h.

Definition at line 268 of file nsFontMetricsXft.h.

Definition at line 307 of file nsFontMetricsXft.h.

Definition at line 295 of file nsFontMetricsXft.h.

Definition at line 296 of file nsFontMetricsXft.h.

Definition at line 294 of file nsFontMetricsXft.h.

Definition at line 293 of file nsFontMetricsXft.h.

Definition at line 297 of file nsFontMetricsXft.h.

Definition at line 298 of file nsFontMetricsXft.h.

Definition at line 278 of file nsFontMetricsXft.h.

Definition at line 292 of file nsFontMetricsXft.h.


The documentation for this class was generated from the following files: