Back to index

lightning-sunbird  0.9+nobinonly
nsRenderingContextMac.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; 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  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef nsRenderingContextMac_h___
00039 #define nsRenderingContextMac_h___
00040 
00041 #include <QDOffscreen.h>
00042 #include <UnicodeConverter.h>
00043 
00044 #include "nsRenderingContextImpl.h"
00045 #include "nsDrawingSurfaceMac.h"
00046 #include "nsUnicodeRenderingToolkit.h"
00047 
00048 #include "nsVoidArray.h"
00049 
00050 class nsIFontMetrics;
00051 class nsIDeviceContext;
00052 class nsIRegion;
00053 class nsFont;
00054 class nsTransform2D;
00055 
00056 class nsGraphicState;
00057 class nsUnicodeFallbackCache;
00058 
00059 //------------------------------------------------------------------------
00060 
00061 
00062 class nsRenderingContextMac : public nsRenderingContextImpl
00063 {
00064 public:
00065   nsRenderingContextMac();
00066   ~nsRenderingContextMac();
00067 
00068   NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
00069 
00070   NS_DECL_ISUPPORTS
00071 
00072   NS_IMETHOD Init(nsIDeviceContext* aContext, nsIWidget *aWindow);
00073   NS_IMETHOD Init(nsIDeviceContext* aContext, nsIDrawingSurface* aSurface);
00074 
00075   NS_IMETHOD Reset(void);
00076   NS_IMETHOD GetDeviceContext(nsIDeviceContext *&aContext);
00077   NS_IMETHOD LockDrawingSurface(PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight,
00078                                 void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes,
00079                                 PRUint32 aFlags);
00080   NS_IMETHOD UnlockDrawingSurface(void);
00081   NS_IMETHOD SelectOffScreenDrawingSurface(nsIDrawingSurface* aSurface);
00082   NS_IMETHOD GetDrawingSurface(nsIDrawingSurface* *aSurface);
00083   NS_IMETHOD GetHints(PRUint32& aResult);
00084   NS_IMETHOD PushState(void);
00085   NS_IMETHOD PopState(void);
00086   NS_IMETHOD IsVisibleRect(const nsRect& aRect, PRBool &aVisible);
00087   NS_IMETHOD SetClipRect(const nsRect& aRect, nsClipCombine aCombine);
00088   NS_IMETHOD GetClipRect(nsRect &aRect, PRBool &aClipValid);
00089   NS_IMETHOD SetClipRegion(const nsIRegion& aRegion, nsClipCombine aCombine);
00090   NS_IMETHOD CopyClipRegion(nsIRegion &aRegion);
00091   NS_IMETHOD GetClipRegion(nsIRegion **aRegion);
00092   NS_IMETHOD SetLineStyle(nsLineStyle aLineStyle);
00093   NS_IMETHOD GetLineStyle(nsLineStyle &aLineStyle);
00094   NS_IMETHOD SetColor(nscolor aColor);
00095   NS_IMETHOD GetColor(nscolor &aColor) const;
00096   NS_IMETHOD SetFont(const nsFont& aFont, nsIAtom* aLangGroup);
00097   NS_IMETHOD SetFont(nsIFontMetrics *aFontMetrics);
00098   NS_IMETHOD GetFontMetrics(nsIFontMetrics *&aFontMetrics);
00099   NS_IMETHOD Translate(nscoord aX, nscoord aY);
00100   NS_IMETHOD Scale(float aSx, float aSy);
00101   NS_IMETHOD GetCurrentTransform(nsTransform2D *&aTransform);
00102   NS_IMETHOD CreateDrawingSurface(const nsRect& aBounds, PRUint32 aSurfFlags, nsIDrawingSurface* &aSurface);
00103   NS_IMETHOD DestroyDrawingSurface(nsIDrawingSurface* aDS);
00104   NS_IMETHOD DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1);
00105   NS_IMETHOD DrawPolyline(const nsPoint aPoints[], PRInt32 aNumPoints);
00106   NS_IMETHOD DrawRect(const nsRect& aRect);
00107   NS_IMETHOD DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00108   NS_IMETHOD FillRect(const nsRect& aRect);
00109   NS_IMETHOD FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00110   NS_IMETHOD InvertRect(const nsRect& aRect);
00111   NS_IMETHOD InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00112   NS_IMETHOD FlushRect(const nsRect& aRect);
00113   NS_IMETHOD FlushRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00114   NS_IMETHOD DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
00115   NS_IMETHOD FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
00116   NS_IMETHOD DrawEllipse(const nsRect& aRect);
00117   NS_IMETHOD DrawEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00118   NS_IMETHOD FillEllipse(const nsRect& aRect);
00119   NS_IMETHOD FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00120   NS_IMETHOD DrawArc(const nsRect& aRect,float aStartAngle, float aEndAngle);
00121   NS_IMETHOD DrawArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,float aStartAngle, float aEndAngle);
00122   NS_IMETHOD FillArc(const nsRect& aRect,float aStartAngle, float aEndAngle);
00123   NS_IMETHOD FillArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,float aStartAngle, float aEndAngle);
00124 
00125   NS_IMETHOD GetWidth(const nsString& aString, nscoord &aWidth,
00126                       PRInt32 *aFontID = nsnull)
00127   { return nsRenderingContextImpl::GetWidth(aString, aWidth, aFontID); }
00128   NS_IMETHOD GetWidth(const char* aString, nscoord& aWidth)
00129   { return nsRenderingContextImpl::GetWidth(aString, aWidth); }
00130   NS_IMETHOD GetWidth(const char* aString, PRUint32 aLength,
00131                       nscoord& aWidth)
00132   { return nsRenderingContextImpl::GetWidth(aString, aLength, aWidth); }
00133   NS_IMETHOD GetWidth(const PRUnichar *aString, PRUint32 aLength,
00134                       nscoord &aWidth, PRInt32 *aFontID = nsnull)
00135   { return nsRenderingContextImpl::GetWidth(aString, aLength, aWidth, aFontID); }
00136   NS_IMETHOD DrawString(const nsString& aString, nscoord aX, nscoord aY,
00137                         PRInt32 aFontID = -1,
00138                         const nscoord* aSpacing = nsnull)
00139   { return nsRenderingContextImpl::DrawString(aString, aX, aY, aFontID, aSpacing); }
00140 
00141   NS_IMETHOD GetWidth(char aC, nscoord &aWidth);
00142   NS_IMETHOD GetWidth(PRUnichar aC, nscoord &aWidth,
00143                       PRInt32 *aFontID);
00144 
00145   NS_IMETHOD GetWidthInternal(const char *aString, PRUint32 aLength, nscoord &aWidth);
00146   NS_IMETHOD GetWidthInternal(const PRUnichar *aString, PRUint32 aLength, nscoord &aWidth,
00147                               PRInt32 *aFontID);
00148 
00149   NS_IMETHOD DrawStringInternal(const char *aString, PRUint32 aLength,
00150                                 nscoord aX, nscoord aY,
00151                                 const nscoord* aSpacing);
00152   NS_IMETHOD DrawStringInternal(const PRUnichar *aString, PRUint32 aLength,
00153                                 nscoord aX, nscoord aY,
00154                                 PRInt32 aFontID,
00155                                 const nscoord* aSpacing);
00156 
00157   NS_IMETHOD GetTextDimensionsInternal(const char* aString, PRUint32 aLength,
00158                                        nsTextDimensions& aDimensions);
00159   NS_IMETHOD GetTextDimensionsInternal(const PRUnichar *aString, PRUint32 aLength,
00160                                        nsTextDimensions& aDimensions,PRInt32 *aFontID);
00161 
00162 #ifdef MOZ_MATHML
00163 
00166   NS_IMETHOD GetBoundingMetricsInternal(const char*        aString,
00167                                         PRUint32           aLength,
00168                                         nsBoundingMetrics& aBoundingMetrics);
00169 
00173   NS_IMETHOD GetBoundingMetricsInternal(const PRUnichar*   aString,
00174                                         PRUint32           aLength,
00175                                         nsBoundingMetrics& aBoundingMetrics,
00176                                         PRInt32*           aFontID = nsnull);
00177 
00178 #endif /* MOZ_MATHML */
00179 
00180   virtual PRInt32 GetMaxStringLength();
00181                                  
00182   NS_IMETHOD CopyOffScreenBits(nsIDrawingSurface* aSrcSurf, PRInt32 aSrcX, PRInt32 aSrcY,
00183                                const nsRect &aDestBounds, PRUint32 aCopyFlags);
00184   NS_IMETHOD RetrieveCurrentNativeGraphicData(void** ngd);
00185 
00186   // nsRenderingContextImpl overrides
00187   NS_IMETHOD ReleaseBackbuffer(void);
00188   NS_IMETHOD UseBackbuffer(PRBool* aUseBackbuffer);
00189 
00190 
00195   NS_IMETHOD SetRightToLeftText(PRBool aIsRTL);
00196   NS_IMETHOD GetRightToLeftText(PRBool* aIsRTL);
00197 
00198   NS_IMETHOD DrawImage(imgIContainer *aImage, const nsRect & aSrcRect, const nsRect & aDestRect);
00199   NS_IMETHOD DrawTile(imgIContainer *aImage,
00200                       nscoord aXImageStart, nscoord aYImageStart,
00201                       const nsRect * aTargetRect);
00202 
00203   //locals
00204   nsresult   SetPortTextState();
00205   nsresult   Init(nsIDeviceContext* aContext, CGrafPtr aPort);
00206 
00207   // for determining if we're running on at least Mac OS X 10.4.0 
00208   static PRBool OnTigerOrLater();
00209 
00210 protected:
00211   enum GraphicStateChanges {
00212               kFontChanged  = (1 << 0),
00213               kColorChanged = (1 << 1),
00214               kClippingChanged = (1 << 2),
00215               
00216               kEverythingChanged = 0xFFFFFFFF
00217        };
00218 
00219        void                 SelectDrawingSurface(nsDrawingSurfaceMac* aSurface, PRUint32 aChanges = kEverythingChanged);
00220   void      SetupPortState();
00221 
00222 protected:
00223     float                   mP2T;               // Pixel to Twip conversion factor
00224     nsIDeviceContext *      mContext;
00225 
00226     nsDrawingSurfaceMac*    mFrontSurface;
00227     nsDrawingSurfaceMac*    mCurrentSurface;    // pointer to the current surface
00228 
00229     CGrafPtr                mPort;              // current grafPort - shortcut for mCurrentSurface->GetPort()
00230     nsGraphicState *        mGS;                // current graphic state - shortcut for mCurrentSurface->GetGS()
00231     nsUnicodeRenderingToolkit mUnicodeRenderingToolkit;
00232     nsAutoVoidArray         mGSStack;           // GraphicStates stack, used for PushState/PopState
00233     PRUint32                mChanges;           // bit mask of attributes that have changed since last Push().
00234     PRBool                  mRightToLeftText;
00235 };
00236 
00237 #endif /* nsRenderingContextMac_h___ */