Back to index

lightning-sunbird  0.9+nobinonly
nsRenderingContextQt.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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  *   Lars Knoll <knoll@kde.org>
00024  *   Zack Rusin <zack@kde.org>
00025  *   John C. Griggs <johng@corel.com>
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either the GNU General Public License Version 2 or later (the "GPL"), or
00029  * 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 nsRenderingContextQt_h___
00042 #define nsRenderingContextQt_h___
00043 
00044 #include "nsRenderingContextImpl.h"
00045 #include "nsUnitConversion.h"
00046 #include "nsFont.h"
00047 #include "nsIFontMetrics.h"
00048 #include "nsPoint.h"
00049 #include "nsString.h"
00050 #include "nsCRT.h"
00051 #include "nsTransform2D.h"
00052 #include "nsIWidget.h"
00053 #include "nsRect.h"
00054 #include "nsIDeviceContext.h"
00055 #include "nsVoidArray.h"
00056 #include "nsCOMPtr.h"
00057 
00058 #include "nsRegionQt.h"
00059 #include "nsDrawingSurfaceQt.h"
00060 #include "prlog.h"
00061 
00062 class nsFontQt;
00063 class nsDrawingSurface;
00064 
00065 class nsRenderingContextQt : public nsRenderingContextImpl
00066 {
00067 public:
00068     nsRenderingContextQt();
00069     virtual ~nsRenderingContextQt();
00070 
00071     NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
00072 
00073     NS_DECL_ISUPPORTS
00074 
00075     NS_IMETHOD Init(nsIDeviceContext* aContext, nsIWidget *aWindow);
00076     NS_IMETHOD Init(nsIDeviceContext* aContext, nsIDrawingSurface* aSurface);
00077 
00078     NS_IMETHOD Reset(void);
00079 
00080     NS_IMETHOD GetDeviceContext(nsIDeviceContext *&aContext);
00081 
00082     NS_IMETHOD LockDrawingSurface(PRInt32 aX,PRInt32 aY,PRUint32 aWidth,
00083                                   PRUint32 aHeight,void **aBits,
00084                                   PRInt32 *aStride,PRInt32 *aWidthBytes,
00085                                   PRUint32 aFlags);
00086     NS_IMETHOD UnlockDrawingSurface(void);
00087 
00088     NS_IMETHOD SelectOffScreenDrawingSurface(nsIDrawingSurface* aSurface);
00089     NS_IMETHOD GetDrawingSurface(nsIDrawingSurface* *aSurface);
00090     NS_IMETHOD GetHints(PRUint32& aResult);
00091 
00092     NS_IMETHOD PushState(void);
00093     NS_IMETHOD PopState(void);
00094 
00095     NS_IMETHOD IsVisibleRect(const nsRect& aRect, PRBool &aVisible);
00096 
00097     NS_IMETHOD SetClipRect(const nsRect& aRect, nsClipCombine aCombine);
00098     NS_IMETHOD CopyClipRegion(nsIRegion &aRegion);
00099     NS_IMETHOD GetClipRect(nsRect &aRect, PRBool &aClipValid);
00100     NS_IMETHOD SetClipRegion(const nsIRegion& aRegion, nsClipCombine aCombine);
00101     NS_IMETHOD GetClipRegion(nsIRegion **aRegion);
00102 
00103     NS_IMETHOD SetLineStyle(nsLineStyle aLineStyle);
00104     NS_IMETHOD GetLineStyle(nsLineStyle &aLineStyle);
00105 
00106     NS_IMETHOD SetColor(nscolor aColor);
00107     NS_IMETHOD GetColor(nscolor &aColor) const;
00108 
00109     NS_IMETHOD SetFont(const nsFont& aFont, nsIAtom* aLangGroup);
00110     NS_IMETHOD SetFont(nsIFontMetrics *aFontMetrics);
00111 
00112     NS_IMETHOD GetFontMetrics(nsIFontMetrics *&aFontMetrics);
00113 
00114     NS_IMETHOD Translate(nscoord aX, nscoord aY);
00115     NS_IMETHOD Scale(float aSx, float aSy);
00116     NS_IMETHOD GetCurrentTransform(nsTransform2D *&aTransform);
00117 
00118     NS_IMETHOD CreateDrawingSurface(const nsRect& aBounds,PRUint32 aSurfFlags,
00119                                     nsIDrawingSurface* &aSurface);
00120     NS_IMETHOD DestroyDrawingSurface(nsIDrawingSurface* aDS);
00121 
00122     NS_IMETHOD DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1);
00123     NS_IMETHOD DrawStdLine(nscoord aX0,nscoord aY0,nscoord aX1,nscoord aY1);
00124     NS_IMETHOD DrawPolyline(const nsPoint aPoints[], PRInt32 aNumPoints);
00125 
00126     NS_IMETHOD DrawRect(const nsRect& aRect);
00127     NS_IMETHOD DrawRect(nscoord aX,nscoord aY,nscoord aWidth,nscoord aHeight);
00128     NS_IMETHOD FillRect(const nsRect& aRect);
00129     NS_IMETHOD FillRect(nscoord aX,nscoord aY,nscoord aWidth,nscoord aHeight);
00130     NS_IMETHOD InvertRect(const nsRect& aRect);
00131     NS_IMETHOD InvertRect(nscoord aX,nscoord aY,nscoord aWidth,nscoord aHeight);
00132 
00133     NS_IMETHOD DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
00134     NS_IMETHOD FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
00135 
00136     NS_IMETHOD DrawEllipse(const nsRect& aRect);
00137     NS_IMETHOD DrawEllipse(nscoord aX,nscoord aY,nscoord aWidth,
00138                            nscoord aHeight);
00139     NS_IMETHOD FillEllipse(const nsRect& aRect);
00140     NS_IMETHOD FillEllipse(nscoord aX,nscoord aY,nscoord aWidth,
00141                            nscoord aHeight);
00142 
00143     NS_IMETHOD DrawArc(const nsRect& aRect,float aStartAngle,float aEndAngle);
00144     NS_IMETHOD DrawArc(nscoord aX,nscoord aY,nscoord aWidth,nscoord aHeight,
00145                        float aStartAngle,float aEndAngle);
00146     NS_IMETHOD FillArc(const nsRect& aRect,float aStartAngle,float aEndAngle);
00147     NS_IMETHOD FillArc(nscoord aX,nscoord aY,nscoord aWidth,nscoord aHeight,
00148                        float aStartAngle,float aEndAngle);
00149 
00150     NS_IMETHOD GetWidth(char aC, nscoord &aWidth);
00151     NS_IMETHOD GetWidth(PRUnichar aC, nscoord &aWidth, PRInt32 *aFontID);
00152     NS_IMETHOD GetWidth(const nsString& aString,nscoord &aWidth,
00153                         PRInt32 *aFontID);
00154     NS_IMETHOD GetWidth(const char *aString, nscoord &aWidth);
00155     NS_IMETHOD GetWidth(const char *aString,PRUint32 aLength,nscoord &aWidth);
00156     NS_IMETHOD GetWidth(const PRUnichar *aString,PRUint32 aLength,
00157                         nscoord &aWidth,PRInt32 *aFontID);
00158 
00159     NS_IMETHOD GetTextDimensions(const char* aString,
00160                                  PRUint32 aLength,
00161                                  nsTextDimensions& aDimensions);
00162 
00163     NS_IMETHOD GetTextDimensions(const PRUnichar *aString,
00164                                  PRUint32 aLength,
00165                                  nsTextDimensions& aDimensions,
00166                                  PRInt32 *aFontID);
00167 
00168     NS_IMETHOD GetTextDimensions(const char*       aString,
00169                                  PRInt32           aLength,
00170                                  PRInt32           aAvailWidth,
00171                                  PRInt32*          aBreaks,
00172                                  PRInt32           aNumBreaks,
00173                                  nsTextDimensions& aDimensions,
00174                                  PRInt32&          aNumCharsFit,
00175                                  nsTextDimensions& aLastWordDimensions,
00176                                  PRInt32*          aFontID);
00177 
00178     NS_IMETHOD GetTextDimensions(const PRUnichar*  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);
00187 
00188 #ifdef MOZ_MATHML
00189     /* Returns metrics (in app units) of an 8-bit character string */
00190     NS_IMETHOD GetBoundingMetrics(const char *aString,PRUint32 aLength,
00191                                   nsBoundingMetrics& aBoundingMetrics);
00192 
00193     /* Returns metrics (in app units) of a Unicode character string */
00194     NS_IMETHOD GetBoundingMetrics(const PRUnichar *aString,PRUint32 aLength,
00195                                   nsBoundingMetrics& aBoundingMetrics,
00196                                   PRInt32 *aFontID = nsnull);
00197 #endif /* MOZ_MATHML */
00198 
00199     NS_IMETHOD DrawString(const char *aString,PRUint32 aLength,
00200                           nscoord aX,nscoord aY,const nscoord* aSpacing);
00201     NS_IMETHOD DrawString(const PRUnichar *aString,PRUint32 aLength,
00202                           nscoord aX,nscoord aY,PRInt32 aFontID,
00203                           const nscoord* aSpacing);
00204     NS_IMETHOD DrawString(const nsString& aString,nscoord aX,nscoord aY,
00205                           PRInt32 aFontID,const nscoord* aSpacing);
00206 
00207     NS_IMETHOD CopyOffScreenBits(nsIDrawingSurface* aSrcSurf,
00208                                  PRInt32 aSrcX, PRInt32 aSrcY,
00209                                  const nsRect &aDestBounds,
00210                                  PRUint32 aCopyFlags);
00211 
00212     NS_IMETHOD RetrieveCurrentNativeGraphicData(PRUint32 *ngd);
00213 
00214     //locals
00215     NS_IMETHOD CommonInit();
00216     void       UpdateGC();
00217     void       ConditionRect(nscoord &x, nscoord &y, nscoord &w, nscoord &h);
00218     void       CreateClipRegion();
00219 
00220     QPainter *painter() const { return mSurface->GetGC(); }
00221     QPaintDevice *paintDevice() const { return mSurface->GetPaintDevice(); }
00222     nsTransform2D *matrix() const { return mTranMatrix; }
00223 
00224     QRect qRect(const nsRect &aRect) {
00225         int x = aRect.x;
00226         int y = aRect.y;
00227         int w = aRect.width;
00228         int h = aRect.height;
00229         mTranMatrix->TransformCoord(&x,&y,&w,&h);
00230         return QRect (x, y, w, h);
00231     }
00232 
00233 protected:
00234     nsDrawingSurfaceQt   *mOffscreenSurface;
00235     nsDrawingSurfaceQt   *mSurface;
00236     nsIDeviceContext     *mContext;
00237     nsIFontMetrics       *mFontMetrics;
00238     nsCOMPtr<nsIRegion>  mClipRegion;
00239     float                mP2T;
00240 
00241     // graphic state stack (GraphicsState)
00242     nsVoidArray          mStateCache;
00243 
00244     nscolor              mCurrentColor;
00245     nsLineStyle          mCurrentLineStyle;
00246 
00247     nsFontQt             *mCurrentFont;
00248     Qt::PenStyle      mQLineStyle;
00249     Qt::RasterOp      mFunction;
00250 };
00251 
00252 #endif /* nsRenderingContextQt_h___ */