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
42namespace blink {
43
44// Encapsulates stroke geometry information.
45// It is pulled out of GraphicsContextState to enable other methods to use it.
46class PLATFORM_EXPORT StrokeData {
47public:
48    StrokeData()
49        : m_style(SolidStroke)
50        , m_thickness(0)
51        , m_lineCap(SkPaint::kDefault_Cap)
52        , m_lineJoin(SkPaint::kDefault_Join)
53        , m_miterLimit(4)
54    {
55    }
56
57    StrokeStyle style() const { return m_style; }
58    void setStyle(StrokeStyle style) { m_style = style; }
59
60    float thickness() const { return m_thickness; }
61    void setThickness(float thickness) { m_thickness = thickness; }
62
63    LineCap lineCap() const { return (LineCap)m_lineCap; }
64    void setLineCap(LineCap cap) { m_lineCap = (SkPaint::Cap)cap; }
65
66    LineJoin lineJoin() const { return (LineJoin)m_lineJoin; }
67    void setLineJoin(LineJoin join) { m_lineJoin = (SkPaint::Join)join; }
68
69    float miterLimit() const { return m_miterLimit; }
70    void setMiterLimit(float miterLimit) { m_miterLimit = miterLimit; }
71
72    void setLineDash(const DashArray&, float);
73
74    // Sets everything on the paint except the pattern, gradient and color.
75    // If a non-zero length is provided, the number of dashes/dots on a
76    // dashed/dotted line will be adjusted to start and end that length with a
77    // dash/dot.
78    void setupPaint(SkPaint*, int length = 0) const;
79
80    // Setup any DashPathEffect on the paint. If a non-zero length is provided,
81    // and no line dash has been set, the number of dashes/dots on a dashed/dotted
82    // line will be adjusted to start and end that length with a dash/dot.
83    void setupPaintDashPathEffect(SkPaint*, int) const;
84
85private:
86    StrokeStyle m_style;
87    float m_thickness;
88    SkPaint::Cap m_lineCap;
89    SkPaint::Join m_lineJoin;
90    float m_miterLimit;
91    RefPtr<SkDashPathEffect> m_dash;
92};
93
94} // namespace blink
95
96#endif // StrokeData_h
97