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;
69 class GraphicsContext : Noncopyable {
71 GraphicsContext(PlatformGraphicsContext*);
74 PlatformGraphicsContext* platformContext() const;
76 const Font& font() const;
77 void setFont(const Font&);
79 const Pen& pen() const;
80 void setPen(const Pen&);
81 void setPen(Pen::PenStyle);
84 Color fillColor() const;
85 void setFillColor(const Color&);
90 void drawRect(const IntRect&);
91 void drawLine(const IntPoint&, const IntPoint&);
92 void drawEllipse(const IntRect&);
93 void drawArc(const IntRect&, float thickness, int startAngle, int angleSpan);
94 void drawConvexPolygon(size_t numPoints, const FloatPoint*, bool shouldAntialias = false);
96 void fillRect(const IntRect&, const Color&);
97 void fillRect(const FloatRect&, const Color&);
98 void clearRect(const FloatRect&);
99 void strokeRect(const FloatRect&, float lineWidth);
101 void drawImage(Image*, const IntPoint&, CompositeOperator = CompositeSourceOver);
102 void drawImage(Image*, const IntRect&, CompositeOperator = CompositeSourceOver);
103 void drawImage(Image*, const IntPoint& destPoint, const IntRect& srcRect, CompositeOperator = CompositeSourceOver);
104 void drawImage(Image*, const IntRect& destRect, const IntRect& srcRect, CompositeOperator = CompositeSourceOver);
105 void drawImage(Image*, const FloatRect& destRect, const FloatRect& srcRect = FloatRect(0, 0, -1, -1),
106 CompositeOperator = CompositeSourceOver);
107 void drawTiledImage(Image*, const IntRect& destRect, const IntPoint& srcPoint, const IntSize& tileSize,
108 CompositeOperator = CompositeSourceOver);
109 void drawTiledImage(Image*, const IntRect& destRect, const IntRect& srcRect,
110 Image::TileRule hRule = Image::StretchTile, Image::TileRule vRule = Image::StretchTile,
111 CompositeOperator = CompositeSourceOver);
113 void clip(const IntRect&);
114 void addRoundedRectClip(const IntRect&, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight);
115 void addInnerRoundedRectClip(const IntRect&, int thickness);
117 // Functions to work around bugs in focus ring clipping on Mac.
118 void setFocusRingClip(const IntRect&);
119 void clearFocusRingClip();
121 void drawText(const TextRun&, const IntPoint&);
122 void drawText(const TextRun&, const IntPoint&, const TextStyle&);
123 void drawHighlightForText(const TextRun&, const IntPoint&, int h, const TextStyle&, const Color& backgroundColor);
125 FloatRect roundToDevicePixels(const FloatRect&);
127 void drawLineForText(const IntPoint&, int yOffset, int width, bool printing);
128 void drawLineForMisspellingOrBadGrammar(const IntPoint&, int width, bool grammar);
130 bool paintingDisabled() const;
131 void setPaintingDisabled(bool);
133 bool updatingControlTints() const;
134 void setUpdatingControlTints(bool);
136 void beginTransparencyLayer(float opacity);
137 void endTransparencyLayer();
139 void setShadow(const IntSize&, int blur, const Color&);
142 void initFocusRing(int width, int offset);
143 void addFocusRingRect(const IntRect&);
144 void drawFocusRing(const Color&);
145 void clearFocusRing();
146 IntRect focusRingBoundingRect();
148 void setLineWidth(float);
149 void setLineCap(LineCap);
150 void setLineJoin(LineJoin);
151 void setMiterLimit(float);
153 void setAlpha(float);
155 void setCompositeOperation(CompositeOperator);
158 void addPath(const Path& path);
160 void clip(const Path&);
162 void scale(const FloatSize&);
163 void rotate(float angleInRadians);
164 void translate(float x, float y);
167 void setURLForRect(const KURL&, const IntRect&);
169 void concatCTM(const AffineTransform&);
172 GraphicsContext(HDC); // FIXME: To be removed.
173 HDC getWindowsContext(bool supportAlphaBlend = false, const IntRect* = 0); // The passed in rect is used to create a bitmap for compositing inside transparency layers.
174 void releaseWindowsContext(HDC, bool supportAlphaBlend = false, const IntRect* = 0); // The passed in HDC should be the one handed back by getWindowsContext.
178 void setFillRule(WindRule);
179 PlatformPath* currentPath();
183 void savePlatformState();
184 void restorePlatformState();
185 void setPlatformPen(const Pen& pen);
186 void setPlatformFillColor(const Color& fill);
187 void setPlatformFont(const Font& font);
189 int focusRingWidth() const;
190 int focusRingOffset() const;
191 const Vector<IntRect>& focusRingRects() const;
193 static GraphicsContextPrivate* createGraphicsContextPrivate();
194 static void destroyGraphicsContextPrivate(GraphicsContextPrivate*);
196 GraphicsContextPrivate* m_common;
197 GraphicsContextPlatformPrivate* m_data;
201 class SVGResourceImage;
202 GraphicsContext* contextForImage(SVGResourceImage*);
205 } // namespace WebCore
207 #endif // GraphicsContext_h