28 #include "wtf/Platform.h"
41 SVGPaintServer::SVGPaintServer()
45 SVGPaintServer::~SVGPaintServer()
54 SVGPaintServer* getPaintServerById(Document* document,
const AtomicString&
id)
56 SVGResource* resource = getResourceById(document,
id);
57 if (resource && resource->isPaintServer())
58 return static_cast<SVGPaintServer*>(resource);
63 SVGPaintServerSolid* SVGPaintServer::sharedSolidPaintServer()
65 static SVGPaintServerSolid* _sharedSolidPaintServer = SVGPaintServerSolid::create().releaseRef();
67 return _sharedSolidPaintServer;
70 SVGPaintServer* SVGPaintServer::fillPaintServer(
const RenderStyle* style,
const RenderObject* item)
72 if (!style->svgStyle()->hasFill())
75 SVGPaintImpl* fill = style->svgStyle()->fillPaint();
77 SVGPaintServer* fillPaintServer = 0;
78 SVGPaintImpl::SVGPaintType paintType = fill->paintType();
79 if (paintType == SVGPaintImpl::SVG_PAINTTYPE_URI ||
80 paintType == SVGPaintImpl::SVG_PAINTTYPE_URI_RGBCOLOR) {
81 AtomicString id(SVGURIReference::getTarget(fill->uri()));
82 fillPaintServer = getPaintServerById(item->document(), id);
83 SVGElement* svgElement =
static_cast<SVGElement*
>(item->element());
84 ASSERT(svgElement && svgElement->document() && svgElement->isStyled());
86 if (item->isRenderPath() && fillPaintServer)
87 fillPaintServer->addClient(static_cast<SVGStyledElement*>(svgElement));
88 else if (!fillPaintServer && paintType == SVGPaintImpl::SVG_PAINTTYPE_URI)
89 svgElement->document()->accessSVGExtensions()->addPendingResource(
id, static_cast<SVGStyledElement*>(svgElement));
91 if (paintType != SVGPaintImpl::SVG_PAINTTYPE_URI && !fillPaintServer) {
92 fillPaintServer = sharedSolidPaintServer();
93 SVGPaintServerSolid* fillPaintServerSolid =
static_cast<SVGPaintServerSolid*
>(fillPaintServer);
94 if (paintType == SVGPaintImpl::SVG_PAINTTYPE_CURRENTCOLOR)
95 fillPaintServerSolid->setColor(style->color());
97 fillPaintServerSolid->setColor(fill->color());
99 if (!fillPaintServerSolid->color().isValid())
102 if (!fillPaintServer) {
104 fillPaintServer = sharedSolidPaintServer();
105 static_cast<SVGPaintServerSolid*
>(fillPaintServer)->setColor(Qt::black);
107 return fillPaintServer;
110 SVGPaintServer* SVGPaintServer::strokePaintServer(
const RenderStyle* style,
const RenderObject* item)
112 if (!style->svgStyle()->hasStroke())
115 SVGPaintImpl* stroke = style->svgStyle()->strokePaint();
117 SVGPaintServer* strokePaintServer = 0;
118 SVGPaintImpl::SVGPaintType paintType = stroke->paintType();
119 if (paintType == SVGPaintImpl::SVG_PAINTTYPE_URI ||
120 paintType == SVGPaintImpl::SVG_PAINTTYPE_URI_RGBCOLOR) {
121 AtomicString id(SVGURIReference::getTarget(stroke->uri()));
122 strokePaintServer = getPaintServerById(item->document(), id);
124 SVGElement* svgElement =
static_cast<SVGElement*
>(item->element());
125 ASSERT(svgElement && svgElement->document() && svgElement->isStyled());
127 if (item->isRenderPath() && strokePaintServer)
128 strokePaintServer->addClient(static_cast<SVGStyledElement*>(svgElement));
129 else if (!strokePaintServer && paintType == SVGPaintImpl::SVG_PAINTTYPE_URI)
130 svgElement->document()->accessSVGExtensions()->addPendingResource(
id, static_cast<SVGStyledElement*>(svgElement));
132 if (paintType != SVGPaintImpl::SVG_PAINTTYPE_URI && !strokePaintServer) {
133 strokePaintServer = sharedSolidPaintServer();
134 SVGPaintServerSolid* strokePaintServerSolid =
static_cast<SVGPaintServerSolid*
>(strokePaintServer);
135 if (paintType == SVGPaintImpl::SVG_PAINTTYPE_CURRENTCOLOR)
136 strokePaintServerSolid->setColor(style->color());
138 strokePaintServerSolid->setColor(stroke->color());
140 if (!strokePaintServerSolid->color().isValid())
141 strokePaintServer = 0;
144 return strokePaintServer;
147 DashArray dashArrayFromRenderingStyle(
const RenderStyle* style)