1 /* 2 Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann (at) kde.org> 3 2004, 2005 Rob Buis <buis (at) kde.org> 4 Copyright (C) 2005, 2006 Apple Computer, Inc. 5 6 This library is free software; you can redistribute it and/or 7 modify it under the terms of the GNU Library General Public 8 License as published by the Free Software Foundation; either 9 version 2 of the License, or (at your option) any later version. 10 11 This library is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 Library General Public License for more details. 15 16 You should have received a copy of the GNU Library General Public License 17 along with this library; see the file COPYING.LIB. If not, write to 18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 Boston, MA 02110-1301, USA. 20 */ 21 22 #ifndef SVGRenderStyle_h 23 #define SVGRenderStyle_h 24 25 #if ENABLE(SVG) 26 #include "CSSValueList.h" 27 #include "DataRef.h" 28 #include "GraphicsTypes.h" 29 #include "SVGPaint.h" 30 #include "SVGRenderStyleDefs.h" 31 #include "ShadowData.h" 32 33 #include <wtf/Platform.h> 34 35 namespace WebCore { 36 37 class FloatRect; 38 class IntRect; 39 class RenderObject; 40 class RenderStyle; 41 42 class SVGRenderStyle : public RefCounted<SVGRenderStyle> { 43 public: 44 static PassRefPtr<SVGRenderStyle> create() { return adoptRef(new SVGRenderStyle); } 45 PassRefPtr<SVGRenderStyle> copy() const { return adoptRef(new SVGRenderStyle(*this));} 46 ~SVGRenderStyle(); 47 48 bool inheritedNotEqual(const SVGRenderStyle*) const; 49 void inheritFrom(const SVGRenderStyle*); 50 51 // FIXME: These functions should move to ShadowData. 52 void inflateForShadow(IntRect&) const; 53 void inflateForShadow(FloatRect&) const; 54 55 bool operator==(const SVGRenderStyle&) const; 56 bool operator!=(const SVGRenderStyle& o) const { return !(*this == o); } 57 58 // SVG CSS Properties 59 SVG_RS_DEFINE_ATTRIBUTE(EAlignmentBaseline, AlignmentBaseline, alignmentBaseline, AB_AUTO) 60 SVG_RS_DEFINE_ATTRIBUTE(EDominantBaseline, DominantBaseline, dominantBaseline, DB_AUTO) 61 SVG_RS_DEFINE_ATTRIBUTE(EBaselineShift, BaselineShift, baselineShift, BS_BASELINE) 62 63 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(LineCap, CapStyle, capStyle, ButtCap) 64 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(WindRule, ClipRule, clipRule, RULE_NONZERO) 65 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EColorInterpolation, ColorInterpolation, colorInterpolation, CI_SRGB) 66 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EColorInterpolation, ColorInterpolationFilters, colorInterpolationFilters, CI_LINEARRGB) 67 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EColorRendering, ColorRendering, colorRendering, CR_AUTO) 68 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(WindRule, FillRule, fillRule, RULE_NONZERO) 69 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EImageRendering, ImageRendering, imageRendering, IR_AUTO) 70 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(LineJoin, JoinStyle, joinStyle, MiterJoin) 71 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EShapeRendering, ShapeRendering, shapeRendering, SR_AUTO) 72 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(ETextAnchor, TextAnchor, textAnchor, TA_START) 73 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EWritingMode, WritingMode, writingMode, WM_LRTB) 74 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EGlyphOrientation, GlyphOrientationHorizontal, glyphOrientationHorizontal, GO_0DEG) 75 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EGlyphOrientation, GlyphOrientationVertical, glyphOrientationVertical, GO_AUTO) 76 77 // SVG CSS Properties (using DataRef's) 78 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, fill, opacity, FillOpacity, fillOpacity, 1.0f) 79 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(SVGPaint, fill, paint, FillPaint, fillPaint, SVGPaint::defaultFill()) 80 81 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, stroke, opacity, StrokeOpacity, strokeOpacity, 1.0f) 82 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(SVGPaint, stroke, paint, StrokePaint, strokePaint, SVGPaint::defaultStroke()) 83 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(CSSValueList, stroke, dashArray, StrokeDashArray, strokeDashArray, 0) 84 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, stroke, miterLimit, StrokeMiterLimit, strokeMiterLimit, 4.0f) 85 86 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(CSSValue, stroke, width, StrokeWidth, strokeWidth, 0) 87 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(CSSValue, stroke, dashOffset, StrokeDashOffset, strokeDashOffset, 0); 88 89 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(CSSValue, text, kerning, Kerning, kerning, 0) 90 91 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, stops, opacity, StopOpacity, stopOpacity, 1.0f) 92 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(Color, stops, color, StopColor, stopColor, Color(0, 0, 0)) 93 94 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(String, clip, clipPath, ClipPath, clipPath, String()) 95 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(String, mask, maskElement, MaskElement, maskElement, String()) 96 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(String, markers, startMarker, StartMarker, startMarker, String()) 97 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(String, markers, midMarker, MidMarker, midMarker, String()) 98 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(String, markers, endMarker, EndMarker, endMarker, String()) 99 100 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(String, misc, filter, Filter, filter, String()) 101 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, misc, floodOpacity, FloodOpacity, floodOpacity, 1.0f) 102 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(Color, misc, floodColor, FloodColor, floodColor, Color(0, 0, 0)) 103 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(Color, misc, lightingColor, LightingColor, lightingColor, Color(255, 255, 255)) 104 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(CSSValue, misc, baselineShiftValue, BaselineShiftValue, baselineShiftValue, 0) 105 106 SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_OWNPTR(ShadowData, shadowSVG, shadow, Shadow, shadow, 0) 107 108 // convenience 109 bool hasStroke() const { return (strokePaint()->paintType() != SVGPaint::SVG_PAINTTYPE_NONE); } 110 bool hasFill() const { return (fillPaint()->paintType() != SVGPaint::SVG_PAINTTYPE_NONE); } 111 112 static float cssPrimitiveToLength(const RenderObject*, CSSValue*, float defaultValue = 0.0f); 113 114 protected: 115 // inherit 116 struct InheritedFlags { 117 bool operator==(const InheritedFlags& other) const 118 { 119 return (_colorRendering == other._colorRendering) 120 && (_imageRendering == other._imageRendering) 121 && (_shapeRendering == other._shapeRendering) 122 && (_clipRule == other._clipRule) 123 && (_fillRule == other._fillRule) 124 && (_capStyle == other._capStyle) 125 && (_joinStyle == other._joinStyle) 126 && (_textAnchor == other._textAnchor) 127 && (_colorInterpolation == other._colorInterpolation) 128 && (_colorInterpolationFilters == other._colorInterpolationFilters) 129 && (_writingMode == other._writingMode) 130 && (_glyphOrientationHorizontal == other._glyphOrientationHorizontal) 131 && (_glyphOrientationVertical == other._glyphOrientationVertical); 132 } 133 134 bool operator!=(const InheritedFlags& other) const 135 { 136 return !(*this == other); 137 } 138 139 unsigned _colorRendering : 2; // EColorRendering 140 unsigned _imageRendering : 2; // EImageRendering 141 unsigned _shapeRendering : 2; // EShapeRendering 142 unsigned _clipRule : 1; // WindRule 143 unsigned _fillRule : 1; // WindRule 144 unsigned _capStyle : 2; // LineCap 145 unsigned _joinStyle : 2; // LineJoin 146 unsigned _textAnchor : 2; // ETextAnchor 147 unsigned _colorInterpolation : 2; // EColorInterpolation 148 unsigned _colorInterpolationFilters : 2; // EColorInterpolation 149 unsigned _writingMode : 3; // EWritingMode 150 unsigned _glyphOrientationHorizontal : 3; // EGlyphOrientation 151 unsigned _glyphOrientationVertical : 3; // EGlyphOrientation 152 } svg_inherited_flags; 153 154 // don't inherit 155 struct NonInheritedFlags { 156 // 32 bit non-inherited, don't add to the struct, or the operator will break. 157 bool operator==(const NonInheritedFlags &other) const { return _niflags == other._niflags; } 158 bool operator!=(const NonInheritedFlags &other) const { return _niflags != other._niflags; } 159 160 union { 161 struct { 162 unsigned _alignmentBaseline : 4; // EAlignmentBaseline 163 unsigned _dominantBaseline : 4; // EDominantBaseline 164 unsigned _baselineShift : 2; // EBaselineShift 165 // 22 bits unused 166 } f; 167 uint32_t _niflags; 168 }; 169 } svg_noninherited_flags; 170 171 // inherited attributes 172 DataRef<StyleFillData> fill; 173 DataRef<StyleStrokeData> stroke; 174 DataRef<StyleMarkerData> markers; 175 DataRef<StyleTextData> text; 176 177 // non-inherited attributes 178 DataRef<StyleStopData> stops; 179 DataRef<StyleClipData> clip; 180 DataRef<StyleMaskData> mask; 181 DataRef<StyleMiscData> misc; 182 DataRef<StyleShadowSVGData> shadowSVG; 183 184 private: 185 enum CreateDefaultType { CreateDefault }; 186 187 SVGRenderStyle(); 188 SVGRenderStyle(const SVGRenderStyle&); 189 SVGRenderStyle(CreateDefaultType); // Used to create the default style. 190 191 void setBitDefaults() 192 { 193 svg_inherited_flags._clipRule = initialClipRule(); 194 svg_inherited_flags._colorRendering = initialColorRendering(); 195 svg_inherited_flags._fillRule = initialFillRule(); 196 svg_inherited_flags._imageRendering = initialImageRendering(); 197 svg_inherited_flags._shapeRendering = initialShapeRendering(); 198 svg_inherited_flags._textAnchor = initialTextAnchor(); 199 svg_inherited_flags._capStyle = initialCapStyle(); 200 svg_inherited_flags._joinStyle = initialJoinStyle(); 201 svg_inherited_flags._colorInterpolation = initialColorInterpolation(); 202 svg_inherited_flags._colorInterpolationFilters = initialColorInterpolationFilters(); 203 svg_inherited_flags._writingMode = initialWritingMode(); 204 svg_inherited_flags._glyphOrientationHorizontal = initialGlyphOrientationHorizontal(); 205 svg_inherited_flags._glyphOrientationVertical = initialGlyphOrientationVertical(); 206 207 svg_noninherited_flags._niflags = 0; 208 svg_noninherited_flags.f._alignmentBaseline = initialAlignmentBaseline(); 209 svg_noninherited_flags.f._dominantBaseline = initialDominantBaseline(); 210 svg_noninherited_flags.f._baselineShift = initialBaselineShift(); 211 } 212 }; 213 214 } // namespace WebCore 215 216 #endif // ENABLE(SVG) 217 #endif // SVGRenderStyle_h 218 219 // vim:ts=4:noet 220