Back to index

lightning-sunbird  0.9+nobinonly
nsRenderingContextImpl.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 nsRenderingContextImpl_h___
00039 #define nsRenderingContextImpl_h___
00040 
00041 #include "gfxCore.h"
00042 #include "nsIRenderingContext.h"
00043 #include "nsPoint.h"
00044 #include "nsSize.h"
00045 
00046 
00047 typedef struct {     
00048     double x;   // x coordinate of edge's intersection with current scanline */
00049     double dx;       // change in x with respect to y 
00050     int i;        // edge number: edge i goes from mPointList[i] to mPointList[i+1] 
00051 } Edge;
00052 
00053 #undef  IMETHOD_VISIBILITY
00054 #define IMETHOD_VISIBILITY NS_VISIBILITY_DEFAULT
00055 
00056 class nsRenderingContextImpl : public nsIRenderingContext
00057 {
00058 
00059 // CLASS MEMBERS
00060 public:
00061 
00062 
00063 protected:
00064   nsTransform2D               *mTranMatrix;                           // The rendering contexts transformation matrix
00065   int               mAct;                               // number of active edges 
00066   Edge              *mActive;                    // active edge list:edges crossing scanline y
00067 
00068 public:
00069   nsRenderingContextImpl();
00070 
00071 
00072 // CLASS METHODS
00073 
00074   // See the description in nsIRenderingContext.h
00075   NS_IMETHOD FlushRect(const nsRect& aRect);
00076   NS_IMETHOD FlushRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00077 
00083   NS_IMETHOD GetPenMode(nsPenMode &aPenMode) { return NS_ERROR_FAILURE;}
00084 
00090   NS_IMETHOD SetPenMode(nsPenMode aPenMode) { return NS_ERROR_FAILURE;};
00091 
00092   NS_IMETHOD GetBackbuffer(const nsRect &aRequestedSize, const nsRect &aMaxSize, PRBool aForBlending, nsIDrawingSurface* &aBackbuffer); 
00093   NS_IMETHOD ReleaseBackbuffer(void);
00094   NS_IMETHOD DestroyCachedBackbuffer(void);
00095   NS_IMETHOD UseBackbuffer(PRBool* aUseBackbuffer);
00096   
00097   NS_IMETHOD PushTranslation(PushedTranslation* aState);
00098   NS_IMETHOD PopTranslation(PushedTranslation* aState);
00099 
00106   virtual PRInt32 GetMaxStringLength() { return 1; }
00107 
00112   NS_IMETHOD SetRightToLeftText(PRBool aIsRTL);
00113   NS_IMETHOD GetRightToLeftText(PRBool* aIsRTL);
00114 
00115   NS_IMETHOD DrawImage(imgIContainer *aImage, const nsRect & aSrcRect, const nsRect & aDestRect);
00116   NS_IMETHOD DrawTile(imgIContainer *aImage, nscoord aXOffset, nscoord aYOffset, const nsRect * aTargetRect);
00117 
00118   NS_IMETHOD GetClusterInfo(const PRUnichar *aText,
00119                             PRUint32 aLength,
00120                             PRUint8 *aClusterStarts);
00121   virtual PRInt32 GetPosition(const PRUnichar *aText,
00122                               PRUint32 aLength,
00123                               nsPoint aPt);
00124   NS_IMETHOD GetRangeWidth(const PRUnichar *aText,
00125                            PRUint32 aLength,
00126                            PRUint32 aStart,
00127                            PRUint32 aEnd,
00128                            PRUint32 &aWidth);
00129   NS_IMETHOD GetRangeWidth(const char *aText,
00130                            PRUint32 aLength,
00131                            PRUint32 aStart,
00132                            PRUint32 aEnd,
00133                            PRUint32 &aWidth);
00134 
00135   // Silence C++ hiding warnings
00136   NS_IMETHOD GetWidth(char aC, nscoord &aWidth) = 0;
00137   NS_IMETHOD GetWidth(PRUnichar aC, nscoord &aWidth,
00138                       PRInt32 *aFontID = nsnull) = 0;
00139 
00140   // Safe string method variants: by default, these defer to the more
00141   // elaborate methods below
00142   NS_IMETHOD GetWidth(const nsString& aString, nscoord &aWidth,
00143                       PRInt32 *aFontID = nsnull);
00144   NS_IMETHOD GetWidth(const char* aString, nscoord& aWidth);
00145   NS_IMETHOD DrawString(const nsString& aString, nscoord aX, nscoord aY,
00146                         PRInt32 aFontID = -1,
00147                         const nscoord* aSpacing = nsnull);
00148 
00149   // Safe string methods
00150   NS_IMETHOD GetWidth(const char* aString, PRUint32 aLength,
00151                       nscoord& aWidth);
00152   NS_IMETHOD GetWidth(const PRUnichar *aString, PRUint32 aLength,
00153                       nscoord &aWidth, PRInt32 *aFontID = nsnull);
00154 
00155   NS_IMETHOD GetTextDimensions(const char* aString, PRUint32 aLength,
00156                                nsTextDimensions& aDimensions);
00157   NS_IMETHOD GetTextDimensions(const PRUnichar* aString, PRUint32 aLength,
00158                                nsTextDimensions& aDimensions, PRInt32* aFontID = nsnull);
00159 
00160 #if defined(_WIN32) || defined(XP_OS2) || defined(MOZ_X11) || defined(XP_BEOS)
00161   NS_IMETHOD GetTextDimensions(const char*       aString,
00162                                PRInt32           aLength,
00163                                PRInt32           aAvailWidth,
00164                                PRInt32*          aBreaks,
00165                                PRInt32           aNumBreaks,
00166                                nsTextDimensions& aDimensions,
00167                                PRInt32&          aNumCharsFit,
00168                                nsTextDimensions& aLastWordDimensions,
00169                                PRInt32*          aFontID = nsnull);
00170 
00171   NS_IMETHOD GetTextDimensions(const PRUnichar*  aString,
00172                                PRInt32           aLength,
00173                                PRInt32           aAvailWidth,
00174                                PRInt32*          aBreaks,
00175                                PRInt32           aNumBreaks,
00176                                nsTextDimensions& aDimensions,
00177                                PRInt32&          aNumCharsFit,
00178                                nsTextDimensions& aLastWordDimensions,
00179                                PRInt32*          aFontID = nsnull);
00180 #endif
00181 #ifdef MOZ_MATHML
00182   NS_IMETHOD
00183   GetBoundingMetrics(const char*        aString,
00184                      PRUint32           aLength,
00185                      nsBoundingMetrics& aBoundingMetrics);
00186   NS_IMETHOD
00187   GetBoundingMetrics(const PRUnichar*   aString,
00188                      PRUint32           aLength,
00189                      nsBoundingMetrics& aBoundingMetrics,
00190                      PRInt32*           aFontID = nsnull);
00191 #endif
00192   NS_IMETHOD DrawString(const char *aString, PRUint32 aLength,
00193                         nscoord aX, nscoord aY,
00194                         const nscoord* aSpacing = nsnull);
00195   NS_IMETHOD DrawString(const PRUnichar *aString, PRUint32 aLength,
00196                         nscoord aX, nscoord aY,
00197                         PRInt32 aFontID = -1,
00198                         const nscoord* aSpacing = nsnull);
00199 
00200   // Unsafe platform-specific implementations
00201   NS_IMETHOD GetWidthInternal(const char* aString, PRUint32 aLength,
00202                               nscoord& aWidth)
00203   { return NS_ERROR_NOT_IMPLEMENTED; }
00204   NS_IMETHOD GetWidthInternal(const PRUnichar *aString, PRUint32 aLength,
00205                               nscoord &aWidth, PRInt32 *aFontID = nsnull)
00206   { return NS_ERROR_NOT_IMPLEMENTED; }
00207   NS_IMETHOD GetTextDimensionsInternal(const char* aString, PRUint32 aLength,
00208                                        nsTextDimensions& aDimensions)
00209   { return NS_ERROR_NOT_IMPLEMENTED; }
00210   NS_IMETHOD GetTextDimensionsInternal(const PRUnichar* aString, PRUint32 aLength,
00211                                        nsTextDimensions& aDimensions, PRInt32* aFontID = nsnull)
00212   { return NS_ERROR_NOT_IMPLEMENTED; }
00213 
00214 #if defined(_WIN32) || defined(XP_OS2) || defined(MOZ_X11) || defined(XP_BEOS)
00215   NS_IMETHOD GetTextDimensionsInternal(const char*       aString,
00216                                        PRInt32           aLength,
00217                                        PRInt32           aAvailWidth,
00218                                        PRInt32*          aBreaks,
00219                                        PRInt32           aNumBreaks,
00220                                        nsTextDimensions& aDimensions,
00221                                        PRInt32&          aNumCharsFit,
00222                                        nsTextDimensions& aLastWordDimensions,
00223                                        PRInt32*          aFontID = nsnull)
00224   { return NS_ERROR_NOT_IMPLEMENTED; }
00225 
00226   NS_IMETHOD GetTextDimensionsInternal(const PRUnichar*  aString,
00227                                        PRInt32           aLength,
00228                                        PRInt32           aAvailWidth,
00229                                        PRInt32*          aBreaks,
00230                                        PRInt32           aNumBreaks,
00231                                        nsTextDimensions& aDimensions,
00232                                        PRInt32&          aNumCharsFit,
00233                                        nsTextDimensions& aLastWordDimensions,
00234                                        PRInt32*          aFontID = nsnull)
00235   { return NS_ERROR_NOT_IMPLEMENTED; }
00236 #endif
00237 #ifdef MOZ_MATHML
00238   NS_IMETHOD
00239   GetBoundingMetricsInternal(const char*        aString,
00240                              PRUint32           aLength,
00241                              nsBoundingMetrics& aBoundingMetrics)
00242   { return NS_ERROR_NOT_IMPLEMENTED; }
00243   NS_IMETHOD
00244   GetBoundingMetricsInternal(const PRUnichar*   aString,
00245                              PRUint32           aLength,
00246                              nsBoundingMetrics& aBoundingMetrics,
00247                              PRInt32*           aFontID = nsnull)
00248   { return NS_ERROR_NOT_IMPLEMENTED; }
00249 #endif
00250   NS_IMETHOD DrawStringInternal(const char *aString, PRUint32 aLength,
00251                                 nscoord aX, nscoord aY,
00252                                 const nscoord* aSpacing = nsnull)
00253   { return NS_ERROR_NOT_IMPLEMENTED; }
00254   NS_IMETHOD DrawStringInternal(const PRUnichar *aString, PRUint32 aLength,
00255                                 nscoord aX, nscoord aY,
00256                                 PRInt32 aFontID = -1,
00257                                 const nscoord* aSpacing = nsnull)
00258   { return NS_ERROR_NOT_IMPLEMENTED; }
00259 
00260   NS_IMETHOD RenderEPS(const nsRect& aRect, FILE *aDataFile);
00261 
00262 protected:
00263   virtual ~nsRenderingContextImpl();
00264 
00274   PRBool RectFitsInside(const nsRect& aRect, PRInt32 aWidth, PRInt32 aHeight) const;
00275 
00285   PRBool BothRectsFitInside(const nsRect& aRect1, const nsRect& aRect2, PRInt32 aWidth, PRInt32 aHeight, nsRect& aNewSize) const;
00286 
00296   void CalculateDiscreteSurfaceSize(const nsRect& aMaxBackbufferSize, const nsRect& aRequestedSize, nsRect& aSize);
00297 
00305   void GetDrawingSurfaceSize(const nsRect& aMaxBackbufferSize, const nsRect& aRequestedSize, nsRect& aSurfaceSize);
00306 
00316   nsresult AllocateBackbuffer(const nsRect &aRequestedSize, const nsRect &aMaxSize, nsIDrawingSurface* &aBackbuffer, PRBool aCacheBackbuffer, PRUint32 aSurfFlags);
00317 
00318 public:
00319 
00320 protected:
00321   nsPenMode   mPenMode;
00322 private:
00323   static nsIDrawingSurface*  gBackbuffer;         //singleton backbuffer 
00324   static nsRect            gBackbufferBounds;   //backbuffer bounds
00325     // Largest requested offscreen size if larger than a full screen.
00326   static nsSize            gLargestRequestedSize;
00327 
00328 };
00329 
00330 #undef  IMETHOD_VISIBILITY
00331 #define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN
00332 
00333 #endif /* nsRenderingContextImpl */