Home | History | Annotate | Download | only in graphics
      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:
     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 
     58     StrokeStyle style() const { return m_style; }
     59     void setStyle(StrokeStyle style) { m_style = style; }
     60 
     61     float thickness() const { return m_thickness; }
     62     void setThickness(float thickness) { m_thickness = thickness; }
     63 
     64     Color color() const { return m_color; }
     65     void setColor(const Color& color) { m_color = color; }
     66 
     67     Gradient* gradient() const { return m_gradient.get(); }
     68     void setGradient(const PassRefPtr<Gradient> gradient) { m_gradient = gradient; }
     69     void clearGradient() { m_gradient.clear(); }
     70 
     71     Pattern* pattern() const { return m_pattern.get(); }
     72     void setPattern(const PassRefPtr<Pattern> pattern) { m_pattern = pattern; }
     73     void clearPattern() { m_pattern.clear(); }
     74 
     75     LineCap lineCap() const { return (LineCap)m_lineCap; }
     76     void setLineCap(LineCap cap) { m_lineCap = (SkPaint::Cap)cap; }
     77 
     78     LineJoin lineJoin() const { return (LineJoin)m_lineJoin; }
     79     void setLineJoin(LineJoin join) { m_lineJoin = (SkPaint::Join)join; }
     80 
     81     float miterLimit() const { return m_miterLimit; }
     82     void setMiterLimit(float miterLimit) { m_miterLimit = miterLimit; }
     83 
     84     void setLineDash(const DashArray&, float);
     85 
     86     // Sets everything on the paint except the pattern, gradient and color.
     87     // If a non-zero length is provided, the number of dashes/dots on a
     88     // dashed/dotted line will be adjusted to start and end that length with a
     89     // dash/dot.
     90     void setupPaint(SkPaint*, int length = 0) const;
     91 
     92     // Setup any DashPathEffect on the paint. If a non-zero length is provided,
     93     // and no line dash has been set, the number of dashes/dots on a dashed/dotted
     94     // line will be adjusted to start and end that length with a dash/dot.
     95     void setupPaintDashPathEffect(SkPaint*, int) const;
     96 
     97 private:
     98     StrokeStyle m_style;
     99     float m_thickness;
    100     Color m_color;
    101     RefPtr<Gradient> m_gradient;
    102     RefPtr<Pattern> m_pattern;
    103     SkPaint::Cap m_lineCap;
    104     SkPaint::Join m_lineJoin;
    105     float m_miterLimit;
    106     RefPtr<SkDashPathEffect> m_dash;
    107 };
    108 
    109 } // namespace WebCore
    110 
    111 #endif // StrokeData_h
    112