KHTML
SVGPaintServer.cpp
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
00027 #include "config.h"
00028 #include "wtf/Platform.h"
00029
00030 #if ENABLE(SVG)
00031 #include "SVGPaintServer.h"
00032
00033 #include "RenderObject.h"
00034 #include "RenderStyle.h"
00035 #include "SVGPaintServerSolid.h"
00036 #include "SVGStyledElement.h"
00037 #include "SVGURIReference.h"
00038
00039 namespace WebCore {
00040
00041 SVGPaintServer::SVGPaintServer()
00042 {
00043 }
00044
00045 SVGPaintServer::~SVGPaintServer()
00046 {
00047 }
00048
00049
00050
00051
00052
00053
00054 SVGPaintServer* getPaintServerById(Document* document, const AtomicString& id)
00055 {
00056 SVGResource* resource = getResourceById(document, id);
00057 if (resource && resource->isPaintServer())
00058 return static_cast<SVGPaintServer*>(resource);
00059
00060 return 0;
00061 }
00062
00063 SVGPaintServerSolid* SVGPaintServer::sharedSolidPaintServer()
00064 {
00065 static SVGPaintServerSolid* _sharedSolidPaintServer = SVGPaintServerSolid::create().releaseRef();
00066
00067 return _sharedSolidPaintServer;
00068 }
00069
00070 SVGPaintServer* SVGPaintServer::fillPaintServer(const RenderStyle* style, const RenderObject* item)
00071 {
00072 if (!style->svgStyle()->hasFill())
00073 return 0;
00074
00075 SVGPaint* fill = style->svgStyle()->fillPaint();
00076
00077 SVGPaintServer* fillPaintServer = 0;
00078 SVGPaint::SVGPaintType paintType = fill->paintType();
00079 if (paintType == SVGPaint::SVG_PAINTTYPE_URI ||
00080 paintType == SVGPaint::SVG_PAINTTYPE_URI_RGBCOLOR) {
00081 AtomicString id(SVGURIReference::getTarget(fill->uri()));
00082 fillPaintServer = getPaintServerById(item->document(), id);
00083 SVGElement* svgElement = static_cast<SVGElement*>(item->element());
00084 ASSERT(svgElement && svgElement->document() && svgElement->isStyled());
00085
00086 if (item->isRenderPath() && fillPaintServer)
00087 fillPaintServer->addClient(static_cast<SVGStyledElement*>(svgElement));
00088 else if (!fillPaintServer && paintType == SVGPaint::SVG_PAINTTYPE_URI)
00089 svgElement->document()->accessSVGExtensions()->addPendingResource(id, static_cast<SVGStyledElement*>(svgElement));
00090 }
00091 if (paintType != SVGPaint::SVG_PAINTTYPE_URI && !fillPaintServer) {
00092 fillPaintServer = sharedSolidPaintServer();
00093 SVGPaintServerSolid* fillPaintServerSolid = static_cast<SVGPaintServerSolid*>(fillPaintServer);
00094 if (paintType == SVGPaint::SVG_PAINTTYPE_CURRENTCOLOR)
00095 fillPaintServerSolid->setColor(style->color());
00096 else
00097 fillPaintServerSolid->setColor(fill->color());
00098
00099 if (!fillPaintServerSolid->color().isValid())
00100 fillPaintServer = 0;
00101 }
00102 if (!fillPaintServer) {
00103
00104 fillPaintServer = sharedSolidPaintServer();
00105 static_cast<SVGPaintServerSolid*>(fillPaintServer)->setColor(Qt::black);
00106 }
00107 return fillPaintServer;
00108 }
00109
00110 SVGPaintServer* SVGPaintServer::strokePaintServer(const RenderStyle* style, const RenderObject* item)
00111 {
00112 if (!style->svgStyle()->hasStroke())
00113 return 0;
00114
00115 SVGPaint* stroke = style->svgStyle()->strokePaint();
00116
00117 SVGPaintServer* strokePaintServer = 0;
00118 SVGPaint::SVGPaintType paintType = stroke->paintType();
00119 if (paintType == SVGPaint::SVG_PAINTTYPE_URI ||
00120 paintType == SVGPaint::SVG_PAINTTYPE_URI_RGBCOLOR) {
00121 AtomicString id(SVGURIReference::getTarget(stroke->uri()));
00122 strokePaintServer = getPaintServerById(item->document(), id);
00123
00124 SVGElement* svgElement = static_cast<SVGElement*>(item->element());
00125 ASSERT(svgElement && svgElement->document() && svgElement->isStyled());
00126
00127 if (item->isRenderPath() && strokePaintServer)
00128 strokePaintServer->addClient(static_cast<SVGStyledElement*>(svgElement));
00129 else if (!strokePaintServer && paintType == SVGPaint::SVG_PAINTTYPE_URI)
00130 svgElement->document()->accessSVGExtensions()->addPendingResource(id, static_cast<SVGStyledElement*>(svgElement));
00131 }
00132 if (paintType != SVGPaint::SVG_PAINTTYPE_URI && !strokePaintServer) {
00133 strokePaintServer = sharedSolidPaintServer();
00134 SVGPaintServerSolid* strokePaintServerSolid = static_cast<SVGPaintServerSolid*>(strokePaintServer);
00135 if (paintType == SVGPaint::SVG_PAINTTYPE_CURRENTCOLOR)
00136 strokePaintServerSolid->setColor(style->color());
00137 else
00138 strokePaintServerSolid->setColor(stroke->color());
00139
00140 if (!strokePaintServerSolid->color().isValid())
00141 strokePaintServer = 0;
00142 }
00143
00144 return strokePaintServer;
00145 }
00146
00147 DashArray dashArrayFromRenderingStyle(const RenderStyle* style)
00148 {
00149 DashArray array;
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164 return array;
00165 }
00166
00167 }
00168
00169 #endif