• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012, 2013 Adobe Systems Incorporated. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1.  Redistributions of source code must retain the above copyright
9  *     notice, this list of conditions and the following disclaimer.
10  * 2.  Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
18  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
19  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
23  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
24  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #ifndef Path2D_h
29 #define Path2D_h
30 
31 #include "bindings/core/v8/ScriptWrappable.h"
32 #include "core/html/canvas/CanvasPathMethods.h"
33 #include "core/svg/SVGMatrixTearOff.h"
34 #include "core/svg/SVGPathUtilities.h"
35 #include "platform/heap/Handle.h"
36 #include "platform/transforms/AffineTransform.h"
37 #include "wtf/PassRefPtr.h"
38 #include "wtf/RefCounted.h"
39 
40 namespace blink {
41 
42 class Path2D FINAL : public RefCountedWillBeGarbageCollectedFinalized<Path2D>, public CanvasPathMethods, public ScriptWrappable {
43     DEFINE_WRAPPERTYPEINFO();
44     WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
45     WTF_MAKE_NONCOPYABLE(Path2D);
46 public:
create()47     static PassRefPtrWillBeRawPtr<Path2D> create() { return adoptRefWillBeNoop(new Path2D); }
create(const String & pathData)48     static PassRefPtrWillBeRawPtr<Path2D> create(const String& pathData) { return adoptRefWillBeNoop(new Path2D(pathData)); }
create(Path2D * path)49     static PassRefPtrWillBeRawPtr<Path2D> create(Path2D* path) { return adoptRefWillBeNoop(new Path2D(path)); }
50 
create(const Path & path)51     static PassRefPtrWillBeRawPtr<Path2D> create(const Path& path) { return adoptRefWillBeNoop(new Path2D(path)); }
52 
path()53     const Path& path() const { return m_path; }
54 
addPath(Path2D * path)55     void addPath(Path2D* path)
56     {
57         addPath(path, 0);
58     }
59 
addPath(Path2D * path,SVGMatrixTearOff * transform)60     void addPath(Path2D* path, SVGMatrixTearOff* transform)
61     {
62         Path src = path->path();
63         m_path.addPath(src, transform ? transform->value() : AffineTransform(1, 0, 0, 1, 0, 0));
64     }
65 
~Path2D()66     virtual ~Path2D() { }
trace(Visitor *)67     void trace(Visitor*) { }
68 
69 private:
Path2D()70     Path2D() : CanvasPathMethods() { }
71 
Path2D(const Path & path)72     Path2D(const Path& path)
73         : CanvasPathMethods(path) { }
74 
Path2D(Path2D * path)75     Path2D(Path2D* path)
76         : CanvasPathMethods(path->path()) { }
77 
Path2D(const String & pathData)78     Path2D(const String& pathData)
79         : CanvasPathMethods()
80     {
81         buildPathFromString(pathData, m_path);
82     }
83 };
84 
85 } // namespace blink
86 
87 #endif // Path2D_h
88