KHtml

SVGPaintServerGradient.h
1 /*
2  * Copyright (C) 2006 Nikolas Zimmermann <[email protected]>
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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.
24  */
25 
26 #ifndef SVGPaintServerGradient_h
27 #define SVGPaintServerGradient_h
28 
29 #if ENABLE(SVG)
30 
31 #include "AffineTransform.h"
32 #include "SVGPaintServer.h"
33 
34 #include <wtf/RefCounted.h>
35 #include <wtf/RefPtr.h>
36 
37 #if PLATFORM(QT)
38 #include <qglobal.h>
39 QT_BEGIN_NAMESPACE
40 class QGradient;
41 QT_END_NAMESPACE
42 #endif
43 
44 namespace WebCore
45 {
46 
47 class ImageBuffer;
48 class SVGGradientElement;
49 
50 // FIXME: Remove the spread method enum in SVGGradientElement
51 enum SVGGradientSpreadMethod {
52  SPREADMETHOD_PAD = 1,
53  SPREADMETHOD_REFLECT = 2,
54  SPREADMETHOD_REPEAT = 3
55 };
56 
57 typedef std::pair<float, QColor> SVGGradientStop;
58 
59 class SVGPaintServerGradient : public SVGPaintServer
60 {
61 public:
62  virtual ~SVGPaintServerGradient();
63 
64  const Vector<SVGGradientStop> &gradientStops() const;
65  void setGradientStops(const Vector<SVGGradientStop> &);
66 
67  SVGGradientSpreadMethod spreadMethod() const;
68  void setGradientSpreadMethod(const SVGGradientSpreadMethod &);
69 
70  // Gradient start and end points are percentages when used in boundingBox mode.
71  // For instance start point with value (0,0) is top-left and end point with
72  // value (100, 100) is bottom-right. BoundingBox mode is enabled by default.
73  bool boundingBoxMode() const;
74  void setBoundingBoxMode(bool mode = true);
75 
76  AffineTransform gradientTransform() const;
77  void setGradientTransform(const AffineTransform &);
78 
79  /*virtual TextStream& externalRepresentation(TextStream&) const;*/
80 
81  bool setup(QPainter *painter, QPainterPath *path, const RenderObject *, SVGPaintTargetType, bool isPaintingText) const override;
82 #if PLATFORM(CG)
83  virtual void teardown(GraphicsContext *&, const RenderObject *, SVGPaintTargetType, bool isPaintingText) const;
84  virtual void renderPath(GraphicsContext *&, const RenderObject *, SVGPaintTargetType) const;
85 
86  virtual void invalidate();
87 
88  // Helpers
89  void updateQuartzGradientStopsCache(const Vector<SVGGradientStop> &);
90  void updateQuartzGradientCache(const SVGPaintServerGradient *);
91  void handleBoundingBoxModeAndGradientTransformation(GraphicsContext *, const FloatRect &targetRect) const;
92 #endif
93 
94 #if PLATFORM(QT)
95 protected:
96  void fillColorArray(QGradient &, const Vector<SVGGradientStop> &, float opacity) const;
97  virtual QGradient setupGradient(QPainter *painter, QPainterPath *painterPath, const RenderObject *) const = 0;
98 #endif
99 
100 protected:
101  SVGPaintServerGradient(const SVGGradientElement *owner);
102 
103 private:
104  Vector<SVGGradientStop> m_stops;
105  SVGGradientSpreadMethod m_spreadMethod;
106  bool m_boundingBoxMode;
107  AffineTransform m_gradientTransform;
108  const SVGGradientElement *m_ownerElement;
109 
110 #if PLATFORM(CG)
111 public:
112  typedef struct {
113  CGFloat colorArray[4];
114  CGFloat offset;
115  CGFloat previousDeltaInverse;
116  } QuartzGradientStop;
117 
118  struct SharedStopCache : public RefCounted<SharedStopCache> {
119  public:
120  static PassRefPtr<SharedStopCache> create()
121  {
122  return adoptRef(new SharedStopCache);
123  }
124 
125  Vector<QuartzGradientStop> m_stops;
126 
127  private:
128  SharedStopCache() { }
129  };
130 
131  RefPtr<SharedStopCache> m_stopsCache;
132 
133  CGShadingRef m_shadingCache;
134  mutable GraphicsContext *m_savedContext;
135  mutable ImageBuffer *m_imageBuffer;
136 #endif
137 };
138 
139 inline SVGGradientStop makeGradientStop(float offset, const QColor &color)
140 {
141  return std::make_pair(offset, color);
142 }
143 
144 } // namespace WebCore
145 
146 #endif
147 
148 #endif // SVGPaintServerGradient_h
QAction * create(StandardAction id, const QObject *recvr, Func slot, QObject *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:10 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.