File indexing completed on 2024-11-10 09:39:10
0001 /* 0002 Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> 0003 2004, 2005 Rob Buis <buis@kde.org> 0004 0005 Based on khtml code by: 0006 Copyright (C) 1999 Antti Koivisto (koivisto@kde.org) 0007 Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org) 0008 Copyright (C) 2002-2003 Dirk Mueller (mueller@kde.org) 0009 Copyright (C) 2002 Apple Computer, Inc. 0010 0011 This file is part of the KDE project 0012 0013 This library is free software; you can redistribute it and/or 0014 modify it under the terms of the GNU Library General Public 0015 License as published by the Free Software Foundation; either 0016 version 2 of the License, or (at your option) any later version. 0017 0018 This library is distributed in the hope that it will be useful, 0019 but WITHOUT ANY WARRANTY; without even the implied warranty of 0020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0021 Library General Public License for more details. 0022 0023 You should have received a copy of the GNU Library General Public License 0024 along with this library; see the file COPYING.LIB. If not, write to 0025 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0026 Boston, MA 02110-1301, USA. 0027 */ 0028 0029 #include "wtf/Platform.h" 0030 #if ENABLE(SVG) 0031 #include "SVGRenderStyle.h" 0032 0033 #include "RenderObject.h" 0034 #include "RenderStyle.h" 0035 #include "SVGStyledElement.h" 0036 0037 namespace khtml 0038 { 0039 0040 SVGRenderStyle::SVGRenderStyle() 0041 { 0042 static SVGRenderStyle *defaultStyle = new SVGRenderStyle(CreateDefault); 0043 0044 fill = defaultStyle->fill; 0045 stroke = defaultStyle->stroke; 0046 text = defaultStyle->text; 0047 stops = defaultStyle->stops; 0048 clip = defaultStyle->clip; 0049 mask = defaultStyle->mask; 0050 misc = defaultStyle->misc; 0051 markers = defaultStyle->markers; 0052 0053 setBitDefaults(); 0054 } 0055 0056 SVGRenderStyle::SVGRenderStyle(CreateDefaultType) 0057 { 0058 setBitDefaults(); 0059 0060 fill.init(); 0061 stroke.init(); 0062 text.init(); 0063 stops.init(); 0064 clip.init(); 0065 mask.init(); 0066 misc.init(); 0067 markers.init(); 0068 } 0069 0070 SVGRenderStyle::SVGRenderStyle(const SVGRenderStyle &other) 0071 : RefCounted<SVGRenderStyle>() 0072 { 0073 fill = other.fill; 0074 stroke = other.stroke; 0075 text = other.text; 0076 stops = other.stops; 0077 clip = other.clip; 0078 mask = other.mask; 0079 misc = other.misc; 0080 markers = other.markers; 0081 0082 svg_inherited_flags = other.svg_inherited_flags; 0083 svg_noninherited_flags = other.svg_noninherited_flags; 0084 } 0085 0086 SVGRenderStyle::~SVGRenderStyle() 0087 { 0088 } 0089 0090 bool SVGRenderStyle::operator==(const SVGRenderStyle &o) const 0091 { 0092 return (fill == o.fill && stroke == o.stroke && text == o.text && 0093 stops == o.stops && clip == o.clip && mask == o.mask && 0094 misc == o.misc && markers == o.markers && 0095 svg_inherited_flags == o.svg_inherited_flags && 0096 svg_noninherited_flags == o.svg_noninherited_flags); 0097 } 0098 0099 bool SVGRenderStyle::inheritedNotEqual(const SVGRenderStyle *other) const 0100 { 0101 return (fill != other->fill 0102 || stroke != other->stroke 0103 || markers != other->markers 0104 || text != other->text 0105 || svg_inherited_flags != other->svg_inherited_flags); 0106 } 0107 0108 void SVGRenderStyle::inheritFrom(const SVGRenderStyle *svgInheritParent) 0109 { 0110 if (!svgInheritParent) { 0111 return; 0112 } 0113 0114 fill = svgInheritParent->fill; 0115 stroke = svgInheritParent->stroke; 0116 markers = svgInheritParent->markers; 0117 text = svgInheritParent->text; 0118 0119 svg_inherited_flags = svgInheritParent->svg_inherited_flags; 0120 } 0121 0122 float SVGRenderStyle::cssPrimitiveToLength(const RenderObject *item, DOM::CSSValueImpl *value, float defaultValue) 0123 { 0124 Q_UNUSED(item); 0125 DOM::CSSPrimitiveValueImpl *primitive = static_cast<DOM::CSSPrimitiveValueImpl *>(value); 0126 if (!primitive) { 0127 return defaultValue; 0128 } 0129 0130 /*unsigned short cssType = (primitive ? primitive->primitiveType() : (unsigned short) DOM::CSSPrimitiveValue::CSS_UNKNOWN); 0131 if (!(cssType > DOM::CSSPrimitiveValue::CSS_UNKNOWN && cssType <= DOM::CSSPrimitiveValue::CSS_PC)) 0132 return defaultValue; 0133 0134 if (cssType == DOM::CSSPrimitiveValue::CSS_PERCENTAGE) { 0135 SVGStyledElement* element = static_cast<SVGStyledElement*>(item->element()); 0136 SVGElement* viewportElement = (element ? element->viewportElement() : 0); 0137 if (viewportElement) { 0138 float result = primitive->getFloatValue() / 100.0f; 0139 return SVGLength::PercentageOfViewport(result, element, LengthModeOther); 0140 } 0141 } 0142 0143 return primitive->computeLengthFloat(const_cast<RenderStyle*>(item->style()));*/ 0144 return (primitive->floatValue() > 0 ? primitive->floatValue() : defaultValue); 0145 } 0146 0147 } 0148 0149 #endif // ENABLE(SVG) 0150