Back to index

lightning-sunbird  0.9+nobinonly
nsRenderingContextXlib.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 1; 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  *   Peter Hartshorn <peter@igelaus.com.au>
00024  *   Tim Copperfield <timecop@network.email.ne.jp>
00025  *   Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
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 #ifndef nsRenderingContextXlib_h___
00042 #define nsRenderingContextXlib_h___
00043 
00044 #include "nsIDeviceContext.h"
00045 #include "nsIWidget.h"
00046 #include "nsRenderingContextImpl.h"
00047 #include "nsUnitConversion.h"
00048 #include "nsFont.h"
00049 #include "nsFontMetricsXlib.h"
00050 #include "nsPoint.h"
00051 #include "nsString.h"
00052 #include "nsCRT.h"
00053 #include "nsTransform2D.h"
00054 #include "nsRect.h"
00055 #include "nsVoidArray.h"
00056 #include "nsGfxCIID.h"
00057 #include "nsDrawingSurfaceXlib.h"
00058 #include "nsRegionXlib.h"
00059 
00060 class nsFontXlib;
00061 
00062 class nsRenderingContextXlibContext
00063 {
00064 public:
00065   nsGCCacheXlib mGcCache;
00066 };
00067 
00068 /* Note |nsRenderingContextXp| may override some of these methods here */
00069 class nsRenderingContextXlib : public nsRenderingContextImpl
00070 {
00071 public:
00072   nsRenderingContextXlib();
00073   virtual ~nsRenderingContextXlib();
00074 
00075   NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
00076 
00077   NS_DECL_ISUPPORTS
00078 
00079   NS_IMETHOD Init(nsIDeviceContext* aContext, nsIWidget *aWindow);
00080   NS_IMETHOD Init(nsIDeviceContext* aContext, nsIDrawingSurface* aSurface);
00081 
00082   NS_IMETHOD Reset(void);
00083 
00084   NS_IMETHOD GetDeviceContext(nsIDeviceContext *&aContext);
00085 
00086   NS_IMETHOD LockDrawingSurface(PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight,
00087                                 void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes,
00088                                 PRUint32 aFlags);
00089   NS_IMETHOD UnlockDrawingSurface(void);
00090 
00091   NS_IMETHOD SelectOffScreenDrawingSurface(nsIDrawingSurface* aSurface);
00092   NS_IMETHOD GetDrawingSurface(nsIDrawingSurface* *aSurface);
00093   NS_IMETHOD GetHints(PRUint32& aResult);
00094 
00095   NS_IMETHOD PushState(void);
00096   NS_IMETHOD PopState(void);
00097 
00098   NS_IMETHOD IsVisibleRect(const nsRect& aRect, PRBool &aVisible);
00099 
00100   NS_IMETHOD SetClipRect(const nsRect& aRect, nsClipCombine aCombine);
00101   NS_IMETHOD GetClipRect(nsRect &aRect, PRBool &aClipValid);
00102   NS_IMETHOD SetClipRegion(const nsIRegion& aRegion, nsClipCombine aCombine);
00103   NS_IMETHOD CopyClipRegion(nsIRegion &aRegion);
00104   NS_IMETHOD GetClipRegion(nsIRegion **aRegion);
00105 
00106   NS_IMETHOD SetLineStyle(nsLineStyle aLineStyle);
00107   NS_IMETHOD GetLineStyle(nsLineStyle &aLineStyle);
00108 
00109   NS_IMETHOD SetColor(nscolor aColor);
00110   NS_IMETHOD GetColor(nscolor &aColor) const;
00111 
00112   NS_IMETHOD SetFont(const nsFont& aFont, nsIAtom* aLangGroup);
00113   NS_IMETHOD SetFont(nsIFontMetrics *aFontMetrics);
00114 
00115   NS_IMETHOD GetFontMetrics(nsIFontMetrics *&aFontMetrics);
00116 
00117   NS_IMETHOD Translate(nscoord aX, nscoord aY);
00118   NS_IMETHOD Scale(float aSx, float aSy);
00119   NS_IMETHOD GetCurrentTransform(nsTransform2D *&aTransform);
00120 
00121   NS_IMETHOD CreateDrawingSurface(const nsRect& aBounds, PRUint32 aSurfFlags, nsIDrawingSurface* &aSurface);
00122   NS_IMETHOD DestroyDrawingSurface(nsIDrawingSurface* aDS);
00123 
00124   NS_IMETHOD DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1);
00125   NS_IMETHOD DrawPolyline(const nsPoint aPoints[], PRInt32 aNumPoints);
00126 
00127   NS_IMETHOD DrawRect(const nsRect& aRect);
00128   NS_IMETHOD DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00129 
00130   NS_IMETHOD FillRect(const nsRect& aRect);
00131   NS_IMETHOD FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00132 
00133   NS_IMETHOD InvertRect(const nsRect& aRect);
00134   NS_IMETHOD InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00135 
00136   NS_IMETHOD DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
00137   NS_IMETHOD FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
00138 
00139   NS_IMETHOD DrawEllipse(const nsRect& aRect);
00140   NS_IMETHOD DrawEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00141   NS_IMETHOD FillEllipse(const nsRect& aRect);
00142   NS_IMETHOD FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00143 
00144   NS_IMETHOD DrawArc(const nsRect& aRect,
00145                      float aStartAngle, float aEndAngle);
00146   NS_IMETHOD DrawArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
00147                      float aStartAngle, float aEndAngle);
00148   NS_IMETHOD FillArc(const nsRect& aRect,
00149                      float aStartAngle, float aEndAngle);
00150   NS_IMETHOD FillArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
00151                      float aStartAngle, float aEndAngle);
00152 
00153   NS_IMETHOD GetWidth(char aC, nscoord &aWidth);
00154   NS_IMETHOD GetWidth(PRUnichar aC, nscoord &aWidth,
00155                       PRInt32 *aFontID);
00156   NS_IMETHOD GetWidth(const nsString& aString, nscoord &aWidth,
00157                       PRInt32 *aFontID);
00158   NS_IMETHOD GetWidth(const char *aString, nscoord &aWidth);
00159   NS_IMETHOD GetWidth(const char *aString, PRUint32 aLength, nscoord &aWidth);
00160   NS_IMETHOD GetWidth(const PRUnichar *aString, PRUint32 aLength, nscoord &aWidth,
00161                       PRInt32 *aFontID);
00162 
00163   NS_IMETHOD DrawString(const char *aString, PRUint32 aLength,
00164                         nscoord aX, nscoord aY,
00165                         const nscoord* aSpacing);
00166   NS_IMETHOD DrawString(const PRUnichar *aString, PRUint32 aLength,
00167                         nscoord aX, nscoord aY,
00168                         PRInt32 aFontID,
00169                         const nscoord* aSpacing);
00170   NS_IMETHOD DrawString(const nsString& aString, nscoord aX, nscoord aY,
00171                         PRInt32 aFontID,
00172                         const nscoord* aSpacing);
00173 
00174   NS_IMETHOD GetTextDimensions(const char* aString, PRUint32 aLength,
00175                                nsTextDimensions& aDimensions);
00176   NS_IMETHOD GetTextDimensions(const PRUnichar *aString, PRUint32 aLength,
00177                                nsTextDimensions& aDimensions, PRInt32 *aFontID);
00178   NS_IMETHOD GetTextDimensions(const char*       aString,
00179                                PRInt32           aLength,
00180                                PRInt32           aAvailWidth,
00181                                PRInt32*          aBreaks,
00182                                PRInt32           aNumBreaks,
00183                                nsTextDimensions& aDimensions,
00184                                PRInt32&          aNumCharsFit,
00185                                nsTextDimensions& aLastWordDimensions,
00186                                PRInt32*          aFontID = nsnull);
00187   NS_IMETHOD GetTextDimensions(const PRUnichar*  aString,
00188                                PRInt32           aLength,
00189                                PRInt32           aAvailWidth,
00190                                PRInt32*          aBreaks,
00191                                PRInt32           aNumBreaks,
00192                                nsTextDimensions& aDimensions,
00193                                PRInt32&          aNumCharsFit,
00194                                nsTextDimensions& aLastWordDimensions,
00195                                PRInt32*          aFontID = nsnull);
00196 
00197   NS_IMETHOD CopyOffScreenBits(nsIDrawingSurface* aSrcSurf, PRInt32 aSrcX, PRInt32 aSrcY,
00198                                const nsRect &aDestBounds, PRUint32 aCopyFlags);
00199   NS_IMETHOD RetrieveCurrentNativeGraphicData(void ** ngd);
00200 
00201   NS_IMETHOD DrawImage(imgIContainer *aImage, const nsRect & aSrcRect, const nsRect & aDestRect);
00202 
00203   NS_IMETHOD GetBackbuffer(const nsRect &aRequestedSize, const nsRect &aMaxSize,
00204                            PRBool aForBlending, nsIDrawingSurface* &aBackbuffer);
00205   NS_IMETHOD ReleaseBackbuffer(void);
00206 
00207 #ifdef MOZ_MATHML
00208 
00211   NS_IMETHOD GetBoundingMetrics(const char*        aString,
00212                                 PRUint32           aLength,
00213                                 nsBoundingMetrics& aBoundingMetrics);
00214   
00218   NS_IMETHOD GetBoundingMetrics(const PRUnichar*   aString,
00219                                 PRUint32           aLength,
00220                                 nsBoundingMetrics& aBoundingMetrics,
00221                                 PRInt32*           aFontID = nsnull);
00222 
00223 #endif /* MOZ_MATHML */
00224 
00225   void SetClipRectInPixels(const nsRect& aRect, nsClipCombine aCombine);
00226 
00227   xGC *GetGC() { mGC->AddRef(); return mGC; }
00228   void UpdateGC();
00229   
00230   /* Use UpdateGC() to update GC-cache !! */
00231   void SetCurrentFont(nsFontXlib *cf) { mCurrentFont = cf; };
00232   nsFontXlib *GetCurrentFont() { return mCurrentFont; };
00233 
00234 protected:
00235   /* This is a common init function for all of the |Init()| functions.*/
00236   nsresult CommonInit(void);
00237 
00238   nsCOMPtr<nsIDeviceContext>      mContext;
00239   nsCOMPtr<nsIDrawingSurfaceXlib> mOffscreenSurface;
00240   nsCOMPtr<nsIDrawingSurfaceXlib> mSurface;
00241   nsCOMPtr<nsIFontMetrics>        mFontMetrics;
00242   nsCOMPtr<nsIRegion>             mClipRegion;
00243   float                           mP2T;
00244 
00245  // graphic state stack (GraphicsState)
00246   nsAutoVoidArray          mStateCache;
00247 
00248   xGC                     *mGC;
00249   int                      mFunction;
00250   int                      mLineStyle;
00251   char                    *mDashList;
00252   int                      mDashes;
00253   nscolor                  mCurrentColor;
00254   XlibRgbHandle           *mXlibRgbHandle; 
00255   Display                 *mDisplay;
00256 
00257   nsFontXlib              *mCurrentFont;
00258   nsLineStyle              mCurrentLineStyle;
00259 
00260   // ConditionRect is used to fix coordinate overflow problems for
00261   // rectangles after they are transformed to screen coordinates
00262   void ConditionRect(nscoord &x, nscoord &y, nscoord &w, nscoord &h) {
00263     if ( y < -32766 ) {
00264       y = -32766;
00265     }
00266 
00267     if ( y + h > 32766 ) {
00268       h  = 32766 - y;
00269     }
00270 
00271     if ( x < -32766 ) {
00272       x = -32766;
00273     }
00274 
00275     if ( x + w > 32766 ) {
00276       w  = 32766 - x;
00277     }
00278   }
00279 };
00280 
00281 /* Prototypes */
00282 nsresult CreateRenderingContextXlibContext(nsIDeviceContext *aDevice, nsRenderingContextXlibContext **aContext);
00283 void DeleteRenderingContextXlibContext(nsRenderingContextXlibContext *aContext);
00284 
00285 #endif /* !nsRenderingContextXlib_h___ */