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 #include "FloatPoint.h"
     24 #include "FloatRect.h"
     25 #include "Path.h"
     26 #include <wtf/Vector.h>
     27 
     28 namespace WebCore {
     29 
     30     class GraphicsContext;
     31 
     32     struct PathPoint {
     33         float m_x;
     34         float m_y;
     35         const float& x() const { return m_x; }
     36         const float& y() const { return m_y; }
     37         void set(float x, float y)
     38         {
     39             m_x = x;
     40             m_y = y;
     41         };
     42         operator FloatPoint() const { return FloatPoint(m_x, m_y); }
     43         void move(const FloatSize& offset)
     44         {
     45             m_x += offset.width();
     46             m_y += offset.height();
     47         }
     48         PathPoint& operator=(const FloatPoint& p)
     49         {
     50             m_x = p.x();
     51             m_y = p.y();
     52             return *this;
     53         }
     54         void clear() { m_x = m_y = 0; }
     55     };
     56 
     57     struct PathPolygon: public Vector<PathPoint> {
     58         void move(const FloatSize& offset);
     59         void transform(const AffineTransform& t);
     60         bool contains(const FloatPoint& point) const;
     61     };
     62 
     63     class PlatformPathElement {
     64     public:
     65         enum PlaformPathElementType {
     66             PathMoveTo,
     67             PathLineTo,
     68             PathArcTo,
     69             PathQuadCurveTo,
     70             PathBezierCurveTo,
     71             PathCloseSubpath,
     72         };
     73 
     74         struct MoveTo {
     75             PathPoint m_end;
     76         };
     77 
     78         struct LineTo {
     79             PathPoint m_end;
     80         };
     81 
     82         struct ArcTo {
     83             PathPoint m_end;
     84             PathPoint m_center;
     85             PathPoint m_radius;
     86             bool m_clockwise;
     87         };
     88 
     89         struct QuadCurveTo {
     90             PathPoint m_point0;
     91             PathPoint m_point1;
     92         };
     93 
     94         struct BezierCurveTo {
     95             PathPoint m_point0;
     96             PathPoint m_point1;
     97             PathPoint m_point2;
     98         };
     99 
    100         PlatformPathElement(): m_type(PathCloseSubpath) { m_data.m_points[0].set(0, 0);    }
    101         PlatformPathElement(const MoveTo& data): m_type(PathMoveTo) { m_data.m_moveToData = data; }
    102         PlatformPathElement(const LineTo& data): m_type(PathLineTo) { m_data.m_lineToData = data; }
    103         PlatformPathElement(const ArcTo& data): m_type(PathArcTo) { m_data.m_arcToData = data; }
    104         PlatformPathElement(const QuadCurveTo& data): m_type(PathQuadCurveTo) { m_data.m_quadCurveToData = data; }
    105         PlatformPathElement(const BezierCurveTo& data): m_type(PathBezierCurveTo) { m_data.m_bezierCurveToData = data; }
    106 
    107         const MoveTo& moveTo() const { return m_data.m_moveToData; }
    108         const LineTo& lineTo() const { return m_data.m_lineToData; }
    109         const ArcTo& arcTo() const { return m_data.m_arcToData; }
    110         const QuadCurveTo& quadCurveTo() const { return m_data.m_quadCurveToData; }
    111         const BezierCurveTo& bezierCurveTo() const { return m_data.m_bezierCurveToData; }
    112         const PathPoint& lastPoint() const
    113         {
    114             int n = numPoints();
    115             return n > 1 ? m_data.m_points[n - 1] : m_data.m_points[0];
    116         }
    117         const PathPoint& pointAt(int index) const { return m_data.m_points[index]; }
    118         int numPoints() const;
    119         int numControlPoints() const;
    120         void move(const FloatSize& offset);
    121         void transform(const AffineTransform& t);
    122         PathElementType type() const;
    123         PlaformPathElementType platformType() const { return m_type; }
    124         void inflateRectToContainMe(FloatRect& r, const FloatPoint& lastPoint) const;
    125 
    126     private:
    127         PlaformPathElementType m_type;
    128         union {
    129             MoveTo m_moveToData;
    130             LineTo m_lineToData;
    131             ArcTo m_arcToData;
    132             QuadCurveTo m_quadCurveToData;
    133             BezierCurveTo m_bezierCurveToData;
    134             PathPoint m_points[4];
    135         } m_data;
    136     };
    137 
    138     typedef Vector<PlatformPathElement> PlatformPathElements;
    139 
    140     class PlatformPath {
    141     public:
    142         PlatformPath();
    143         const PlatformPathElements& elements() const { return m_elements; }
    144         void append(const PlatformPathElement& e);
    145         void append(const PlatformPath& p);
    146         void clear();
    147         bool isEmpty() const { return m_elements.isEmpty(); }
    148 
    149         void strokePath(HDC, const AffineTransform* tr) const;
    150         void fillPath(HDC, const AffineTransform* tr) const;
    151         FloatPoint lastPoint() const { return m_elements.isEmpty() ? FloatPoint(0, 0) : m_elements.last().lastPoint(); }
    152 
    153         const FloatRect& boundingRect() const { return m_boundingRect; }
    154         bool contains(const FloatPoint& point, WindRule rule) const;
    155         void translate(const FloatSize& size);
    156         void transform(const AffineTransform& t);
    157 
    158         void moveTo(const FloatPoint&);
    159         void addLineTo(const FloatPoint&);
    160         void addQuadCurveTo(const FloatPoint& controlPoint, const FloatPoint& point);
    161         void addBezierCurveTo(const FloatPoint& controlPoint1, const FloatPoint& controlPoint2, const FloatPoint&);
    162         void addArcTo(const FloatPoint&, const FloatPoint&, float radius);
    163         void closeSubpath();
    164         void addEllipse(const FloatPoint& p, float a, float b, float sar, float ear, bool anticlockwise);
    165         void addRect(const FloatRect& r);
    166         void addEllipse(const FloatRect& r);
    167         void apply(void* info, PathApplierFunction function) const;
    168 
    169     private:
    170         void ensureSubpath();
    171         void addToSubpath(const PlatformPathElement& e);
    172 
    173         PlatformPathElements m_elements;
    174         FloatRect m_boundingRect;
    175         Vector<PathPolygon> m_subpaths;
    176         PathPoint m_currentPoint;
    177         bool m_penLifted;
    178     };
    179 
    180 }
    181 
    182 #endif // PlatformPathWinCE_h
    183