KHtml

SVGRenderStyle.h
1 /*
2  Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <[email protected]>
3  2004, 2005 Rob Buis <[email protected]>
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 #include "css/css_svgvalueimpl.h"
28 #include "platform/graphics/GraphicsTypes.h"
29 #include "platform/graphics/Path.h"
30 #include "rendering/DataRef.h"
31 #include "SVGRenderStyleDefs.h"
32 
33 #include <stdint.h>
34 
35 using DOM::DOMString;
36 
37 namespace khtml
38 {
39 class SVGRenderStyle : public RefCounted<SVGRenderStyle>
40 {
41 public:
42  static PassRefPtr<SVGRenderStyle> create()
43  {
44  return adoptRef(new SVGRenderStyle);
45  }
46  PassRefPtr<SVGRenderStyle> copy() const
47  {
48  return adoptRef(new SVGRenderStyle(*this));
49  }
50  ~SVGRenderStyle();
51 
52  bool inheritedNotEqual(const SVGRenderStyle *) const;
53  void inheritFrom(const SVGRenderStyle *);
54 
55  bool operator==(const SVGRenderStyle &) const;
56  bool operator!=(const SVGRenderStyle &o) const
57  {
58  return !(*this == o);
59  }
60 
61  // SVG CSS Properties
62  SVG_RS_DEFINE_ATTRIBUTE(EAlignmentBaseline, AlignmentBaseline, alignmentBaseline, AB_AUTO)
63  SVG_RS_DEFINE_ATTRIBUTE(EDominantBaseline, DominantBaseline, dominantBaseline, DB_AUTO)
64  SVG_RS_DEFINE_ATTRIBUTE(EBaselineShift, BaselineShift, baselineShift, BS_BASELINE)
65 
66  SVG_RS_DEFINE_ATTRIBUTE_INHERITED(LineCap, CapStyle, capStyle, ButtCap)
67  SVG_RS_DEFINE_ATTRIBUTE_INHERITED(WindRule, ClipRule, clipRule, RULE_NONZERO)
68  SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EColorInterpolation, ColorInterpolation, colorInterpolation, CI_SRGB)
69  SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EColorInterpolation, ColorInterpolationFilters, colorInterpolationFilters, CI_LINEARRGB)
70  SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EColorRendering, ColorRendering, colorRendering, CR_AUTO)
71  SVG_RS_DEFINE_ATTRIBUTE_INHERITED(WindRule, FillRule, fillRule, RULE_NONZERO)
72  SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EImageRendering, ImageRendering, imageRendering, IR_AUTO)
73  SVG_RS_DEFINE_ATTRIBUTE_INHERITED(LineJoin, JoinStyle, joinStyle, MiterJoin)
74  SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EPointerEvents, PointerEvents, pointerEvents, PE_VISIBLE_PAINTED)
75  SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EShapeRendering, ShapeRendering, shapeRendering, SR_AUTO)
76  SVG_RS_DEFINE_ATTRIBUTE_INHERITED(ETextAnchor, TextAnchor, textAnchor, TA_START)
77  SVG_RS_DEFINE_ATTRIBUTE_INHERITED(ETextRendering, TextRendering, textRendering, TR_AUTO)
78  SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EWritingMode, WritingMode, writingMode, WM_LRTB)
79  SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EGlyphOrientation, GlyphOrientationHorizontal, glyphOrientationHorizontal, GO_0DEG)
80  SVG_RS_DEFINE_ATTRIBUTE_INHERITED(EGlyphOrientation, GlyphOrientationVertical, glyphOrientationVertical, GO_AUTO)
81 
82  // SVG CSS Properties (using DataRef's)
83  SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, fill, opacity, FillOpacity, fillOpacity, 1.0f)
84  SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(SVGPaintImpl, fill, paint, FillPaint, fillPaint, SVGPaintImpl::defaultFill())
85 
86  SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, stroke, opacity, StrokeOpacity, strokeOpacity, 1.0f)
87  SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(SVGPaintImpl, stroke, paint, StrokePaint, strokePaint, SVGPaintImpl::defaultStroke())
88  SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(CSSValueListImpl, stroke, dashArray, StrokeDashArray, strokeDashArray, nullptr)
89  SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, stroke, miterLimit, StrokeMiterLimit, strokeMiterLimit, 4.0f)
90 
91  SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(CSSValueImpl, stroke, width, StrokeWidth, strokeWidth, nullptr)
92  SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(CSSValueImpl, stroke, dashOffset, StrokeDashOffset, strokeDashOffset, nullptr);
93 
94  SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(CSSValueImpl, text, kerning, Kerning, kerning, nullptr)
95 
96  SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, stops, opacity, StopOpacity, stopOpacity, 1.0f)
97  SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(QColor, stops, color, StopColor, stopColor, QColor(0, 0, 0))
98 
99  SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(DOMString, clip, clipPath, ClipPath, clipPath, DOMString())
100  SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(DOMString, mask, maskElement, MaskElement, maskElement, DOMString())
101  SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(DOMString, markers, startMarker, StartMarker, startMarker, DOMString())
102  SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(DOMString, markers, midMarker, MidMarker, midMarker, DOMString())
103  SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(DOMString, markers, endMarker, EndMarker, endMarker, DOMString())
104 
105  SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(DOMString, misc, filter, Filter, filter, DOMString())
106  SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(float, misc, floodOpacity, FloodOpacity, floodOpacity, 1.0f)
107  SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(QColor, misc, floodColor, FloodColor, floodColor, QColor(0, 0, 0))
108  SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL(QColor, misc, lightingColor, LightingColor, lightingColor, QColor(255, 255, 255))
109  SVG_RS_DEFINE_ATTRIBUTE_DATAREF_WITH_INITIAL_REFCOUNTED(CSSValueImpl, misc, baselineShiftValue, BaselineShiftValue, baselineShiftValue, nullptr)
110 
111  // convenience
112  bool hasStroke() const
113  {
114  return (strokePaint()->paintType() != SVGPaintImpl::SVG_PAINTTYPE_NONE);
115  }
116  bool hasFill() const
117  {
118  return (fillPaint()->paintType() != SVGPaintImpl::SVG_PAINTTYPE_NONE);
119  }
120 
121  static float cssPrimitiveToLength(const RenderObject *, CSSValueImpl *, float defaultValue = 0.0f);
122 
123 protected:
124  // inherit
125  struct InheritedFlags {
126  bool operator==(const InheritedFlags &other) const
127  {
128  return (_colorRendering == other._colorRendering) &&
129  (_imageRendering == other._imageRendering) &&
130  (_shapeRendering == other._shapeRendering) &&
131  (_textRendering == other._textRendering) &&
132  (_clipRule == other._clipRule) &&
133  (_fillRule == other._fillRule) &&
134  (_capStyle == other._capStyle) &&
135  (_joinStyle == other._joinStyle) &&
136  (_textAnchor == other._textAnchor) &&
137  (_colorInterpolation == other._colorInterpolation) &&
138  (_colorInterpolationFilters == other._colorInterpolationFilters) &&
139  (_pointerEvents == other._pointerEvents) &&
140  (_writingMode == other._writingMode) &&
141  (_glyphOrientationHorizontal == other._glyphOrientationHorizontal) &&
142  (_glyphOrientationVertical == other._glyphOrientationVertical);
143  }
144 
145  bool operator!=(const InheritedFlags &other) const
146  {
147  return !(*this == other);
148  }
149 
150  unsigned _colorRendering : 2; // EColorRendering
151  unsigned _imageRendering : 2; // EImageRendering
152  unsigned _shapeRendering : 2; // EShapeRendering
153  unsigned _textRendering : 2; // ETextRendering
154  unsigned _clipRule : 1; // WindRule
155  unsigned _fillRule : 1; // WindRule
156  unsigned _capStyle : 2; // LineCap
157  unsigned _joinStyle : 2; // LineJoin
158  unsigned _textAnchor : 2; // ETextAnchor
159  unsigned _colorInterpolation : 2; // EColorInterpolation
160  unsigned _colorInterpolationFilters : 2; // EColorInterpolation
161  unsigned _pointerEvents : 4; // EPointerEvents
162  unsigned _writingMode : 3; // EWritingMode
163  unsigned _glyphOrientationHorizontal : 3; // EGlyphOrientation
164  unsigned _glyphOrientationVertical : 3; // EGlyphOrientation
165  } svg_inherited_flags;
166 
167  // don't inherit
168  struct NonInheritedFlags {
169  // 32 bit non-inherited, don't add to the struct, or the operator will break.
170  bool operator==(const NonInheritedFlags &other) const
171  {
172  return _niflags == other._niflags;
173  }
174  bool operator!=(const NonInheritedFlags &other) const
175  {
176  return _niflags != other._niflags;
177  }
178 
179  union {
180  struct {
181  unsigned _alignmentBaseline : 4; // EAlignmentBaseline
182  unsigned _dominantBaseline : 4; // EDominantBaseline
183  unsigned _baselineShift : 2; // EBaselineShift
184  // 22 bits unused
185  } f;
186  uint32_t _niflags;
187  };
188  } svg_noninherited_flags;
189 
190  // inherited attributes
191  khtml::DataRef<StyleFillData> fill;
192  DataRef<StyleStrokeData> stroke;
193  DataRef<StyleMarkerData> markers;
194  DataRef<StyleTextData> text;
195 
196  // non-inherited attributes
197  DataRef<StyleStopData> stops;
198  DataRef<StyleClipData> clip;
199  DataRef<StyleMaskData> mask;
200  DataRef<StyleMiscData> misc;
201 
202 private:
203  enum CreateDefaultType { CreateDefault };
204 
205 public:
206  SVGRenderStyle();
207  SVGRenderStyle(const SVGRenderStyle &);
208 private:
209  SVGRenderStyle(CreateDefaultType); // Used to create the default style.
210 
211  void setBitDefaults()
212  {
213  svg_inherited_flags._clipRule = initialClipRule();
214  svg_inherited_flags._colorRendering = initialColorRendering();
215  svg_inherited_flags._fillRule = initialFillRule();
216  svg_inherited_flags._imageRendering = initialImageRendering();
217  svg_inherited_flags._shapeRendering = initialShapeRendering();
218  svg_inherited_flags._textRendering = initialTextRendering();
219  svg_inherited_flags._textAnchor = initialTextAnchor();
220  svg_inherited_flags._capStyle = initialCapStyle();
221  svg_inherited_flags._joinStyle = initialJoinStyle();
222  svg_inherited_flags._colorInterpolation = initialColorInterpolation();
223  svg_inherited_flags._colorInterpolationFilters = initialColorInterpolationFilters();
224  svg_inherited_flags._pointerEvents = initialPointerEvents();
225  svg_inherited_flags._writingMode = initialWritingMode();
226  svg_inherited_flags._glyphOrientationHorizontal = initialGlyphOrientationHorizontal();
227  svg_inherited_flags._glyphOrientationVertical = initialGlyphOrientationVertical();
228 
229  svg_noninherited_flags._niflags = 0;
230  svg_noninherited_flags.f._alignmentBaseline = initialAlignmentBaseline();
231  svg_noninherited_flags.f._dominantBaseline = initialDominantBaseline();
232  svg_noninherited_flags.f._baselineShift = initialBaselineShift();
233  }
234 };
235 
236 } // namespace khtml
237 
238 #endif // SVGRenderStyle_h
239 
QAction * create(StandardAction id, const QObject *recvr, Func slot, QObject *parent)
This file is part of the HTML rendering engine for KDE.
bool operator==(const Qt3DRender::QGraphicsApiFilter &reference, const Qt3DRender::QGraphicsApiFilter &sample)
KIOCORE_EXPORT CopyJob * copy(const QUrl &src, const QUrl &dest, JobFlags flags=DefaultFlags)
This class implements the basic string we use in the DOM.
Definition: dom_string.h:44
bool operator!=(const Qt3DRender::QGraphicsApiFilter &reference, const Qt3DRender::QGraphicsApiFilter &sample)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 25 2021 22:48:23 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.