2 * Copyright (C) 2003, 2006, 2007 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef GraphicsContext_h
27 #define GraphicsContext_h
29 #include "FloatRect.h"
33 #include "TextDirection.h"
34 #include <wtf/Noncopyable.h>
35 #include <wtf/Platform.h>
38 typedef struct CGContext PlatformGraphicsContext;
40 typedef struct _cairo PlatformGraphicsContext;
43 typedef QPainter PlatformGraphicsContext;
48 // wxGraphicsContext allows us to support Path, etc.
49 // but on some platforms, e.g. Linux, it requires fairly
52 // On OS X, wxGCDC is just a typedef for wxDC, so use wxDC explicitly to make
56 typedef wxDC PlatformGraphicsContext;
58 typedef wxGCDC PlatformGraphicsContext;
61 typedef wxWindowDC PlatformGraphicsContext;
64 typedef void PlatformGraphicsContext;
68 typedef struct _GdkDrawable GdkDrawable;
69 typedef struct _GdkEventExpose GdkEventExpose;
73 typedef struct HDC__* HDC;
78 const int cMisspellingLineThickness = 3;
79 const int cMisspellingLinePatternWidth = 4;
80 const int cMisspellingLinePatternGapWidth = 1;
82 class AffineTransform;
84 class GraphicsContextPrivate;
85 class GraphicsContextPlatformPrivate;
90 // These bits can be ORed together for a total of 8 possible text drawing modes.
91 const int cTextInvisible = 0;
92 const int cTextFill = 1;
93 const int cTextStroke = 2;
94 const int cTextClip = 4;
103 class GraphicsContext : Noncopyable {
105 GraphicsContext(PlatformGraphicsContext*);
108 PlatformGraphicsContext* platformContext() const;
110 const Font& font() const;
111 void setFont(const Font&);
113 float strokeThickness() const;
114 void setStrokeThickness(float);
115 StrokeStyle strokeStyle() const;
116 void setStrokeStyle(const StrokeStyle& style);
117 Color strokeColor() const;
118 void setStrokeColor(const Color&);
120 Color fillColor() const;
121 void setFillColor(const Color&);
126 // These draw methods will do both stroking and filling.
127 void drawRect(const IntRect&);
128 void drawLine(const IntPoint&, const IntPoint&);
129 void drawEllipse(const IntRect&);
130 void drawConvexPolygon(size_t numPoints, const FloatPoint*, bool shouldAntialias = false);
132 // Arc drawing (used by border-radius in CSS) just supports stroking at the moment.
133 void strokeArc(const IntRect&, int startAngle, int angleSpan);
135 void fillRect(const IntRect&, const Color&);
136 void fillRect(const FloatRect&, const Color&);
137 void fillRoundedRect(const IntRect&, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight, const Color&);
138 void clearRect(const FloatRect&);
139 void strokeRect(const FloatRect&, float lineWidth);
141 void drawImage(Image*, const IntPoint&, CompositeOperator = CompositeSourceOver);
142 void drawImage(Image*, const IntRect&, CompositeOperator = CompositeSourceOver, bool useLowQualityScale = false);
143 void drawImage(Image*, const IntPoint& destPoint, const IntRect& srcRect, CompositeOperator = CompositeSourceOver);
144 void drawImage(Image*, const IntRect& destRect, const IntRect& srcRect, CompositeOperator = CompositeSourceOver, bool useLowQualityScale = false);
145 void drawImage(Image*, const FloatRect& destRect, const FloatRect& srcRect = FloatRect(0, 0, -1, -1),
146 CompositeOperator = CompositeSourceOver, bool useLowQualityScale = false);
147 void drawTiledImage(Image*, const IntRect& destRect, const IntPoint& srcPoint, const IntSize& tileSize,
148 CompositeOperator = CompositeSourceOver);
149 void drawTiledImage(Image*, const IntRect& destRect, const IntRect& srcRect,
150 Image::TileRule hRule = Image::StretchTile, Image::TileRule vRule = Image::StretchTile,
151 CompositeOperator = CompositeSourceOver);
153 void setUseLowQualityImageInterpolation(bool = true);
154 bool useLowQualityImageInterpolation() const;
156 void setUseLowQualityImageInterpolation(bool = true) {}
157 bool useLowQualityImageInterpolation() const { return false; }
160 void clip(const IntRect&);
161 void addRoundedRectClip(const IntRect&, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight);
162 void addInnerRoundedRectClip(const IntRect&, int thickness);
163 void clipOut(const IntRect&);
164 void clipOutEllipseInRect(const IntRect&);
165 void clipOutRoundedRect(const IntRect&, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight);
167 int textDrawingMode();
168 void setTextDrawingMode(int);
170 void drawText(const TextRun&, const IntPoint&, int from = 0, int to = -1);
171 void drawBidiText(const TextRun&, const IntPoint&);
172 void drawHighlightForText(const TextRun&, const IntPoint&, int h, const Color& backgroundColor, int from = 0, int to = -1);
174 FloatRect roundToDevicePixels(const FloatRect&);
176 void drawLineForText(const IntPoint&, int width, bool printing);
177 void drawLineForMisspellingOrBadGrammar(const IntPoint&, int width, bool grammar);
179 bool paintingDisabled() const;
180 void setPaintingDisabled(bool);
182 bool updatingControlTints() const;
183 void setUpdatingControlTints(bool);
185 void beginTransparencyLayer(float opacity);
186 void endTransparencyLayer();
188 void setShadow(const IntSize&, int blur, const Color&);
191 void initFocusRing(int width, int offset);
192 void addFocusRingRect(const IntRect&);
193 void drawFocusRing(const Color&);
194 void clearFocusRing();
195 IntRect focusRingBoundingRect();
197 void setLineCap(LineCap);
198 void setLineJoin(LineJoin);
199 void setMiterLimit(float);
201 void setAlpha(float);
203 void setCompositeOperation(CompositeOperator);
206 void addPath(const Path&);
208 void clip(const Path&);
209 void clipOut(const Path&);
211 void scale(const FloatSize&);
212 void rotate(float angleInRadians);
213 void translate(float x, float y);
216 void setURLForRect(const KURL&, const IntRect&);
218 void concatCTM(const AffineTransform&);
221 GraphicsContext(HDC); // FIXME: To be removed.
222 HDC getWindowsContext(bool supportAlphaBlend = false, const IntRect* = 0); // The passed in rect is used to create a bitmap for compositing inside transparency layers.
223 void releaseWindowsContext(HDC, bool supportAlphaBlend = false, const IntRect* = 0); // The passed in HDC should be the one handed back by getWindowsContext.
227 void setFillRule(WindRule);
228 PlatformPath* currentPath();
232 void setGdkExposeEvent(GdkEventExpose*);
233 GdkDrawable* gdkDrawable() const;
234 GdkEventExpose* gdkExposeEvent() const;
235 IntPoint translatePoint(const IntPoint&) const;
239 void savePlatformState();
240 void restorePlatformState();
241 void setPlatformTextDrawingMode(int);
242 void setPlatformStrokeColor(const Color&);
243 void setPlatformStrokeStyle(const StrokeStyle&);
244 void setPlatformStrokeThickness(float);
245 void setPlatformFillColor(const Color&);
246 void setPlatformFont(const Font& font);
248 int focusRingWidth() const;
249 int focusRingOffset() const;
250 const Vector<IntRect>& focusRingRects() const;
252 static GraphicsContextPrivate* createGraphicsContextPrivate();
253 static void destroyGraphicsContextPrivate(GraphicsContextPrivate*);
255 GraphicsContextPrivate* m_common;
256 GraphicsContextPlatformPrivate* m_data;
259 } // namespace WebCore
261 #endif // GraphicsContext_h