WebCore/platform/graphics/Path.h
changeset 0 4f2f89ce4247
child 2 303757a437d3
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     1 /*
       
     2  * Copyright (C) 2003, 2006, 2009 Apple Inc. All rights reserved.
       
     3  *               2006 Rob Buis <buis@kde.org>
       
     4  * Copyright (C) 2007-2008 Torch Mobile, Inc.
       
     5  *
       
     6  * Redistribution and use in source and binary forms, with or without
       
     7  * modification, are permitted provided that the following conditions
       
     8  * are met:
       
     9  * 1. Redistributions of source code must retain the above copyright
       
    10  *    notice, this list of conditions and the following disclaimer.
       
    11  * 2. Redistributions in binary form must reproduce the above copyright
       
    12  *    notice, this list of conditions and the following disclaimer in the
       
    13  *    documentation and/or other materials provided with the distribution.
       
    14  *
       
    15  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
       
    16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
       
    17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
       
    18  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
       
    19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
       
    20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
       
    21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
       
    22  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
       
    23  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
       
    26  */
       
    27 
       
    28 #ifndef Path_h
       
    29 #define Path_h
       
    30 
       
    31 #include <algorithm>
       
    32 #include <wtf/FastAllocBase.h>
       
    33 
       
    34 #if PLATFORM(CG)
       
    35 typedef struct CGPath PlatformPath;
       
    36 #elif PLATFORM(OPENVG)
       
    37 namespace WebCore {
       
    38 class PlatformPathOpenVG;
       
    39 }
       
    40 typedef WebCore::PlatformPathOpenVG PlatformPath;
       
    41 #elif PLATFORM(QT)
       
    42 #include <qpainterpath.h>
       
    43 typedef QPainterPath PlatformPath;
       
    44 #elif PLATFORM(WX) && USE(WXGC)
       
    45 class wxGraphicsPath;
       
    46 typedef wxGraphicsPath PlatformPath;
       
    47 #elif PLATFORM(CAIRO)
       
    48 namespace WebCore {
       
    49     struct CairoPath;
       
    50 }
       
    51 typedef WebCore::CairoPath PlatformPath;
       
    52 #elif PLATFORM(SKIA)
       
    53 class SkPath;
       
    54 typedef SkPath PlatformPath;
       
    55 #elif PLATFORM(HAIKU)
       
    56 class BRegion;
       
    57 typedef BRegion PlatformPath;
       
    58 #elif OS(WINCE)
       
    59 namespace WebCore {
       
    60     class PlatformPath;
       
    61 }
       
    62 #else
       
    63 typedef void PlatformPath;
       
    64 #endif
       
    65 
       
    66 #if PLATFORM(QT)
       
    67 /* QPainterPath is valued based */
       
    68 typedef PlatformPath PlatformPathPtr;
       
    69 #else
       
    70 typedef PlatformPath* PlatformPathPtr;
       
    71 #endif
       
    72 
       
    73 namespace WebCore {
       
    74 
       
    75     class AffineTransform;
       
    76     class FloatPoint;
       
    77     class FloatRect;
       
    78     class FloatSize;
       
    79     class GraphicsContext;
       
    80     class String;
       
    81     class StrokeStyleApplier;
       
    82 
       
    83     enum WindRule {
       
    84         RULE_NONZERO = 0,
       
    85         RULE_EVENODD = 1
       
    86     };
       
    87 
       
    88     enum PathElementType {
       
    89         PathElementMoveToPoint,
       
    90         PathElementAddLineToPoint,
       
    91         PathElementAddQuadCurveToPoint,
       
    92         PathElementAddCurveToPoint,
       
    93         PathElementCloseSubpath
       
    94     };
       
    95 
       
    96     struct PathElement {
       
    97         PathElementType type;
       
    98         FloatPoint* points;
       
    99     };
       
   100 
       
   101     typedef void (*PathApplierFunction)(void* info, const PathElement*);
       
   102 
       
   103     class Path : public FastAllocBase {
       
   104     public:
       
   105         Path();
       
   106         ~Path();
       
   107 
       
   108         Path(const Path&);
       
   109         Path& operator=(const Path&);
       
   110 
       
   111         void swap(Path& other) { std::swap(m_path, other.m_path); }
       
   112 
       
   113         bool contains(const FloatPoint&, WindRule rule = RULE_NONZERO) const;
       
   114         bool strokeContains(StrokeStyleApplier*, const FloatPoint&) const;
       
   115         FloatRect boundingRect() const;
       
   116         FloatRect strokeBoundingRect(StrokeStyleApplier* = 0);
       
   117         
       
   118         float length();
       
   119         FloatPoint pointAtLength(float length, bool& ok);
       
   120         float normalAngleAtLength(float length, bool& ok);
       
   121 
       
   122         void clear();
       
   123         bool isEmpty() const;
       
   124         // Gets the current point of the current path, which is conceptually the final point reached by the path so far.
       
   125         // Note the Path can be empty (isEmpty() == true) and still have a current point.
       
   126         bool hasCurrentPoint() const;
       
   127         FloatPoint currentPoint() const;
       
   128 
       
   129         void moveTo(const FloatPoint&);
       
   130         void addLineTo(const FloatPoint&);
       
   131         void addQuadCurveTo(const FloatPoint& controlPoint, const FloatPoint& endPoint);
       
   132         void addBezierCurveTo(const FloatPoint& controlPoint1, const FloatPoint& controlPoint2, const FloatPoint& endPoint);
       
   133         void addArcTo(const FloatPoint&, const FloatPoint&, float radius);
       
   134         void closeSubpath();
       
   135 
       
   136         void addArc(const FloatPoint&, float radius, float startAngle, float endAngle, bool anticlockwise);
       
   137         void addRect(const FloatRect&);
       
   138         void addEllipse(const FloatRect&);
       
   139 
       
   140         void translate(const FloatSize&);
       
   141 
       
   142         String debugString() const;
       
   143 
       
   144         PlatformPathPtr platformPath() const { return m_path; }
       
   145 
       
   146         static Path createRoundedRectangle(const FloatRect&, const FloatSize& roundingRadii);
       
   147         static Path createRoundedRectangle(const FloatRect&, const FloatSize& topLeftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& bottomRightRadius);
       
   148         static Path createRectangle(const FloatRect&);
       
   149         static Path createEllipse(const FloatPoint& center, float rx, float ry);
       
   150         static Path createCircle(const FloatPoint& center, float r);
       
   151         static Path createLine(const FloatPoint&, const FloatPoint&);
       
   152 
       
   153         void apply(void* info, PathApplierFunction) const;
       
   154         void transform(const AffineTransform&);
       
   155 
       
   156     private:
       
   157         PlatformPathPtr m_path;
       
   158     };
       
   159 
       
   160 }
       
   161 
       
   162 #endif