Back to index

lightning-sunbird  0.9+nobinonly
nsXPrintContext.h
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
00024  *   Leon Sha <leon.sha@sun.com>
00025  *   Julien Lafon <julien.lafon@gmail.com>
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either of the GNU General Public License Version 2 or later (the "GPL"),
00029  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041  
00042 #ifndef _XPCONTEXT_H_
00043 #define _XPCONTEXT_H_
00044 
00045 #include <X11/Xlib.h>
00046 #include <X11/extensions/Print.h>
00047 #include "nsColor.h"
00048 #include "nsCoord.h"
00049 #include "nsIImage.h"
00050 #include "nsGCCache.h"
00051 #include "nsIDeviceContextSpecXPrint.h"
00052 #include "nsDrawingSurfaceXlib.h"
00053 #include "xlibrgb.h"
00054 
00055 class nsDeviceContextXp;
00056 
00057 class nsXPrintContext : public nsIDrawingSurfaceXlib
00058 {
00059 public:
00060   nsXPrintContext();
00061   virtual ~nsXPrintContext();
00062 
00063   NS_DECL_ISUPPORTS
00064 
00065   NS_IMETHOD Lock(PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight,
00066                   void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes,
00067                   PRUint32 aFlags)  { return NS_OK; };
00068   NS_IMETHOD Unlock(void)  { return NS_OK; };
00069   
00070   NS_IMETHOD GetDimensions(PRUint32 *aWidth, PRUint32 *aHeight);
00071   NS_IMETHOD IsOffscreen(PRBool *aOffScreen);
00072   NS_IMETHOD IsPixelAddressable(PRBool *aAddressable);
00073   NS_IMETHOD GetPixelFormat(nsPixelFormat *aFormat);
00074 
00075   NS_IMETHOD Init(nsDeviceContextXp *dc, nsIDeviceContextSpecXp *aSpec);
00076   NS_IMETHOD BeginPage();
00077   NS_IMETHOD EndPage();
00078   NS_IMETHOD RenderEPS(Drawable aDrawable, const nsRect& aRect, const unsigned char *aData, unsigned long aDatalen);
00079   NS_IMETHOD BeginDocument(PRUnichar * aTitle, PRUnichar* aPrintToFileName, PRInt32 aStartPage, PRInt32 aEndPage);
00080   NS_IMETHOD EndDocument();
00081   NS_IMETHOD AbortDocument();
00082 
00083   int                     GetHeight() { return mHeight; }
00084   int                     GetWidth() { return mWidth; }
00085   NS_IMETHOD GetDrawable(Drawable &aDrawable) { aDrawable = mDrawable; return NS_OK; }
00086   NS_IMETHOD GetXlibRgbHandle(XlibRgbHandle *&aHandle) { aHandle = mXlibRgbHandle; return NS_OK; }
00087   NS_IMETHOD GetGC(xGC *&aXGC) { mGC->AddRef(); aXGC = mGC; return NS_OK; }
00088 
00089   virtual Drawable GetDrawable() { return mDrawable; }
00090   
00091   void                    SetGC(xGC *aGC) { mGC = aGC; mGC->AddRef(); }
00092 
00093   NS_IMETHOD GetPrintResolution(int &aXres, int &aYres);
00094 
00095   NS_IMETHOD DrawImage(Drawable aDrawable, xGC *gc, nsIImage *aImage,
00096                 PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
00097                 PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight);
00098 
00099   NS_IMETHOD DrawImage(Drawable aDrawable, xGC *gc, nsIImage *aImage,
00100                  PRInt32 aX, PRInt32 aY,
00101                  PRInt32 aWidth, PRInt32 aHeight);
00102 
00103 private:
00104   nsresult DrawImageBitsScaled(Drawable aDrawable,
00105                 xGC *gc, nsIImage *aImage,
00106                 PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
00107                 PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight);
00108                 
00109   nsresult DrawImageBits(Drawable aDrawable, xGC *gc, 
00110                          PRUint8 *alphaBits, PRInt32  alphaRowBytes, PRUint8 alphaDepth,
00111                          PRUint8 *image_bits, PRInt32  row_bytes,
00112                          PRInt32 aX, PRInt32 aY,
00113                          PRInt32 aWidth, PRInt32 aHeight); 
00114 
00115   XlibRgbHandle *mXlibRgbHandle;
00116   Display      *mPDisplay;
00117   Screen       *mScreen;
00118   Visual       *mVisual;
00119   Drawable      mDrawable; /* window/paper surface */
00120   nsPixelFormat mPixFormat;
00121   xGC          *mGC;
00122   int           mXpEventBase, /* XpExtension X event base */
00123                 mXpErrorBase; /* XpExtension X error base */
00124   int           mDepth;
00125   int           mScreenNumber;
00126   int           mWidth;
00127   int           mHeight;
00128   XPContext     mPContext;
00129   PRBool        mJobStarted;  /* |PR_TRUE| when being between XpStartJob() and XpEndJob() */
00130   PRBool        mIsGrayscale; /* color or grayscale ? */
00131   PRBool        mIsAPrinter;  /* destination: printer or file ? */
00132   const char   *mPrintFile;   /* file to "print" to */
00133   void         *mXpuPrintToFileHandle; /* handle for XpuPrintToFile/XpuWaitForPrintFileChild when printing to file */
00134   long          mPrintXResolution,
00135                 mPrintYResolution;
00136   nsDeviceContextXp *mContext; /* DeviceContext which created this object */
00137 
00138   static PRUint8 ConvertMaskToCount(unsigned long val);
00139   static PRUint8 GetShiftForMask(unsigned long val);
00140 
00141   nsresult SetupWindow(int x, int y, int width, int height);
00142   nsresult SetupPrintContext(nsIDeviceContextSpecXp *aSpec);
00143   nsresult SetMediumSize(const char *paper_name);
00144   nsresult SetOrientation(int landscape);
00145   nsresult SetPlexMode(const char *plexname);
00146   nsresult SetResolution(const char *resolution_name);
00147 };
00148 
00149 
00150 #endif /* !_XPCONTEXT_H_ */
00151