Back to index

lightning-sunbird  0.9+nobinonly
nsRenderingContextPS.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  *   Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef nsRenderingContextPS_h___
00040 #define nsRenderingContextPS_h___
00041 
00042 #include "nsIRenderingContext.h"
00043 #include "nsRenderingContextImpl.h"
00044 #include "nsUnitConversion.h"
00045 #include "nsFont.h"
00046 #include "nsFontMetricsPS.h"
00047 #include "nsPoint.h"
00048 #include "nsString.h"
00049 #include "nsCRT.h"
00050 #include "nsTransform2D.h"
00051 #include "nsIViewManager.h"
00052 #include "nsIWidget.h"
00053 #include "nsRect.h"
00054 #include "nsDeviceContextPS.h"
00055 #include "nsVoidArray.h"
00056 
00057 class nsPostScriptObj;
00058 class PS_State;
00059 
00060 class nsRenderingContextPS :  public nsRenderingContextImpl
00061 {
00062 public:
00063   nsRenderingContextPS();
00064   virtual ~nsRenderingContextPS();
00065 
00066   NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
00067 
00068   NS_DECL_ISUPPORTS
00069 
00070 public:
00071   // nsIRenderingContext
00072   NS_IMETHOD Init(nsIDeviceContext* aContext);
00073   NS_IMETHOD Init(nsIDeviceContext* aContext, nsIWidget *aWidget) {return NS_ERROR_NOT_IMPLEMENTED;}
00074   NS_IMETHOD Init(nsIDeviceContext* aContext, nsIDrawingSurface* aSurface) {return NS_ERROR_NOT_IMPLEMENTED;}
00075 
00076   NS_IMETHOD Reset(void);
00077 
00078   NS_IMETHOD GetDeviceContext(nsIDeviceContext *&aContext);
00079 
00080   NS_IMETHOD LockDrawingSurface(PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight,
00081                                 void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes,
00082                                 PRUint32 aFlags);
00083   NS_IMETHOD UnlockDrawingSurface(void);
00084 
00085   NS_IMETHOD SelectOffScreenDrawingSurface(nsIDrawingSurface* aSurface);
00086   NS_IMETHOD GetDrawingSurface(nsIDrawingSurface* *aSurface);
00087   NS_IMETHOD GetHints(PRUint32& aResult);
00088 
00089   NS_IMETHOD PushState(void);
00090   NS_IMETHOD PopState(void);
00091 
00092   NS_IMETHOD IsVisibleRect(const nsRect& aRect, PRBool &aClipState);
00093 
00094   NS_IMETHOD SetClipRect(const nsRect& aRect, nsClipCombine aCombine);
00095   NS_IMETHOD GetClipRect(nsRect &aRect, PRBool &aClipState);
00096   NS_IMETHOD SetClipRegion(const nsIRegion& aRegion, nsClipCombine aCombine);
00097   NS_IMETHOD CopyClipRegion(nsIRegion &aRegion);
00098   NS_IMETHOD GetClipRegion(nsIRegion **aRegion);
00099 
00100   NS_IMETHOD SetLineStyle(nsLineStyle aLineStyle);
00101   NS_IMETHOD GetLineStyle(nsLineStyle &aLineStyle);
00102 
00103   NS_IMETHOD SetColor(nscolor aColor);
00104   NS_IMETHOD GetColor(nscolor &aColor) const;
00105 
00106   NS_IMETHOD SetFont(const nsFont& aFont, nsIAtom* aLangGroup);
00107   NS_IMETHOD SetFont(nsIFontMetrics *aFontMetrics);
00108 
00109   NS_IMETHOD GetFontMetrics(nsIFontMetrics *&aFontMetrics);
00110 
00111   NS_IMETHOD Translate(nscoord aX, nscoord aY);
00112   NS_IMETHOD Scale(float aSx, float aSy);
00113   NS_IMETHOD GetCurrentTransform(nsTransform2D *&aTransform);
00114 
00115   NS_IMETHOD CreateDrawingSurface(const nsRect& aBounds, PRUint32 aSurfFlags, nsIDrawingSurface* &aSurface);
00116   NS_IMETHOD DestroyDrawingSurface(nsIDrawingSurface* aDS);
00117 
00118   NS_IMETHOD DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1);
00119   NS_IMETHOD DrawPolyline(const nsPoint aPoints[], PRInt32 aNumPoints);
00120 
00121   NS_IMETHOD DrawRect(const nsRect& aRect);
00122   NS_IMETHOD DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00123 
00124   NS_IMETHOD FillRect(const nsRect& aRect);
00125   NS_IMETHOD FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00126 
00127   NS_IMETHOD InvertRect(const nsRect& aRect);
00128   NS_IMETHOD InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00129 
00130   NS_IMETHOD DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
00131   NS_IMETHOD FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
00132 
00133   NS_IMETHOD DrawEllipse(const nsRect& aRect);
00134   NS_IMETHOD DrawEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00135   NS_IMETHOD FillEllipse(const nsRect& aRect);
00136   NS_IMETHOD FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00137 
00138   NS_IMETHOD DrawArc(const nsRect& aRect,
00139                      float aStartAngle, float aEndAngle);
00140   NS_IMETHOD DrawArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
00141                      float aStartAngle, float aEndAngle);
00142   NS_IMETHOD FillArc(const nsRect& aRect,
00143                      float aStartAngle, float aEndAngle);
00144   NS_IMETHOD FillArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
00145                      float aStartAngle, float aEndAngle);
00146 
00147   NS_IMETHOD GetWidth(char aC, nscoord& aWidth);
00148   NS_IMETHOD GetWidth(PRUnichar aC, nscoord& aWidth,
00149                       PRInt32 *aFontID);
00150   NS_IMETHOD GetWidth(const nsString& aString, nscoord& aWidth,
00151                       PRInt32 *aFontID);
00152   NS_IMETHOD GetWidth(const char* aString, nscoord& aWidth);
00153   NS_IMETHOD GetWidth(const char* aString, PRUint32 aLength, nscoord& aWidth);
00154   NS_IMETHOD GetWidth(const PRUnichar* aString, PRUint32 aLength,
00155                       nscoord& aWidth, PRInt32 *aFontID);
00156 
00157   NS_IMETHOD DrawString(const char *aString, PRUint32 aLength,
00158                         nscoord aX, nscoord aY,
00159                         const nscoord* aSpacing);
00160   NS_IMETHOD DrawString(const PRUnichar *aString, PRUint32 aLength,
00161                         nscoord aX, nscoord aY,
00162                         PRInt32 aFontID,
00163                         const nscoord* aSpacing);
00164   NS_IMETHOD DrawString(const nsString& aString, nscoord aX, nscoord aY,
00165                         PRInt32 aFontID,
00166                         const nscoord* aSpacing);
00167 protected:
00168   PRInt32 DrawString(const PRUnichar *aString, PRUint32 aLength,
00169                         nscoord aX, nscoord aY, nsFontPS* aFontPS,
00170                         const nscoord* aSpacing);
00171   PRInt32 DrawString(const char *aString, PRUint32 aLength,
00172                         nscoord &aX, nscoord &aY, nsFontPS* aFontPS,
00173                         const nscoord* aSpacing);
00174 public:
00175 
00176   NS_IMETHOD GetTextDimensions(const char* aString, PRUint32 aLength,
00177                                nsTextDimensions& aDimensions);
00178   NS_IMETHOD GetTextDimensions(const PRUnichar *aString, PRUint32 aLength,
00179                                nsTextDimensions& aDimensions, PRInt32 *aFontID);
00180   NS_IMETHOD GetTextDimensions(const char*       aString,
00181                                PRInt32           aLength,
00182                                PRInt32           aAvailWidth,
00183                                PRInt32*          aBreaks,
00184                                PRInt32           aNumBreaks,
00185                                nsTextDimensions& aDimensions,
00186                                PRInt32&          aNumCharsFit,
00187                                nsTextDimensions& aLastWordDimensions,
00188                                PRInt32*          aFontID = nsnull);
00189   NS_IMETHOD GetTextDimensions(const PRUnichar*  aString,
00190                                PRInt32           aLength,
00191                                PRInt32           aAvailWidth,
00192                                PRInt32*          aBreaks,
00193                                PRInt32           aNumBreaks,
00194                                nsTextDimensions& aDimensions,
00195                                PRInt32&          aNumCharsFit,
00196                                nsTextDimensions& aLastWordDimensions,
00197                                PRInt32*          aFontID = nsnull);
00198 
00208   NS_IMETHOD DrawImage(imgIContainer *aImage,
00209     const nsRect & aSrcRect, const nsRect & aDestRect);
00210 
00211   /*
00212    *    Tiles an image over an area
00213    *    @param aImage Image to tile
00214    *    @param aXImageStart x location where the origin (0,0) of the image starts
00215    *    @param aYImageStart y location where the origin (0,0) of the image starts
00216    *    @param aTargetRect  area to draw to
00217    *
00218    */
00219   NS_IMETHOD DrawTile(imgIContainer *aImage,
00220     nscoord aXImageStart, nscoord aYImageStart, const nsRect *aTargetRect);
00221 
00222   NS_IMETHOD CopyOffScreenBits(nsIDrawingSurface* aSrcSurf, PRInt32 aSrcX, PRInt32 aSrcY,
00223                                const nsRect &aDestBounds, PRUint32 aCopyFlags);
00224   NS_IMETHOD RetrieveCurrentNativeGraphicData(void** ngd);
00225 
00226   // Postscript utilities
00231   void PostscriptFont(nscoord aHeight, PRUint8 aStyle, 
00232                        PRUint8 aVariant, PRUint16 aWeight, PRUint8 decorations);
00233 
00234   inline nsPostScriptObj* GetPostScriptObj() { return mPSObj; };
00235 
00236 #ifdef XP_WIN
00237 // this define is here only so the postscript can be compiled
00238 // and tested on the windows platform. 
00239   NS_IMETHOD GetWidth(const char *aString,
00240                       PRInt32     aLength,
00241                       PRInt32     aAvailWidth,
00242                       PRInt32*    aBreaks,
00243                       PRInt32     aNumBreaks,
00244                       nscoord&    aWidth,
00245                       PRInt32&    aNumCharsFit,
00246                       PRInt32*    aFontID = nsnull) {return NS_OK;}
00247 
00248   NS_IMETHOD GetWidth(const PRUnichar *aString,
00249                       PRInt32          aLength,
00250                       PRInt32          aAvailWidth,
00251                       PRInt32*         aBreaks,
00252                       PRInt32          aNumBreaks,
00253                       nscoord&         aWidth,
00254                       PRInt32&         aNumCharsFit,
00255                       PRInt32*         aFontID = nsnull) {return NS_OK;}
00256 
00257 #endif
00258 
00259 
00260 #ifdef MOZ_MATHML
00261 
00264   NS_IMETHOD GetBoundingMetrics(const char*        aString,
00265                                 PRUint32           aLength,
00266                                 nsBoundingMetrics& aBoundingMetrics);
00267   
00271   NS_IMETHOD GetBoundingMetrics(const PRUnichar*   aString,
00272                                 PRUint32           aLength,
00273                                 nsBoundingMetrics& aBoundingMetrics,
00274                                 PRInt32*           aFontID = nsnull);
00275 #endif /* MOZ_MATHML */
00276 
00285   NS_IMETHOD RenderEPS(const nsRect& aRect, FILE *aDataFile);
00286 
00287 private:
00288   nsresult CommonInit(void);
00289   void PushClipState(void);
00290 
00291 protected:
00292   nsCOMPtr<nsIDeviceContext> mContext;
00293   nsCOMPtr<nsIFontMetrics>   mFontMetrics;
00294   nsLineStyle          mCurrLineStyle;
00295   PS_State            *mStates;
00296   nsVoidArray         *mStateCache;
00297   float               mP2T;
00298   nscolor             mCurrentColor;
00299 
00300   //state management
00301   PRUint8             *mGammaTable;
00302   nsPostScriptObj     *mPSObj;
00303 };
00304 
00305 
00306 #endif /* !nsRenderingContextPS_h___ */