KHTML
Path.h
Go to the documentation of this file.
00001 /* 00002 * Copyright (C) 2003, 2006 Apple Computer, Inc. All rights reserved. 00003 * 2006 Rob Buis <buis@kde.org> 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 00014 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 00015 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00016 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00017 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 00018 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00019 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00020 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00021 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00022 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00023 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00024 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00025 */ 00026 00027 #ifndef Path_h 00028 #define Path_h 00029 00030 #include "dom/dom_string.h" 00031 #include "platform/graphics/FloatPoint.h" 00032 #include "platform/graphics/FloatRect.h" 00033 #include <QPainterPath> 00034 00035 typedef QPainterPath PlatformPath; 00036 00037 namespace WebCore { 00038 class AffineTransform; 00039 } 00040 00041 namespace khtml { 00042 using WebCore::AffineTransform; 00043 using WebCore::FloatPoint; 00044 using WebCore::FloatSize; 00045 using WebCore::FloatRect; 00046 //class String; 00047 00048 enum WindRule { 00049 RULE_NONZERO = 0, 00050 RULE_EVENODD = 1 00051 }; 00052 00053 enum PathElementType { 00054 PathElementMoveToPoint, 00055 PathElementAddLineToPoint, 00056 PathElementAddQuadCurveToPoint, 00057 PathElementAddCurveToPoint, 00058 PathElementCloseSubpath 00059 }; 00060 00061 struct PathElement { 00062 PathElementType type; 00063 FloatPoint* points; 00064 }; 00065 00066 typedef void (*PathApplierFunction) (void* info, const PathElement*); 00067 00068 class Path { 00069 public: 00070 Path(); 00071 ~Path(); 00072 00073 Path(const Path&); 00074 Path& operator=(const Path&); 00075 00076 bool contains(const FloatPoint&, WindRule rule = RULE_NONZERO) const; 00077 FloatRect boundingRect() const; 00078 00079 float length(); 00080 FloatPoint pointAtLength(float length, bool& ok); 00081 float normalAngleAtLength(float length, bool& ok); 00082 00083 void clear(); 00084 bool isEmpty() const; 00085 00086 void moveTo(const FloatPoint&); 00087 void addLineTo(const FloatPoint&); 00088 void addQuadCurveTo(const FloatPoint& controlPoint, const FloatPoint& point); 00089 void addBezierCurveTo(const FloatPoint& controlPoint1, const FloatPoint& controlPoint2, const FloatPoint&); 00090 void addArcTo(const FloatPoint&, const FloatPoint&, float radius); 00091 void closeSubpath(); 00092 00093 void addArc(const FloatPoint&, float radius, float startAngle, float endAngle, bool anticlockwise); 00094 void addRect(const FloatRect&); 00095 void addEllipse(const FloatRect&); 00096 00097 void translate(const FloatSize&); 00098 00099 void setWindingRule(WindRule rule) { m_rule = rule; } 00100 WindRule windingRule() const { return m_rule; } 00101 00102 DOM::DOMString debugString() const; 00103 00104 PlatformPath* platformPath() const { return m_path; } 00105 00106 static Path createRoundedRectangle(const FloatRect&, const FloatSize& roundingRadii); 00107 static Path createRoundedRectangle(const FloatRect&, const FloatSize& topLeftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& bottomRightRadius); 00108 static Path createRectangle(const FloatRect&); 00109 static Path createEllipse(const FloatPoint& center, float rx, float ry); 00110 static Path createCircle(const FloatPoint& center, float r); 00111 static Path createLine(const FloatPoint&, const FloatPoint&); 00112 00113 void apply(void* info, PathApplierFunction) const; 00114 void transform(const AffineTransform&); 00115 00116 private: 00117 PlatformPath* m_path; 00118 WindRule m_rule; 00119 }; 00120 00121 } 00122 00123 #endif
KDE 4.6 API Reference