2 * Copyright (C) 2003, 2006 Apple Computer, 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"
34 #include "TextDirection.h"
36 #include <wtf/Noncopyable.h>
37 #include <wtf/Platform.h>
40 typedef struct CGContext PlatformGraphicsContext;
42 typedef struct _cairo PlatformGraphicsContext;
45 typedef QPainter PlatformGraphicsContext;
47 typedef void PlatformGraphicsContext;
51 typedef struct HDC__* HDC;
56 const int cMisspellingLineThickness = 3;
57 const int cMisspellingLinePatternWidth = 4;
58 const int cMisspellingLinePatternGapWidth = 1;
60 class AffineTransform;
62 class GraphicsContextPrivate;
63 class GraphicsContextPlatformPrivate;
66 class SVGResourceImage;
70 class GraphicsContext : Noncopyable {
72 GraphicsContext(PlatformGraphicsContext*);
75 PlatformGraphicsContext* platformContext() const;
77 const Font& font() const;
78 void setFont(const Font&);
80 const Pen& pen() const;
81 void setPen(const Pen&);
82 void setPen(Pen::PenStyle);
85 Color fillColor() const;
86 void setFillColor(const Color&);
91 void drawRect(const IntRect&);
92 void drawLine(const IntPoint&, const IntPoint&);
93 void drawEllipse(const IntRect&);
94 void drawArc(const IntRect&, float thickness, int startAngle, int angleSpan);
95 void drawConvexPolygon(size_t numPoints, const FloatPoint*, bool shouldAntialias = false);
97 void fillRect(const IntRect&, const Color&);
98 void fillRect(const FloatRect&, const Color&);
99 void clearRect(const FloatRect&);
100 void strokeRect(const FloatRect&, float lineWidth);
102 void drawImage(Image*, const IntPoint&, CompositeOperator = CompositeSourceOver);
103 void drawImage(Image*, const IntRect&, CompositeOperator = CompositeSourceOver);
104 void drawImage(Image*, const IntPoint& destPoint, const IntRect& srcRect, CompositeOperator = CompositeSourceOver);
105 void drawImage(Image*, const IntRect& destRect, const IntRect& srcRect, CompositeOperator = CompositeSourceOver);
106 void drawImage(Image*, const FloatRect& destRect, const FloatRect& srcRect = FloatRect(0, 0, -1, -1),
107 CompositeOperator = CompositeSourceOver);
108 void drawTiledImage(Image*, const IntRect& destRect, const IntPoint& srcPoint, const IntSize& tileSize,
109 CompositeOperator = CompositeSourceOver);
110 void drawTiledImage(Image*, const IntRect& destRect, const IntRect& srcRect,
111 Image::TileRule hRule = Image::StretchTile, Image::TileRule vRule = Image::StretchTile,
112 CompositeOperator = CompositeSourceOver);
114 void clip(const IntRect&);
115 void addRoundedRectClip(const IntRect&, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight);
116 void addInnerRoundedRectClip(const IntRect&, int thickness);
118 // Functions to work around bugs in focus ring clipping on Mac.
119 void setFocusRingClip(const IntRect&);
120 void clearFocusRingClip();
122 void drawText(const TextRun&, const IntPoint&);
123 void drawText(const TextRun&, const IntPoint&, const TextStyle&);
124 void drawHighlightForText(const TextRun&, const IntPoint&, int h, const TextStyle&, const Color& backgroundColor);
126 FloatRect roundToDevicePixels(const FloatRect&);
128 void drawLineForText(const IntPoint&, int yOffset, int width, bool printing);
129 void drawLineForMisspellingOrBadGrammar(const IntPoint&, int width, bool grammar);
131 bool paintingDisabled() const;
132 void setPaintingDisabled(bool);
134 bool updatingControlTints() const;
135 void setUpdatingControlTints(bool);
137 void beginTransparencyLayer(float opacity);
138 void endTransparencyLayer();
140 void setShadow(const IntSize&, int blur, const Color&);
143 void initFocusRing(int width, int offset);
144 void addFocusRingRect(const IntRect&);
145 void drawFocusRing(const Color&);
146 void clearFocusRing();
147 IntRect focusRingBoundingRect();
149 void setLineWidth(float);
150 void setLineCap(LineCap);
151 void setLineJoin(LineJoin);
152 void setMiterLimit(float);
154 void setAlpha(float);
156 void setCompositeOperation(CompositeOperator);
159 void addPath(const Path& path);
161 void clip(const Path&);
163 void scale(const FloatSize&);
164 void rotate(float angleInRadians);
165 void translate(float x, float y);
168 void setURLForRect(const KURL&, const IntRect&);
170 void concatCTM(const AffineTransform&);
173 GraphicsContext(HDC); // FIXME: To be removed.
174 HDC getWindowsContext(bool supportAlphaBlend = false, const IntRect* = 0); // The passed in rect is used to create a bitmap for compositing inside transparency layers.
175 void releaseWindowsContext(HDC, bool supportAlphaBlend = false, const IntRect* = 0); // The passed in HDC should be the one handed back by getWindowsContext.
179 void setFillRule(WindRule);
180 PlatformPath* currentPath();
184 void savePlatformState();
185 void restorePlatformState();
186 void setPlatformPen(const Pen& pen);
187 void setPlatformFillColor(const Color& fill);
188 void setPlatformFont(const Font& font);
190 int focusRingWidth() const;
191 int focusRingOffset() const;
192 const Vector<IntRect>& focusRingRects() const;
194 static GraphicsContextPrivate* createGraphicsContextPrivate();
195 static void destroyGraphicsContextPrivate(GraphicsContextPrivate*);
197 GraphicsContextPrivate* m_common;
198 GraphicsContextPlatformPrivate* m_data;
202 GraphicsContext* contextForImage(SVGResourceImage*);
205 } // namespace WebCore
207 #endif // GraphicsContext_h