• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2013 Google Inc. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
7 //    * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 //    * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
12 // distribution.
13 //    * Neither the name of Google Inc. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 #ifndef StrokeData_h
30 #define StrokeData_h
31 
32 #include "platform/PlatformExport.h"
33 #include "platform/graphics/DashArray.h"
34 #include "platform/graphics/Gradient.h"
35 #include "platform/graphics/GraphicsTypes.h"
36 #include "platform/graphics/Pattern.h"
37 #include "third_party/skia/include/core/SkColorPriv.h"
38 #include "third_party/skia/include/effects/SkDashPathEffect.h"
39 #include "wtf/PassRefPtr.h"
40 #include "wtf/RefPtr.h"
41 
42 namespace WebCore {
43 
44 // Encapsulates stroke painting information.
45 // It is pulled out of GraphicsContextState to enable other methods to use it.
46 class PLATFORM_EXPORT StrokeData {
47 public:
StrokeData()48     StrokeData()
49         : m_style(SolidStroke)
50         , m_thickness(0)
51         , m_color(Color::black)
52         , m_lineCap(SkPaint::kDefault_Cap)
53         , m_lineJoin(SkPaint::kDefault_Join)
54         , m_miterLimit(4)
55     {
56     }
57 
style()58     StrokeStyle style() const { return m_style; }
setStyle(const StrokeStyle style)59     void setStyle(const StrokeStyle style) { m_style = style; }
60 
thickness()61     float thickness() const { return m_thickness; }
setThickness(const float thickness)62     void setThickness(const float thickness) { m_thickness = thickness; }
63 
color()64     Color color() const { return m_color; }
setColor(const Color & color)65     void setColor(const Color& color) { m_color = color; }
66 
gradient()67     Gradient* gradient() const { return m_gradient.get(); }
setGradient(const PassRefPtr<Gradient> gradient)68     void setGradient(const PassRefPtr<Gradient> gradient) { m_gradient = gradient; }
clearGradient()69     void clearGradient() { m_gradient.clear(); }
70 
pattern()71     Pattern* pattern() const { return m_pattern.get(); }
setPattern(const PassRefPtr<Pattern> pattern)72     void setPattern(const PassRefPtr<Pattern> pattern) { m_pattern = pattern; }
clearPattern()73     void clearPattern() { m_pattern.clear(); }
74 
lineCap()75     LineCap lineCap() const { return (LineCap)m_lineCap; }
setLineCap(const LineCap cap)76     void setLineCap(const LineCap cap) { m_lineCap = (SkPaint::Cap)cap; }
77 
lineJoin()78     LineJoin lineJoin() const { return (LineJoin)m_lineJoin; }
setLineJoin(const LineJoin join)79     void setLineJoin(const LineJoin join) { m_lineJoin = (SkPaint::Join)join; }
80 
miterLimit()81     float miterLimit() const { return m_miterLimit; }
setMiterLimit(const float miterLimit)82     void setMiterLimit(const float miterLimit) { m_miterLimit = miterLimit; }
83 
84     void setLineDash(const DashArray&, const float);
85 
86     // Sets everything on the paint except the pattern, gradient and color.
87     // GraphicsContext::setupShader does that. Returns a float representing the
88     // effective width of the pen. If a non-zero length is provided, the
89     // number of dashes/dots on a dashed/dotted line will be adjusted to
90     // start and end that length with a dash/dot.
91     float setupPaint(SkPaint*, int length = 0) const;
92 
93 private:
94     StrokeStyle m_style;
95     float m_thickness;
96     Color m_color;
97     RefPtr<Gradient> m_gradient;
98     RefPtr<Pattern> m_pattern;
99     SkPaint::Cap m_lineCap;
100     SkPaint::Join m_lineJoin;
101     float m_miterLimit;
102     RefPtr<SkDashPathEffect> m_dash;
103 };
104 
105 } // namespace WebCore
106 
107 #endif // StrokeData_h
108