KHTML
SVGPaintServerGradient.h
Go to the documentation of this file.
00001 /* 00002 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> 00003 * 00004 * Redistribution and use in source and binary forms, with or without 00005 * modification, are permitted provided that the following conditions 00006 * are met: 00007 * 1. Redistributions of source code must retain the above copyright 00008 * notice, this list of conditions and the following disclaimer. 00009 * 2. Redistributions in binary form must reproduce the above copyright 00010 * notice, this list of conditions and the following disclaimer in the 00011 * documentation and/or other materials provided with the distribution. 00012 * 00013 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 00014 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00015 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00016 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 00017 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00018 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00019 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00020 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00021 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00022 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00023 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00024 */ 00025 00026 #ifndef SVGPaintServerGradient_h 00027 #define SVGPaintServerGradient_h 00028 00029 #if ENABLE(SVG) 00030 00031 #include "AffineTransform.h" 00032 #include "SVGPaintServer.h" 00033 00034 #include <wtf/RefCounted.h> 00035 #include <wtf/RefPtr.h> 00036 00037 #if PLATFORM(QT) 00038 #include <qglobal.h> 00039 QT_BEGIN_NAMESPACE 00040 class QGradient; 00041 QT_END_NAMESPACE 00042 #endif 00043 00044 namespace WebCore { 00045 00046 class ImageBuffer; 00047 class SVGGradientElement; 00048 00049 // FIXME: Remove the spread method enum in SVGGradientElement 00050 enum SVGGradientSpreadMethod { 00051 SPREADMETHOD_PAD = 1, 00052 SPREADMETHOD_REFLECT = 2, 00053 SPREADMETHOD_REPEAT = 3 00054 }; 00055 00056 typedef std::pair<float, QColor> SVGGradientStop; 00057 00058 00059 class SVGPaintServerGradient : public SVGPaintServer { 00060 public: 00061 virtual ~SVGPaintServerGradient(); 00062 00063 const Vector<SVGGradientStop>& gradientStops() const; 00064 void setGradientStops(const Vector<SVGGradientStop>&); 00065 00066 SVGGradientSpreadMethod spreadMethod() const; 00067 void setGradientSpreadMethod(const SVGGradientSpreadMethod&); 00068 00069 // Gradient start and end points are percentages when used in boundingBox mode. 00070 // For instance start point with value (0,0) is top-left and end point with 00071 // value (100, 100) is bottom-right. BoundingBox mode is enabled by default. 00072 bool boundingBoxMode() const; 00073 void setBoundingBoxMode(bool mode = true); 00074 00075 AffineTransform gradientTransform() const; 00076 void setGradientTransform(const AffineTransform&); 00077 00078 /*virtual TextStream& externalRepresentation(TextStream&) const;*/ 00079 00080 virtual bool setup(QPainter* painter, QPainterPath* path, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const; 00081 #if PLATFORM(CG) 00082 virtual void teardown(GraphicsContext*&, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const; 00083 virtual void renderPath(GraphicsContext*&, const RenderObject*, SVGPaintTargetType) const; 00084 00085 virtual void invalidate(); 00086 00087 // Helpers 00088 void updateQuartzGradientStopsCache(const Vector<SVGGradientStop>&); 00089 void updateQuartzGradientCache(const SVGPaintServerGradient*); 00090 void handleBoundingBoxModeAndGradientTransformation(GraphicsContext*, const FloatRect& targetRect) const; 00091 #endif 00092 00093 #if PLATFORM(QT) 00094 protected: 00095 void fillColorArray(QGradient&, const Vector<SVGGradientStop>&, float opacity) const; 00096 virtual QGradient setupGradient(QPainter* painter, QPainterPath* painterPath, const RenderObject*) const = 0; 00097 #endif 00098 00099 protected: 00100 SVGPaintServerGradient(const SVGGradientElement* owner); 00101 00102 private: 00103 Vector<SVGGradientStop> m_stops; 00104 SVGGradientSpreadMethod m_spreadMethod; 00105 bool m_boundingBoxMode; 00106 AffineTransform m_gradientTransform; 00107 const SVGGradientElement* m_ownerElement; 00108 00109 #if PLATFORM(CG) 00110 public: 00111 typedef struct { 00112 CGFloat colorArray[4]; 00113 CGFloat offset; 00114 CGFloat previousDeltaInverse; 00115 } QuartzGradientStop; 00116 00117 struct SharedStopCache : public RefCounted<SharedStopCache> { 00118 public: 00119 static PassRefPtr<SharedStopCache> create() { return adoptRef(new SharedStopCache); } 00120 00121 Vector<QuartzGradientStop> m_stops; 00122 00123 private: 00124 SharedStopCache() { } 00125 }; 00126 00127 RefPtr<SharedStopCache> m_stopsCache; 00128 00129 CGShadingRef m_shadingCache; 00130 mutable GraphicsContext* m_savedContext; 00131 mutable ImageBuffer* m_imageBuffer; 00132 #endif 00133 }; 00134 00135 inline SVGGradientStop makeGradientStop(float offset, const QColor& color) 00136 { 00137 return std::make_pair(offset, color); 00138 } 00139 00140 } // namespace WebCore 00141 00142 #endif 00143 00144 #endif // SVGPaintServerGradient_h
KDE 4.6 API Reference