KHTML
SVGPaintServer.cpp
Go to the documentation of this file.
00001 /* 00002 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> 00003 * 2007 Rob Buis <buis@kde.org> 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 00014 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 00015 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00016 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00017 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 00018 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00019 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00020 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00021 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00022 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00023 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00024 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 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 /*TextStream& operator<<(TextStream& ts, const SVGPaintServer& paintServer) 00050 { 00051 return paintServer.externalRepresentation(ts); 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 SVGPaintImpl* fill = style->svgStyle()->fillPaint(); 00076 00077 SVGPaintServer* fillPaintServer = 0; 00078 SVGPaintImpl::SVGPaintType paintType = fill->paintType(); 00079 if (paintType == SVGPaintImpl::SVG_PAINTTYPE_URI || 00080 paintType == SVGPaintImpl::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 == SVGPaintImpl::SVG_PAINTTYPE_URI) 00089 svgElement->document()->accessSVGExtensions()->addPendingResource(id, static_cast<SVGStyledElement*>(svgElement)); 00090 } 00091 if (paintType != SVGPaintImpl::SVG_PAINTTYPE_URI && !fillPaintServer) { 00092 fillPaintServer = sharedSolidPaintServer(); 00093 SVGPaintServerSolid* fillPaintServerSolid = static_cast<SVGPaintServerSolid*>(fillPaintServer); 00094 if (paintType == SVGPaintImpl::SVG_PAINTTYPE_CURRENTCOLOR) 00095 fillPaintServerSolid->setColor(style->color()); 00096 else 00097 fillPaintServerSolid->setColor(fill->color()); 00098 // FIXME: Ideally invalid colors would never get set on the RenderStyle and this could turn into an ASSERT 00099 if (!fillPaintServerSolid->color().isValid()) 00100 fillPaintServer = 0; 00101 } 00102 if (!fillPaintServer) { 00103 // default value (black), see bug 11017 00104 fillPaintServer = sharedSolidPaintServer(); 00105 static_cast<SVGPaintServerSolid*>(fillPaintServer)->setColor(/*Color::black*/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 SVGPaintImpl* stroke = style->svgStyle()->strokePaint(); 00116 00117 SVGPaintServer* strokePaintServer = 0; 00118 SVGPaintImpl::SVGPaintType paintType = stroke->paintType(); 00119 if (paintType == SVGPaintImpl::SVG_PAINTTYPE_URI || 00120 paintType == SVGPaintImpl::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 == SVGPaintImpl::SVG_PAINTTYPE_URI) 00130 svgElement->document()->accessSVGExtensions()->addPendingResource(id, static_cast<SVGStyledElement*>(svgElement)); 00131 } 00132 if (paintType != SVGPaintImpl::SVG_PAINTTYPE_URI && !strokePaintServer) { 00133 strokePaintServer = sharedSolidPaintServer(); 00134 SVGPaintServerSolid* strokePaintServerSolid = static_cast<SVGPaintServerSolid*>(strokePaintServer); 00135 if (paintType == SVGPaintImpl::SVG_PAINTTYPE_CURRENTCOLOR) 00136 strokePaintServerSolid->setColor(style->color()); 00137 else 00138 strokePaintServerSolid->setColor(stroke->color()); 00139 // FIXME: Ideally invalid colors would never get set on the RenderStyle and this could turn into an ASSERT 00140 if (!strokePaintServerSolid->color().isValid()) 00141 strokePaintServer = 0; 00142 } 00143 00144 return strokePaintServer; 00145 } 00146 00147 DashArray dashArrayFromRenderingStyle(const RenderStyle* style) 00148 { 00149 Q_UNUSED(style); 00150 DashArray array; 00151 00152 /*CSSValueList* dashes = style->svgStyle()->strokeDashArray(); 00153 if (dashes) { 00154 CSSPrimitiveValue* dash = 0; 00155 unsigned long len = dashes->length(); 00156 for (unsigned long i = 0; i < len; i++) { 00157 dash = static_cast<CSSPrimitiveValue*>(dashes->itemWithoutBoundsCheck(i)); 00158 if (!dash) 00159 continue; 00160 00161 array.append((float) dash->computeLengthFloat(const_cast<RenderStyle*>(style))); 00162 } 00163 }*/ 00164 00165 return array; 00166 } 00167 00168 } // namespace WebCore 00169 00170 #endif
KDE 4.6 API Reference