~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/gfx/src/nsRenderingContextImpl.h

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
 *
 
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/
 
9
 *
 
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
 
13
 * License.
 
14
 *
 
15
 * The Original Code is mozilla.org code.
 
16
 *
 
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.
 
21
 *
 
22
 * Contributor(s):
 
23
 *
 
24
 *
 
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.
 
36
 *
 
37
 * ***** END LICENSE BLOCK ***** */
 
38
 
 
39
#ifndef nsRenderingContextImpl_h___
 
40
#define nsRenderingContextImpl_h___
 
41
 
 
42
#include "nsComObsolete.h"
 
43
#include "nsIRenderingContext.h"
 
44
#include "nsPoint.h"
 
45
#include "nsSize.h"
 
46
 
 
47
 
 
48
typedef struct {        
 
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] 
 
52
} Edge;
 
53
 
 
54
#undef  IMETHOD_VISIBILITY
 
55
#define IMETHOD_VISIBILITY NS_VISIBILITY_DEFAULT
 
56
 
 
57
class nsRenderingContextImpl : public nsIRenderingContext
 
58
{
 
59
 
 
60
// CLASS MEMBERS
 
61
public:
 
62
 
 
63
 
 
64
protected:
 
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
 
69
 
 
70
public:
 
71
  nsRenderingContextImpl();
 
72
 
 
73
 
 
74
// CLASS METHODS
 
75
 
 
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);
 
79
 
 
80
  /**
 
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
 
84
   */
 
85
  NS_IMETHOD GetPenMode(nsPenMode &aPenMode) { return NS_ERROR_FAILURE;}
 
86
 
 
87
  /**
 
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
 
91
   */
 
92
  NS_IMETHOD SetPenMode(nsPenMode aPenMode) { return NS_ERROR_FAILURE;};
 
93
 
 
94
 
 
95
  /** ---------------------------------------------------
 
96
   *  See documentation in nsIRenderingContext.h
 
97
   *    @update 03/29/00 dwc
 
98
   */
 
99
  NS_IMETHOD DrawPath(nsPathPoint aPointArray[],PRInt32 aNumPts);
 
100
 
 
101
    /** ---------------------------------------------------
 
102
   *  See documentation in nsIRenderingContext.h
 
103
   *    @update 03/29/00 dwc
 
104
   */
 
105
  NS_IMETHOD FillPath(nsPathPoint aPointArray[],PRInt32 aNumPts);
 
106
 
 
107
  /**
 
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
 
111
   */
 
112
  NS_IMETHOD RasterPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
 
113
 
 
114
  /** ---------------------------------------------------
 
115
   *  See documentation in nsIRenderingContext.h
 
116
   *    @update 05/01/00 dwc
 
117
   */
 
118
  NS_IMETHOD DrawStdLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1) { return NS_OK;}
 
119
 
 
120
  /** ---------------------------------------------------
 
121
   *  See documentation in nsIRenderingContext.h
 
122
   *    @update 05/01/00 dwc
 
123
   */
 
124
  NS_IMETHOD FillStdPolygon(const nsPoint aPoints[], PRInt32 aNumPoints) { return NS_OK; }
 
125
 
 
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);
 
130
  
 
131
  /**
 
132
   * Let the device context know whether we want text reordered with
 
133
   * right-to-left base direction
 
134
   */
 
135
  NS_IMETHOD SetRightToLeftText(PRBool aIsRTL);
 
136
 
 
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);
 
140
 
 
141
protected:
 
142
  virtual ~nsRenderingContextImpl();
 
143
 
 
144
  void cdelete(int i);
 
145
  void cinsert(int i,int y,const nsPoint aPointArray[],PRInt32 aNumPts);
 
146
 
 
147
  /**
 
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
 
153
   * otherwise.
 
154
   */
 
155
 
 
156
  PRBool RectFitsInside(const nsRect& aRect, PRInt32 aWidth, PRInt32 aHeight) const;
 
157
 
 
158
  /**
 
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.
 
166
   */
 
167
  PRBool BothRectsFitInside(const nsRect& aRect1, const nsRect& aRect2, PRInt32 aWidth, PRInt32 aHeight, nsRect& aNewSize) const;
 
168
 
 
169
  /**
 
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.
 
173
   *
 
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 
 
177
   */
 
178
  void CalculateDiscreteSurfaceSize(const nsRect& aMaxBackbufferSize, const nsRect& aRequestedSize, nsRect& aSize);
 
179
 
 
180
  /**
 
181
   * Get the size of the offscreen drawing surface..
 
182
   *
 
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.
 
186
   */
 
187
  void GetDrawingSurfaceSize(const nsRect& aMaxBackbufferSize, const nsRect& aRequestedSize, nsRect& aSurfaceSize);
 
188
 
 
189
  /**
 
190
   * Utility method used to implement NS_IMETHOD GetBackbuffer
 
191
   *
 
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
 
196
   */
 
197
  nsresult AllocateBackbuffer(const nsRect &aRequestedSize, const nsRect &aMaxSize, nsDrawingSurface &aBackbuffer, PRBool aCacheBackbuffer);
 
198
 
 
199
public:
 
200
 
 
201
protected:
 
202
  nsPenMode   mPenMode;
 
203
private:
 
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;
 
208
 
 
209
};
 
210
 
 
211
#undef  IMETHOD_VISIBILITY
 
212
#define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN
 
213
 
 
214
/** ---------------------------------------------------
 
215
 *  Class QBezierCurve, a quadratic bezier curve
 
216
 *      @update 4/27/2000 dwc
 
217
 */
 
218
class QBezierCurve
 
219
{
 
220
 
 
221
public:
 
222
        nsFloatPoint    mAnc1;
 
223
        nsFloatPoint    mCon;
 
224
        nsFloatPoint  mAnc2;
 
225
 
 
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);}
 
230
  void DebugPrint();
 
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
 
236
 */
 
237
  void SubDivide(nsIRenderingContext *aRenderingContext);
 
238
 
 
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
 
245
 */
 
246
  void SubDivide(nsPoint aThePoints[],PRInt16 *aNumPts);
 
247
 
 
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
 
253
 */
 
254
  void MidPointDivide(QBezierCurve *A,QBezierCurve *B);
 
255
};
 
256
 
 
257
  enum eSegType {eUNDEF,eLINE,eQCURVE,eCCURVE};
 
258
 
 
259
 
 
260
/** ---------------------------------------------------
 
261
 *  A class to iterate through a nsPathPoint array and return segments
 
262
 *      @update 04/27/00 dwc
 
263
 */
 
264
class nsPathIter {
 
265
 
 
266
public:
 
267
  enum eSegType {eUNDEF,eLINE,eQCURVE,eCCURVE};
 
268
 
 
269
private:
 
270
  PRUint32    mCurPoint;
 
271
  PRUint32    mNumPoints;
 
272
  nsPathPoint *mThePath;
 
273
 
 
274
public:
 
275
  nsPathIter();
 
276
  nsPathIter(nsPathPoint* aThePath,PRUint32 aNumPts);
 
277
 
 
278
  PRBool  NextSeg(QBezierCurve& TheSegment,eSegType& aCurveType);
 
279
 
 
280
};
 
281
 
 
282
 
 
283
#endif /* nsRenderingContextImpl */