• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

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 "Color.h"
00033 #include "SVGPaintServer.h"
00034 
00035 #include <wtf/RefCounted.h>
00036 #include <wtf/RefPtr.h>
00037 
00038 #if PLATFORM(QT)
00039 #include <qglobal.h>
00040 QT_BEGIN_NAMESPACE
00041 class QGradient;
00042 QT_END_NAMESPACE
00043 #endif
00044 
00045 namespace WebCore {
00046 
00047     class ImageBuffer;
00048     class SVGGradientElement;
00049 
00050     // FIXME: Remove the spread method enum in SVGGradientElement
00051     enum SVGGradientSpreadMethod {
00052         SPREADMETHOD_PAD = 1,
00053         SPREADMETHOD_REFLECT = 2,
00054         SPREADMETHOD_REPEAT = 3
00055     };
00056 
00057 #if PLATFORM(CG)
00058     typedef std::pair<CGFloat, Color> SVGGradientStop;
00059 #else
00060     typedef std::pair<float, Color> SVGGradientStop;
00061 #endif
00062 
00063 
00064     class SVGPaintServerGradient : public SVGPaintServer {
00065     public:
00066         virtual ~SVGPaintServerGradient();
00067 
00068         const Vector<SVGGradientStop>& gradientStops() const;
00069         void setGradientStops(const Vector<SVGGradientStop>&);
00070 
00071         SVGGradientSpreadMethod spreadMethod() const;
00072         void setGradientSpreadMethod(const SVGGradientSpreadMethod&);
00073 
00074         // Gradient start and end points are percentages when used in boundingBox mode.
00075         // For instance start point with value (0,0) is top-left and end point with
00076         // value (100, 100) is bottom-right. BoundingBox mode is enabled by default.
00077         bool boundingBoxMode() const;
00078         void setBoundingBoxMode(bool mode = true);
00079 
00080         AffineTransform gradientTransform() const;
00081         void setGradientTransform(const AffineTransform&);
00082 
00083         /*virtual TextStream& externalRepresentation(TextStream&) const;*/
00084 
00085         virtual bool setup(QPainter* painter, QPainterPath* path, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const;
00086 #if PLATFORM(CG)
00087         virtual void teardown(GraphicsContext*&, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const;
00088         virtual void renderPath(GraphicsContext*&, const RenderObject*, SVGPaintTargetType) const;
00089 
00090         virtual void invalidate();
00091 
00092         // Helpers
00093         void updateQuartzGradientStopsCache(const Vector<SVGGradientStop>&);
00094         void updateQuartzGradientCache(const SVGPaintServerGradient*);
00095         void handleBoundingBoxModeAndGradientTransformation(GraphicsContext*, const FloatRect& targetRect) const;
00096 #endif
00097 
00098 #if PLATFORM(QT)
00099     protected:
00100         void fillColorArray(QGradient&, const Vector<SVGGradientStop>&, float opacity) const;
00101         virtual QGradient setupGradient(QPainter* painter, QPainterPath* painterPath, const RenderObject*) const = 0;
00102 #endif
00103 
00104     protected:
00105         SVGPaintServerGradient(const SVGGradientElement* owner);
00106         
00107     private:
00108         Vector<SVGGradientStop> m_stops;
00109         SVGGradientSpreadMethod m_spreadMethod;
00110         bool m_boundingBoxMode;
00111         AffineTransform m_gradientTransform;
00112         const SVGGradientElement* m_ownerElement;
00113 
00114 #if PLATFORM(CG)
00115     public:
00116         typedef struct {
00117             CGFloat colorArray[4];
00118             CGFloat offset;
00119             CGFloat previousDeltaInverse;
00120         } QuartzGradientStop;
00121         
00122         struct SharedStopCache : public RefCounted<SharedStopCache> {
00123         public:
00124             static PassRefPtr<SharedStopCache> create() { return adoptRef(new SharedStopCache); }
00125             
00126             Vector<QuartzGradientStop> m_stops;
00127         
00128         private:
00129             SharedStopCache() { }
00130         };
00131 
00132         RefPtr<SharedStopCache> m_stopsCache;
00133 
00134         CGShadingRef m_shadingCache;
00135         mutable GraphicsContext* m_savedContext;
00136         mutable ImageBuffer* m_imageBuffer;
00137 #endif
00138     };
00139 
00140     inline SVGGradientStop makeGradientStop(float offset, const Color& color)
00141     {
00142         return std::make_pair(offset, color);
00143     }
00144 
00145 } // namespace WebCore
00146 
00147 #endif
00148 
00149 #endif // SVGPaintServerGradient_h

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal