2 Copyright (C) 2004, 2005 Nikolas Zimmermann <wildfox@kde.org>
3 2004, 2005 Rob Buis <buis@kde.org>
4 Copyright (C) 2005, 2006 Apple Computer, Inc.
6 This file is part of the KDE project
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.
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.
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., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.
24 #ifndef KSVG_SVGRenderStyle_H
25 #define KSVG_SVGRenderStyle_H
29 #include <ksvg2/svg/SVGPaint.h>
30 #include <ksvg2/css/SVGRenderStyleDefs.h>
31 #include <wtf/Platform.h>
34 typedef unsigned long long uint64_t;
37 // Helper macros for SVG's 'RenderStyle' properties
38 #define RS_DEFINE_ATTRIBUTE(Data, Type, Name, Initial) \
39 void set##Type(Data val) { noninherited_flags.f._##Name = val; } \
40 Data Name() const { return (Data) noninherited_flags.f._##Name; } \
41 static Data initial##Type() { return Initial; }
43 #define RS_DEFINE_ATTRIBUTE_INHERITED(Data, Type, Name, Initial) \
44 void set##Type(Data val) { inherited_flags.f._##Name = val; } \
45 Data Name() const { return (Data) inherited_flags.f._##Name; } \
46 static Data initial##Type() { return Initial; }
48 #define RS_DEFINE_ATTRIBUTE_DATAREF(Data, Group, Variable, Type, Name) \
49 Data Name() const { return Group->Variable; } \
50 void set##Type(Data obj) { RS_SET_VARIABLE(Group, Variable, obj) }
52 #define RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(Data, Group, Variable, Type, Name, Initial) \
53 RS_DEFINE_ATTRIBUTE_DATAREF(Data, Group, Variable, Type, Name) \
54 static Data initial##Type() { return Initial; }
56 #define RS_SET_VARIABLE(Group, Variable, Value) \
57 if(!(Group->Variable == Value)) \
58 Group.access()->Variable = Value;
62 class SVGRenderStyle : public Shared<SVGRenderStyle> {
65 SVGRenderStyle(bool); // Used to create the default style.
66 SVGRenderStyle(const SVGRenderStyle &other);
69 bool inheritedNotEqual(const SVGRenderStyle *other) const;
71 void inheritFrom(const SVGRenderStyle *inheritParent);
73 bool operator==(const SVGRenderStyle& o) const;
74 bool operator!=(const SVGRenderStyle& o) const { return !(*this == o); }
77 SVG_RS_DEFINE_ATTRIBUTE(EAlignmentBaseline, AlignmentBaseline, alignmentBaseline, AB_AUTO)
78 SVG_RS_DEFINE_ATTRIBUTE(EDominantBaseline, DominantBaseline, dominantBaseline, DB_AUTO)
80 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(ECapStyle, CapStyle, capStyle, CS_BUTT)
81 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(WindRule, ClipRule, clipRule, RULE_NONZERO)
82 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EColorInterpolation, ColorInterpolation, colorInterpolation, CI_SRGB)
83 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EColorInterpolation, ColorInterpolationFilters, colorInterpolationFilters, CI_LINEARRGB)
84 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EColorRendering, ColorRendering, colorRendering, CR_AUTO)
85 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(WindRule, FillRule, fillRule, RULE_NONZERO)
86 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EImageRendering, ImageRendering, imageRendering, IR_AUTO)
87 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EJoinStyle, JoinStyle, joinStyle, JS_MITER)
88 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EPointerEvents, PointerEvents, pointerEvents, PE_VISIBLE_PAINTED)
89 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EShapeRendering, ShapeRendering, shapeRendering, SR_AUTO)
90 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(ETextAnchor, TextAnchor, textAnchor, TA_START)
91 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(ETextRendering, TextRendering, textRendering, TR_AUTO)
92 SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EWritingMode, WritingMode, writingMode, WM_LRTB)
94 // SVG CSS Properties (using DataRef's)
95 RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, fill, opacity, FillOpacity, fillOpacity, 1.0)
96 RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(SVGPaint *, fill, paint, FillPaint, fillPaint, 0)
98 RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, stroke, opacity, StrokeOpacity, strokeOpacity, 1.0)
99 RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(SVGPaint *, stroke, paint, StrokePaint, strokePaint, 0)
100 RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(CSSValueList *, stroke, dashArray, StrokeDashArray, strokeDashArray, 0)
101 RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(unsigned int, stroke, miterLimit, StrokeMiterLimit, strokeMiterLimit, 4)
103 RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(CSSValue *, stroke, width, StrokeWidth, strokeWidth, 0)
104 RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(CSSValue *, stroke, dashOffset, StrokeDashOffset, strokeDashOffset, 0);
106 RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, stops, opacity, StopOpacity, stopOpacity, 1.0)
107 RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(Color, stops, color, StopColor, stopColor, Color(0, 0, 0))
109 RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(String, clip, clipPath, ClipPath, clipPath, String())
110 RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(String, mask, maskElement, MaskElement, maskElement, String())
111 RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(String, markers, startMarker, StartMarker, startMarker, String())
112 RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(String, markers, midMarker, MidMarker, midMarker, String())
113 RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(String, markers, endMarker, EndMarker, endMarker, String())
115 RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(String, misc, filter, Filter, filter, String())
116 RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, misc, floodOpacity, FloodOpacity, floodOpacity, 1.0)
117 RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(Color, misc, floodColor, FloodColor, floodColor, Color(0, 0, 0))
121 struct InheritedFlags {
122 // 64 bit inherited, don't add to the struct, or the operator will break.
123 bool operator==(const InheritedFlags &other) const { return _iflags == other._iflags; }
124 bool operator!=(const InheritedFlags &other) const { return _iflags != other._iflags; }
128 unsigned _colorRendering : 2; // EColorRendering
129 unsigned _imageRendering : 2; // EImageRendering
130 unsigned _shapeRendering : 2; // EShapeRendering
131 unsigned _textRendering : 2; // ETextRendering
132 unsigned _clipRule : 1; // WindRule
133 unsigned _fillRule : 1; // WindRule
134 unsigned _capStyle : 2; // ECapStyle
135 unsigned _joinStyle : 2; // EJoinStyle
136 unsigned _textAnchor : 2; // ETextAnchor
137 unsigned _colorInterpolation : 2; // EColorInterpolation
138 unsigned _colorInterpolationFilters : 2; // EColorInterpolation
139 unsigned _pointerEvents : 4; // EPointerEvents
140 unsigned _writingMode : 3; // EWritingMode
145 } svg_inherited_flags;
148 struct NonInheritedFlags {
149 // 64 bit non-inherited, don't add to the struct, or the operator will break.
150 bool operator==(const NonInheritedFlags &other) const { return _niflags == other._niflags; }
151 bool operator!=(const NonInheritedFlags &other) const { return _niflags != other._niflags; }
155 unsigned _alignmentBaseline : 4; // EAlignmentBaseline
156 unsigned _dominantBaseline : 4; // EDominantBaseline
161 } svg_noninherited_flags;
163 // inherited attributes
164 DataRef<StyleFillData> fill;
165 DataRef<StyleStrokeData> stroke;
166 DataRef<StyleStopData> stops;
167 DataRef<StyleMiscData> misc;
168 DataRef<StyleMarkerData> markers;
170 // non-inherited attributes
171 DataRef<StyleClipData> clip;
172 DataRef<StyleMaskData> mask;
174 // static default style
175 static SVGRenderStyle *s_defaultStyle;
178 SVGRenderStyle(const SVGRenderStyle *) { }
180 void setBitDefaults()
182 svg_inherited_flags.f._clipRule = initialClipRule();
183 svg_inherited_flags.f._colorRendering = initialColorRendering();
184 svg_inherited_flags.f._fillRule = initialFillRule();
185 svg_inherited_flags.f._imageRendering = initialImageRendering();
186 svg_inherited_flags.f._shapeRendering = initialShapeRendering();
187 svg_inherited_flags.f._textRendering = initialTextRendering();
188 svg_inherited_flags.f._textAnchor = initialTextAnchor();
189 svg_inherited_flags.f._capStyle = initialCapStyle();
190 svg_inherited_flags.f._joinStyle = initialJoinStyle();
191 svg_inherited_flags.f._colorInterpolation = initialColorInterpolation();
192 svg_inherited_flags.f._colorInterpolationFilters = initialColorInterpolationFilters();
193 svg_inherited_flags.f._pointerEvents = initialPointerEvents();
194 svg_inherited_flags.f._writingMode = initialWritingMode();
196 svg_noninherited_flags.f._alignmentBaseline = initialAlignmentBaseline();
197 svg_noninherited_flags.f._dominantBaseline = initialDominantBaseline();
201 } // namespace WebCore
203 #endif // SVG_SUPPORT
204 #endif // KSVG_SVGRenderStyle_H