Home | History | Annotate | Download | only in wince
      1 /*
      2  *  Copyright (C) 2007-2009 Torch Mobile, Inc.
      3  *
      4  *  This library is free software; you can redistribute it and/or
      5  *  modify it under the terms of the GNU Library General Public
      6  *  License as published by the Free Software Foundation; either
      7  *  version 2 of the License, or (at your option) any later version.
      8  *
      9  *  This library is distributed in the hope that it will be useful,
     10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12  *  Library General Public License for more details.
     13  *
     14  *  You should have received a copy of the GNU Library General Public License
     15  *  along with this library; see the file COPYING.LIB.  If not, write to
     16  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     17  *  Boston, MA 02110-1301, USA.
     18  */
     19 
     20 #ifndef PlatformPathWince_h
     21 #define PlatformPathWince_h
     22 
     23 namespace WebCore {
     24 
     25     class GraphicsContext;
     26 
     27     struct PathPoint {
     28         float m_x;
     29         float m_y;
     30         const float& x() const { return m_x; }
     31         const float& y() const { return m_y; }
     32         void set(float x, float y)
     33         {
     34             m_x = x;
     35             m_y = y;
     36         };
     37         operator FloatPoint() const { return FloatPoint(m_x, m_y); }
     38         void move(const FloatSize& offset)
     39         {
     40             m_x += offset.width();
     41             m_y += offset.height();
     42         }
     43         PathPoint& operator=(const FloatPoint& p)
     44         {
     45             m_x = p.x();
     46             m_y = p.y();
     47             return *this;
     48         }
     49         void clear() { m_x = m_y = 0; }
     50     };
     51 
     52     struct PathPolygon: public Vector<PathPoint> {
     53         void move(const FloatSize& offset);
     54         void transform(const AffineTransform& t);
     55         bool contains(const FloatPoint& point) const;
     56     };
     57 
     58     class PlatformPathElement {
     59     public:
     60         enum PlaformPathElementType {
     61             PathMoveTo,
     62             PathLineTo,
     63             PathArcTo,
     64             PathQuadCurveTo,
     65             PathBezierCurveTo,
     66             PathCloseSubpath,
     67         };
     68 
     69         struct MoveTo {
     70             PathPoint m_end;
     71         };
     72 
     73         struct LineTo {
     74             PathPoint m_end;
     75         };
     76 
     77         struct ArcTo {
     78             PathPoint m_end;
     79             PathPoint m_center;
     80             PathPoint m_radius;
     81             bool m_clockwise;
     82         };
     83 
     84         struct QuadCurveTo {
     85             PathPoint m_point0;
     86             PathPoint m_point1;
     87         };
     88 
     89         struct BezierCurveTo {
     90             PathPoint m_point0;
     91             PathPoint m_point1;
     92             PathPoint m_point2;
     93         };
     94 
     95         PlatformPathElement(): m_type(PathCloseSubpath) { m_data.m_points[0].set(0, 0);    }
     96         PlatformPathElement(const MoveTo& data): m_type(PathMoveTo) { m_data.m_moveToData = data; }
     97         PlatformPathElement(const LineTo& data): m_type(PathLineTo) { m_data.m_lineToData = data; }
     98         PlatformPathElement(const ArcTo& data): m_type(PathArcTo) { m_data.m_arcToData = data; }
     99         PlatformPathElement(const QuadCurveTo& data): m_type(PathQuadCurveTo) { m_data.m_quadCurveToData = data; }
    100         PlatformPathElement(const BezierCurveTo& data): m_type(PathBezierCurveTo) { m_data.m_bezierCurveToData = data; }
    101 
    102         const MoveTo& moveTo() const { return m_data.m_moveToData; }
    103         const LineTo& lineTo() const { return m_data.m_lineToData; }
    104         const ArcTo& arcTo() const { return m_data.m_arcToData; }
    105         const QuadCurveTo& quadCurveTo() const { return m_data.m_quadCurveToData; }
    106         const BezierCurveTo& bezierCurveTo() const { return m_data.m_bezierCurveToData; }
    107         const PathPoint& lastPoint() const
    108         {
    109             int n = numPoints();
    110             return n > 1 ? m_data.m_points[n - 1] : m_data.m_points[0];
    111         }
    112         const PathPoint& pointAt(int index) const { return m_data.m_points[index]; }
    113         int numPoints() const;
    114         int numControlPoints() const;
    115         void move(const FloatSize& offset);
    116         void transform(const AffineTransform& t);
    117         PathElementType type() const;
    118         PlaformPathElementType platformType() const { return m_type; }
    119         void inflateRectToContainMe(FloatRect& r, const FloatPoint& lastPoint) const;
    120 
    121     private:
    122         PlaformPathElementType m_type;
    123         union {
    124             MoveTo m_moveToData;
    125             LineTo m_lineToData;
    126             ArcTo m_arcToData;
    127             QuadCurveTo m_quadCurveToData;
    128             BezierCurveTo m_bezierCurveToData;
    129             PathPoint m_points[4];
    130         } m_data;
    131     };
    132 
    133     typedef Vector<PlatformPathElement> PlatformPathElements;
    134 
    135     class PlatformPath {
    136     public:
    137         PlatformPath();
    138         const PlatformPathElements& elements() const { return m_elements; }
    139         void append(const PlatformPathElement& e);
    140         void append(const PlatformPath& p);
    141         void clear();
    142         bool isEmpty() const { return m_elements.isEmpty(); }
    143 
    144         void strokePath(HDC, const AffineTransform* tr) const;
    145         void fillPath(HDC, const AffineTransform* tr) const;
    146         FloatPoint lastPoint() const { return m_elements.isEmpty() ? FloatPoint(0, 0) : m_elements.last().lastPoint(); }
    147 
    148         const FloatRect& boundingRect() const { return m_boundingRect; }
    149         bool contains(const FloatPoint& point, WindRule rule) const;
    150         void translate(const FloatSize& size);
    151         void transform(const AffineTransform& t);
    152 
    153         void moveTo(const FloatPoint&);
    154         void addLineTo(const FloatPoint&);
    155         void addQuadCurveTo(const FloatPoint& controlPoint, const FloatPoint& point);
    156         void addBezierCurveTo(const FloatPoint& controlPoint1, const FloatPoint& controlPoint2, const FloatPoint&);
    157         void addArcTo(const FloatPoint&, const FloatPoint&, float radius);
    158         void closeSubpath();
    159         void addEllipse(const FloatPoint& p, float a, float b, float sar, float ear, bool anticlockwise);
    160         void addRect(const FloatRect& r);
    161         void addEllipse(const FloatRect& r);
    162         String debugString() const;
    163         void apply(void* info, PathApplierFunction function) const;
    164 
    165     private:
    166         void ensureSubpath();
    167         void addToSubpath(const PlatformPathElement& e);
    168 
    169         PlatformPathElements m_elements;
    170         FloatRect m_boundingRect;
    171         Vector<PathPolygon> m_subpaths;
    172         PathPoint m_currentPoint;
    173         bool m_penLifted;
    174     };
    175 
    176 }
    177 
    178 #endif // PlatformPathWince_h
    179