Bug 126799 [ps] Print preview spews errors to terminal window

patch by Roland.Mainz@informatik.med.uni-giessen.de r=rods rs=attinasi a=asa
This commit is contained in:
timeless%mac.com 2002-03-14 23:12:31 +00:00
Родитель 73907f947c
Коммит cee6adc427
8 изменённых файлов: 280 добавлений и 218 удалений

Просмотреть файл

@ -45,12 +45,20 @@
*/
#define WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS 1
#define FORCE_PR_LOG /* Allow logging in the release build */
#define PR_LOGGING 1
#include "prlog.h"
#include "nsDeviceContextPS.h"
#include "nsRenderingContextPS.h"
#include "nsString.h"
#include "nsFontMetricsPS.h"
#include "nsPostScriptObj.h"
#ifdef PR_LOGGING
static PRLogModuleInfo *nsDeviceContextPSLM = PR_NewLogModule("nsDeviceContextPS");
#endif /* PR_LOGGING */
#ifdef WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS
static int instance_counter = 0;
#endif /* WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS */
@ -60,11 +68,12 @@ static int instance_counter = 0;
* @update 12/21/98 dwc
*/
nsDeviceContextPS :: nsDeviceContextPS()
: DeviceContextImpl()
{
mSpec = nsnull;
mParentDeviceContext = nsnull;
: DeviceContextImpl(),
mSpec(nsnull),
mParentDeviceContext(nsnull)
{
PR_LOG(nsDeviceContextPSLM, PR_LOG_DEBUG, ("nsDeviceContextPS::nsDeviceContextPS()\n"));
#ifdef WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS
instance_counter++;
NS_ASSERTION(instance_counter < 2, "Cannot have more than one print device context.");
@ -75,8 +84,15 @@ nsDeviceContextPS :: nsDeviceContextPS()
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
nsDeviceContextPS :: ~nsDeviceContextPS()
nsDeviceContextPS::~nsDeviceContextPS()
{
PR_LOG(nsDeviceContextPSLM, PR_LOG_DEBUG, ("nsDeviceContextPS::~nsDeviceContextPS()\n"));
if (mPSObj) {
delete mPSObj;
mPSObj = nsnull;
}
/* nsCOMPtr<> will dispose the objects... */
mSpec = nsnull;
mParentDeviceContext = nsnull;
@ -88,8 +104,10 @@ nsDeviceContextPS :: ~nsDeviceContextPS()
}
NS_IMETHODIMP
nsDeviceContextPS :: SetSpec(nsIDeviceContextSpec* aSpec)
nsDeviceContextPS::SetSpec(nsIDeviceContextSpec* aSpec)
{
PR_LOG(nsDeviceContextPSLM, PR_LOG_DEBUG, ("nsDeviceContextPS::SetSpec()\n"));
nsresult rv = NS_ERROR_FAILURE;
#ifdef WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS
@ -126,8 +144,10 @@ NS_IMPL_ISUPPORTS_INHERITED1(nsDeviceContextPS,
NS_IMETHODIMP
nsDeviceContextPS::InitDeviceContextPS(nsIDeviceContext *aCreatingDeviceContext,nsIDeviceContext *aParentContext)
{
float origscale, newscale;
float t2d, a2d;
PR_LOG(nsDeviceContextPSLM, PR_LOG_DEBUG, ("nsDeviceContextPS::InitDeviceContextPS()\n"));
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.");
@ -136,6 +156,8 @@ float t2d, a2d;
}
#endif /* WE_DO_NOT_SUPPORT_MULTIPLE_PRINT_DEVICECONTEXTS */
NS_ENSURE_ARG_POINTER(aParentContext);
mDepth = 1; // just for arguments sake
mTwipsToPixels = (float)72.0/(float)NSIntPointsToTwips(72);
@ -152,8 +174,7 @@ float t2d, a2d;
mDevUnitsToAppUnits = 1.0f / mAppUnitsToDevUnits;
mParentDeviceContext = aParentContext;
NS_ASSERTION(mParentDeviceContext, "aCreatingDeviceContext cannot be NULL!!!");
return NS_OK;
return NS_OK;
}
/** ---------------------------------------------------
@ -163,8 +184,10 @@ float t2d, a2d;
* @param aContext -- our newly created Postscript RenderingContextPS
* @return -- NS_OK if everything succeeded.
*/
NS_IMETHODIMP nsDeviceContextPS :: CreateRenderingContext(nsIRenderingContext *&aContext)
NS_IMETHODIMP nsDeviceContextPS::CreateRenderingContext(nsIRenderingContext *&aContext)
{
PR_LOG(nsDeviceContextPSLM, PR_LOG_DEBUG, ("nsDeviceContextPS::CreateRenderingContext()\n"));
nsresult rv;
aContext = nsnull;
@ -187,8 +210,10 @@ NS_IMETHODIMP nsDeviceContextPS :: CreateRenderingContext(nsIRenderingContext *&
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS :: SupportsNativeWidgets(PRBool &aSupportsWidgets)
NS_IMETHODIMP nsDeviceContextPS::SupportsNativeWidgets(PRBool &aSupportsWidgets)
{
PR_LOG(nsDeviceContextPSLM, PR_LOG_DEBUG, ("nsDeviceContextPS::SupportsNativeWidgets()\n"));
aSupportsWidgets = PR_FALSE;
return NS_OK;
}
@ -197,8 +222,10 @@ NS_IMETHODIMP nsDeviceContextPS :: SupportsNativeWidgets(PRBool &aSupportsWidget
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS :: GetScrollBarDimensions(float &aWidth, float &aHeight) const
NS_IMETHODIMP nsDeviceContextPS::GetScrollBarDimensions(float &aWidth, float &aHeight) const
{
PR_LOG(nsDeviceContextPSLM, PR_LOG_DEBUG, ("nsDeviceContextPS::GetScrollBarDimensions()\n"));
//XXX: Hardcoded values for Postscript
aWidth = 20.f;
aHeight = 20.f;
@ -209,8 +236,10 @@ NS_IMETHODIMP nsDeviceContextPS :: GetScrollBarDimensions(float &aWidth, float &
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS :: GetDrawingSurface(nsIRenderingContext &aContext, nsDrawingSurface &aSurface)
NS_IMETHODIMP nsDeviceContextPS::GetDrawingSurface(nsIRenderingContext &aContext, nsDrawingSurface &aSurface)
{
PR_LOG(nsDeviceContextPSLM, PR_LOG_DEBUG, ("nsDeviceContextPS::GetDrawingSurface()\n"));
aSurface = nsnull;
return NS_OK;
}
@ -221,6 +250,8 @@ NS_IMETHODIMP nsDeviceContextPS :: GetDrawingSurface(nsIRenderingContext &aConte
*/
NS_IMETHODIMP nsDeviceContextPS::GetDepth(PRUint32& aDepth)
{
PR_LOG(nsDeviceContextPSLM, PR_LOG_DEBUG, ("nsDeviceContextPS::GetDepth(mDepth=%d)\n", 24));
/* PostScript module uses 24bit RGB images */
return(24);
}
@ -229,15 +260,18 @@ NS_IMETHODIMP nsDeviceContextPS::GetDepth(PRUint32& aDepth)
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS :: CheckFontExistence(const nsString& aFontName)
NS_IMETHODIMP nsDeviceContextPS::CheckFontExistence(const nsString& aFontName)
{
PR_LOG(nsDeviceContextPSLM, PR_LOG_DEBUG, ("nsDeviceContextPS::CheckFontExistence()\n"));
// XXX this needs to find out if this font is supported for postscript
return NS_OK;
}
NS_IMETHODIMP nsDeviceContextPS :: GetSystemFont(nsSystemFontID aID, nsFont *aFont) const
NS_IMETHODIMP nsDeviceContextPS::GetSystemFont(nsSystemFontID aID, nsFont *aFont) const
{
PR_LOG(nsDeviceContextPSLM, PR_LOG_DEBUG, ("nsDeviceContextPS::GetSystemFont()\n"));
if (mParentDeviceContext != nsnull) {
return mParentDeviceContext->GetSystemFont(aID, aFont);
}
@ -250,9 +284,9 @@ NS_IMETHODIMP nsDeviceContextPS :: GetSystemFont(nsSystemFontID aID, nsFont *aFo
*/
NS_IMETHODIMP nsDeviceContextPS::GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight)
{
nsIDeviceContextSpecPS *psSpec;
PR_LOG(nsDeviceContextPSLM, PR_LOG_DEBUG, ("nsDeviceContextPS::GetDeviceSurfaceDimensions()\n"));
nsresult rv = NS_ERROR_FAILURE;
float width, height;
if (mPSObj && mPSObj->mPrintSetup) {
aWidth = NSToIntRound(mPSObj->mPrintSetup->width * mDevUnitsToAppUnits);
@ -267,6 +301,8 @@ NS_IMETHODIMP nsDeviceContextPS::GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRI
*/
NS_IMETHODIMP nsDeviceContextPS::GetRect(nsRect &aRect)
{
PR_LOG(nsDeviceContextPSLM, PR_LOG_DEBUG, ("nsDeviceContextPS::GetRect()\n"));
PRInt32 width, height;
nsresult rv;
rv = GetDeviceSurfaceDimensions(width, height);
@ -282,6 +318,8 @@ NS_IMETHODIMP nsDeviceContextPS::GetRect(nsRect &aRect)
*/
NS_IMETHODIMP nsDeviceContextPS::GetClientRect(nsRect &aRect)
{
PR_LOG(nsDeviceContextPSLM, PR_LOG_DEBUG, ("nsDeviceContextPS::GetClientRect()\n"));
return GetRect(aRect);
}
@ -289,8 +327,10 @@ NS_IMETHODIMP nsDeviceContextPS::GetClientRect(nsRect &aRect)
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS::GetDeviceContextFor(nsIDeviceContextSpec *aDevice,nsIDeviceContext *&aContext)
NS_IMETHODIMP nsDeviceContextPS::GetDeviceContextFor(nsIDeviceContextSpec *aDevice, nsIDeviceContext *&aContext)
{
PR_LOG(nsDeviceContextPSLM, PR_LOG_DEBUG, ("nsDeviceContextPS::GetDeviceContextFor()\n"));
return NS_OK;
}
@ -300,8 +340,9 @@ NS_IMETHODIMP nsDeviceContextPS::GetDeviceContextFor(nsIDeviceContextSpec *aDevi
*/
NS_IMETHODIMP nsDeviceContextPS::BeginDocument(PRUnichar * aTitle)
{
if (!mPSObj)
return NS_ERROR_NULL_POINTER;
PR_LOG(nsDeviceContextPSLM, PR_LOG_DEBUG, ("nsDeviceContextPS::BeginDocument()\n"));
NS_ENSURE_TRUE(mPSObj != nsnull, NS_ERROR_NULL_POINTER);
mPSObj->settitle(aTitle);
return NS_OK;
@ -313,8 +354,31 @@ NS_IMETHODIMP nsDeviceContextPS::BeginDocument(PRUnichar * aTitle)
*/
NS_IMETHODIMP nsDeviceContextPS::EndDocument(void)
{
PR_LOG(nsDeviceContextPSLM, PR_LOG_DEBUG, ("nsDeviceContextPS::EndDocument()\n"));
NS_ENSURE_TRUE(mPSObj != nsnull, NS_ERROR_NULL_POINTER);
/* Finish the document and print it... */
mPSObj->end_document();
delete mPSObj;
mPSObj = nsnull;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIDeviceContext.h
*/
NS_IMETHODIMP nsDeviceContextPS::AbortDocument(void)
{
PR_LOG(nsDeviceContextPSLM, PR_LOG_DEBUG, ("nsDeviceContextPS::AbortDocument()\n"));
NS_ENSURE_TRUE(mPSObj != nsnull, NS_ERROR_NULL_POINTER);
delete mPSObj;
mPSObj = nsnull;
return NS_OK;
}
@ -324,8 +388,9 @@ NS_IMETHODIMP nsDeviceContextPS::EndDocument(void)
*/
NS_IMETHODIMP nsDeviceContextPS::BeginPage(void)
{
if (!mPSObj)
return NS_ERROR_NULL_POINTER;
PR_LOG(nsDeviceContextPSLM, PR_LOG_DEBUG, ("nsDeviceContextPS::BeginPage()\n"));
NS_ENSURE_TRUE(mPSObj != nsnull, NS_ERROR_NULL_POINTER);
// begin the page
mPSObj->begin_page();
@ -338,6 +403,10 @@ NS_IMETHODIMP nsDeviceContextPS::BeginPage(void)
*/
NS_IMETHODIMP nsDeviceContextPS::EndPage(void)
{
PR_LOG(nsDeviceContextPSLM, PR_LOG_DEBUG, ("nsDeviceContextPS::EndPage()\n"));
NS_ENSURE_TRUE(mPSObj != nsnull, NS_ERROR_NULL_POINTER);
// end the page
mPSObj->end_page();
return NS_OK;
@ -347,8 +416,10 @@ NS_IMETHODIMP nsDeviceContextPS::EndPage(void)
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS :: ConvertPixel(nscolor aColor, PRUint32 & aPixel)
NS_IMETHODIMP nsDeviceContextPS::ConvertPixel(nscolor aColor, PRUint32 & aPixel)
{
PR_LOG(nsDeviceContextPSLM, PR_LOG_DEBUG, ("nsDeviceContextPS::ConvertPixel()\n"));
aPixel = aColor;
return NS_OK;
}
@ -375,12 +446,14 @@ NS_IMETHODIMP nsFontCachePS::CreateFontMetricsInstance(nsIFontMetrics** aResult)
/* override DeviceContextImpl::CreateFontCache() */
NS_IMETHODIMP nsDeviceContextPS::CreateFontCache()
{
PR_LOG(nsDeviceContextPSLM, PR_LOG_DEBUG, ("nsDeviceContextPS::CreateFontCache()\n"));
mFontCache = new nsFontCachePS();
if (nsnull == mFontCache) {
if (!mFontCache) {
return NS_ERROR_OUT_OF_MEMORY;
}
mFontCache->Init(this);
return NS_OK;
return mFontCache->Init(this);
}

Просмотреть файл

@ -91,12 +91,15 @@ public:
NS_IMETHOD GetSystemFont(nsSystemFontID anID, nsFont *aFont) const;
NS_IMETHOD BeginDocument(PRUnichar * aTitle);
NS_IMETHOD EndDocument(void);
NS_IMETHOD AbortDocument(void);
NS_IMETHOD BeginPage(void);
NS_IMETHOD EndPage(void);
NS_IMETHOD CreateFontCache();
NS_IMETHOD SetSpec(nsIDeviceContextSpec *aSpec);
nsPostScriptObj* GetPrintContext() { return mPSObj; }
protected:
virtual ~nsDeviceContextPS();
@ -105,10 +108,6 @@ protected:
nsCOMPtr<nsIDeviceContextSpec> mSpec;
nsCOMPtr<nsIDeviceContext> mParentDeviceContext;
nsPostScriptObj *mPSObj;
public:
nsPostScriptObj* GetPrintContext() { return mPSObj; }
};
#endif /* nsDeviceContextPS_h___ */

Просмотреть файл

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
*
*
* Alternatively, the contents of this file may be used under the terms of
@ -39,8 +40,6 @@
#include "nsFontMetricsPS.h"
#include "nsDeviceContextPS.h"
static NS_DEFINE_IID(kIFontMetricsIID, NS_IFONT_METRICS_IID);
/** ---------------------------------------------------
* See documentation in nsFontMetricsPS.h
* @update 2/26/99 dwc

Просмотреть файл

@ -28,6 +28,10 @@
* 04/20/2000 IBM Corp. OS/2 VisualAge build.
* 10/09/2000 IPLabs Linux Team True Unicode glyps support added.
*/
#define FORCE_PR_LOG /* Allow logging in the release build */
#define PR_LOGGING 1
#include "prlog.h"
#include "nscore.h"
#include "nsPostScriptObj.h"
@ -60,6 +64,10 @@
#include "prprf.h"
#endif
#ifdef PR_LOGGING
static PRLogModuleInfo *nsPostScriptObjLM = PR_NewLogModule("nsPostScriptObj");
#endif /* PR_LOGGING */
extern "C" PS_FontInfo *PSFE_MaskToFI[N_FONTS]; // need fontmetrics.c
// These set the location to standard C and back
@ -159,16 +167,16 @@ PrintAsDSCTextline(FILE *f, const char *text, int maxlen)
* Default Constructor
* @update 2/1/99 dwc
*/
nsPostScriptObj::nsPostScriptObj()
nsPostScriptObj::nsPostScriptObj() :
mPrintContext(nsnull),
mPrintSetup(nsnull),
mTitle(nsnull)
{
mPrintContext = nsnull;
mPrintSetup = nsnull;
PR_LOG(nsPostScriptObjLM, PR_LOG_DEBUG, ("nsPostScriptObj::nsPostScriptObj()\n"));
nsServiceManager::GetService(kPrefCID, NS_GET_IID(nsIPref),
(nsISupports**) &gPrefs);
nsServiceManager::GetService(kPrefCID, NS_GET_IID(nsIPref), (nsISupports**) &gPrefs);
gLangGroups = new nsHashtable();
mTitle = nsnull;
gLangGroups = new nsHashtable();
}
/** ---------------------------------------------------
@ -177,6 +185,8 @@ nsPostScriptObj::nsPostScriptObj()
*/
nsPostScriptObj::~nsPostScriptObj()
{
PR_LOG(nsPostScriptObjLM, PR_LOG_DEBUG, ("nsPostScriptObj::~nsPostScriptObj()\n"));
// The mPrintContext can be null
// if opening the PostScript document
// fails. Giving an invalid path, relative path
@ -184,29 +194,14 @@ nsPostScriptObj::~nsPostScriptObj()
// write permissions for will fail to open a document
// see bug 85535
if (mPrintContext) {
// end the document
end_document();
finalize_translation();
if ( mPrintSetup->filename != nsnull )
fclose( mPrintSetup->out );
else {
#if defined(XP_OS2_VACPP) || defined(XP_PC)
// pclose not defined OS2TODO
#else
pclose( mPrintSetup->out );
#endif
}
#ifdef VMS
if ( mPrintSetup->print_cmd != nsnull ) {
char VMSPrintCommand[1024];
PR_snprintf(VMSPrintCommand, sizeof(VMSPrintCommand), "%s /delete %s.",
mPrintSetup->print_cmd, mPrintSetup->filename);
// FixMe: Check for error and return one of NS_ERROR_GFX_PRINTER_* on demand
system(VMSPrintCommand);
free((void *)mPrintSetup->filename);
}
#endif
if (mPrintSetup->out) {
fclose(mPrintSetup->out);
mPrintSetup->out = nsnull;
}
}
finalize_translation();
// Cleanup things allocated along the way
if (nsnull != mTitle){
nsMemory::Free(mTitle);
@ -235,9 +230,8 @@ nsPostScriptObj::~nsPostScriptObj()
delete gLangGroups;
gLangGroups = nsnull;
}
#ifdef DEBUG
puts("nsPostScriptObj::~nsPostScriptObj(): printing done.");
#endif /* DEBUG */
PR_LOG(nsPostScriptObjLM, PR_LOG_DEBUG, ("nsPostScriptObj::~nsPostScriptObj(): printing done."));
}
void
@ -277,8 +271,9 @@ const char *paper_size_to_paper_name(float width_in_inch, float height_in_inch)
nsresult
nsPostScriptObj::Init( nsIDeviceContextSpecPS *aSpec )
{
PRBool isGray, isAPrinter, isFirstPageFirst;
int printSize;
PRBool isGray,
isAPrinter,
isFirstPageFirst;
int landscape;
float fwidth, fheight;
const char *printername;
@ -347,20 +342,14 @@ nsPostScriptObj::Init( nsIDeviceContextSpecPS *aSpec )
PR_SetEnv(envvar);
free(envvar);
const char *command;
aSpec->GetCommand(&mPrintSetup->print_cmd);
#ifndef VMS
aSpec->GetCommand( &command );
#if defined(XP_OS2_VACPP) || defined(XP_PC)
mPrintSetup->out = nsnull;
// popen not defined OS2TODO
#else
mPrintSetup->out = popen(command, "w");
#endif
mPrintSetup->out = tmpfile();
mPrintSetup->filename = nsnull;
#else
// We can not open a pipe and print the contents of it. Instead
// we have to print to a file and then print that.
aSpec->GetCommand( &mPrintSetup->print_cmd );
mPrintSetup->filename = tempnam("SYS$SCRATCH:","MOZ_P");
mPrintSetup->out = fopen(mPrintSetup->filename, "w");
#endif
@ -2024,9 +2013,11 @@ nsPostScriptObj::end_page()
* See documentation in nsPostScriptObj.h
* @update 2/1/99 dwc
*/
void
nsresult
nsPostScriptObj::end_document()
{
PR_LOG(nsPostScriptObjLM, PR_LOG_DEBUG, ("nsPostScriptObj::end_document()\n"));
FILE *f;
f = mPrintContext->prSetup->out;
@ -2034,6 +2025,49 @@ nsPostScriptObj::end_document()
fprintf(f, "%%%%Trailer\n");
fprintf(f, "%%%%Pages: %d\n", (int) mPageNumber - 1);
fprintf(f, "%%%%EOF\n");
if (mPrintSetup->filename) {
PR_LOG(nsPostScriptObjLM, PR_LOG_DEBUG, ("print to file completed.\n"));
}
else {
PR_LOG(nsPostScriptObjLM, PR_LOG_DEBUG, ("piping job to '%s'\n", mPrintSetup->print_cmd));
#ifdef VMS
char VMSPrintCommand[1024];
PR_snprintf(VMSPrintCommand, sizeof(VMSPrintCommand), "%s %s.",
mPrintSetup->print_cmd, mPrintSetup->filename);
// FixMe: Check for error and return one of NS_ERROR_GFX_PRINTER_* on demand
system(VMSPrintCommand);
free((void *)mPrintSetup->filename);
#else
FILE *pipe;
char buf[256];
size_t len;
pipe = popen(mPrintSetup->print_cmd, "w");
/* XXX: We should look at |errno| in this case and return something
* more specific here... */
if (!pipe)
return NS_ERROR_GFX_PRINTER_CMD_FAILURE;
size_t job_size = 0;
/* Reset file pointer to the beginning of the temp file... */
fseek(mPrintSetup->out, 0, SEEK_SET);
do {
len = fread(buf, 1, sizeof(buf), mPrintSetup->out);
fwrite(buf, 1, len, pipe);
job_size += len;
} while(len == sizeof(buf));
pclose(pipe);
PR_LOG(nsPostScriptObjLM, PR_LOG_DEBUG, ("piping done, copied %ld bytes.\n", job_size));
#endif /* VMS */
}
return NS_OK;
}
/** ---------------------------------------------------

Просмотреть файл

@ -200,9 +200,7 @@ struct PrintSetup_ {
XL_CompletionRoutine completion; /* Called when translation finished */
void* carg; /* Data saved for completion routine */
int status; /* Status of URL on completion */
#ifdef VMS
const char *print_cmd; /* print command issued in dtor*/
#endif
const char *print_cmd; /* print command */
/* "other" font is for encodings other than iso-8859-1 */
char *otherFontName[N_FONTS];
@ -260,7 +258,7 @@ public:
* end the current document
* @update 2/1/99 dwc
*/
void end_document();
nsresult end_document();
/** ---------------------------------------------------
* move the cursor to this location
* @update 2/1/99 dwc

Просмотреть файл

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
*
*
* Alternatively, the contents of this file may be used under the terms of
@ -41,12 +42,16 @@
#include "nsDeviceContextPS.h"
#include "nsPostScriptObj.h"
#include "nsIRegion.h"
#include "nsIImage.h"
#include "nsIImage.h"
#include "imgIContainer.h"
#include "gfxIImageFrame.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include <math.h>
// Macro to convert from TWIPS (1440 per inch) to POINTS (72 per inch)
#define NS_PIXELS_TO_POINTS(x) (x * 10)
#define NS_PIXELS_TO_POINTS(x) ((x) * 10)
#define FLAG_CLIP_VALID 0x0001
#define FLAG_CLIP_CHANGED 0x0002
@ -69,7 +74,7 @@ public:
PS_State *mNext;
nsTransform2D mMatrix;
nsRect mLocalClip;
nsIFontMetrics *mFontMetrics;
nsCOMPtr<nsIFontMetrics> mFontMetrics;
nscolor mCurrentColor;
nscolor mTextColor;
nsLineStyle mLineStyle;
@ -142,25 +147,25 @@ nsRenderingContextPS :: nsRenderingContextPS()
mStateCache = new nsVoidArray();
PushState();
mP2T = 1.0f;
PushState();
}
/** ---------------------------------------------------
* See documentation in nsIRenderingContext.h
* @update 12/21/98 dwc
*/
nsRenderingContextPS :: ~nsRenderingContextPS()
nsRenderingContextPS::~nsRenderingContextPS()
{
if (nsnull != mStateCache){
if (mStateCache){
PRInt32 cnt = mStateCache->Count();
while (--cnt >= 0){
PS_State *state = (PS_State *)mStateCache->ElementAt(cnt);
mStateCache->RemoveElementAt(cnt);
if (nsnull != state)
if (state)
delete state;
}
@ -169,9 +174,6 @@ nsRenderingContextPS :: ~nsRenderingContextPS()
}
mTranMatrix = nsnull;
NS_IF_RELEASE(mContext);
NS_IF_RELEASE(mFontMetrics);
}
/** ---------------------------------------------------
@ -179,19 +181,21 @@ nsRenderingContextPS :: ~nsRenderingContextPS()
* @update 12/21/98 dwc
*/
NS_IMETHODIMP
nsRenderingContextPS :: Init(nsIDeviceContext* aContext)
nsRenderingContextPS::Init(nsIDeviceContext* aContext)
{
float app2dev;
float app2dev;
NS_ENSURE_TRUE(nsnull != aContext, NS_ERROR_NULL_POINTER);
mContext = aContext;
if (mContext) {
mPSObj = ((nsDeviceContextPS*)mContext)->GetPrintContext();
}
NS_IF_ADDREF(mContext);
mPSObj = NS_REINTERPRET_CAST(nsDeviceContextPS *, mContext.get())->GetPrintContext();
NS_ENSURE_TRUE(nsnull != mPSObj, NS_ERROR_NULL_POINTER);
// initialize the matrix
mContext->GetAppUnitsToDevUnits(app2dev);
mTranMatrix->AddScale(app2dev, app2dev);
mTranMatrix->AddScale(app2dev, app2dev);
mContext->GetDevUnitsToAppUnits(mP2T);
return NS_OK;
}
@ -265,8 +269,8 @@ nsRenderingContextPS :: Reset()
NS_IMETHODIMP
nsRenderingContextPS :: GetDeviceContext(nsIDeviceContext *&aContext)
{
NS_IF_ADDREF(mContext);
aContext = mContext;
NS_IF_ADDREF(aContext);
return NS_OK;
}
@ -512,12 +516,24 @@ nsRenderingContextPS :: GetLineStyle(nsLineStyle &aLineStyle)
* @update 12/21/98 dwc
*/
NS_IMETHODIMP
nsRenderingContextPS :: SetFont(const nsFont& aFont)
nsRenderingContextPS::SetFont(const nsFont& aFont)
{
NS_IF_RELEASE(mFontMetrics);
if (mContext) {
mContext->GetMetricsFor(aFont, mFontMetrics);
nsCOMPtr<nsIFontMetrics> newMetrics;
nsresult rv = mContext->GetMetricsFor(aFont, *getter_AddRefs(newMetrics));
if (NS_SUCCEEDED(rv)) {
rv = SetFont(newMetrics);
}
return rv;
}
/** ---------------------------------------------------
* See documentation in nsIRenderingContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP
nsRenderingContextPS::SetFont(nsIFontMetrics *aFontMetrics)
{
mFontMetrics = (nsFontMetricsPS *)aFontMetrics;
return NS_OK;
}
@ -526,12 +542,10 @@ nsRenderingContextPS :: SetFont(const nsFont& aFont)
* @update 12/21/98 dwc
*/
NS_IMETHODIMP
nsRenderingContextPS :: SetFont(nsIFontMetrics *aFontMetrics)
nsRenderingContextPS::GetFontMetrics(nsIFontMetrics *&aFontMetrics)
{
NS_IF_RELEASE(mFontMetrics);
mFontMetrics = aFontMetrics;
NS_IF_ADDREF(mFontMetrics);
aFontMetrics = (nsIFontMetrics *)mFontMetrics;
NS_IF_ADDREF(aFontMetrics);
return NS_OK;
}
@ -540,22 +554,9 @@ nsRenderingContextPS :: SetFont(nsIFontMetrics *aFontMetrics)
* @update 12/21/98 dwc
*/
NS_IMETHODIMP
nsRenderingContextPS :: GetFontMetrics(nsIFontMetrics *&aFontMetrics)
nsRenderingContextPS::Translate(nscoord aX, nscoord aY)
{
NS_IF_ADDREF(mFontMetrics);
aFontMetrics = mFontMetrics;
return NS_OK;
}
/** ---------------------------------------------------
* See documentation in nsIRenderingContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP
nsRenderingContextPS :: Translate(nscoord aX, nscoord aY)
{
mTranMatrix->AddTranslation((float)aX,(float)aY);
mTranMatrix->AddTranslation((float)aX,(float)aY);
return NS_OK;
}
@ -963,7 +964,7 @@ nsRenderingContextPS :: GetWidth(char ch, nscoord& aWidth)
* @update 12/21/98 dwc
*/
NS_IMETHODIMP
nsRenderingContextPS :: GetWidth(PRUnichar ch, nscoord &aWidth, PRInt32 *aFontID)
nsRenderingContextPS::GetWidth(PRUnichar ch, nscoord &aWidth, PRInt32 *aFontID)
{
PRUnichar buf[1];
buf[0] = ch;
@ -975,7 +976,7 @@ nsRenderingContextPS :: GetWidth(PRUnichar ch, nscoord &aWidth, PRInt32 *aFontID
* @update 12/21/98 dwc
*/
NS_IMETHODIMP
nsRenderingContextPS :: GetWidth(const char* aString, nscoord& aWidth)
nsRenderingContextPS::GetWidth(const char* aString, nscoord& aWidth)
{
return GetWidth(aString, strlen(aString),aWidth);
}
@ -985,16 +986,14 @@ nsRenderingContextPS :: GetWidth(const char* aString, nscoord& aWidth)
* @update 12/21/98 dwc
*/
NS_IMETHODIMP
nsRenderingContextPS :: GetWidth(const char* aString,PRUint32 aLength,nscoord& aWidth)
nsRenderingContextPS::GetWidth(const char* aString,PRUint32 aLength,nscoord& aWidth)
{
if (nsnull != mFontMetrics){
((nsFontMetricsPS*)mFontMetrics)->GetStringWidth(aString,aWidth,aLength);
return NS_OK;
} else {
return NS_ERROR_FAILURE;
nsresult rv = NS_ERROR_FAILURE;
if (mFontMetrics) {
rv = NS_REINTERPRET_CAST(nsFontMetricsPS *, mFontMetrics.get())->GetStringWidth(aString,aWidth,aLength);
}
return rv;
}
/** ---------------------------------------------------
@ -1002,7 +1001,7 @@ nsRenderingContextPS :: GetWidth(const char* aString,PRUint32 aLength,nscoord& a
* @update 12/21/98 dwc
*/
NS_IMETHODIMP
nsRenderingContextPS :: GetWidth(const nsString& aString, nscoord& aWidth, PRInt32 *aFontID)
nsRenderingContextPS::GetWidth(const nsString& aString, nscoord& aWidth, PRInt32 *aFontID)
{
return GetWidth(aString.get(), aString.Length(), aWidth, aFontID);
}
@ -1014,14 +1013,13 @@ nsRenderingContextPS :: GetWidth(const nsString& aString, nscoord& aWidth, PRInt
NS_IMETHODIMP
nsRenderingContextPS :: GetWidth(const PRUnichar *aString,PRUint32 aLength,nscoord &aWidth, PRInt32 *aFontID)
{
nsresult rv = NS_ERROR_FAILURE;
if (nsnull != mFontMetrics){
((nsFontMetricsPS*)mFontMetrics)->GetStringWidth(aString,aWidth,aLength);
return NS_OK;
} else {
return NS_ERROR_FAILURE;
if (mFontMetrics) {
rv = NS_REINTERPRET_CAST(nsFontMetricsPS *, mFontMetrics.get())->GetStringWidth(aString, aWidth, aLength);
}
return rv;
}
/** --------------------------------------------------- */
@ -1030,29 +1028,35 @@ NS_IMETHODIMP
nsRenderingContextPS :: GetTextDimensions(const char* aString, PRUint32 aLength,
nsTextDimensions& aDimensions)
{
if (nsnull != mFontMetrics){
((nsFontMetricsPS*)mFontMetrics)->GetStringWidth(aString,aDimensions.width,aLength);
mFontMetrics->GetMaxAscent(aDimensions.ascent);
mFontMetrics->GetMaxDescent(aDimensions.descent);
return NS_OK;
} else {
return NS_ERROR_FAILURE;
nsresult rv = NS_ERROR_FAILURE;
if (mFontMetrics) {
nsFontMetricsPS *metrics = NS_REINTERPRET_CAST(nsFontMetricsPS *, mFontMetrics.get());
metrics->GetStringWidth(aString, aDimensions.width, aLength);
metrics->GetMaxAscent(aDimensions.ascent);
metrics->GetMaxDescent(aDimensions.descent);
rv = NS_OK;
}
return rv;
}
NS_IMETHODIMP
nsRenderingContextPS :: GetTextDimensions(const PRUnichar* aString, PRUint32 aLength,
nsTextDimensions& aDimensions, PRInt32* aFontID)
{
if (nsnull != mFontMetrics){
((nsFontMetricsPS*)mFontMetrics)->GetStringWidth(aString,aDimensions.width,aLength);
nsresult rv = NS_ERROR_FAILURE;
if (mFontMetrics) {
nsFontMetricsPS *metrics = NS_REINTERPRET_CAST(nsFontMetricsPS *, mFontMetrics.get());
metrics->GetStringWidth(aString, aDimensions.width, aLength);
//XXX temporary - bug 96609
mFontMetrics->GetMaxAscent(aDimensions.ascent);
mFontMetrics->GetMaxDescent(aDimensions.descent);
return NS_OK;
} else {
return NS_ERROR_FAILURE;
metrics->GetMaxAscent(aDimensions.ascent);
metrics->GetMaxDescent(aDimensions.descent);
rv = NS_OK;
}
return rv;
}
/** ---------------------------------------------------
@ -1090,7 +1094,7 @@ PRInt32 y = aY;
#if 0
//this doesn't need to happen here anymore, but a
//new api will come along that will need this stuff. MMP
if (nsnull != mFontMetrics){
if (mFontMetrics) {
nsFont *font;
mFontMetrics->GetFont(font);
PRUint8 decorations = font->decorations;
@ -1122,7 +1126,7 @@ PRInt32 y = aY;
nsIFontMetrics *fMetrics;
nsCOMPtr<nsIAtom> langGroup = nsnull;
((nsFontMetricsPS*)mFontMetrics)->GetLangGroup(getter_AddRefs(langGroup));
mFontMetrics->GetLangGroup(getter_AddRefs(langGroup));
mPSObj->setlanggroup(langGroup.get());
/* build up conversion table */
@ -1148,7 +1152,7 @@ nsIFontMetrics *fMetrics;
fMetrics = mFontMetrics;
if (nsnull != fMetrics){
if (fMetrics) {
const nsFont *font;
fMetrics->GetFont(font);
PRUint8 decorations = font->decorations;
@ -1264,18 +1268,10 @@ NS_IMETHODIMP
nsRenderingContextPS::DrawTile(nsIImage *aImage,nscoord aX0,nscoord aY0,nscoord aX1,nscoord aY1,
nscoord aWidth,nscoord aHeight)
{
return NS_OK;
}
#ifdef USE_IMG2
#include "imgIContainer.h"
#include "gfxIImageFrame.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
/* [noscript] void drawImage (in imgIContainer aImage, [const] in nsRect aSrcRect, [const] in nsPoint aDestPoint); */
NS_IMETHODIMP nsRenderingContextPS::DrawImage(imgIContainer *aImage, const nsRect * aSrcRect, const nsPoint * aDestPoint)
{
@ -1317,12 +1313,12 @@ NS_IMETHODIMP nsRenderingContextPS::DrawImage(imgIContainer *aImage, const nsRec
NS_IMETHODIMP nsRenderingContextPS::DrawScaledImage(imgIContainer *aImage, const nsRect * aSrcRect, const nsRect * aDestRect)
{
nsRect dr;
nsRect sr;
dr = *aDestRect;
mTranMatrix->TransformCoord(&dr.x, &dr.y, &dr.width, &dr.height);
#if 0
nsRect sr;
// need to do this if we fix the comments below
sr = *aSrcRect;
mTranMatrix->TransformCoord(&sr.x, &sr.y, &sr.width, &sr.height);
@ -1350,8 +1346,6 @@ NS_IMETHODIMP nsRenderingContextPS::DrawScaledImage(imgIContainer *aImage, const
return NS_OK;
}
#endif
#ifdef MOZ_MATHML
/**
* Returns metrics (in app units) of an 8-bit character string
@ -1416,9 +1410,11 @@ nsAutoString fontFamily;
//mStates->mFont = mCurrFont = tfont;
mStates->mFontMetrics = mFontMetrics;
nsFontMetricsPS *metrics = NS_REINTERPRET_CAST(nsFontMetricsPS *, mFontMetrics.get());
// get the fontfamily we are using, not what we want, but what we are using
fontFamily.AssignWithConversion(((nsFontMetricsPS*)mFontMetrics)->mAFMInfo->mPSFontInfo->mFamilyName);
fontIndex = ((nsFontMetricsPS*)mFontMetrics)->GetFontIndex();
fontFamily.AssignWithConversion(metrics->mAFMInfo->mPSFontInfo->mFamilyName);
fontIndex = metrics->GetFontIndex();
mPSObj->setscriptfont(fontIndex,fontFamily,fontHeight,font->style,font->variant,font->weight,font->decorations);
}
@ -1484,32 +1480,5 @@ HPEN nsRenderingContextPS :: SetupDottedPen(void)
return mCurrPen;
}
#endif
#endif /* NOTNOW */
#ifdef DC
NS_IMETHODIMP
nsRenderingContextPS::GetColor(nsString& aColor)
{
char cbuf[40];
PR_snprintf(cbuf, sizeof(cbuf), "#%02x%02x%02x",
NS_GET_R(mCurrentColor),
NS_GET_G(mCurrentColor),
NS_GET_B(mCurrentColor));
aColor = cbuf;
return NS_OK;
}
NS_IMETHODIMP
nsRenderingContextPS::SetColor(const nsString& aColor)
{
nscolor rgb;
if (NS_ColorNameToRGB(aColor, &rgb)) {
SetColor(rgb);
}
else if (NS_HexToRGB(aColor, &rgb)) {
SetColor(rgb);
}
return NS_OK;
}
#endif

Просмотреть файл

@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
*
*
* Alternatively, the contents of this file may be used under the terms of
@ -43,7 +44,7 @@
#include "nsRenderingContextImpl.h"
#include "nsUnitConversion.h"
#include "nsFont.h"
#include "nsIFontMetrics.h"
#include "nsFontMetricsPS.h"
#include "nsPoint.h"
#include "nsString.h"
#include "nsCRT.h"
@ -51,14 +52,12 @@
#include "nsIViewManager.h"
#include "nsIWidget.h"
#include "nsRect.h"
#include "nsIDeviceContext.h"
#include "nsDeviceContextPS.h"
#include "nsVoidArray.h"
class nsPostScriptObj;
class nsPostScriptObj;
class PS_State;
typedef void* nsDrawingSurfacePS;
class nsRenderingContextPS : public nsRenderingContextImpl
{
public:
@ -69,10 +68,6 @@ public:
NS_DECL_ISUPPORTS
// nsIPrinterRenderingContext methods
protected:
public:
// nsIRenderingContext
NS_IMETHOD Init(nsIDeviceContext* aContext);
@ -184,10 +179,8 @@ public:
NS_IMETHOD DrawTile(nsIImage *aImage,nscoord aX0,nscoord aY0,nscoord aX1,nscoord aY1,
nscoord aWidth,nscoord aHeight);
#ifdef USE_IMG2
NS_IMETHOD DrawImage(imgIContainer *aImage, const nsRect * aSrcRect, const nsPoint * aDestPoint);
NS_IMETHOD DrawScaledImage(imgIContainer *aImage, const nsRect * aSrcRect, const nsRect * aDestRect);
#endif
NS_IMETHOD CopyOffScreenBits(nsDrawingSurface aSrcSurf, PRInt32 aSrcX, PRInt32 aSrcY,
const nsRect &aDestBounds, PRUint32 aCopyFlags);
@ -260,21 +253,18 @@ private:
void PushClipState(void);
protected:
nsIDeviceContext *mContext;
nsIFontMetrics *mFontMetrics;
nsCOMPtr<nsIDeviceContext> mContext;
nsCOMPtr<nsIFontMetrics> mFontMetrics;
nsLineStyle mCurrLineStyle;
PS_State *mStates;
nsVoidArray *mStateCache;
float mP2T;
nscolor mCurrentColor;
//state management
PRUint8 *mGammaTable;
nsPostScriptObj *mPSObj;
};
#endif /* nsRenderingContextPS_h___ */
#endif /* !nsRenderingContextPS_h___ */

Просмотреть файл

@ -51,8 +51,8 @@ pref("applications.tn3270", "create /term /detach \"telnet /term=IBM-3278-5 %h %
pref("applications.rlogin", "create /term /detach \"rlogin %h\"");
pref("applications.rlogin_with_user", "create /term /detach \"rlogin %h -l %u\"");
/* PostScript module specific */
pref("print.postscript.print_command", "print");
/* PostScript module specific (see unix.js for additional configuration details) */
pref("print.postscript.print_command", "print /delete");
/* Print module independant */
pref("print.print_color", false);