Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes
nsFontXft Class Reference
Inheritance diagram for nsFontXft:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 nsFontXft (FcPattern *aPattern, FcPattern *aFontName)
virtual ~nsFontXft ()=0
XftFont * GetXftFont (void)
virtual nsresult GetTextExtents32 (const FcChar32 *aString, PRUint32 aLen, XGlyphInfo &aGlyphInfo)
gint GetWidth32 (const FcChar32 *aString, PRUint32 aLen)
PRInt16 GetMaxAscent (void)
PRInt16 GetMaxDescent (void)
virtual PRBool HasChar (PRUint32 aChar)=0
virtual FT_UInt CharToGlyphIndex (FcChar32 aChar)
virtual nsresult DrawStringSpec (FcChar32 *aString, PRUint32 aLen, void *aData)
 nsFontXft (FcPattern *aPattern, FcPattern *aFontName)
virtual ~nsFontXft ()=0
XftFont * GetXftFont (void)
virtual nsresult GetTextExtents32 (const FcChar32 *aString, PRUint32 aLen, XGlyphInfo &aGlyphInfo)
gint GetWidth32 (const FcChar32 *aString, PRUint32 aLen)
PRInt16 GetMaxAscent (void)
PRInt16 GetMaxDescent (void)
virtual PRBool HasChar (PRUint32 aChar)=0
virtual FT_UInt CharToGlyphIndex (FcChar32 aChar)
virtual nsresult DrawStringSpec (FcChar32 *aString, PRUint32 aLen, void *aData)

Public Attributes

XftFont * mXftFont
FcPattern * mPattern
FcPattern * mFontName
FcCharSet * mCharset

Detailed Description

Definition at line 83 of file nsFontMetricsXft.cpp.


Constructor & Destructor Documentation

nsFontXft::nsFontXft ( FcPattern *  aPattern,
FcPattern *  aFontName 
)

Definition at line 1837 of file nsFontMetricsXft.cpp.

{
    // save our pattern - we own it now
    mPattern = aPattern;
    mFontName = aFontName;
    // don't destroy it out from under us
    FcPatternReference(aPattern);
    FcPatternReference(mFontName);

    mXftFont = nsnull;

    // set up our charset
    mCharset = nsnull;
    FcCharSet *charset = nsnull;

    // this references an internal charset, we need to copy it
    FcPatternGetCharSet(aFontName, FC_CHARSET, 0, &charset);
    if (charset)
        mCharset = FcCharSetCopy(charset);
}
nsFontXft::~nsFontXft ( ) [pure virtual]

Definition at line 1858 of file nsFontMetricsXft.cpp.

{
    if (mXftFont)
        XftFontClose(GDK_DISPLAY(), mXftFont);
    if (mCharset)
        FcCharSetDestroy(mCharset);
    if (mPattern)
        FcPatternDestroy(mPattern);
    if (mFontName)
        FcPatternDestroy(mFontName);
}
nsFontXft::nsFontXft ( FcPattern *  aPattern,
FcPattern *  aFontName 
)
virtual nsFontXft::~nsFontXft ( ) [pure virtual]

Member Function Documentation

FT_UInt nsFontXft::CharToGlyphIndex ( FcChar32  aChar) [virtual]

Reimplemented in nsFontXftCustom, and nsFontXftCustom.

Definition at line 1959 of file nsFontMetricsXft.cpp.

{
    return XftCharIndex(GDK_DISPLAY(), mXftFont, aChar);
}

Here is the caller graph for this function:

virtual FT_UInt nsFontXft::CharToGlyphIndex ( FcChar32  aChar) [virtual]

Reimplemented in nsFontXftCustom, and nsFontXftCustom.

nsresult nsFontXft::DrawStringSpec ( FcChar32 *  aString,
PRUint32  aLen,
void aData 
) [virtual]

Reimplemented in nsFontXftCustom, and nsFontXftCustom.

Definition at line 1966 of file nsFontMetricsXft.cpp.

{
    NS_PRECONDITION(mXftFont, "FindFont should not return bad fonts");
    DrawStringData *data = (DrawStringData *)aData;

    FcChar32 *pstr = aString;
    const FcChar32 *end = aString + aLen;

    while(pstr < end) {
        nscoord x = data->x + data->xOffset;
        nscoord y = data->y;
        /* Convert to device coordinate. */
//        fprintf (stderr, "[%d %d -> ", x, y);
        data->context->TransformCoord(&x, &y);
//        fprintf (stderr, "%d %d] ", x, y);

        /* position in X is the location offset in the string 
           plus whatever offset is required for the spacing   
           argument                                           
        */                                                  

        FT_UInt glyph = CharToGlyphIndex(*pstr);
        data->drawBuffer->Draw(x, y, mXftFont, glyph);

        if (data->spacing) {
            data->xOffset += *data->spacing;
            data->spacing += IS_NON_BMP(*pstr) ? 2 : 1; 
        }
        else {
            XGlyphInfo info;                        
            XftGlyphExtents(GDK_DISPLAY(), mXftFont, &glyph, 1, &info);
            data->xOffset += NSToCoordRound(info.xOff * data->p2t);
        }

        ++pstr;
    }
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

virtual nsresult nsFontXft::DrawStringSpec ( FcChar32 *  aString,
PRUint32  aLen,
void aData 
) [virtual]

Reimplemented in nsFontXftCustom, and nsFontXftCustom.

Definition at line 1944 of file nsFontMetricsXft.cpp.

{
    NS_PRECONDITION(mXftFont, "FindFont should not return bad fonts");

    return mXftFont->ascent;
}

Here is the caller graph for this function:

Definition at line 1952 of file nsFontMetricsXft.cpp.

{
    NS_PRECONDITION(mXftFont, "FindFont should not return bad fonts");
    return mXftFont->descent;
}

Here is the caller graph for this function:

nsresult nsFontXft::GetTextExtents32 ( const FcChar32 *  aString,
PRUint32  aLen,
XGlyphInfo &  aGlyphInfo 
) [virtual]

Reimplemented in nsFontXftCustom, and nsFontXftCustom.

Definition at line 1901 of file nsFontMetricsXft.cpp.

{
    NS_PRECONDITION(mXftFont, "FindFont should not return bad fonts");

    // NS_CONST_CAST needed for older versions of Xft
    XftTextExtents32(GDK_DISPLAY(), mXftFont,
                     NS_CONST_CAST(FcChar32*, aString), aLen, &aGlyphInfo);

    return NS_OK;
}

Here is the caller graph for this function:

virtual nsresult nsFontXft::GetTextExtents32 ( const FcChar32 *  aString,
PRUint32  aLen,
XGlyphInfo &  aGlyphInfo 
) [virtual]

Reimplemented in nsFontXftCustom, and nsFontXftCustom.

gint nsFontXft::GetWidth32 ( const FcChar32 *  aString,
PRUint32  aLen 
)

Definition at line 1914 of file nsFontMetricsXft.cpp.

{
    XGlyphInfo glyphInfo;
    GetTextExtents32(aString, aLen, glyphInfo);

    return glyphInfo.xOff;
}

Here is the call graph for this function:

Here is the caller graph for this function:

gint nsFontXft::GetWidth32 ( const FcChar32 *  aString,
PRUint32  aLen 
)
XftFont* nsFontXft::GetXftFont ( void  )
XftFont * nsFontXft::GetXftFont ( void  )

Definition at line 1871 of file nsFontMetricsXft.cpp.

{
    if (!mXftFont) {
        FcPattern *pat = FcFontRenderPrepare(0, mPattern, mFontName);
        if (!pat)
            return nsnull;

        // bug 196312 : work around problem with CJK bi-width fonts
        // and fontconfig prior to 2.2. CJK bi-width fonts are regarded
        // as genuinely monospace by fontconfig that  sets FC_SPACING
        // to FC_MONOSPACE, which makes Xft drawing/measuring routines
        // use the global advance width (the width of double width glyphs 
        // and twice the width of single width glyphs) even for single width
        // characters (e.g. Latin letters and digits). This results in
        // spaced-out ('s p a c e d - o u t') rendering. By deleting
        // FC_SPACING here, we're emulating the behavior of fontconfig 2.2 or 
        // later that does not set FC_SPACING for any font.
        if (FcGetVersion() < 20300)
            FcPatternDel(pat, FC_SPACING);

        mXftFont = XftFontOpenPattern(GDK_DISPLAY(), pat);
        if (!mXftFont)
            FcPatternDestroy(pat);
    }

    return mXftFont;
}

Here is the caller graph for this function:

virtual PRBool nsFontXft::HasChar ( PRUint32  aChar) [pure virtual]

Implemented in nsFontXftCustom, nsFontXftCustom, nsFontXftUnicode, and nsFontXftUnicode.

Here is the caller graph for this function:

virtual PRBool nsFontXft::HasChar ( PRUint32  aChar) [pure virtual]

Member Data Documentation

FcCharSet * nsFontXft::mCharset

Definition at line 115 of file nsFontMetricsXft.cpp.

FcPattern * nsFontXft::mFontName

Definition at line 114 of file nsFontMetricsXft.cpp.

FcPattern * nsFontXft::mPattern

Definition at line 113 of file nsFontMetricsXft.cpp.

Definition at line 112 of file nsFontMetricsXft.cpp.


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