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