diff --git a/gfx/src/xlib/nsFontMetricsXlib.cpp b/gfx/src/xlib/nsFontMetricsXlib.cpp index ffbd776276ac..aec084110b06 100644 --- a/gfx/src/xlib/nsFontMetricsXlib.cpp +++ b/gfx/src/xlib/nsFontMetricsXlib.cpp @@ -23,6 +23,8 @@ * Peter Hartshorn * Quy Tonthat * Tony Tsui + * pocemit + * Roland Mainz */ #include "xp_core.h" @@ -1735,6 +1737,10 @@ nsFontXlib::LoadFont(void) XFontStruct *xlibFont = XLoadQueryFont(aDisplay, mName); + PR_LOG(FontMetricsXlibLM, PR_LOG_DEBUG, + ("nsFontXlib::LoadFont(): XLoadQueryFont(aDisplay='%s',mName='%s') returned %lx\n", + XDisplayString(aDisplay), mName, (long)xlibFont)); + if (xlibFont) { if (mCharSetInfo == &ISO106461) { mMap = GetMapFor10646Font(xlibFont); @@ -1869,8 +1875,9 @@ nsFontXlibNormal::DrawString(nsRenderingContextXlib* aContext, int len = mCharSetInfo->Convert(mCharSetInfo, mFont, aString, aLength, p, bufLen); - xGC *gc = aContext->GetGC(); if ((mFont->min_byte1 == 0) && (mFont->max_byte1 == 0)) { + xGC *gc = aContext->GetGC(); + XDrawString(aSurface->GetDisplay(), aSurface->GetDrawable(), *gc, @@ -1881,32 +1888,30 @@ nsFontXlibNormal::DrawString(nsRenderingContextXlib* aContext, } else { - /* XXX is this the right way to do it? Can I get GCCache to give me a - * new GC? */ - GC copyGC; - XGCValues values; - memset(&values, 0, sizeof(XGCValues)); - - XGetGCValues(aSurface->GetDisplay(), *gc, GCForeground | GCBackground, - &values); - values.font = mFont->fid; - copyGC = XCreateGC(aSurface->GetDisplay(), aSurface->GetDrawable(), - GCForeground | GCBackground | GCFont, &values); + XFontStruct *savedFont = aContext->GetCurrentFont(); + aContext->SetCurrentFont(mFont); + aContext->UpdateGC(); + xGC *gc = aContext->GetGC(); + /* note the length must be divided by 2 for X*16 functions */ XDrawString16(aSurface->GetDisplay(), aSurface->GetDrawable(), - copyGC, + *gc, aX, aY + mBaselineAdjust, (XChar2b *)p, len / 2); - XFreeGC(aSurface->GetDisplay(), copyGC); + gc->Release(); + textWidth = XTextWidth16(mFont, (XChar2b *)p, len / 2); + + aContext->SetCurrentFont(savedFont); + aContext->UpdateGC(); } ENCODER_BUFFER_FREE_IF_NEEDED(p, buf); return textWidth; } -#endif +#endif /* !_IMPL_NS_XPRINT */ #ifdef USE_XPRINT int @@ -1932,8 +1937,9 @@ nsFontXlibNormal::DrawString(nsRenderingContextXp* aContext, int len = mCharSetInfo->Convert(mCharSetInfo, mFont, aString, aLength, p, bufLen); - xGC *gc = aContext->GetGC(); if ((mFont->min_byte1 == 0) && (mFont->max_byte1 == 0)) { + xGC *gc = aContext->GetGC(); + XDrawString(aSurface->GetDisplay(), aSurface->GetDrawable(), *gc, @@ -1944,26 +1950,24 @@ nsFontXlibNormal::DrawString(nsRenderingContextXp* aContext, } else { - /* XXX is this the right way to do it? Can I get GCCache to give me a - * new GC? */ - GC copyGC; - XGCValues values; - memset(&values, 0, sizeof(XGCValues)); - - XGetGCValues(aSurface->GetDisplay(), *gc, GCForeground | GCBackground, - &values); - values.font = mFont->fid; - copyGC = XCreateGC(aSurface->GetDisplay(), aSurface->GetDrawable(), - GCForeground | GCBackground | GCFont, &values); + XFontStruct *savedFont = aContext->GetCurrentFont(); + aContext->SetCurrentFont(mFont); + aContext->UpdateGC(); + xGC *gc = aContext->GetGC(); + /* note the length must be divided by 2 for X*16 functions */ XDrawString16(aSurface->GetDisplay(), aSurface->GetDrawable(), - copyGC, + *gc, aX, aY + mBaselineAdjust, (XChar2b *)p, len / 2); - XFreeGC(aSurface->GetDisplay(), copyGC); + gc->Release(); + textWidth = XTextWidth16(mFont, (XChar2b *)p, len / 2); + + aContext->SetCurrentFont(savedFont); + aContext->UpdateGC(); } ENCODER_BUFFER_FREE_IF_NEEDED(p, buf); diff --git a/gfx/src/xlib/nsRenderingContextXlib.cpp b/gfx/src/xlib/nsRenderingContextXlib.cpp index 0d790456b8b4..45ede74ad004 100644 --- a/gfx/src/xlib/nsRenderingContextXlib.cpp +++ b/gfx/src/xlib/nsRenderingContextXlib.cpp @@ -23,6 +23,8 @@ * Ken Faulkner * Tony Tsui * Tomi Leppikangas + * pocemit + * Roland Mainz */ #include "nsRenderingContextXlib.h" diff --git a/gfx/src/xlib/nsRenderingContextXlib.h b/gfx/src/xlib/nsRenderingContextXlib.h index 8e69a370cad3..af816daa6b45 100644 --- a/gfx/src/xlib/nsRenderingContextXlib.h +++ b/gfx/src/xlib/nsRenderingContextXlib.h @@ -19,6 +19,8 @@ * * Contributor(s): * Peter Hartshorn + * pocemit + * Roland Mainz */ #ifndef nsRenderingContextXlib_h___ @@ -202,9 +204,13 @@ class nsRenderingContextXlib : public nsRenderingContextImpl nsresult CommonInit(void); xGC *GetGC() { mGC->AddRef(); return mGC; } - -private: void UpdateGC(); + + /* use UpdateGC() to update GC-cache !! */ + void SetCurrentFont(XFontStruct *cf){ mCurrentFont = cf; }; + XFontStruct *GetCurrentFont() { return mCurrentFont; }; + +private: nsDrawingSurfaceXlib *mOffscreenSurface; nsDrawingSurfaceXlib *mRenderingSurface; nsIDeviceContext *mContext; diff --git a/gfx/src/xprint/nsRenderingContextXP.h b/gfx/src/xprint/nsRenderingContextXP.h index f5e5dcb87b48..c0c3b02b4a87 100644 --- a/gfx/src/xprint/nsRenderingContextXP.h +++ b/gfx/src/xprint/nsRenderingContextXP.h @@ -18,6 +18,7 @@ * Rights Reserved. * * Contributor(s): + * Roland Mainz */ #ifndef nsRenderingContextXp_h___ @@ -190,9 +191,13 @@ class nsRenderingContextXp : public nsRenderingContextImpl nsresult CommonInit(void); xGC *GetGC() { mGC->AddRef(); return mGC; }; - -private: void UpdateGC(); + + /* use UpdateGC() to update GC-cache !! */ + void SetCurrentFont(XFontStruct *cf){ mCurrentFont = cf; }; + XFontStruct *GetCurrentFont() { return mCurrentFont; }; + +private: nsXPrintContext *mPrintContext; nsCOMPtr mContext; nsIFontMetrics *mFontMetrics;