Commit cf044eba authored by treat@webkit.org's avatar treat@webkit.org

WINCE PORT: Implement Path for WINCE. Most code can be

reused for other ports that don't have native path support
https://bugs.webkit.org/show_bug.cgi?id=28188

Patch by Yong Li <yong.li@torchmobile.com> on 2009-08-08
Reviewed by Adam Treat.

Written also by George Staikos (including quadCurve() and bezier())

* platform/graphics/wince/PathWince.cpp: Added.
* platform/graphics/wince/PlatformPathWince.cpp: Added.
* platform/graphics/wince/PlatformPathWince.h: Added.
* platform/graphics/wince/WinceGraphicsExtras.h: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@47118 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f7b25a35
2009-08-08 Yong Li <yong.li@torchmobile.com>
Reviewed by Adam Treat.
WINCE PORT: Implement Path for WINCE. Most code can be
reused for other ports that don't have native path support
https://bugs.webkit.org/show_bug.cgi?id=28188
Written also by George Staikos (including quadCurve() and bezier())
* platform/graphics/wince/PathWince.cpp: Added.
* platform/graphics/wince/PlatformPathWince.cpp: Added.
* platform/graphics/wince/PlatformPathWince.h: Added.
* platform/graphics/wince/WinceGraphicsExtras.h: Added.
2009-08-12 Joseph Pecoraro <joepeck02@gmail.com>
"Double-click to add" new style button does not always show up [quick fix]
/*
* Copyright (C) 2007-2009 Torch Mobile, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "Path.h"
#include "FloatRect.h"
#include "NotImplemented.h"
#include "PlatformPathWince.h"
#include "PlatformString.h"
#include "TransformationMatrix.h"
#include <wtf/OwnPtr.h>
namespace WebCore {
Path::Path()
: m_path(new PlatformPath())
{
}
Path::Path(const Path& other)
: m_path(new PlatformPath(*other.m_path))
{
}
Path::~Path()
{
delete m_path;
}
Path& Path::operator=(const Path& other)
{
if (&other != this) {
delete m_path;
m_path = new PlatformPath(*other.m_path);
}
return *this;
}
bool Path::contains(const FloatPoint& point, WindRule rule) const
{
return m_path->contains(point, rule);
}
void Path::translate(const FloatSize& size)
{
m_path->translate(size);
}
FloatRect Path::boundingRect() const
{
return m_path->boundingRect();
}
void Path::moveTo(const FloatPoint& point)
{
m_path->moveTo(point);
}
void Path::addLineTo(const FloatPoint& point)
{
m_path->addLineTo(point);
}
void Path::addQuadCurveTo(const FloatPoint& cp, const FloatPoint& p)
{
m_path->addQuadCurveTo(cp, p);
}
void Path::addBezierCurveTo(const FloatPoint& cp1, const FloatPoint& cp2, const FloatPoint& p)
{
m_path->addBezierCurveTo(cp1, cp2, p);
}
void Path::addArcTo(const FloatPoint& p1, const FloatPoint& p2, float radius)
{
m_path->addArcTo(p1, p2, radius);
}
void Path::closeSubpath()
{
m_path->closeSubpath();
}
void Path::addArc(const FloatPoint& p, float r, float sar, float ear, bool anticlockwise)
{
m_path->addEllipse(p, r, r, sar, ear, anticlockwise);
}
void Path::addRect(const FloatRect& r)
{
m_path->addRect(r);
}
void Path::addEllipse(const FloatRect& r)
{
m_path->addEllipse(r);
}
void Path::clear()
{
m_path->clear();
}
bool Path::isEmpty() const
{
return m_path->isEmpty();
}
String Path::debugString() const
{
return m_path->debugString();
}
void Path::apply(void* info, PathApplierFunction function) const
{
m_path->apply(info, function);
}
void Path::transform(const TransformationMatrix& t)
{
m_path->transform(t);
}
FloatRect Path::strokeBoundingRect(StrokeStyleApplier *)
{
notImplemented();
return FloatRect();
}
bool Path::strokeContains(StrokeStyleApplier*, const FloatPoint&) const
{
notImplemented();
return false;
}
bool Path::hasCurrentPoint() const
{
// Not sure if this is correct. At the meantime, we do what other ports
// do.
// See https://bugs.webkit.org/show_bug.cgi?id=27266,
// https://bugs.webkit.org/show_bug.cgi?id=27187, and
// http://trac.webkit.org/changeset/45873
return !isEmpty();
}
}
This diff is collapsed.
/*
* Copyright (C) 2007-2009 Torch Mobile, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef PlatformPathWince_h
#define PlatformPathWince_h
namespace WebCore {
class GraphicsContext;
struct PathPoint {
float m_x;
float m_y;
const float& x() const { return m_x; }
const float& y() const { return m_y; }
void set(float x, float y)
{
m_x = x;
m_y = y;
};
operator FloatPoint() const { return FloatPoint(m_x, m_y); }
void move(const FloatSize& offset)
{
m_x += offset.width();
m_y += offset.height();
}
PathPoint& operator=(const FloatPoint& p)
{
m_x = p.x();
m_y = p.y();
return *this;
}
void clear() { m_x = m_y = 0; }
};
struct PathPolygon: public Vector<PathPoint> {
void move(const FloatSize& offset);
void transform(const TransformationMatrix& t);
bool contains(const FloatPoint& point) const;
};
class PlatformPathElement {
public:
enum PlaformPathElementType {
PathMoveTo,
PathLineTo,
PathArcTo,
PathQuadCurveTo,
PathBezierCurveTo,
PathCloseSubpath,
};
struct MoveTo {
PathPoint m_end;
};
struct LineTo {
PathPoint m_end;
};
struct ArcTo {
PathPoint m_end;
PathPoint m_center;
PathPoint m_radius;
bool m_clockwise;
};
struct QuadCurveTo {
PathPoint m_point0;
PathPoint m_point1;
};
struct BezierCurveTo {
PathPoint m_point0;
PathPoint m_point1;
PathPoint m_point2;
};
PlatformPathElement(): m_type(PathCloseSubpath) { m_data.m_points[0].set(0, 0); }
PlatformPathElement(const MoveTo& data): m_type(PathMoveTo) { m_data.m_moveToData = data; }
PlatformPathElement(const LineTo& data): m_type(PathLineTo) { m_data.m_lineToData = data; }
PlatformPathElement(const ArcTo& data): m_type(PathArcTo) { m_data.m_arcToData = data; }
PlatformPathElement(const QuadCurveTo& data): m_type(PathQuadCurveTo) { m_data.m_quadCurveToData = data; }
PlatformPathElement(const BezierCurveTo& data): m_type(PathBezierCurveTo) { m_data.m_bezierCurveToData = data; }
const MoveTo& moveTo() const { return m_data.m_moveToData; }
const LineTo& lineTo() const { return m_data.m_lineToData; }
const ArcTo& arcTo() const { return m_data.m_arcToData; }
const QuadCurveTo& quadCurveTo() const { return m_data.m_quadCurveToData; }
const BezierCurveTo& bezierCurveTo() const { return m_data.m_bezierCurveToData; }
const PathPoint& lastPoint() const
{
int n = numPoints();
return n > 1 ? m_data.m_points[n - 1] : m_data.m_points[0];
}
const PathPoint& pointAt(int index) const { return m_data.m_points[index]; }
int numPoints() const;
int numControlPoints() const;
void move(const FloatSize& offset);
void transform(const TransformationMatrix& t);
PathElementType type() const;
PlaformPathElementType platformType() const { return m_type; }
void inflateRectToContainMe(FloatRect& r, const FloatPoint& lastPoint) const;
private:
PlaformPathElementType m_type;
union {
MoveTo m_moveToData;
LineTo m_lineToData;
ArcTo m_arcToData;
QuadCurveTo m_quadCurveToData;
BezierCurveTo m_bezierCurveToData;
PathPoint m_points[4];
} m_data;
};
typedef Vector<PlatformPathElement> PlatformPathElements;
class PlatformPath {
public:
PlatformPath();
const PlatformPathElements& elements() const { return m_elements; }
void append(const PlatformPathElement& e);
void append(const PlatformPath& p);
void clear();
bool isEmpty() const { return m_elements.isEmpty(); }
void strokePath(HDC, const TransformationMatrix* tr) const;
void fillPath(HDC, const TransformationMatrix* tr) const;
FloatPoint lastPoint() const { return m_elements.isEmpty() ? FloatPoint(0, 0) : m_elements.last().lastPoint(); }
const FloatRect& boundingRect() const { return m_boundingRect; }
bool contains(const FloatPoint& point, WindRule rule) const;
void translate(const FloatSize& size);
void transform(const TransformationMatrix& t);
void moveTo(const FloatPoint&);
void addLineTo(const FloatPoint&);
void addQuadCurveTo(const FloatPoint& controlPoint, const FloatPoint& point);
void addBezierCurveTo(const FloatPoint& controlPoint1, const FloatPoint& controlPoint2, const FloatPoint&);
void addArcTo(const FloatPoint&, const FloatPoint&, float radius);
void closeSubpath();
void addEllipse(const FloatPoint& p, float a, float b, float sar, float ear, bool anticlockwise);
void addRect(const FloatRect& r);
void addEllipse(const FloatRect& r);
String debugString() const;
void apply(void* info, PathApplierFunction function) const;
private:
void ensureSubpath();
void addToSubpath(const PlatformPathElement& e);
PlatformPathElements m_elements;
FloatRect m_boundingRect;
Vector<PathPolygon> m_subpaths;
PathPoint m_currentPoint;
bool m_penLifted;
};
}
#endif // PlatformPathWince_h
/*
* Copyright (C) 2007-2009 Torch Mobile, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef WinceGraphicsExtras_h
#define WinceGraphicsExtras_h
// This file is used to contain small utilities used by WINCE graphics code.
namespace WebCore {
// Always round to same direction. 0.5 is rounded to 1,
// and -0.5 (0.5 - 1) is rounded to 0 (1 - 1), so that it
// is consistent when transformation shifts.
static inline int stableRound(double d)
{
if (d > 0)
return static_cast<int>(d + 0.5);
int i = static_cast<int>(d);
return i - d > 0.5 ? i - 1 : i;
}
}
#endif WinceGraphicsExtras_h
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment