Back to index

lightning-sunbird  0.9+nobinonly
nsRenderingContextOS2.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the Mozilla OS/2 libraries.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * John Fairhurst, <john_fairhurst@iname.com>.
00018  * Portions created by the Initial Developer are Copyright (C) 1999
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Henry Sobotka <sobotka@axess.com>
00023  *   Pierre Phaneuf <pp@ludusdesign.com>
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  * This Original Code has been modified by IBM Corporation. Modifications made by IBM 
00040  * described herein are Copyright (c) International Business Machines Corporation, 2000.
00041  * Modifications to Mozilla code or documentation identified per MPL Section 3.3
00042  *
00043  * Date             Modified by     Description of modification
00044  * 05/11/2000     IBM Corp.       Make more like Windows.
00045  */
00046 
00047 #ifndef _nsRenderingContextOS2_h
00048 #define _nsRenderingContextOS2_h
00049 
00050 #include "nsIRenderingContext.h"
00051 #include "nsUnitConversion.h"
00052 #include "nsFont.h"
00053 #include "nsIFontMetrics.h"
00054 #include "nsPoint.h"
00055 #include "nsString.h"
00056 #include "nsCRT.h"
00057 #include "nsTransform2D.h"
00058 #include "nsIWidget.h"
00059 #include "nsRect.h"
00060 #include "nscoord.h"
00061 #include "nsImageOS2.h"
00062 #include "nsIDeviceContext.h"
00063 #include "nsVoidArray.h"
00064 #include "nsIRenderingContextOS2.h"
00065 #include "nsDrawingSurfaceOS2.h"
00066 #include "nsRenderingContextImpl.h"
00067 
00068 class GraphicsState;
00069 class nsDrawingSurfaceOS2;
00070 class nsFontOS2;
00071 
00072 class nsRenderingContextOS2 : public nsRenderingContextImpl,
00073                               nsIRenderingContextOS2
00074 {
00075 public:
00076   nsRenderingContextOS2();
00077 
00078   NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
00079 
00080   NS_DECL_ISUPPORTS
00081 
00082   NS_IMETHOD Init(nsIDeviceContext* aContext, nsIWidget *aWindow);
00083   NS_IMETHOD Init(nsIDeviceContext* aContext, nsIDrawingSurface* aSurface);
00084 
00085   NS_IMETHOD Reset(void);
00086 
00087   NS_IMETHOD GetDeviceContext(nsIDeviceContext *&aContext);
00088 
00089   NS_IMETHOD LockDrawingSurface(PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight,
00090                                 void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes,
00091                                 PRUint32 aFlags);
00092   NS_IMETHOD UnlockDrawingSurface(void);
00093 
00094   NS_IMETHOD SelectOffScreenDrawingSurface(nsIDrawingSurface* aSurface);
00095   NS_IMETHOD GetDrawingSurface(nsIDrawingSurface* *aSurface);
00096   NS_IMETHOD GetHints(PRUint32& aResult);
00097 
00098   NS_IMETHOD PushState(void);
00099   NS_IMETHOD PopState(void);
00100 
00101   NS_IMETHOD IsVisibleRect(const nsRect& aRect, PRBool &aClipState);
00102 
00103   NS_IMETHOD SetClipRect(const nsRect& aRect, nsClipCombine aCombine);
00104   NS_IMETHOD GetClipRect(nsRect &aRect, PRBool &aClipState);
00105   NS_IMETHOD SetClipRegion(const nsIRegion& aRegion, nsClipCombine aCombine);
00106   NS_IMETHOD CopyClipRegion(nsIRegion &aRegion);
00107   NS_IMETHOD GetClipRegion(nsIRegion **aRegion);
00108 
00109   NS_IMETHOD SetLineStyle(nsLineStyle aLineStyle);
00110   NS_IMETHOD GetLineStyle(nsLineStyle &aLineStyle);
00111 
00112   NS_IMETHOD SetColor(nscolor aColor);
00113   NS_IMETHOD GetColor(nscolor &aColor) const;
00114 
00115   NS_IMETHOD SetFont(const nsFont& aFont, nsIAtom* aLangGroup);
00116   NS_IMETHOD SetFont(nsIFontMetrics *aFontMetrics);
00117 
00118   NS_IMETHOD GetFontMetrics(nsIFontMetrics *&aFontMetrics);
00119 
00120   NS_IMETHOD Translate(nscoord aX, nscoord aY);
00121   NS_IMETHOD Scale(float aSx, float aSy);
00122   NS_IMETHOD GetCurrentTransform(nsTransform2D *&aTransform);
00123 
00124   NS_IMETHOD CreateDrawingSurface(const nsRect& aBounds, PRUint32 aSurfFlags, nsIDrawingSurface* &aSurface);
00125   NS_IMETHOD DestroyDrawingSurface(nsIDrawingSurface* aDS);
00126 
00127   NS_IMETHOD DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1);
00128   NS_IMETHOD DrawPolyline(const nsPoint aPoints[], PRInt32 aNumPoints);
00129 
00130   NS_IMETHOD DrawRect(const nsRect& aRect);
00131   NS_IMETHOD DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00132 
00133   NS_IMETHOD FillRect(const nsRect& aRect);
00134   NS_IMETHOD FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00135 
00136   NS_IMETHOD InvertRect(const nsRect& aRect);
00137   NS_IMETHOD InvertRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00138 
00139   NS_IMETHOD DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
00140   NS_IMETHOD FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
00141 
00142   NS_IMETHOD DrawEllipse(const nsRect& aRect);
00143   NS_IMETHOD DrawEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00144   NS_IMETHOD FillEllipse(const nsRect& aRect);
00145   NS_IMETHOD FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
00146 
00147   NS_IMETHOD DrawArc(const nsRect& aRect,
00148                      float aStartAngle, float aEndAngle);
00149   NS_IMETHOD DrawArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
00150                      float aStartAngle, float aEndAngle);
00151   NS_IMETHOD FillArc(const nsRect& aRect,
00152                      float aStartAngle, float aEndAngle);
00153   NS_IMETHOD FillArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
00154                      float aStartAngle, float aEndAngle);
00155 
00156   NS_IMETHOD GetWidth(char aC, nscoord& aWidth);
00157   NS_IMETHOD GetWidth(PRUnichar aC, nscoord& aWidth,
00158                       PRInt32 *aFontID);
00159   NS_IMETHOD GetWidth(const nsString& aString, nscoord& aWidth,
00160                       PRInt32 *aFontID);
00161   NS_IMETHOD GetWidth(const char* aString, nscoord& aWidth);
00162   NS_IMETHOD GetWidth(const char* aString, PRUint32 aLength, nscoord& aWidth);
00163   NS_IMETHOD GetWidth(const PRUnichar* aString, PRUint32 aLength,
00164                       nscoord& aWidth, PRInt32 *aFontID);
00165 
00166   NS_IMETHOD GetTextDimensions(const char* aString, PRUint32 aLength,
00167                                nsTextDimensions& aDimensions);
00168   NS_IMETHOD GetTextDimensions(const PRUnichar *aString, PRUint32 aLength,
00169                                nsTextDimensions& aDimensions, PRInt32 *aFontID);
00170   NS_IMETHOD GetTextDimensions(const char*       aString,
00171                                PRInt32           aLength,
00172                                PRInt32           aAvailWidth,
00173                                PRInt32*          aBreaks,
00174                                PRInt32           aNumBreaks,
00175                                nsTextDimensions& aDimensions,
00176                                PRInt32&          aNumCharsFit,
00177                                nsTextDimensions& aLastWordDimensions,
00178                                PRInt32*          aFontID = nsnull);
00179   NS_IMETHOD GetTextDimensions(const PRUnichar*  aString,
00180                                PRInt32           aLength,
00181                                PRInt32           aAvailWidth,
00182                                PRInt32*          aBreaks,
00183                                PRInt32           aNumBreaks,
00184                                nsTextDimensions& aDimensions,
00185                                PRInt32&          aNumCharsFit,
00186                                nsTextDimensions& aLastWordDimensions,
00187                                PRInt32*          aFontID = nsnull);
00188 
00189   NS_IMETHOD DrawString(const char *aString, PRUint32 aLength,
00190                         nscoord aX, nscoord aY,
00191                         const nscoord* aSpacing);
00192   NS_IMETHOD DrawString(const PRUnichar *aString, PRUint32 aLength,
00193                         nscoord aX, nscoord aY,
00194                         PRInt32 aFontID,
00195                         const nscoord* aSpacing);
00196   NS_IMETHOD DrawString(const nsString& aString, nscoord aX, nscoord aY,
00197                         PRInt32 aFontID,
00198                         const nscoord* aSpacing);
00199 
00200   NS_IMETHOD CopyOffScreenBits(nsIDrawingSurface* aSrcSurf, PRInt32 aSrcX, PRInt32 aSrcY,
00201                                const nsRect &aDestBounds, PRUint32 aCopyFlags);
00202   //~~~
00203   NS_IMETHOD RetrieveCurrentNativeGraphicData(void** ngd);
00204 
00205   NS_IMETHOD CreateDrawingSurface(HPS aPS, nsIDrawingSurface* &aSurface, nsIWidget *aWidget);
00206 
00207 #ifdef MOZ_MATHML
00208   NS_IMETHOD
00209   GetBoundingMetrics(const char*        aString,
00210                      PRUint32           aLength,
00211                      nsBoundingMetrics& aBoundingMetrics);
00212 
00213   NS_IMETHOD
00214   GetBoundingMetrics(const PRUnichar*   aString,
00215                      PRUint32           aLength,
00216                      nsBoundingMetrics& aBoundingMetrics,
00217                      PRInt32*           aFontID);
00218 #endif
00219 
00220 private:
00221   // ConditionRect is used to fix coordinate overflow problems for
00222   // rectangles after they are transformed to screen coordinates
00223   NS_IMETHOD ConditionRect( nscoord &x, nscoord &y, nscoord &w, nscoord &h );
00224 
00225   nsresult CommonInit (void);
00226   nsresult SetupPS (void);
00227   LONG     GetGPIColor (void);
00228   void     PushClipState(void);
00229 
00230 
00231   // Colour/font setting; call before drawing things.
00232   void SetupLineColorAndStyle (void);
00233   void SetupFillColor (void);
00234   void SetupFontAndColor (void);
00235 
00236   // Primitive draw-ers
00237   void PMDrawRect( nsRect &rect, BOOL fill);
00238   void PMDrawPoly( const nsPoint aPoints[], PRInt32 aNumPoints, PRBool bFilled, PRBool bDoTransform = PR_TRUE);
00239   void PMDrawArc( nsRect &rect, PRBool bFilled, PRBool bFull, float start=0, float end=0);
00240 
00241 protected:
00242 
00243   ~nsRenderingContextOS2();
00244 
00245   nsIDeviceContext    *mContext;         // device context
00246   nsDrawingSurfaceOS2 *mSurface;         // draw things here
00247   nsDrawingSurfaceOS2 *mMainSurface;     // if offscreen selected, this is original one that was set on init time
00248   nscolor              mColor;           // current colour
00249   nsLineStyle          mLineStyle;       // current line style
00250   nsTransform2D        mTMatrix;         // current xform matrix
00251   float                mP2T;             // cache pix-2-app factor from DC
00252   GraphicsState       *mStates;
00253   nsVoidArray         *mStateCache;
00254   nsIFontMetrics      *mFontMetrics;     // current font
00255   nscolor              mCurrFillColor;   // currently selected fill color
00256   PRBool               mPreservedInitialClipRegion;
00257   PRBool               mPaletteMode;     // GPI colors are indexes into selected palette
00258   HPS                  mPS;              // GPI presentation space of current drawing surface
00259   nsIWidget           *mDCOwner;         // Parent widget
00260   nsFontOS2           *mCurrFontOS2;
00261 
00262   PRBool            mRightToLeftText;
00263 };
00264 
00265 
00266 #endif