1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is mozilla.org code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
25
* Alternatively, the contents of this file may be used under the terms of
26
* either the GNU General Public License Version 2 or later (the "GPL"), or
27
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
* in which case the provisions of the GPL or the LGPL are applicable instead
29
* of those above. If you wish to allow use of your version of this file only
30
* under the terms of either the GPL or the LGPL, and not to allow others to
31
* use your version of this file under the terms of the NPL, indicate your
32
* decision by deleting the provisions above and replace them with the notice
33
* and other provisions required by the GPL or the LGPL. If you do not delete
34
* the provisions above, a recipient may use your version of this file under
35
* the terms of any one of the NPL, the GPL or the LGPL.
37
* ***** END LICENSE BLOCK ***** */
39
#ifndef nsRenderingContextImpl_h___
40
#define nsRenderingContextImpl_h___
42
#include "nsComObsolete.h"
43
#include "nsIRenderingContext.h"
49
double x; // x coordinate of edge's intersection with current scanline */
50
double dx; // change in x with respect to y
51
int i; // edge number: edge i goes from mPointList[i] to mPointList[i+1]
54
#undef IMETHOD_VISIBILITY
55
#define IMETHOD_VISIBILITY NS_VISIBILITY_DEFAULT
57
class nsRenderingContextImpl : public nsIRenderingContext
65
nsTransform2D *mTranMatrix; // The rendering contexts transformation matrix
66
nsLineStyle mLineStyle; // The current linestyle, currenly used on mac, other platfroms to follow
67
int mAct; // number of active edges
68
Edge *mActive; // active edge list:edges crossing scanline y
71
nsRenderingContextImpl();
76
// See the description in nsIRenderingContext.h
77
NS_IMETHOD FlushRect(const nsRect& aRect);
78
NS_IMETHOD FlushRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
81
* Gets the Pen Mode for the RenderingContext
82
* @param aPenMode The Pen Mode to be retrieved
83
* @return NS_OK if the Pen Mode is correctly retrieved
85
NS_IMETHOD GetPenMode(nsPenMode &aPenMode) { return NS_ERROR_FAILURE;}
88
* Sets the Pen Mode for the RenderingContext
89
* @param aPenMode The Pen Mode
90
* @return NS_OK if the Pen Mode is correctly set
92
NS_IMETHOD SetPenMode(nsPenMode aPenMode) { return NS_ERROR_FAILURE;};
95
/** ---------------------------------------------------
96
* See documentation in nsIRenderingContext.h
97
* @update 03/29/00 dwc
99
NS_IMETHOD DrawPath(nsPathPoint aPointArray[],PRInt32 aNumPts);
101
/** ---------------------------------------------------
102
* See documentation in nsIRenderingContext.h
103
* @update 03/29/00 dwc
105
NS_IMETHOD FillPath(nsPathPoint aPointArray[],PRInt32 aNumPts);
108
* Fill a poly in the current foreground color
109
* @param aPoints points to use for the drawing, last must equal first
110
* @param aNumPonts number of points in the polygon
112
NS_IMETHOD RasterPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
114
/** ---------------------------------------------------
115
* See documentation in nsIRenderingContext.h
116
* @update 05/01/00 dwc
118
NS_IMETHOD DrawStdLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1) { return NS_OK;}
120
/** ---------------------------------------------------
121
* See documentation in nsIRenderingContext.h
122
* @update 05/01/00 dwc
124
NS_IMETHOD FillStdPolygon(const nsPoint aPoints[], PRInt32 aNumPoints) { return NS_OK; }
126
NS_IMETHOD GetBackbuffer(const nsRect &aRequestedSize, const nsRect &aMaxSize, nsDrawingSurface &aBackbuffer);
127
NS_IMETHOD ReleaseBackbuffer(void);
128
NS_IMETHOD DestroyCachedBackbuffer(void);
129
NS_IMETHOD UseBackbuffer(PRBool* aUseBackbuffer);
132
* Let the device context know whether we want text reordered with
133
* right-to-left base direction
135
NS_IMETHOD SetRightToLeftText(PRBool aIsRTL);
137
NS_IMETHOD DrawImage(imgIContainer *aImage, const nsRect * aSrcRect, const nsPoint * aDestPoint);
138
NS_IMETHOD DrawScaledImage(imgIContainer *aImage, const nsRect * aSrcRect, const nsRect * aDestRect);
139
NS_IMETHOD DrawTile(imgIContainer *aImage, nscoord aXOffset, nscoord aYOffset, const nsRect * aTargetRect);
142
virtual ~nsRenderingContextImpl();
145
void cinsert(int i,int y,const nsPoint aPointArray[],PRInt32 aNumPts);
148
* Determine if a rect's width and height will fit within a specified width and height
149
* @param aRect rectangle to test
150
* @param aWidth width to determine if the rectangle's width will fit within
151
* @param aHeight height to determine if the rectangles height will fit within
152
* @returns PR_TRUE if the rect width and height fits with aWidth, aHeight, PR_FALSE
156
PRBool RectFitsInside(const nsRect& aRect, PRInt32 aWidth, PRInt32 aHeight) const;
159
* Determine if two rectangles width and height will fit within a specified width and height
160
* @param aRect1 first rectangle to test
161
* @param aRect1 second rectangle to test
162
* @param aWidth width to determine if both rectangle's width will fit within
163
* @param aHeight height to determine if both rectangles height will fit within
164
* @returns PR_TRUE if the rect1's and rect2's width and height fits with aWidth,
165
* aHeight, PR_FALSE otherwise.
167
PRBool BothRectsFitInside(const nsRect& aRect1, const nsRect& aRect2, PRInt32 aWidth, PRInt32 aHeight, nsRect& aNewSize) const;
170
* Return an offscreen surface size from a set of discrete surface sizes.
171
* The smallest discrete surface size that can enclose both the Maximum widget
172
* size (@see GetMaxWidgetBounds) and the requested size is returned.
174
* @param aMaxBackbufferSize Maximum size that may be requested for the backbuffer
175
* @param aRequestedSize Requested size for the offscreen.
176
* @param aSurfaceSize contains the surface size
178
void CalculateDiscreteSurfaceSize(const nsRect& aMaxBackbufferSize, const nsRect& aRequestedSize, nsRect& aSize);
181
* Get the size of the offscreen drawing surface..
183
* @param aMaxBackbufferSize Maximum size that may be requested for the backbuffer
184
* @param aRequestedSize Desired size for the offscreen.
185
* @param aSurfaceSize Offscreen adjusted to a discrete size which encloses aRequestedSize.
187
void GetDrawingSurfaceSize(const nsRect& aMaxBackbufferSize, const nsRect& aRequestedSize, nsRect& aSurfaceSize);
190
* Utility method used to implement NS_IMETHOD GetBackbuffer
192
* @param aRequestedSize size of the backbuffer area requested
193
* @param aMaxSize maximum size that may be requested for the backbuffer
194
* @param aBackbuffer drawing surface used as the backbuffer
195
* @param aCacheBackbuffer PR_TRUE then the backbuffer will be cached, if PR_FALSE it is created each time
197
nsresult AllocateBackbuffer(const nsRect &aRequestedSize, const nsRect &aMaxSize, nsDrawingSurface &aBackbuffer, PRBool aCacheBackbuffer);
204
static nsDrawingSurface gBackbuffer; //singleton backbuffer
205
static nsRect gBackbufferBounds; //backbuffer bounds
206
// Largest requested offscreen size if larger than a full screen.
207
static nsSize gLargestRequestedSize;
211
#undef IMETHOD_VISIBILITY
212
#define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN
214
/** ---------------------------------------------------
215
* Class QBezierCurve, a quadratic bezier curve
216
* @update 4/27/2000 dwc
226
QBezierCurve() {mAnc1.x=0;mAnc1.y=0;mCon=mAnc2=mAnc1;}
227
void SetControls(nsFloatPoint &aAnc1,nsFloatPoint &aCon,nsFloatPoint &aAnc2) { mAnc1 = aAnc1; mCon = aCon; mAnc2 = aAnc2;}
228
void SetPoints(nscoord a1x,nscoord a1y,nscoord acx,nscoord acy,nscoord a2x,nscoord a2y) {mAnc1.MoveTo(a1x,a1y),mCon.MoveTo(acx,acy),mAnc2.MoveTo(a2x,a2y);}
229
void SetPoints(float a1x,float a1y,float acx,float acy,float a2x,float a2y) {mAnc1.MoveTo(a1x,a1y),mCon.MoveTo(acx,acy),mAnc2.MoveTo(a2x,a2y);}
231
/** ---------------------------------------------------
232
* Divide a Quadratic curve into line segments if it is not smaller than a certain size
233
* else it is so small that it can be approximated by 2 lineto calls
234
* @param aRenderingContext -- The RenderingContext to use to draw with
235
* @update 3/26/99 dwc
237
void SubDivide(nsIRenderingContext *aRenderingContext);
239
/** ---------------------------------------------------
240
* Divide a Quadratic curve into line segments if it is not smaller than a certain size
241
* else it is so small that it can be approximated by 2 lineto calls
242
* @param nsPoint* -- The points array to rasterize into
243
* @param aNumPts* -- Current number of points in this array
244
* @update 3/26/99 dwc
246
void SubDivide(nsPoint aThePoints[],PRInt16 *aNumPts);
248
/** ---------------------------------------------------
249
* Divide a Quadratic Bezier curve at the mid-point
250
* @update 3/26/99 dwc
251
* @param aCurve1 -- Curve 1 as a result of the division
252
* @param aCurve2 -- Curve 2 as a result of the division
254
void MidPointDivide(QBezierCurve *A,QBezierCurve *B);
257
enum eSegType {eUNDEF,eLINE,eQCURVE,eCCURVE};
260
/** ---------------------------------------------------
261
* A class to iterate through a nsPathPoint array and return segments
262
* @update 04/27/00 dwc
267
enum eSegType {eUNDEF,eLINE,eQCURVE,eCCURVE};
272
nsPathPoint *mThePath;
276
nsPathIter(nsPathPoint* aThePath,PRUint32 aNumPts);
278
PRBool NextSeg(QBezierCurve& TheSegment,eSegType& aCurveType);
283
#endif /* nsRenderingContextImpl */