1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
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 thebes gfx
17 * The Initial Developer of the Original Code is
19 * Portions created by the Initial Developer are Copyright (C) 2005
20 * the Initial Developer. All Rights Reserved.
23 * Vladimir Vukicevic <vladimir@pobox.com>
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 MPL, 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 MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef NSTHEBESRENDERINGCONTEXT__H__
40 #define NSTHEBESRENDERINGCONTEXT__H__
44 #include "nsIRenderingContext.h"
45 #include "nsRenderingContextImpl.h"
46 #include "nsIDeviceContext.h"
47 #include "nsIFontMetrics.h"
48 #include "nsIWidget.h"
53 #include "nsIRegion.h"
54 #include "nsTransform2D.h"
55 #include "nsVoidArray.h"
56 #include "nsIThebesFontMetrics.h"
57 #include "gfxContext.h"
61 class nsThebesRenderingContext
: public nsRenderingContextImpl
64 nsThebesRenderingContext();
65 virtual ~nsThebesRenderingContext();
69 NS_IMETHOD
Init(nsIDeviceContext
* aContext
, gfxASurface
* aThebesSurface
);
70 NS_IMETHOD
Init(nsIDeviceContext
* aContext
, gfxContext
* aThebesContext
);
72 NS_IMETHOD
Init(nsIDeviceContext
* aContext
, nsIWidget
*aWidget
);
73 NS_IMETHOD
CommonInit(void);
74 NS_IMETHOD
GetDeviceContext(nsIDeviceContext
*& aDeviceContext
);
75 NS_IMETHOD
GetHints(PRUint32
& aResult
);
76 NS_IMETHOD
PushState(void);
77 NS_IMETHOD
PopState(void);
78 NS_IMETHOD
SetClipRect(const nsRect
& aRect
, nsClipCombine aCombine
);
79 NS_IMETHOD
SetLineStyle(nsLineStyle aLineStyle
);
80 NS_IMETHOD
SetClipRegion(const nsIRegion
& aRegion
, nsClipCombine aCombine
);
81 NS_IMETHOD
SetColor(nscolor aColor
);
82 NS_IMETHOD
GetColor(nscolor
&aColor
) const;
83 NS_IMETHOD
SetFont(const nsFont
& aFont
, nsIAtom
* aLangGroup
);
84 NS_IMETHOD
SetFont(nsIFontMetrics
*aFontMetrics
);
85 NS_IMETHOD
GetFontMetrics(nsIFontMetrics
*&aFontMetrics
);
86 NS_IMETHOD
Translate(nscoord aX
, nscoord aY
);
87 NS_IMETHOD
Scale(float aSx
, float aSy
);
88 NS_IMETHOD
GetCurrentTransform(nsTransform2D
*&aTransform
);
90 NS_IMETHOD
DrawLine(nscoord aX0
, nscoord aY0
, nscoord aX1
, nscoord aY1
);
91 NS_IMETHOD
DrawRect(const nsRect
& aRect
);
92 NS_IMETHOD
DrawRect(nscoord aX
, nscoord aY
, nscoord aWidth
, nscoord aHeight
);
93 NS_IMETHOD
FillRect(const nsRect
& aRect
);
94 NS_IMETHOD
FillRect(nscoord aX
, nscoord aY
, nscoord aWidth
, nscoord aHeight
);
95 NS_IMETHOD
InvertRect(const nsRect
& aRect
);
96 NS_IMETHOD
InvertRect(nscoord aX
, nscoord aY
, nscoord aWidth
, nscoord aHeight
);
97 NS_IMETHOD
FillPolygon(const nsPoint aPoints
[], PRInt32 aNumPoints
);
98 NS_IMETHOD
DrawEllipse(const nsRect
& aRect
);
99 NS_IMETHOD
DrawEllipse(nscoord aX
, nscoord aY
, nscoord aWidth
, nscoord aHeight
);
100 NS_IMETHOD
FillEllipse(const nsRect
& aRect
);
101 NS_IMETHOD
FillEllipse(nscoord aX
, nscoord aY
, nscoord aWidth
, nscoord aHeight
);
103 NS_IMETHOD
GetWidth(const nsString
& aString
, nscoord
&aWidth
,
104 PRInt32
*aFontID
= nsnull
)
105 { return nsRenderingContextImpl::GetWidth(aString
, aWidth
, aFontID
); }
106 NS_IMETHOD
GetWidth(const char* aString
, nscoord
& aWidth
)
107 { return nsRenderingContextImpl::GetWidth(aString
, aWidth
); }
108 NS_IMETHOD
GetWidth(const char* aString
, PRUint32 aLength
,
110 { return nsRenderingContextImpl::GetWidth(aString
, aLength
, aWidth
); }
111 NS_IMETHOD
GetWidth(const PRUnichar
*aString
, PRUint32 aLength
,
112 nscoord
&aWidth
, PRInt32
*aFontID
= nsnull
)
113 { return nsRenderingContextImpl::GetWidth(aString
, aLength
, aWidth
, aFontID
); }
114 NS_IMETHOD
DrawString(const nsString
& aString
, nscoord aX
, nscoord aY
,
115 PRInt32 aFontID
= -1,
116 const nscoord
* aSpacing
= nsnull
)
117 { return nsRenderingContextImpl::DrawString(aString
, aX
, aY
, aFontID
, aSpacing
); }
119 NS_IMETHOD
GetWidth(char aC
, nscoord
&aWidth
);
120 NS_IMETHOD
GetWidth(PRUnichar aC
, nscoord
&aWidth
,
123 NS_IMETHOD
GetWidthInternal(const char *aString
, PRUint32 aLength
, nscoord
&aWidth
);
124 NS_IMETHOD
GetWidthInternal(const PRUnichar
*aString
, PRUint32 aLength
, nscoord
&aWidth
,
127 NS_IMETHOD
DrawStringInternal(const char *aString
, PRUint32 aLength
,
128 nscoord aX
, nscoord aY
,
129 const nscoord
* aSpacing
);
130 NS_IMETHOD
DrawStringInternal(const PRUnichar
*aString
, PRUint32 aLength
,
131 nscoord aX
, nscoord aY
,
133 const nscoord
* aSpacing
);
135 NS_IMETHOD
GetTextDimensionsInternal(const char* aString
, PRUint32 aLength
,
136 nsTextDimensions
& aDimensions
);
137 NS_IMETHOD
GetTextDimensionsInternal(const PRUnichar
*aString
, PRUint32 aLength
,
138 nsTextDimensions
& aDimensions
,PRInt32
*aFontID
);
139 NS_IMETHOD
GetTextDimensionsInternal(const char* aString
,
144 nsTextDimensions
& aDimensions
,
145 PRInt32
& aNumCharsFit
,
146 nsTextDimensions
& aLastWordDimensions
,
148 NS_IMETHOD
GetTextDimensionsInternal(const PRUnichar
* aString
,
153 nsTextDimensions
& aDimensions
,
154 PRInt32
& aNumCharsFit
,
155 nsTextDimensions
& aLastWordDimensions
,
160 * Returns metrics (in app units) of an 8-bit character string
162 NS_IMETHOD
GetBoundingMetricsInternal(const char* aString
,
164 nsBoundingMetrics
& aBoundingMetrics
);
167 * Returns metrics (in app units) of a Unicode character string
169 NS_IMETHOD
GetBoundingMetricsInternal(const PRUnichar
* aString
,
171 nsBoundingMetrics
& aBoundingMetrics
,
172 PRInt32
* aFontID
= nsnull
);
174 #endif /* MOZ_MATHML */
176 virtual PRInt32
GetMaxStringLength();
178 NS_IMETHOD
PushFilter(const nsRect
& aRect
, PRBool aAreaIsOpaque
, float aOpacity
);
179 NS_IMETHOD
PopFilter();
181 virtual void* GetNativeGraphicData(GraphicDataType aType
);
183 NS_IMETHOD
PushTranslation(PushedTranslation
* aState
);
184 NS_IMETHOD
PopTranslation(PushedTranslation
* aState
);
185 NS_IMETHOD
SetTranslation(nscoord aX
, nscoord aY
);
187 NS_IMETHOD
DrawTile(imgIContainer
*aImage
, nscoord aXOffset
, nscoord aYOffset
,
188 const nsRect
* aTargetRect
, const nsIntRect
* aSubimageRect
);
189 NS_IMETHOD
SetRightToLeftText(PRBool aIsRTL
);
190 NS_IMETHOD
GetRightToLeftText(PRBool
* aIsRTL
);
191 virtual void SetTextRunRTL(PRBool aIsRTL
);
193 NS_IMETHOD
GetClusterInfo(const PRUnichar
*aText
,
195 PRUint8
*aClusterStarts
);
196 virtual PRInt32
GetPosition(const PRUnichar
*aText
,
199 NS_IMETHOD
GetRangeWidth(const PRUnichar
*aText
,
204 NS_IMETHOD
GetRangeWidth(const char *aText
,
210 NS_IMETHOD
RenderEPS(const nsRect
& aRect
, FILE *aDataFile
);
212 // Thebes specific stuff
214 gfxContext
*ThebesContext() { return mThebes
; }
216 nsTransform2D
& CurrentTransform();
218 void TransformCoord (nscoord
*aX
, nscoord
*aY
);
221 nsCOMPtr
<nsIDeviceContext
> mDeviceContext
;
222 // cached pixels2twips, twips2pixels values
225 nsCOMPtr
<nsIWidget
> mWidget
;
227 // we need to manage our own clip region (since we can't get at
228 // the old one from cairo)
229 nsCOMPtr
<nsIThebesFontMetrics
> mFontMetrics
;
231 nsLineStyle mLineStyle
;
234 // the rendering context
235 nsRefPtr
<gfxContext
> mThebes
;
237 // for handing out to people
238 void UpdateTempTransformMatrix();
239 nsTransform2D mTempTransform
;
241 // keeping track of pushgroup/popgroup opacities
242 nsTArray
<float> mOpacityArray
;
245 #endif // NSCAIRORENDERINGCONTEXT__H__