KHTML
GraphicsContext.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef GraphicsContext_h
00027 #define GraphicsContext_h
00028
00029 #include "FloatRect.h"
00030
00031 #include "IntRect.h"
00032 #include "Path.h"
00033
00034 #include <wtf/Noncopyable.h>
00035 #include <wtf/Platform.h>
00036
00037 #if PLATFORM(CG)
00038 typedef struct CGContext PlatformGraphicsContext;
00039 #elif PLATFORM(CAIRO)
00040 typedef struct _cairo PlatformGraphicsContext;
00041 #elif PLATFORM(QT)
00042 QT_BEGIN_NAMESPACE
00043 class QPainter;
00044 QT_END_NAMESPACE
00045 typedef QPainter PlatformGraphicsContext;
00046 #elif PLATFORM(WX)
00047 class wxGCDC;
00048 class wxWindowDC;
00049
00050
00051
00052
00053 #if USE(WXGC)
00054
00055
00056 #ifdef __APPLE__
00057 class wxDC;
00058 typedef wxDC PlatformGraphicsContext;
00059 #else
00060 typedef wxGCDC PlatformGraphicsContext;
00061 #endif
00062 #else
00063 typedef wxWindowDC PlatformGraphicsContext;
00064 #endif
00065 #else
00066 typedef void PlatformGraphicsContext;
00067 #endif
00068
00069 #if PLATFORM(GTK)
00070 typedef struct _GdkDrawable GdkDrawable;
00071 typedef struct _GdkEventExpose GdkEventExpose;
00072 #endif
00073
00074 #if PLATFORM(WIN)
00075 typedef struct HDC__* HDC;
00076 #endif
00077
00078 namespace WebCore {
00079
00080 const int cMisspellingLineThickness = 3;
00081 const int cMisspellingLinePatternWidth = 4;
00082 const int cMisspellingLinePatternGapWidth = 1;
00083
00084 class AffineTransform;
00085
00086 class Generator;
00087 class GraphicsContextPrivate;
00088 class GraphicsContextPlatformPrivate;
00089
00090
00091 class Path;
00092
00093
00094
00095 const int cTextInvisible = 0;
00096 const int cTextFill = 1;
00097 const int cTextStroke = 2;
00098 const int cTextClip = 4;
00099
00100 enum StrokeStyle {
00101 NoStroke,
00102 SolidStroke,
00103 DottedStroke,
00104 DashedStroke
00105 };
00106
00107 class GraphicsContext : Noncopyable {
00108 public:
00109 GraphicsContext(PlatformGraphicsContext*);
00110 ~GraphicsContext();
00111
00112 PlatformGraphicsContext* platformContext() const;
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 void save();
00128 void restore();
00129
00130
00131 void drawRect(const IntRect&);
00132 void drawLine(const IntPoint&, const IntPoint&);
00133 void drawEllipse(const IntRect&);
00134 void drawConvexPolygon(size_t numPoints, const FloatPoint*, bool shouldAntialias = false);
00135
00136
00137 void strokeArc(const IntRect&, int startAngle, int angleSpan);
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166 void clip(const FloatRect&);
00167 void addRoundedRectClip(const IntRect&, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight);
00168 void addInnerRoundedRectClip(const IntRect&, int thickness);
00169 void clipOut(const IntRect&);
00170 void clipOutEllipseInRect(const IntRect&);
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181 FloatRect roundToDevicePixels(const FloatRect&);
00182
00183 void drawLineForText(const IntPoint&, int width, bool printing);
00184 void drawLineForMisspellingOrBadGrammar(const IntPoint&, int width, bool grammar);
00185
00186 bool paintingDisabled() const;
00187 void setPaintingDisabled(bool);
00188
00189 bool updatingControlTints() const;
00190 void setUpdatingControlTints(bool);
00191
00192 void beginTransparencyLayer(float opacity);
00193 void endTransparencyLayer();
00194
00195
00196
00197
00198
00199 void initFocusRing(int width, int offset);
00200 void addFocusRingRect(const IntRect&);
00201
00202 void clearFocusRing();
00203 IntRect focusRingBoundingRect();
00204
00205
00206
00207 void setMiterLimit(float);
00208
00209 void setAlpha(float);
00210
00211
00212
00213 void beginPath();
00214 void addPath(const Path&);
00215
00216 void clip(const Path&);
00217 void clipOut(const Path&);
00218
00219 void scale(const FloatSize&);
00220 void rotate(float angleInRadians);
00221 void translate(float x, float y);
00222 IntPoint origin();
00223
00224
00225
00226 void concatCTM(const AffineTransform&);
00227 AffineTransform getCTM() const;
00228
00229 void setUseAntialiasing(bool = true);
00230
00231 #if PLATFORM(WIN)
00232 GraphicsContext(HDC);
00233 bool inTransparencyLayer() const;
00234 HDC getWindowsContext(const IntRect&, bool supportAlphaBlend = true, bool mayCreateBitmap = true);
00235 void releaseWindowsContext(HDC, const IntRect&, bool supportAlphaBlend = true, bool mayCreateBitmap = true);
00236
00237 class WindowsBitmap : public Noncopyable {
00238 public:
00239 WindowsBitmap(HDC, IntSize);
00240 ~WindowsBitmap();
00241
00242 HDC hdc() const { return m_hdc; }
00243 UInt8* buffer() const { return m_bitmapBuffer; }
00244 unsigned bufferLength() const { return m_bitmapBufferLength; }
00245 IntSize size() const { return m_size; }
00246 unsigned bytesPerRow() const { return m_bytesPerRow; }
00247
00248 private:
00249 HDC m_hdc;
00250 HBITMAP m_bitmap;
00251 UInt8* m_bitmapBuffer;
00252 unsigned m_bitmapBufferLength;
00253 IntSize m_size;
00254 unsigned m_bytesPerRow;
00255 };
00256
00257 WindowsBitmap* createWindowsBitmap(IntSize);
00258
00259 void drawWindowsBitmap(WindowsBitmap*, const IntPoint&);
00260 #endif
00261
00262 #if PLATFORM(QT)
00263 void setFillRule(WindRule);
00264 PlatformPath* currentPath();
00265 #endif
00266
00267 #if PLATFORM(GTK)
00268 void setGdkExposeEvent(GdkEventExpose*);
00269 GdkDrawable* gdkDrawable() const;
00270 GdkEventExpose* gdkExposeEvent() const;
00271 IntPoint translatePoint(const IntPoint&) const;
00272 #endif
00273
00274 private:
00275 void savePlatformState();
00276 void restorePlatformState();
00277 void setPlatformTextDrawingMode(int);
00278
00279
00280 void setPlatformStrokeThickness(float);
00281
00282
00283
00284 void clearPlatformShadow();
00285
00286 int focusRingWidth() const;
00287 int focusRingOffset() const;
00288 const Vector<IntRect>& focusRingRects() const;
00289
00290 static GraphicsContextPrivate* createGraphicsContextPrivate();
00291 static void destroyGraphicsContextPrivate(GraphicsContextPrivate*);
00292
00293 GraphicsContextPrivate* m_common;
00294 GraphicsContextPlatformPrivate* m_data;
00295 };
00296
00297 }
00298
00299 #endif // GraphicsContext_h