From 105a01499040b17d92261e13da54059587d5ca3d Mon Sep 17 00:00:00 2001 From: "pavlov%pavlov.net" Date: Thu, 30 Nov 2006 02:12:03 +0000 Subject: [PATCH] fixing linux printing bustage --- gfx/src/Makefile.in | 5 +- widget/src/gtk2/Makefile.in | 1 + widget/src/gtk2/nsDeviceContextSpecG.cpp | 5 + widget/src/gtk2/nsDeviceContextSpecG.h | 6 + widget/src/gtk2/nsPrintJobGTK.cpp | 1 - widget/src/gtk2/nsTempfilePS.cpp | 133 +++++++++++++++++++++++ widget/src/gtk2/nsTempfilePS.h | 91 ++++++++++++++++ 7 files changed, 240 insertions(+), 2 deletions(-) create mode 100644 widget/src/gtk2/nsTempfilePS.cpp create mode 100644 widget/src/gtk2/nsTempfilePS.h diff --git a/gfx/src/Makefile.in b/gfx/src/Makefile.in index 2e24d94c8432..b37c22692b15 100644 --- a/gfx/src/Makefile.in +++ b/gfx/src/Makefile.in @@ -68,7 +68,10 @@ DIRS += freetype endif ifdef MOZ_ENABLE_POSTSCRIPT -DIRS += psshared ps +DIRS += psshared +ifndef MOZ_ENABLE_CAIRO_GFX +DIRS += ps +endif endif # Build xlibrgb only for X toolkits and/or Xprint diff --git a/widget/src/gtk2/Makefile.in b/widget/src/gtk2/Makefile.in index 0207a7bd979b..9ebbef9a4942 100644 --- a/widget/src/gtk2/Makefile.in +++ b/widget/src/gtk2/Makefile.in @@ -113,6 +113,7 @@ CPPSRCS = \ nsAccessibilityHelper.cpp \ nsPrintJobFactoryGTK.cpp \ nsPrintJobGTK.cpp \ + nsTempfilePS.cpp \ $(NULL) # build our subdirs, too diff --git a/widget/src/gtk2/nsDeviceContextSpecG.cpp b/widget/src/gtk2/nsDeviceContextSpecG.cpp index e92bbe8fc936..f5bc73ade993 100644 --- a/widget/src/gtk2/nsDeviceContextSpecG.cpp +++ b/widget/src/gtk2/nsDeviceContextSpecG.cpp @@ -391,6 +391,10 @@ nsDeviceContextSpecGTK::~nsDeviceContextSpecGTK() } /* Use both PostScript and Xprint module */ +#ifdef MOZ_CAIRO_GFX +NS_IMPL_ISUPPORTS1(nsDeviceContextSpecGTK, + nsIDeviceContextSpec) +#else #if defined(USE_XPRINT) && defined(USE_POSTSCRIPT) NS_IMPL_ISUPPORTS3(nsDeviceContextSpecGTK, nsIDeviceContextSpec, @@ -413,6 +417,7 @@ NS_IMPL_ISUPPORTS1(nsDeviceContextSpecGTK, #else #error "This should not happen" #endif +#endif #ifdef MOZ_CAIRO_GFX //#define USE_PDF 1 diff --git a/widget/src/gtk2/nsDeviceContextSpecG.h b/widget/src/gtk2/nsDeviceContextSpecG.h index 6478c3338d0b..66759656b91e 100644 --- a/widget/src/gtk2/nsDeviceContextSpecG.h +++ b/widget/src/gtk2/nsDeviceContextSpecG.h @@ -44,12 +44,16 @@ #include "nsIPrintOptions.h" #include "nsVoidArray.h" #include "nsCOMPtr.h" + +#ifndef MOZ_CAIRO_GFX #ifdef USE_POSTSCRIPT #include "nsIDeviceContextSpecPS.h" #endif /* USE_POSTSCRIPT */ #ifdef USE_XPRINT #include "nsIDeviceContextSpecXPrint.h" #endif /* USE_XPRINT */ +#endif + #include "nsCRT.h" /* should be ? */ #include "nsIPrintJobGTK.h" @@ -65,12 +69,14 @@ typedef enum } PrintMethod; class nsDeviceContextSpecGTK : public nsIDeviceContextSpec +#ifndef MOZ_CAIRO_GFX #ifdef USE_POSTSCRIPT , public nsIDeviceContextSpecPS #endif /* USE_POSTSCRIPT */ #ifdef USE_XPRINT , public nsIDeviceContextSpecXp #endif /* USE_XPRINT */ +#endif { public: nsDeviceContextSpecGTK(); diff --git a/widget/src/gtk2/nsPrintJobGTK.cpp b/widget/src/gtk2/nsPrintJobGTK.cpp index 4fe249335713..ac36ed90f6d5 100644 --- a/widget/src/gtk2/nsPrintJobGTK.cpp +++ b/widget/src/gtk2/nsPrintJobGTK.cpp @@ -39,7 +39,6 @@ #include "nscore.h" #include "nsIDeviceContext.h" // NS_ERROR_GFX_* -#include "nsIDeviceContextPS.h" // NS_POSTSCRIPT_DRIVER_NAME_LEN #include "nsIDeviceContextSpec.h" #include "nsDeviceContextSpecG.h" diff --git a/widget/src/gtk2/nsTempfilePS.cpp b/widget/src/gtk2/nsTempfilePS.cpp new file mode 100644 index 000000000000..8e527d6451d9 --- /dev/null +++ b/widget/src/gtk2/nsTempfilePS.cpp @@ -0,0 +1,133 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ex: set tabstop=8 softtabstop=4 shiftwidth=4 expandtab: */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Kenneth Herron . + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Kenneth Herron + * + * Alternatively, the contents of this file may be used under the terms of + * either of the GNU General Public License Version 2 or later (the "GPL"), + * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + + +#include "nsTempfilePS.h" +#include "nsCOMPtr.h" +#include "nsDirectoryServiceDefs.h" +#include "nsILocalFile.h" +#include "nsPrintfCString.h" +#include "prtime.h" + + +nsTempfilePS::nsTempfilePS() +{ + nsresult rv; + + // Get the standard temporary directory. + rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(mTempDir)); + if (NS_FAILED(rv)) + return; + + // Grab some low-order bits from the current time for use in temporary + // filenames. + LL_L2UI(mCount, PR_Now()); + + // Append an arbitrary subdirectory name to the temp dir... + rv = mTempDir->Append( + NS_ConvertASCIItoUTF16(nsPrintfCString("%lx.tmp", mCount++))); + if (NS_FAILED(rv)) { + mTempDir = nsnull; + return; + } + // and try to create it as a private directory for our temp files. Note + // CreateUnique() may adjust the subdirectory name we just appended. + rv = mTempDir->CreateUnique(nsIFile::DIRECTORY_TYPE, 0700); + if (NS_FAILED(rv)) + mTempDir = nsnull; +} + +nsTempfilePS::~nsTempfilePS() +{ + if (nsnull != mTempDir) + mTempDir->Remove(PR_TRUE); +} + +nsresult +nsTempfilePS::CreateTempFile(nsILocalFile** aFile) +{ + NS_PRECONDITION(nsnull != aFile, "aFile argument is NULL"); + NS_ENSURE_TRUE(nsnull != mTempDir, NS_ERROR_NOT_INITIALIZED); + + // Get the temporary directory path + nsresult rv; + nsAutoString tmpdir; + rv = mTempDir->GetPath(tmpdir); + NS_ENSURE_SUCCESS(rv, rv); + + // Create a new object for the temporary file + nsCOMPtr tmpfile; + rv = NS_NewLocalFile(tmpdir, PR_FALSE, getter_AddRefs(tmpfile)); + NS_ENSURE_SUCCESS(rv, rv); + NS_POSTCONDITION(nsnull != tmpfile, + "NS_NewLocalFile succeeded but tmpfile is invalid"); + + rv = tmpfile->Append( + NS_ConvertASCIItoUTF16(nsPrintfCString("%lx.tmp", mCount++))); + NS_ENSURE_SUCCESS(rv, rv); + + // Create the temporary file. This may adjust the file's basename. + rv = tmpfile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600); + NS_ENSURE_SUCCESS(rv, rv); + + *aFile = tmpfile.get(); + NS_ADDREF(*aFile); + return NS_OK; +} + + +nsresult +nsTempfilePS::CreateTempFile(nsILocalFile** aFile, + FILE **aHandle, const char *aMode) +{ + NS_PRECONDITION(nsnull != aHandle, "aHandle is invalid"); + NS_PRECONDITION(nsnull != aMode, "aMode is invalid"); + + nsresult rv = CreateTempFile(aFile); + NS_ENSURE_SUCCESS(rv, rv); + NS_POSTCONDITION(nsnull != *aFile, + "CreateTempFile() succeeded but *aFile is invalid"); + + rv = (*aFile)->OpenANSIFileDesc(aMode, aHandle); + if (NS_FAILED(rv)) { + (*aFile)->Remove(PR_FALSE); + NS_RELEASE(*aFile); + } + return rv; +} diff --git a/widget/src/gtk2/nsTempfilePS.h b/widget/src/gtk2/nsTempfilePS.h new file mode 100644 index 000000000000..c6b99ea25a25 --- /dev/null +++ b/widget/src/gtk2/nsTempfilePS.h @@ -0,0 +1,91 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ex: set tabstop=8 softtabstop=4 shiftwidth=4 expandtab: */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Kenneth Herron . + * Portions created by the Initial Developer are Copyright (C) 2003 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Kenneth Herron + * + * Alternatively, the contents of this file may be used under the terms of + * either of the GNU General Public License Version 2 or later (the "GPL"), + * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + + +#ifndef nsTempfilePS_h__ +#define nsTempfilePS_h__ + +#include "nscore.h" +#include "nsCOMPtr.h" +#include "nsIFile.h" +#include "nsString.h" + +class nsILocalFile; + +class nsTempfilePS +{ +public: + nsTempfilePS(); + ~nsTempfilePS(); + + /** + * Create a temporary file and return an nsILocalFile object for + * accessing it. + * + * @param aFileName After a successful return, this will be filled in + * with an nsILocalFile object for a newly-created + * temporary file. There are no open file descriptors + * to the file. + * @return NS_OK on success, or a suitable error value. + */ + nsresult CreateTempFile(nsILocalFile** aFile); + + /** + * Like |CreateTempFile(nsILocalFile**)|, but also initialize a stdio + * file handle for the file. + * + * @param aFileName After a successful return, this will be filled in + * with an nsILocalFile object for a newly-created + * temporary file. + * @param aHandle After a successful return, this will be filled in + * with a file handle that may be used to access the + * file, opened according to the specified mode. + * @param aMode Stdio mode string for opening the temporary file. + * See fopen(3). + * @return NS_OK on success, or a suitable error value. + */ + nsresult CreateTempFile(nsILocalFile** aFile, + FILE **aHandle, const char *aMode); + +private: + nsCOMPtr mTempDir; + PRUint32 mCount; +}; + +#endif /* nsTempfilePS_h__ */