diff --git a/gfx/src/xlib/nsDeviceContextXlib.cpp b/gfx/src/xlib/nsDeviceContextXlib.cpp index f720d94fbb4..9f1619cacd0 100644 --- a/gfx/src/xlib/nsDeviceContextXlib.cpp +++ b/gfx/src/xlib/nsDeviceContextXlib.cpp @@ -387,7 +387,7 @@ NS_IMETHODIMP nsDeviceContextXlib::ConvertPixel(nscolor aColor, PRUint32 & aPixe NS_IMETHODIMP nsDeviceContextXlib::CheckFontExistence(const nsString& aFontName) { - return nsFontMetricsXlib::FamilyExists(aFontName); + return nsFontMetricsXlib::FamilyExists(this, aFontName); } NS_IMETHODIMP nsDeviceContextXlib::GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight) diff --git a/gfx/src/xlib/nsFontMetricsXlib.cpp b/gfx/src/xlib/nsFontMetricsXlib.cpp index 133bedf3f78..80232a997eb 100644 --- a/gfx/src/xlib/nsFontMetricsXlib.cpp +++ b/gfx/src/xlib/nsFontMetricsXlib.cpp @@ -757,10 +757,18 @@ nsFontMetricsXlib::FreeGlobals(void) * Initialize all the font lookup hash tables and other globals */ nsresult -nsFontMetricsXlib::InitGlobals(void) +nsFontMetricsXlib::InitGlobals(nsIDeviceContext *aDevice) { nsresult rv = NS_OK; + NS_ASSERTION(aDevice!=nsnull, "calling InitGlobals() without a device"); +#ifdef USE_XPRINT + if (mPrinterMode) + gXlibRgbHandle = NS_STATIC_CAST(nsDeviceContextXp *,aDevice)->GetXlibRgbHandle(); + else +#endif /* USE_XPRINT */ + gXlibRgbHandle = NS_STATIC_CAST(nsDeviceContextXlib *,aDevice)->GetXlibRgbHandle(); + nsServiceManager::GetService(kCharSetManagerCID, NS_GET_IID(nsICharsetConverterManager2), (nsISupports**) &gCharSetManager); @@ -1035,7 +1043,7 @@ nsFontMetricsXlib::Init(const nsFont& aFont, nsIAtom* aLangGroup, mDocConverterType = nsnull; if (!gInitialized) { - res = InitGlobals(); + res = InitGlobals(aContext); if (NS_FAILED(res)) return res; } @@ -1057,16 +1065,6 @@ nsFontMetricsXlib::Init(const nsFont& aFont, nsIAtom* aLangGroup, mDeviceContext = aContext; - if (!gXlibRgbHandle) - { -#ifdef USE_XPRINT - if (mPrinterMode) - gXlibRgbHandle = NS_STATIC_CAST(nsDeviceContextXp *,mDeviceContext)->GetXlibRgbHandle(); - else -#endif /* USE_XPRINT */ - gXlibRgbHandle = NS_STATIC_CAST(nsDeviceContextXlib *,mDeviceContext)->GetXlibRgbHandle(); - } - float app2dev; mDeviceContext->GetAppUnitsToDevUnits(app2dev); @@ -1885,8 +1883,6 @@ nsFontXlib::LoadFont(void) if (mAlreadyCalledLoadFont) return; - mAlreadyCalledLoadFont = PR_TRUE; - Display *aDisplay = xxlib_rgb_get_display(gXlibRgbHandle); #ifdef USE_XPRINT @@ -1896,11 +1892,17 @@ nsFontXlib::LoadFont(void) { /* applications must not make any assumptions about fonts _before_ XpSetContext() !!! */ NS_ERROR("Obtaining font information without a valid print context (XLoadQueryFont()) _before_ XpSetContext()\n"); +#ifdef DEBUG abort(); +#else + return; +#endif /* DEBUG */ } } #endif /* USE_XPRINT */ + mAlreadyCalledLoadFont = PR_TRUE; + XFontStruct *xlibFont = ::XLoadQueryFont(aDisplay, mName); #ifdef DEBUG @@ -3048,8 +3050,15 @@ GetFontNames(const char* aPattern, nsFontNodeArrayXlib* aNodes) Display *dpy = xxlib_rgb_get_display(gXlibRgbHandle); #ifdef USE_XPRINT +#ifdef DEBUG if(nsFontMetricsXlib::mPrinterMode) { + if (!dpy) + { + NS_ERROR("Obtaining font information without having a |Display *|"); + abort(); /* DIE!! */ + } + if (XpGetContext(dpy) == None) { /* applications must not make any assumptions about fonts _before_ XpSetContext() !!! */ @@ -3057,6 +3066,7 @@ GetFontNames(const char* aPattern, nsFontNodeArrayXlib* aNodes) abort(); /* DIE!! */ } } +#endif /* DEBUG */ #endif /* USE_XPRINT */ int count; char** list = ::XListFonts(dpy, aPattern, INT_MAX, &count); @@ -3404,14 +3414,14 @@ FindFamily(nsCString* aName) } nsresult -nsFontMetricsXlib::FamilyExists(const nsString& aName) +nsFontMetricsXlib::FamilyExists(nsIDeviceContext *aDevice, const nsString& aName) { if (!gInitialized) { - nsresult res = InitGlobals(); + nsresult res = InitGlobals(aDevice); if (NS_FAILED(res)) return res; } - + if (!IsASCIIFontName(aName)) return NS_ERROR_FAILURE; diff --git a/gfx/src/xlib/nsFontMetricsXlib.h b/gfx/src/xlib/nsFontMetricsXlib.h index 24e9a453829..4c39b8cb83e 100644 --- a/gfx/src/xlib/nsFontMetricsXlib.h +++ b/gfx/src/xlib/nsFontMetricsXlib.h @@ -117,7 +117,7 @@ public: static void EnablePrinterMode(PRBool printermode); #endif /* USE_XPRINT */ - static nsresult InitGlobals(void); + static nsresult InitGlobals(nsIDeviceContext *); static void FreeGlobals(void); NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW @@ -171,7 +171,7 @@ public: nsFontCharSetXlibInfo* aCharSet, PRUnichar aChar); - static nsresult FamilyExists(const nsString& aFontName); + static nsresult FamilyExists(nsIDeviceContext*, const nsString& aFontName); nsCAutoString mDefaultFont; nsCString *mGeneric; diff --git a/gfx/src/xlib/nsGCCache.h b/gfx/src/xlib/nsGCCache.h index 32999d808f8..e4bc7323902 100644 --- a/gfx/src/xlib/nsGCCache.h +++ b/gfx/src/xlib/nsGCCache.h @@ -61,7 +61,9 @@ public: } PRInt32 AddRef(void) { - if(mRefCnt>100) abort(); +#ifdef DEBUG + if(mRefCnt>400) abort(); +#endif /* DEBUG */ NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt"); ++mRefCnt; return mRefCnt; diff --git a/gfx/src/xlib/nsRenderingContextXlib.cpp b/gfx/src/xlib/nsRenderingContextXlib.cpp index 1551f0d25ef..cc078c8fa78 100644 --- a/gfx/src/xlib/nsRenderingContextXlib.cpp +++ b/gfx/src/xlib/nsRenderingContextXlib.cpp @@ -1483,7 +1483,12 @@ FoundFont: if (aSpacing) { const PRUnichar* str = &aString[start]; const PRUnichar* end = &aString[i]; + + // save off mCurrentFont and set it so that we cache the GC's font correctly + nsFontXlib *oldFont = mCurrentFont; + mCurrentFont = prevFont; UpdateGC(); + while (str < end) { x = aX; y = aY; @@ -1492,12 +1497,16 @@ FoundFont: aX += *aSpacing++; str++; } + mCurrentFont = oldFont; } - else - { + else { + // save off mCurrentFont and set it so that we cache the GC's font correctly + nsFontXlib *oldFont = mCurrentFont; + mCurrentFont = prevFont; UpdateGC(); - prevFont->DrawString(this, mRenderingSurface, x, y, &aString[start], i - start); - x += prevFont->GetWidth(&aString[start], i -start); + x += prevFont->DrawString(this, mRenderingSurface, x, y, &aString[start], + i - start); + mCurrentFont = oldFont; } prevFont = currFont; start = i; @@ -1510,7 +1519,11 @@ FoundFont: } if (prevFont) { + // save off mCurrentFont and set it so that we cache the GC's font correctly + nsFontXlib *oldFont = mCurrentFont; + mCurrentFont = prevFont; UpdateGC(); + if (aSpacing) { const PRUnichar* str = &aString[start]; const PRUnichar* end = &aString[i]; @@ -1522,10 +1535,13 @@ FoundFont: aX += *aSpacing++; str++; } + } else { prevFont->DrawString(this, mRenderingSurface, x, y, &aString[start], i - start); } + + mCurrentFont = oldFont; } } diff --git a/gfx/src/xprint/nsDeviceContextXP.cpp b/gfx/src/xprint/nsDeviceContextXP.cpp index abf41391e0e..0246131faad 100644 --- a/gfx/src/xprint/nsDeviceContextXP.cpp +++ b/gfx/src/xprint/nsDeviceContextXP.cpp @@ -181,7 +181,7 @@ NS_IMETHODIMP nsDeviceContextXp :: GetDrawingSurface(nsIRenderingContext &aConte */ NS_IMETHODIMP nsDeviceContextXp :: CheckFontExistence(const nsString& aFontName) { - return nsFontMetricsXlib::FamilyExists(aFontName); + return nsFontMetricsXlib::FamilyExists(this, aFontName); } NS_IMETHODIMP nsDeviceContextXp :: GetSystemAttribute(nsSystemAttrID anID,