1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef NSRENDERINGCONTEXT__H__
7 #define NSRENDERINGCONTEXT__H__
9 #include <stdint.h> // for uint32_t
10 #include <sys/types.h> // for int32_t
11 #include "gfxContext.h" // for gfxContext
12 #include "mozilla/Assertions.h" // for MOZ_ASSERT_HELPER2
13 #include "mozilla/gfx/UserData.h" // for UserData, UserDataKey
14 #include "nsAutoPtr.h" // for nsRefPtr
15 #include "nsBoundingMetrics.h" // for nsBoundingMetrics
16 #include "nsColor.h" // for nscolor
17 #include "nsCoord.h" // for nscoord, NSToIntRound
18 #include "nsDeviceContext.h" // for nsDeviceContext
19 #include "nsFontMetrics.h" // for nsFontMetrics
20 #include "nsISupports.h" // for NS_INLINE_DECL_REFCOUNTING, etc
21 #include "nsString.h" // for nsString
22 #include "nscore.h" // for PRUnichar
30 nsLineStyle_kNone
= 0,
31 nsLineStyle_kSolid
= 1,
32 nsLineStyle_kDashed
= 2,
33 nsLineStyle_kDotted
= 3
36 class nsRenderingContext
38 typedef mozilla::gfx::UserData UserData
;
39 typedef mozilla::gfx::UserDataKey UserDataKey
;
42 nsRenderingContext() : mP2A(0.) {}
43 // ~nsRenderingContext() {}
45 NS_INLINE_DECL_REFCOUNTING(nsRenderingContext
)
47 void Init(nsDeviceContext
* aContext
, gfxASurface
* aThebesSurface
);
48 void Init(nsDeviceContext
* aContext
, gfxContext
* aThebesContext
);
50 // These accessors will never return null.
51 gfxContext
*ThebesContext() { return mThebes
; }
52 nsDeviceContext
*DeviceContext() { return mDeviceContext
; }
53 int32_t AppUnitsPerDevPixel() { return NSToIntRound(mP2A
); }
59 void IntersectClip(const nsRect
& aRect
);
60 void SetClip(const nsIntRegion
& aRegion
);
61 void SetLineStyle(nsLineStyle aLineStyle
);
62 void SetColor(nscolor aColor
);
63 void Translate(const nsPoint
& aPt
);
64 void Scale(float aSx
, float aSy
);
66 class AutoPushTranslation
{
67 nsRenderingContext
* mCtx
;
69 AutoPushTranslation(nsRenderingContext
* aCtx
, const nsPoint
& aPt
)
74 ~AutoPushTranslation() {
81 void DrawLine(const nsPoint
& aStartPt
, const nsPoint
& aEndPt
);
82 void DrawLine(nscoord aX0
, nscoord aY0
, nscoord aX1
, nscoord aY1
);
83 void DrawRect(const nsRect
& aRect
);
84 void DrawRect(nscoord aX
, nscoord aY
, nscoord aWidth
, nscoord aHeight
);
85 void DrawEllipse(nscoord aX
, nscoord aY
, nscoord aWidth
, nscoord aHeight
);
87 void FillRect(const nsRect
& aRect
);
88 void FillRect(nscoord aX
, nscoord aY
, nscoord aWidth
, nscoord aHeight
);
89 void FillPolygon(const nsPoint aPoints
[], int32_t aNumPoints
);
91 void FillEllipse(const nsRect
& aRect
);
92 void FillEllipse(nscoord aX
, nscoord aY
, nscoord aWidth
, nscoord aHeight
);
94 void InvertRect(const nsRect
& aRect
);
98 void SetFont(nsFontMetrics
*aFontMetrics
);
99 nsFontMetrics
*FontMetrics() { return mFontMetrics
; } // may be null
101 void SetTextRunRTL(bool aIsRTL
);
103 nscoord
GetWidth(char aC
);
104 nscoord
GetWidth(PRUnichar aC
);
105 nscoord
GetWidth(const nsString
& aString
);
106 nscoord
GetWidth(const char* aString
);
107 nscoord
GetWidth(const char* aString
, uint32_t aLength
);
108 nscoord
GetWidth(const PRUnichar
*aString
, uint32_t aLength
);
110 nsBoundingMetrics
GetBoundingMetrics(const PRUnichar
*aString
,
113 void DrawString(const nsString
& aString
, nscoord aX
, nscoord aY
);
114 void DrawString(const char *aString
, uint32_t aLength
,
115 nscoord aX
, nscoord aY
);
116 void DrawString(const PRUnichar
*aString
, uint32_t aLength
,
117 nscoord aX
, nscoord aY
);
119 void AddUserData(UserDataKey
*key
, void *userData
, void (*destroy
)(void*)) {
120 mUserData
.Add(key
, userData
, destroy
);
122 void *GetUserData(UserDataKey
*key
) {
123 return mUserData
.Get(key
);
125 void *RemoveUserData(UserDataKey
*key
) {
126 return mUserData
.Remove(key
);
130 int32_t GetMaxChunkLength();
132 nsRefPtr
<gfxContext
> mThebes
;
133 nsRefPtr
<nsDeviceContext
> mDeviceContext
;
134 nsRefPtr
<nsFontMetrics
> mFontMetrics
;
136 double mP2A
; // cached app units per device pixel value
141 #endif // NSRENDERINGCONTEXT__H__