From 64367531bf91227d33ed1445c387626217eb8f35 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Tue, 26 Feb 2002 04:05:05 +0000 Subject: [PATCH] Don't create multiple XPrint or PostScript device contexts -- the contexts share globals and are careless... Bug 127627, patch by Roland Mainz , r=bryner,rods, sr=jag, a=asa --- gfx/src/ps/nsDeviceContextPS.cpp | 36 +++++++++++++++++++++++++++ gfx/src/xprint/nsDeviceContextXP.cpp | 37 +++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/gfx/src/ps/nsDeviceContextPS.cpp b/gfx/src/ps/nsDeviceContextPS.cpp index ad27a885e33a..9be37ef998dd 100644 --- a/gfx/src/ps/nsDeviceContextPS.cpp +++ b/gfx/src/ps/nsDeviceContextPS.cpp @@ -36,6 +36,14 @@ * the terms of any one of the NPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ + +/* PostScript/Xprint print modules do not support more than one object + * instance because they use global vars which cannot be shared between + * multiple instances... + * bug 119491 ("Cleanup global vars in PostScript and Xprint modules) will fix + * that... + */ +#define WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS 1 #include "nsDeviceContextPS.h" #include "nsRenderingContextPS.h" @@ -43,6 +51,10 @@ #include "nsFontMetricsPS.h" #include "nsPostScriptObj.h" +#ifdef WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS +static int instance_counter = 0; +#endif /* WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS */ + /** --------------------------------------------------- * See documentation in nsIDeviceContext.h * @update 12/21/98 dwc @@ -52,6 +64,11 @@ nsDeviceContextPS :: nsDeviceContextPS() { mSpec = nsnull; mParentDeviceContext = nsnull; + +#ifdef WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS + instance_counter++; + NS_ASSERTION(instance_counter < 2, "Cannot have more than one print device context."); +#endif /* WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS */ } /** --------------------------------------------------- @@ -63,6 +80,11 @@ nsDeviceContextPS :: ~nsDeviceContextPS() /* nsCOMPtr<> will dispose the objects... */ mSpec = nsnull; mParentDeviceContext = nsnull; + +#ifdef WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS + instance_counter--; + NS_ASSERTION(instance_counter >= 0, "We cannot have less than zero instances."); +#endif /* WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS */ } NS_IMETHODIMP @@ -70,6 +92,13 @@ nsDeviceContextPS :: SetSpec(nsIDeviceContextSpec* aSpec) { nsresult rv = NS_ERROR_FAILURE; +#ifdef WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS + NS_ASSERTION(instance_counter < 2, "Cannot have more than one print device context."); + if (instance_counter > 1) { + return NS_ERROR_GFX_PRINTER_PRINT_WHILE_PREVIEW; + } +#endif /* WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS */ + mSpec = aSpec; nsCOMPtr psSpec; @@ -100,6 +129,13 @@ nsDeviceContextPS::InitDeviceContextPS(nsIDeviceContext *aCreatingDeviceContext, float origscale, newscale; float t2d, a2d; +#ifdef WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS + NS_ASSERTION(instance_counter < 2, "Cannot have more than one print device context."); + if (instance_counter > 1) { + return NS_ERROR_GFX_PRINTER_PRINT_WHILE_PREVIEW; + } +#endif /* WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS */ + mDepth = 1; // just for arguments sake mTwipsToPixels = (float)72.0/(float)NSIntPointsToTwips(72); diff --git a/gfx/src/xprint/nsDeviceContextXP.cpp b/gfx/src/xprint/nsDeviceContextXP.cpp index 261bf749ae01..3f03cc5f6acc 100644 --- a/gfx/src/xprint/nsDeviceContextXP.cpp +++ b/gfx/src/xprint/nsDeviceContextXP.cpp @@ -38,6 +38,14 @@ * * ***** END LICENSE BLOCK ***** */ +/* PostScript/Xprint print modules do not support more than one object + * instance because they use global vars which cannot be shared between + * multiple instances... + * bug 119491 ("Cleanup global vars in PostScript and Xprint modules) will fix + * that... + */ +#define WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS 1 + #include "nsDeviceContextXP.h" #include "nsRenderingContextXp.h" #include "nsFontMetricsXlib.h" @@ -50,6 +58,10 @@ static PRLogModuleInfo *nsDeviceContextXpLM = PR_NewLogModule("nsDeviceContextXp"); #endif /* PR_LOGGING */ +#ifdef WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS +static int instance_counter = 0; +#endif /* WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS */ + /** --------------------------------------------------- * See documentation in nsIDeviceContext.h */ @@ -59,6 +71,11 @@ nsDeviceContextXp :: nsDeviceContextXp() mPrintContext = nsnull; mSpec = nsnull; mParentDeviceContext = nsnull; + +#ifdef WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS + instance_counter++; + NS_ASSERTION(instance_counter < 2, "Cannot have more than one print device context."); +#endif /* WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS */ } /** --------------------------------------------------- @@ -68,6 +85,11 @@ nsDeviceContextXp :: nsDeviceContextXp() nsDeviceContextXp :: ~nsDeviceContextXp() { DestroyXPContext(); + +#ifdef WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS + instance_counter--; + NS_ASSERTION(instance_counter >= 0, "We cannot have less than zero instances."); +#endif /* WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS */ } @@ -75,9 +97,15 @@ NS_IMETHODIMP nsDeviceContextXp::SetSpec(nsIDeviceContextSpec* aSpec) { nsresult rv = NS_ERROR_FAILURE; - PR_LOG(nsDeviceContextXpLM, PR_LOG_DEBUG, ("nsDeviceContextXp::SetSpec()\n")); +#ifdef WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS + NS_ASSERTION(instance_counter < 2, "Cannot have more than one print device context."); + if (instance_counter > 1) { + return NS_ERROR_GFX_PRINTER_PRINT_WHILE_PREVIEW; + } +#endif /* WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS */ + nsCOMPtr xpSpec; mSpec = aSpec; @@ -114,6 +142,13 @@ nsDeviceContextXp::InitDeviceContextXP(nsIDeviceContext *aCreatingDeviceContext, float t2d, a2d; int print_resolution; +#ifdef WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS + NS_ASSERTION(instance_counter < 2, "Cannot have more than one print device context."); + if (instance_counter > 1) { + return NS_ERROR_GFX_PRINTER_PRINT_WHILE_PREVIEW; + } +#endif /* WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS */ + mPrintContext->GetPrintResolution(print_resolution); mPixelsToTwips = (float)NSIntPointsToTwips(72) / (float)print_resolution;