From 72854e98401b6bd394a7411504945d867edf335b Mon Sep 17 00:00:00 2001 From: "rjesup%wgate.com" Date: Sat, 3 Nov 2001 01:39:11 +0000 Subject: [PATCH] Bug 107341: xlib/xprint xcleanup. Checking in for gisburn. r=biesi, r=pocemit, sr=blizzard --- gfx/src/xlib/nsDeviceContextXlib.h | 3 +- gfx/src/xlib/nsFontMetricsXlib.cpp | 11 +- gfx/src/xlib/nsFontMetricsXlib.h | 8 +- gfx/src/xlib/nsRenderingContextXlib.cpp | 224 ------------------------ gfx/src/xlib/nsRenderingContextXlib.h | 61 +------ gfx/src/xprint/Makefile.in | 3 +- gfx/src/xprint/nsDeviceContextXP.cpp | 2 +- gfx/src/xprint/nsDeviceContextXP.h | 10 +- 8 files changed, 14 insertions(+), 308 deletions(-) diff --git a/gfx/src/xlib/nsDeviceContextXlib.h b/gfx/src/xlib/nsDeviceContextXlib.h index 4d2ecc4d884c..c973d3d67d87 100644 --- a/gfx/src/xlib/nsDeviceContextXlib.h +++ b/gfx/src/xlib/nsDeviceContextXlib.h @@ -41,9 +41,8 @@ #ifndef nsDeviceContextXlib_h__ #define nsDeviceContextXlib_h__ -#include "nsDeviceContext.h" +#include "nsDeviceContextX.h" #include "nsRenderingContextXlib.h" -#include "xlibrgb.h" class nsDeviceContextXlib : public nsDeviceContextX { diff --git a/gfx/src/xlib/nsFontMetricsXlib.cpp b/gfx/src/xlib/nsFontMetricsXlib.cpp index f9d346c55750..99d88ff225af 100644 --- a/gfx/src/xlib/nsFontMetricsXlib.cpp +++ b/gfx/src/xlib/nsFontMetricsXlib.cpp @@ -59,9 +59,11 @@ #include "nsReadableUtils.h" #include "nsAWritableString.h" #include "nsXPIDLString.h" - #include #include +#ifdef USE_XPRINT +#include +#endif /* USE_XPRINT */ #include "xlibrgb.h" /* #define NOISY_FONTS 1 */ @@ -614,14 +616,11 @@ FreeStretch(nsFontStretchXlib* aStretch) { PR_smprintf_free(aStretch->mScalable); - PRInt32 count; - while ((count = aStretch->mScaledFonts.Count())) { - // go backwards to keep nsVoidArray from memmoving everything each time - count--; // nsVoidArray is zero based + for (PRInt32 count = aStretch->mScaledFonts.Count()-1; count >= 0; --count) { nsFontXlib *font = (nsFontXlib*)aStretch->mScaledFonts.ElementAt(count); - aStretch->mScaledFonts.RemoveElementAt(count); if (font) delete font; } + // aStretch->mScaledFonts.Clear(); handled by delete of aStretch for (int i = 0; i < aStretch->mSizesCount; i++) { delete aStretch->mSizes[i]; diff --git a/gfx/src/xlib/nsFontMetricsXlib.h b/gfx/src/xlib/nsFontMetricsXlib.h index a5b4621958c2..c9bb94ab8df8 100644 --- a/gfx/src/xlib/nsFontMetricsXlib.h +++ b/gfx/src/xlib/nsFontMetricsXlib.h @@ -44,21 +44,15 @@ #include "nsICharRepresentable.h" #include "nsCompressedCharMap.h" -#include "nsIDeviceContext.h" +#include "nsDeviceContextX.h" #include "nsIFontMetrics.h" #include "nsIFontEnumerator.h" - -#include "nsCRT.h" #include "nsCOMPtr.h" #include "nsDrawingSurfaceXlib.h" -#ifdef USE_XPRINT -#include "nsDeviceContextXP.h" -#endif /* USE_XPRINT */ #include "nsFont.h" #include "nsRenderingContextXlib.h" #include "nsString.h" #include "nsUnitConversion.h" -#include "xlibrgb.h" #undef FONT_HAS_GLYPH #define FONT_HAS_GLYPH(map, char) IS_REPRESENTABLE(map, char) diff --git a/gfx/src/xlib/nsRenderingContextXlib.cpp b/gfx/src/xlib/nsRenderingContextXlib.cpp index df17631c45d4..1a03472c56a0 100644 --- a/gfx/src/xlib/nsRenderingContextXlib.cpp +++ b/gfx/src/xlib/nsRenderingContextXlib.cpp @@ -93,17 +93,7 @@ GraphicsState::~GraphicsState() NS_IF_RELEASE(mFontMetrics); } -#ifdef USE_XPRINT -nsRenderingContextXp::nsRenderingContextXp() - : nsRenderingContextXlib(), - mPrintContext(nsnull) -{ -} -nsRenderingContextXp::~nsRenderingContextXp() -{ -} -#endif /* USE_XPRINT */ nsRenderingContextXlib::nsRenderingContextXlib() { @@ -164,50 +154,6 @@ nsRenderingContextXlib::Shutdown() return NS_OK; } -#ifdef USE_XPRINT -NS_IMETHODIMP -nsRenderingContextXp::Init(nsIDeviceContext* aContext) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::Init(nsIDeviceContext *)\n")); - - mContext = do_QueryInterface(aContext); - NS_ASSERTION(nsnull != mContext, "Device context is null."); - if (mContext) { - nsIDeviceContext *dc = mContext; - NS_STATIC_CAST(nsDeviceContextXp *,dc)->GetPrintContext(mPrintContext); - } - NS_ASSERTION(nsnull != mPrintContext, "mPrintContext is null."); - - mPrintContext->GetXlibRgbHandle(mXlibRgbHandle); - mDisplay = xxlib_rgb_get_display(mXlibRgbHandle); - mScreen = xxlib_rgb_get_screen(mXlibRgbHandle); - mVisual = xxlib_rgb_get_visual(mXlibRgbHandle); - mDepth = xxlib_rgb_get_depth(mXlibRgbHandle); - - /* A printer usually does not support things like multiple drawing surfaces - * (nor "offscreen" drawing surfaces... would be quite difficult to - * implement =:-) ... - * We just feed the nsXPContext object here directly - this is the only - * "surface" the printer can "draw" on ... - */ - Drawable drawable; mPrintContext->GetDrawable(drawable); - UpdateGC(drawable); // fill mGC - mPrintContext->SetGC(mGC); - mRenderingSurface = mPrintContext; - - return CommonInit(); -} - -NS_IMETHODIMP nsRenderingContextXp::Init(nsIDeviceContext* aContext, nsIWidget *aWidget) -{ - return NS_OK; -} - -NS_IMETHODIMP nsRenderingContextXp::Init(nsIDeviceContext* aContext, nsDrawingSurface aSurface) -{ - return NS_OK; -} -#endif /* USE_XPRINT */ NS_IMETHODIMP nsRenderingContextXlib::Init(nsIDeviceContext* aContext, nsIWidget *aWindow) @@ -317,29 +263,6 @@ nsRenderingContextXlib::GetDeviceContext(nsIDeviceContext *&aContext) return NS_OK; } -#ifdef USE_XPRINT -NS_IMETHODIMP -nsRenderingContextXp::LockDrawingSurface(PRInt32 aX, PRInt32 aY, - PRUint32 aWidth, PRUint32 aHeight, - void **aBits, - PRInt32 *aStride, - PRInt32 *aWidthBytes, - PRUint32 aFlags) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::LockDrawingSurface()\n")); - PushState(); - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXp::UnlockDrawingSurface(void) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::UnlockDrawingSurface()\n")); - PRBool clipstate; - PopState(clipstate); - return NS_OK; -} -#endif /* USE_XPRINT */ NS_IMETHODIMP nsRenderingContextXlib::LockDrawingSurface(PRInt32 aX, PRInt32 aY, @@ -365,23 +288,6 @@ nsRenderingContextXlib::UnlockDrawingSurface(void) return NS_OK; } -#ifdef USE_XPRINT -NS_IMETHODIMP -nsRenderingContextXp::SelectOffScreenDrawingSurface(nsDrawingSurface aSurface) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::SelectOffScreenDrawingSurface()\n")); - return NS_OK; -} - -NS_IMETHODIMP -nsRenderingContextXp::GetDrawingSurface(nsDrawingSurface *aSurface) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::GetDrawingSurface()\n")); - *aSurface = nsnull; - return NS_OK; -} -#endif /* USE_XPRINT */ - NS_IMETHODIMP nsRenderingContextXlib::SelectOffScreenDrawingSurface(nsDrawingSurface aSurface) { @@ -760,16 +666,6 @@ nsRenderingContextXlib::GetCurrentTransform(nsTransform2D *&aTransform) return NS_OK; } -#ifdef USE_XPRINT -NS_IMETHODIMP -nsRenderingContextXp::CreateDrawingSurface(nsRect *aBounds, PRUint32 aSurfFlags, nsDrawingSurface &aSurface) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::CreateDrawingSurface()\n")); - aSurface = nsnull; - return NS_OK; -} -#endif /* USE_XPRINT */ - NS_IMETHODIMP nsRenderingContextXlib::CreateDrawingSurface(nsRect *aBounds, PRUint32 aSurfFlags, nsDrawingSurface &aSurface) { @@ -1658,20 +1554,6 @@ nsRenderingContextXlib::DrawImage(nsIImage *aImage, nscoord aX, nscoord aY, return DrawImage(aImage, tr); } -#ifdef USE_XPRINT -NS_IMETHODIMP -nsRenderingContextXp::DrawImage(nsIImage *aImage, const nsRect& aRect) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::DrawImage()\n")); - - nsRect tr; - tr = aRect; - mTranMatrix->TransformCoord(&tr.x, &tr.y, &tr.width, &tr.height); - UpdateGC(); - return mPrintContext->DrawImage(mGC, aImage, tr.x, tr.y, tr.width, tr.height); -} -#endif /* USE_XPRINT */ - NS_IMETHODIMP nsRenderingContextXlib::DrawImage(nsIImage *aImage, const nsRect& aRect) { @@ -1684,32 +1566,6 @@ nsRenderingContextXlib::DrawImage(nsIImage *aImage, const nsRect& aRect) return aImage->Draw(*this, mRenderingSurface, tr.x, tr.y, tr.width, tr.height); } -#ifdef USE_XPRINT -NS_IMETHODIMP -nsRenderingContextXp::DrawImage(nsIImage *aImage, const nsRect& aSRect, const nsRect& aDRect) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::DrawImage()\n")); - nsRect sr,dr; - - sr = aSRect; - mTranMatrix->TransformCoord(&sr.x, &sr.y, - &sr.width, &sr.height); - sr.x = aSRect.x; - sr.y = aSRect.y; - mTranMatrix->TransformNoXLateCoord(&sr.x, &sr.y); - - dr = aDRect; - mTranMatrix->TransformCoord(&dr.x, &dr.y, - &dr.width, &dr.height); - UpdateGC(); - return mPrintContext->DrawImage(mGC, aImage, - sr.x, sr.y, - sr.width, sr.height, - dr.x, dr.y, - dr.width, dr.height); -} -#endif /* USE_XPRINT */ - NS_IMETHODIMP nsRenderingContextXlib::DrawImage(nsIImage *aImage, const nsRect& aSRect, const nsRect& aDRect) { @@ -1748,86 +1604,6 @@ nsRenderingContextXlib::DrawTile(nsIImage *aImage,nscoord aX0,nscoord aY0,nscoor } #endif -#ifdef USE_XPRINT -/* [noscript] void drawImage (in imgIContainer aImage, [const] in nsRect aSrcRect, [const] in nsPoint aDestPoint); */ -NS_IMETHODIMP nsRenderingContextXp::DrawImage(imgIContainer *aImage, const nsRect * aSrcRect, const nsPoint * aDestPoint) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::DrawImage()\n")); - nsPoint pt; - nsRect sr; - - pt = *aDestPoint; - mTranMatrix->TransformCoord(&pt.x, &pt.y); - - sr = *aSrcRect; - mTranMatrix->TransformNoXLateCoord(&sr.x, &sr.y); - - nsCOMPtr iframe; - aImage->GetCurrentFrame(getter_AddRefs(iframe)); - if (!iframe) - return NS_ERROR_FAILURE; - - nsCOMPtr img(do_GetInterface(iframe)); - if (!img) - return NS_ERROR_FAILURE; - - UpdateGC(); - // doesn't it seem like we should use more of the params here? - // img->Draw(*this, surface, sr.x, sr.y, sr.width, sr.height, - // pt.x + sr.x, pt.y + sr.y, sr.width, sr.height); - return mPrintContext->DrawImage(mGC, img, pt.x, pt.y, sr.width, sr.height); -} - -/* [noscript] void drawScaledImage (in imgIContainer aImage, [const] in nsRect aSrcRect, [const] in nsRect aDestRect); */ -NS_IMETHODIMP nsRenderingContextXp::DrawScaledImage(imgIContainer *aImage, const nsRect * aSrcRect, const nsRect * aDestRect) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::DrawScaledImage()\n")); - nsRect dr; - - dr = *aDestRect; - mTranMatrix->TransformCoord(&dr.x, &dr.y, &dr.width, &dr.height); - - nsCOMPtr iframe; - aImage->GetCurrentFrame(getter_AddRefs(iframe)); - if (!iframe) - return NS_ERROR_FAILURE; - - nsCOMPtr img(do_GetInterface(iframe)); - if (!img) - return NS_ERROR_FAILURE; - - // doesn't it seem like we should use more of the params here? - // img->Draw(*this, surface, sr.x, sr.y, sr.width, sr.height, dr.x, dr.y, dr.width, dr.height); - - nsRect sr; - - sr = *aSrcRect; - mTranMatrix->TransformCoord(&sr.x, &sr.y, &sr.width, &sr.height); - sr.x = aSrcRect->x; - sr.y = aSrcRect->y; - mTranMatrix->TransformNoXLateCoord(&sr.x, &sr.y); - - UpdateGC(); - return mPrintContext->DrawImage(mGC, img, - sr.x, sr.y, - sr.width, sr.height, - dr.x, dr.y, - dr.width, dr.height); -} -#endif /* USE_XPRINT */ - -#ifdef USE_XPRINT -NS_IMETHODIMP -nsRenderingContextXp::CopyOffScreenBits(nsDrawingSurface aSrcSurf, PRInt32 aSrcX, PRInt32 aSrcY, - const nsRect &aDestBounds, PRUint32 aCopyFlags) -{ - PR_LOG(RenderingContextXlibLM, PR_LOG_DEBUG, ("nsRenderingContextXlib::CopyOffScreenBits()\n")); - - NS_NOTREACHED("nsRenderingContextXlib::CopyOffScreenBits() not yet implemented"); - return NS_OK; -} -#endif /* USE_XPRINT */ - NS_IMETHODIMP nsRenderingContextXlib::CopyOffScreenBits(nsDrawingSurface aSrcSurf, PRInt32 aSrcX, PRInt32 aSrcY, const nsRect &aDestBounds, PRUint32 aCopyFlags) diff --git a/gfx/src/xlib/nsRenderingContextXlib.h b/gfx/src/xlib/nsRenderingContextXlib.h index 1d24664e6756..5af4cf0f35dd 100644 --- a/gfx/src/xlib/nsRenderingContextXlib.h +++ b/gfx/src/xlib/nsRenderingContextXlib.h @@ -53,10 +53,7 @@ #include "nsIViewManager.h" #include "nsIWidget.h" #include "nsRect.h" -#ifdef USE_XPRINT -#include "nsXPrintContext.h" -#endif /* USE_XPRINT */ -#include "nsDeviceContext.h" +#include "nsDeviceContextX.h" #include "nsImageXlib.h" #include "nsVoidArray.h" #include "nsDrawingSurfaceXlib.h" @@ -69,20 +66,7 @@ class GraphicsState; class nsFontXlib; -class nsDeviceContextX : public DeviceContextImpl -{ -public: - nsDeviceContextX() - : DeviceContextImpl() - { - } - - virtual ~nsDeviceContextX() {} - - - NS_IMETHOD GetXlibRgbHandle(XlibRgbHandle *&aHandle) = 0; -}; - +/* Note |nsRenderingContextXp| may override some of these methods here */ class nsRenderingContextXlib : public nsRenderingContextImpl { public: @@ -292,47 +276,6 @@ protected: static nsGCCacheXlib *gcCache; }; -#ifdef USE_XPRINT -/* Rendering context class to match the special needs of Xprint (X11 print - * system). Nearly identical to nsRenderingContextXlib - except two details: - * - "offscreen" drawing surfaces are not supported by printers, therefore - * we "disable" those functions here by overriding them with empty versions. - * - images are handeled by nsXPrintContext class instead of nsImageXlib - */ -class nsRenderingContextXp : public nsRenderingContextXlib -{ - public: - nsRenderingContextXp(); - virtual ~nsRenderingContextXp(); - - NS_IMETHOD Init(nsIDeviceContext* aContext); - NS_IMETHOD Init(nsIDeviceContext* aContext, nsIWidget *aWindow); - NS_IMETHOD Init(nsIDeviceContext* aContext, nsDrawingSurface aSurface); - - NS_IMETHOD LockDrawingSurface(PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight, - void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes, - PRUint32 aFlags); - NS_IMETHOD UnlockDrawingSurface(void); - - NS_IMETHOD SelectOffScreenDrawingSurface(nsDrawingSurface aSurface); - NS_IMETHOD GetDrawingSurface(nsDrawingSurface *aSurface); - - NS_IMETHOD CreateDrawingSurface(nsRect *aBounds, PRUint32 aSurfFlags, nsDrawingSurface &aSurface); - - NS_IMETHOD DrawImage(nsIImage *aImage, const nsRect& aRect); - NS_IMETHOD DrawImage(nsIImage *aImage, const nsRect& aSRect, const nsRect& aDRect); - NS_IMETHOD DrawImage(imgIContainer *aImage, const nsRect * aSrcRect, const nsPoint * aDestPoint); - NS_IMETHOD DrawScaledImage(imgIContainer *aImage, const nsRect * aSrcRect, const nsRect * aDestRect); - - NS_IMETHOD CopyOffScreenBits(nsDrawingSurface aSrcSurf, PRInt32 aSrcX, PRInt32 aSrcY, - const nsRect &aDestBounds, PRUint32 aCopyFlags); - -protected: - nsXPrintContext *mPrintContext; /* identical to |mRenderingSurface| - * (except the different type) - */ -}; -#endif /* USE_XPRINT */ #endif /* !nsRenderingContextXlib_h___ */ diff --git a/gfx/src/xprint/Makefile.in b/gfx/src/xprint/Makefile.in index 529f1c62bc35..cee4c99b43b1 100644 --- a/gfx/src/xprint/Makefile.in +++ b/gfx/src/xprint/Makefile.in @@ -52,6 +52,7 @@ CSRCS = \ xprintutil_printtofile.c \ $(NULL) +# nsDrawingSurfaceXlib only required for staticbuild XLIB_LCPPSRCS = \ nsDrawingSurfaceXlib.cpp \ nsFontMetricsXlib.cpp \ @@ -60,12 +61,12 @@ XLIB_LCPPSRCS = \ nsGCCache.cpp \ $(NULL) -# nsDrawingSurfaceXlib only required for staticbuild CPPSRCS = \ $(XLIB_LCPPSRCS) \ nsDeviceContextXP.cpp \ nsGfxFactoryXP.cpp \ nsXPrintContext.cpp \ + nsRenderingContextXp.cpp \ $(NULL) EXPORTS = \ diff --git a/gfx/src/xprint/nsDeviceContextXP.cpp b/gfx/src/xprint/nsDeviceContextXP.cpp index ede4d1bd69e6..cee1c7c4f14c 100644 --- a/gfx/src/xprint/nsDeviceContextXP.cpp +++ b/gfx/src/xprint/nsDeviceContextXP.cpp @@ -39,7 +39,7 @@ * ***** END LICENSE BLOCK ***** */ #include "nsDeviceContextXP.h" -#include "nsRenderingContextXlib.h" +#include "nsRenderingContextXp.h" #include "nsFontMetricsXlib.h" #include "nsIDeviceContext.h" #include "nsIDeviceContextSpecXPrint.h" diff --git a/gfx/src/xprint/nsDeviceContextXP.h b/gfx/src/xprint/nsDeviceContextXP.h index f28e7e7aab38..0ec54f9d0795 100644 --- a/gfx/src/xprint/nsDeviceContextXP.h +++ b/gfx/src/xprint/nsDeviceContextXP.h @@ -40,16 +40,10 @@ #ifndef nsDeviceContextXp_h___ #define nsDeviceContextXp_h___ -#include -#include "nsDeviceContext.h" -#include "nsUnitConversion.h" -#include "nsIWidget.h" -#include "nsIView.h" -#include "nsRenderingContextXlib.h" -#include "nsVoidArray.h" +#include "nsDeviceContextX.h" +#include "nsRenderingContextXp.h" #include "nsIDeviceContextXPrint.h" #include "nsXPrintContext.h" -#include "nsISupportsArray.h" class nsDeviceContextXp : public nsDeviceContextX, public nsIDeviceContextXp