#ifndef GraphicsContext_h
#define GraphicsContext_h
#include "ColorSpace.h"
#include "DashArray.h"
#include "FloatRect.h"
#include "Image.h"
#include "IntRect.h"
#include "Path.h"
#include "TextDirection.h"
#include <wtf/Noncopyable.h>
#include <wtf/PassOwnPtr.h>
#if PLATFORM(CG)
typedef struct CGContext PlatformGraphicsContext;
#elif PLATFORM(CAIRO)
typedef struct _cairo PlatformGraphicsContext;
#elif PLATFORM(OPENVG)
namespace WebCore {
class SurfaceOpenVG;
}
typedef class WebCore::SurfaceOpenVG PlatformGraphicsContext;
#elif PLATFORM(QT)
QT_BEGIN_NAMESPACE
class QPainter;
QT_END_NAMESPACE
typedef QPainter PlatformGraphicsContext;
#elif PLATFORM(WX)
class wxGCDC;
class wxWindowDC;
#if USE(WXGC)
#ifdef __APPLE__
class wxDC;
typedef wxDC PlatformGraphicsContext;
#else
typedef wxGCDC PlatformGraphicsContext;
#endif
#else
typedef wxWindowDC PlatformGraphicsContext;
#endif
#elif PLATFORM(SKIA)
typedef class PlatformContextSkia PlatformGraphicsContext;
#elif PLATFORM(HAIKU)
class BView;
typedef BView PlatformGraphicsContext;
struct pattern;
#elif OS(WINCE)
typedef struct HDC__ PlatformGraphicsContext;
#else
typedef void PlatformGraphicsContext;
#endif
#if PLATFORM(GTK)
typedef struct _GdkDrawable GdkDrawable;
typedef struct _GdkEventExpose GdkEventExpose;
#endif
#if PLATFORM(WIN)
typedef struct HDC__* HDC;
#if !PLATFORM(CG)
typedef unsigned char UInt8;
#endif
#endif
#if PLATFORM(QT) && defined(Q_WS_WIN)
#include <windows.h>
#endif
namespace WebCore {
#if OS(WINCE) && !PLATFORM(QT)
class SharedBitmap;
class SimpleFontData;
class GlyphBuffer;
#endif
const int cMisspellingLineThickness = 3;
const int cMisspellingLinePatternWidth = 4;
const int cMisspellingLinePatternGapWidth = 1;
class AffineTransform;
class Font;
class Generator;
class Gradient;
class GraphicsContextPlatformPrivate;
class GraphicsContextPrivate;
class ImageBuffer;
class KURL;
class Path;
class Pattern;
class TextRun;
const int cTextInvisible = 0;
const int cTextFill = 1;
const int cTextStroke = 2;
const int cTextClip = 4;
enum StrokeStyle {
NoStroke,
SolidStroke,
DottedStroke,
DashedStroke
};
enum InterpolationQuality {
InterpolationDefault,
InterpolationNone,
InterpolationLow,
InterpolationMedium,
InterpolationHigh
};
class GraphicsContext : public Noncopyable {
public:
GraphicsContext(PlatformGraphicsContext*);
~GraphicsContext();
#if !OS(WINCE) || PLATFORM(QT)
PlatformGraphicsContext* platformContext() const;
#endif
float strokeThickness() const;
void setStrokeThickness(float);
StrokeStyle strokeStyle() const;
void setStrokeStyle(const StrokeStyle& style);
Color strokeColor() const;
ColorSpace strokeColorSpace() const;
void setStrokeColor(const Color&, ColorSpace);
void setStrokePattern(PassRefPtr<Pattern>);
Pattern* strokePattern() const;
void setStrokeGradient(PassRefPtr<Gradient>);
Gradient* strokeGradient() const;
WindRule fillRule() const;
void setFillRule(WindRule);
Color fillColor() const;
ColorSpace fillColorSpace() const;
void setFillColor(const Color&, ColorSpace);
void setFillPattern(PassRefPtr<Pattern>);
Pattern* fillPattern() const;
void setFillGradient(PassRefPtr<Gradient>);
Gradient* fillGradient() const;
void setShadowsIgnoreTransforms(bool);
void setShouldAntialias(bool);
bool shouldAntialias() const;
#if PLATFORM(CG)
void applyStrokePattern();
void applyFillPattern();
#endif
void save();
void restore();
void drawRect(const IntRect&);
void drawLine(const IntPoint&, const IntPoint&);
void drawEllipse(const IntRect&);
void drawConvexPolygon(size_t numPoints, const FloatPoint*, bool shouldAntialias = false);
void drawPath();
void fillPath();
void strokePath();
void strokeArc(const IntRect&, int startAngle, int angleSpan);
void fillRect(const FloatRect&);
void fillRect(const FloatRect&, const Color&, ColorSpace);
void fillRect(const FloatRect&, Generator&);
void fillRoundedRect(const IntRect&, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight, const Color&, ColorSpace);
void clearRect(const FloatRect&);
void strokeRect(const FloatRect&);
void strokeRect(const FloatRect&, float lineWidth);
void drawImage(Image*, ColorSpace styleColorSpace, const IntPoint&, CompositeOperator = CompositeSourceOver);
void drawImage(Image*, ColorSpace styleColorSpace, const IntRect&, CompositeOperator = CompositeSourceOver, bool useLowQualityScale = false);
void drawImage(Image*, ColorSpace styleColorSpace, const IntPoint& destPoint, const IntRect& srcRect, CompositeOperator = CompositeSourceOver);
void drawImage(Image*, ColorSpace styleColorSpace, const IntRect& destRect, const IntRect& srcRect, CompositeOperator = CompositeSourceOver, bool useLowQualityScale = false);
void drawImage(Image*, ColorSpace styleColorSpace, const FloatRect& destRect, const FloatRect& srcRect = FloatRect(0, 0, -1, -1),
CompositeOperator = CompositeSourceOver, bool useLowQualityScale = false);
void drawTiledImage(Image*, ColorSpace styleColorSpace, const IntRect& destRect, const IntPoint& srcPoint, const IntSize& tileSize,
CompositeOperator = CompositeSourceOver, bool useLowQualityScale = false);
void drawTiledImage(Image*, ColorSpace styleColorSpace, const IntRect& destRect, const IntRect& srcRect,
Image::TileRule hRule = Image::StretchTile, Image::TileRule vRule = Image::StretchTile,
CompositeOperator = CompositeSourceOver, bool useLowQualityScale = false);
void setImageInterpolationQuality(InterpolationQuality);
InterpolationQuality imageInterpolationQuality() const;
void clip(const FloatRect&);
void addRoundedRectClip(const IntRect&, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight);
void addInnerRoundedRectClip(const IntRect&, int thickness);
void clipOut(const IntRect&);
void clipOutEllipseInRect(const IntRect&);
void clipOutRoundedRect(const IntRect&, const IntSize& topLeft, const IntSize& topRight, const IntSize& bottomLeft, const IntSize& bottomRight);
void clipPath(WindRule);
void clipToImageBuffer(const FloatRect&, const ImageBuffer*);
int textDrawingMode();
void setTextDrawingMode(int);
void drawText(const Font&, const TextRun&, const IntPoint&, int from = 0, int to = -1);
void drawBidiText(const Font&, const TextRun&, const FloatPoint&);
void drawHighlightForText(const Font&, const TextRun&, const IntPoint&, int h, const Color& backgroundColor, ColorSpace, int from = 0, int to = -1);
FloatRect roundToDevicePixels(const FloatRect&);
void drawLineForText(const IntPoint&, int width, bool printing);
void drawLineForMisspellingOrBadGrammar(const IntPoint&, int width, bool grammar);
bool paintingDisabled() const;
void setPaintingDisabled(bool);
bool updatingControlTints() const;
void setUpdatingControlTints(bool);
void beginTransparencyLayer(float opacity);
void endTransparencyLayer();
void setShadow(const IntSize&, int blur, const Color&, ColorSpace);
bool getShadow(IntSize&, int&, Color&) const;
void clearShadow();
void drawFocusRing(const Vector<IntRect>&, int width, int offset, const Color&);
void drawFocusRing(const Vector<Path>&, int width, int offset, const Color&);
void setLineCap(LineCap);
void setLineDash(const DashArray&, float dashOffset);
void setLineJoin(LineJoin);
void setMiterLimit(float);
void setAlpha(float);
#if PLATFORM(CAIRO)
float getAlpha();
void createPlatformShadow(PassOwnPtr<ImageBuffer> buffer, const Color& shadowColor, const FloatRect& shadowRect, float kernelSize);
static void calculateShadowBufferDimensions(IntSize& shadowBufferSize, FloatRect& shadowRect, float& kernelSize, const FloatRect& sourceRect, const IntSize& shadowSize, int shadowBlur);
#endif
void setCompositeOperation(CompositeOperator);
void beginPath();
void addPath(const Path&);
void clip(const Path&);
void canvasClip(const Path&);
void clipOut(const Path&);
void scale(const FloatSize&);
void rotate(float angleInRadians);
void translate(const FloatSize& size) { translate(size.width(), size.height()); }
void translate(float x, float y);
IntPoint origin();
void setURLForRect(const KURL&, const IntRect&);
void concatCTM(const AffineTransform&);
AffineTransform getCTM() const;
#if OS(WINCE) && !PLATFORM(QT)
void setBitmap(PassRefPtr<SharedBitmap>);
const TransformationMatrix& affineTransform() const;
TransformationMatrix& affineTransform();
void resetAffineTransform();
void fillRect(const FloatRect&, const Gradient*);
void drawText(const SimpleFontData* fontData, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point);
void drawFrameControl(const IntRect& rect, unsigned type, unsigned state);
void drawFocusRect(const IntRect& rect);
void paintTextField(const IntRect& rect, unsigned state);
void drawBitmap(SharedBitmap*, const IntRect& dstRect, const IntRect& srcRect, CompositeOperator compositeOp);
void drawBitmapPattern(SharedBitmap*, const FloatRect& tileRectIn, const AffineTransform& patternTransform, const FloatPoint& phase, CompositeOperator op, const FloatRect& destRect, const IntSize& origSourceSize);
void drawIcon(HICON icon, const IntRect& dstRect, UINT flags);
HDC getWindowsContext(const IntRect&, bool supportAlphaBlend = false, bool mayCreateBitmap = true); void releaseWindowsContext(HDC, const IntRect&, bool supportAlphaBlend = false, bool mayCreateBitmap = true); void drawRoundCorner(bool newClip, RECT clipRect, RECT rectWin, HDC dc, int width, int height);
#elif PLATFORM(WIN)
GraphicsContext(HDC, bool hasAlpha = false); bool inTransparencyLayer() const;
HDC getWindowsContext(const IntRect&, bool supportAlphaBlend = true, bool mayCreateBitmap = true); void releaseWindowsContext(HDC, const IntRect&, bool supportAlphaBlend = true, bool mayCreateBitmap = true);
void setShouldIncludeChildWindows(bool);
bool shouldIncludeChildWindows() const;
class WindowsBitmap : public Noncopyable {
public:
WindowsBitmap(HDC, IntSize);
~WindowsBitmap();
HDC hdc() const { return m_hdc; }
UInt8* buffer() const { return m_bitmapBuffer; }
unsigned bufferLength() const { return m_bitmapBufferLength; }
IntSize size() const { return m_size; }
unsigned bytesPerRow() const { return m_bytesPerRow; }
private:
HDC m_hdc;
HBITMAP m_bitmap;
UInt8* m_bitmapBuffer;
unsigned m_bitmapBufferLength;
IntSize m_size;
unsigned m_bytesPerRow;
};
WindowsBitmap* createWindowsBitmap(IntSize);
void drawWindowsBitmap(WindowsBitmap*, const IntPoint&);
#endif
#if (PLATFORM(QT) && defined(Q_WS_WIN)) || (PLATFORM(WX) && OS(WINDOWS))
HDC getWindowsContext(const IntRect&, bool supportAlphaBlend = true, bool mayCreateBitmap = true);
void releaseWindowsContext(HDC, const IntRect&, bool supportAlphaBlend = true, bool mayCreateBitmap = true);
bool shouldIncludeChildWindows() const { return false; }
#endif
#if PLATFORM(WX)
bool inTransparencyLayer() const { return false; }
#endif
#if PLATFORM(QT)
bool inTransparencyLayer() const;
PlatformPath* currentPath();
QPen pen();
#endif
#if PLATFORM(GTK)
void setGdkExposeEvent(GdkEventExpose*);
GdkDrawable* gdkDrawable() const;
GdkEventExpose* gdkExposeEvent() const;
#endif
#if PLATFORM(HAIKU)
pattern getHaikuStrokeStyle();
#endif
private:
void savePlatformState();
void restorePlatformState();
void setPlatformTextDrawingMode(int);
void setPlatformFont(const Font& font);
void setPlatformStrokeColor(const Color&, ColorSpace);
void setPlatformStrokeStyle(const StrokeStyle&);
void setPlatformStrokeThickness(float);
void setPlatformStrokeGradient(Gradient*);
void setPlatformStrokePattern(Pattern*);
void setPlatformFillColor(const Color&, ColorSpace);
void setPlatformFillGradient(Gradient*);
void setPlatformFillPattern(Pattern*);
void setPlatformShouldAntialias(bool b);
void setPlatformShadow(const IntSize&, int blur, const Color&, ColorSpace);
void clearPlatformShadow();
static void adjustLineToPixelBoundaries(FloatPoint& p1, FloatPoint& p2, float strokeWidth, const StrokeStyle&);
static GraphicsContextPrivate* createGraphicsContextPrivate();
static void destroyGraphicsContextPrivate(GraphicsContextPrivate*);
GraphicsContextPrivate* m_common;
GraphicsContextPlatformPrivate* m_data; };
}
#endif // GraphicsContext_h