• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • khtml
  • svg
  • graphics
SVGPaintServer.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
3 * 2007 Rob Buis <buis@kde.org>
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include "config.h"
28#include "wtf/Platform.h"
29
30#if ENABLE(SVG)
31#include "SVGPaintServer.h"
32
33#include "RenderObject.h"
34#include "RenderStyle.h"
35#include "SVGPaintServerSolid.h"
36#include "SVGStyledElement.h"
37#include "SVGURIReference.h"
38
39namespace WebCore {
40
41SVGPaintServer::SVGPaintServer()
42{
43}
44
45SVGPaintServer::~SVGPaintServer()
46{
47}
48
49/*TextStream& operator<<(TextStream& ts, const SVGPaintServer& paintServer)
50{
51 return paintServer.externalRepresentation(ts);
52}*/
53
54SVGPaintServer* getPaintServerById(Document* document, const AtomicString& id)
55{
56 SVGResource* resource = getResourceById(document, id);
57 if (resource && resource->isPaintServer())
58 return static_cast<SVGPaintServer*>(resource);
59
60 return 0;
61}
62
63SVGPaintServerSolid* SVGPaintServer::sharedSolidPaintServer()
64{
65 static SVGPaintServerSolid* _sharedSolidPaintServer = SVGPaintServerSolid::create().releaseRef();
66
67 return _sharedSolidPaintServer;
68}
69
70SVGPaintServer* SVGPaintServer::fillPaintServer(const RenderStyle* style, const RenderObject* item)
71{
72 if (!style->svgStyle()->hasFill())
73 return 0;
74
75 SVGPaintImpl* fill = style->svgStyle()->fillPaint();
76
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());
85
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));
90 }
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());
96 else
97 fillPaintServerSolid->setColor(fill->color());
98 // FIXME: Ideally invalid colors would never get set on the RenderStyle and this could turn into an ASSERT
99 if (!fillPaintServerSolid->color().isValid())
100 fillPaintServer = 0;
101 }
102 if (!fillPaintServer) {
103 // default value (black), see bug 11017
104 fillPaintServer = sharedSolidPaintServer();
105 static_cast<SVGPaintServerSolid*>(fillPaintServer)->setColor(/*Color::black*/Qt::black);
106 }
107 return fillPaintServer;
108}
109
110SVGPaintServer* SVGPaintServer::strokePaintServer(const RenderStyle* style, const RenderObject* item)
111{
112 if (!style->svgStyle()->hasStroke())
113 return 0;
114
115 SVGPaintImpl* stroke = style->svgStyle()->strokePaint();
116
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);
123
124 SVGElement* svgElement = static_cast<SVGElement*>(item->element());
125 ASSERT(svgElement && svgElement->document() && svgElement->isStyled());
126
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));
131 }
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());
137 else
138 strokePaintServerSolid->setColor(stroke->color());
139 // FIXME: Ideally invalid colors would never get set on the RenderStyle and this could turn into an ASSERT
140 if (!strokePaintServerSolid->color().isValid())
141 strokePaintServer = 0;
142 }
143
144 return strokePaintServer;
145}
146
147DashArray dashArrayFromRenderingStyle(const RenderStyle* style)
148{
149 Q_UNUSED(style);
150 DashArray array;
151
152 /*CSSValueList* dashes = style->svgStyle()->strokeDashArray();
153 if (dashes) {
154 CSSPrimitiveValue* dash = 0;
155 unsigned long len = dashes->length();
156 for (unsigned long i = 0; i < len; i++) {
157 dash = static_cast<CSSPrimitiveValue*>(dashes->itemWithoutBoundsCheck(i));
158 if (!dash)
159 continue;
160
161 array.append((float) dash->computeLengthFloat(const_cast<RenderStyle*>(style)));
162 }
163 }*/
164
165 return array;
166}
167
168} // namespace WebCore
169
170#endif
RenderObject.h
RenderStyle.h
SVGPaintServerSolid.h
SVGPaintServer.h
SVGStyledElement.h
SVGURIReference.h
WebCore
Definition: CSSHelper.h:7
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

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

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal