platform/StringImpl.cpp
platform/FloatRect.cpp
platform/ResourceLoader.cpp
+ platform/Path.cpp
platform/qt/AffineTransformQt.cpp
platform/qt/StringQt.cpp
platform/qt/ColorQt.cpp
+2006-09-03 Rob Buis <buis@kde.org>
+
+ Reviewed by Darin.
+
+ http://bugzilla.opendarwin.org/show_bug.cgi?id=10696
+ RenderPathQuartz and RenderPathQt should not be needed
+
+ Cleanup of code related to RenderPath.
+
+ * CMakeLists.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ * kcanvas/KCanvasCreator.cpp:
+ * kcanvas/KCanvasCreator.h:
+ * kcanvas/RenderPath.cpp:
+ (WebCore::):
+ (WebCore::DrawMarkersData::DrawMarkersData):
+ (WebCore::drawMarkerWithData):
+ (WebCore::updateMarkerDataForElement):
+ (WebCore::drawStartAndMidMarkers):
+ (WebCore::RenderPath::drawMarkersIfNeeded):
+ * kcanvas/RenderPath.h:
+ * kcanvas/device/KRenderingDevice.h:
+ * kcanvas/device/qt/KRenderingDeviceQt.cpp:
+ * kcanvas/device/qt/KRenderingDeviceQt.h:
+ * kcanvas/device/qt/RenderPathQt.cpp:
+ (WebCore::RenderPath::strokeContains):
+ (WebCore::RenderPath::strokeBBox):
+ * kcanvas/device/qt/RenderPathQt.h:
+ * kcanvas/device/quartz/KCanvasItemQuartz.h:
+ * kcanvas/device/quartz/KCanvasItemQuartz.mm:
+ (WebCore::RenderPath::strokeBBox):
+ (WebCore::RenderPath::strokeContains):
+ * kcanvas/device/quartz/KRenderingDeviceQuartz.h:
+ * kcanvas/device/quartz/KRenderingDeviceQuartz.mm:
+ * kcanvas/device/quartz/QuartzSupport.h:
+ * ksvg2/svg/SVGAElement.cpp:
+ * ksvg2/svg/SVGCircleElement.cpp:
+ (SVGCircleElement::toPathData):
+ * ksvg2/svg/SVGEllipseElement.cpp:
+ (WebCore::SVGEllipseElement::toPathData):
+ * ksvg2/svg/SVGFEImageElement.cpp:
+ * ksvg2/svg/SVGGElement.cpp:
+ * ksvg2/svg/SVGImageElement.cpp:
+ * ksvg2/svg/SVGLineElement.cpp:
+ (SVGLineElement::toPathData):
+ * ksvg2/svg/SVGMarkerElement.cpp:
+ * ksvg2/svg/SVGPathElement.cpp:
+ * ksvg2/svg/SVGPatternElement.cpp:
+ * ksvg2/svg/SVGPolygonElement.cpp:
+ * ksvg2/svg/SVGPolylineElement.cpp:
+ * ksvg2/svg/SVGRectElement.cpp:
+ (WebCore::SVGRectElement::toPathData):
+ * ksvg2/svg/SVGSVGElement.cpp:
+ * ksvg2/svg/SVGStyledElement.cpp:
+ (WebCore::SVGStyledElement::createRenderer):
+ * ksvg2/svg/SVGSwitchElement.cpp:
+ * ksvg2/svg/SVGTextElement.cpp:
+ * ksvg2/svg/SVGUseElement.cpp:
+ * platform/Path.h:
+ (WebCore::):
+ * platform/cg/PathCG.cpp:
+ (WebCore::CGPathToCFStringApplierFunction):
+ (WebCore::CGPathApplierToPathApplier):
+ (WebCore::Path::apply):
+ (WebCore::Path::transform):
+ * platform/qt/PathQt.cpp:
+ (WebCore::Path::apply):
+
2006-09-03 Timothy Hatcher <timothy@apple.com>
Reviewed by Darin.
A88AD3B60952486E001DD196 /* QuartzSupport.mm in Sources */ = {isa = PBXBuildFile; fileRef = A8C0FB77089701F800BA5114 /* QuartzSupport.mm */; };
A88AD3B90952486E001DD196 /* RenderSVGContainer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8C0FB7A089701F800BA5114 /* RenderSVGContainer.cpp */; };
A88AD3BA0952486E001DD196 /* RenderSVGContainer.h in Headers */ = {isa = PBXBuildFile; fileRef = A8C0FB7B089701F800BA5114 /* RenderSVGContainer.h */; };
- A88AD3BB0952486E001DD196 /* KCanvasCreator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8C0FB7C089701F800BA5114 /* KCanvasCreator.cpp */; };
- A88AD3BC0952486E001DD196 /* KCanvasCreator.h in Headers */ = {isa = PBXBuildFile; fileRef = A8C0FB7D089701F800BA5114 /* KCanvasCreator.h */; };
A88AD3BD0952486E001DD196 /* KCanvasFilters.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A8C0FB7E089701F800BA5114 /* KCanvasFilters.cpp */; };
A88AD3BE0952486E001DD196 /* KCanvasFilters.h in Headers */ = {isa = PBXBuildFile; fileRef = A8C0FB7F089701F800BA5114 /* KCanvasFilters.h */; };
A88AD3C00952486E001DD196 /* KCanvasImage.h in Headers */ = {isa = PBXBuildFile; fileRef = A8C0FB81089701F800BA5114 /* KCanvasImage.h */; };
A8FEFB320979F4F6005839FD /* SVGForeignObjectElement.h in Headers */ = {isa = PBXBuildFile; fileRef = A8FEFB300979F4F6005839FD /* SVGForeignObjectElement.h */; };
AA84FC850AA0FE08007699AF /* JSSVGMetadataElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AA84FC830AA0FE08007699AF /* JSSVGMetadataElement.cpp */; };
AA84FC860AA0FE08007699AF /* JSSVGMetadataElement.h in Headers */ = {isa = PBXBuildFile; fileRef = AA84FC840AA0FE08007699AF /* JSSVGMetadataElement.h */; };
+ AA98B87D0AAA02F8001A44C2 /* Path.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AA98B87C0AAA02F8001A44C2 /* Path.cpp */; };
AAC8DAB10AA1002000DC0907 /* SVGMetadataElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AAC8DAAF0AA1002000DC0907 /* SVGMetadataElement.cpp */; };
AAC8DAB20AA1002000DC0907 /* SVGMetadataElement.h in Headers */ = {isa = PBXBuildFile; fileRef = AAC8DAB00AA1002000DC0907 /* SVGMetadataElement.h */; };
AB23A31209BBA7760067CC53 /* HTMLTextFieldInnerElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = AB23A31009BBA7760067CC53 /* HTMLTextFieldInnerElement.cpp */; };
A8C0FB77089701F800BA5114 /* QuartzSupport.mm */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = QuartzSupport.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
A8C0FB7A089701F800BA5114 /* RenderSVGContainer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderSVGContainer.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
A8C0FB7B089701F800BA5114 /* RenderSVGContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = RenderSVGContainer.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
- A8C0FB7C089701F800BA5114 /* KCanvasCreator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KCanvasCreator.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
- A8C0FB7D089701F800BA5114 /* KCanvasCreator.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = KCanvasCreator.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
A8C0FB7E089701F800BA5114 /* KCanvasFilters.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KCanvasFilters.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
A8C0FB7F089701F800BA5114 /* KCanvasFilters.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = KCanvasFilters.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
A8C0FB81089701F800BA5114 /* KCanvasImage.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = KCanvasImage.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
A8FEFB300979F4F6005839FD /* SVGForeignObjectElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SVGForeignObjectElement.h; sourceTree = "<group>"; };
AA84FC830AA0FE08007699AF /* JSSVGMetadataElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSSVGMetadataElement.cpp; sourceTree = "<group>"; };
AA84FC840AA0FE08007699AF /* JSSVGMetadataElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSSVGMetadataElement.h; sourceTree = "<group>"; };
+ AA98B87C0AAA02F8001A44C2 /* Path.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = Path.cpp; sourceTree = "<group>"; };
AAC8DAAF0AA1002000DC0907 /* SVGMetadataElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = SVGMetadataElement.cpp; sourceTree = "<group>"; };
AAC8DAB00AA1002000DC0907 /* SVGMetadataElement.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = SVGMetadataElement.h; sourceTree = "<group>"; };
AB23A31009BBA7760067CC53 /* HTMLTextFieldInnerElement.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = HTMLTextFieldInnerElement.cpp; sourceTree = "<group>"; };
A8C0FB53089701F700BA5114 /* device */,
A8C0FB7A089701F800BA5114 /* RenderSVGContainer.cpp */,
A8C0FB7B089701F800BA5114 /* RenderSVGContainer.h */,
- A8C0FB7C089701F800BA5114 /* KCanvasCreator.cpp */,
- A8C0FB7D089701F800BA5114 /* KCanvasCreator.h */,
A8C0FB7E089701F800BA5114 /* KCanvasFilters.cpp */,
A8C0FB7F089701F800BA5114 /* KCanvasFilters.h */,
A8C0FB81089701F800BA5114 /* KCanvasImage.h */,
BCF1A5BA097832090061A123 /* platform */ = {
isa = PBXGroup;
children = (
+ AA98B87C0AAA02F8001A44C2 /* Path.cpp */,
1AE42F670AA4B8CB00C8612D /* cf */,
93032CCC09AEC36200F82A18 /* cg */,
6582A14809999D6C00BEEB6D /* mac */,
A88AD3B30952486E001DD196 /* KRenderingPaintServerQuartz.h in Headers */,
A88AD3B50952486E001DD196 /* QuartzSupport.h in Headers */,
A88AD3BA0952486E001DD196 /* RenderSVGContainer.h in Headers */,
- A88AD3BC0952486E001DD196 /* KCanvasCreator.h in Headers */,
A88AD3BE0952486E001DD196 /* KCanvasFilters.h in Headers */,
A88AD3C00952486E001DD196 /* KCanvasImage.h in Headers */,
A88AD3C20952486E001DD196 /* RenderPath.h in Headers */,
A88AD3B40952486E001DD196 /* KRenderingPaintServerQuartz.mm in Sources */,
A88AD3B60952486E001DD196 /* QuartzSupport.mm in Sources */,
A88AD3B90952486E001DD196 /* RenderSVGContainer.cpp in Sources */,
- A88AD3BB0952486E001DD196 /* KCanvasCreator.cpp in Sources */,
A88AD3BD0952486E001DD196 /* KCanvasFilters.cpp in Sources */,
A88AD3C10952486E001DD196 /* RenderPath.cpp in Sources */,
A88AD3C80952486E001DD196 /* KCanvasResources.cpp in Sources */,
852B9E8A0AA79C47002ADA6E /* DOMHTMLOptionElement.mm in Sources */,
1A98955C0AA78149005EF5EF /* CString.cpp in Sources */,
1A98956B0AA78F80005EF5EF /* KURLCFNet.cpp in Sources */,
+ AA98B87D0AAA02F8001A44C2 /* Path.cpp in Sources */,
85032DD80AA8C9BE007D3B7D /* DOMCSSCharsetRule.mm in Sources */,
85032DDA0AA8C9BE007D3B7D /* DOMCSSFontFaceRule.mm in Sources */,
85032DDC0AA8C9BE007D3B7D /* DOMCSSImportRule.mm in Sources */,
-/*
- Copyright (C) 2004, 2005 Nikolas Zimmermann <wildfox@kde.org>
- 2004, 2005 Rob Buis <buis@kde.org>
-
- This file is part of the KDE project
-
- 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
- aint with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
-
-#include "config.h"
-#ifdef SVG_SUPPORT
-#include "KCanvasCreator.h"
-
-#include <math.h>
-
-#include "KRenderingDevice.h"
-#include "RenderSVGContainer.h"
-#include "Path.h"
-
-namespace WebCore {
-
-KCanvasCreator *KCanvasCreator::s_creator = 0;
-
-KCanvasCreator::KCanvasCreator()
-{
-}
-
-KCanvasCreator::~KCanvasCreator()
-{
-}
-
-KCanvasCreator *KCanvasCreator::self()
-{
- if(!s_creator)
- s_creator = new KCanvasCreator();
-
- return s_creator;
-}
-
-Path KCanvasCreator::createRoundedRectangle(const FloatRect& box, const FloatSize& roundingRadii) const
-{
- Path path;
- float x = box.x();
- float y = box.y();
- float width = box.width();
- float height = box.height();
- float rx = roundingRadii.width();
- float ry = roundingRadii.height();
- if (width <= 0.0f || height <= 0.0f)
- return path;
-
- double nrx = rx, nry = ry;
- // If rx is greater than half of the width of the rectangle
- // then set rx to half of the width (required in SVG spec)
- if (nrx > width / 2)
- nrx = width / 2;
-
- // If ry is greater than half of the height of the rectangle
- // then set ry to half of the height (required in SVG spec)
- if (nry > height / 2)
- nry = height / 2;
-
- path.moveTo(FloatPoint(x + nrx, y));
-
- if (nrx < width / 2)
- path.addLineTo(FloatPoint(x + width - rx, y));
-
- path.addBezierCurveTo(FloatPoint(x + width - nrx * (1 - 0.552), y), FloatPoint(x + width, y + nry * (1 - 0.552)), FloatPoint(x + width, y + nry));
-
- if (nry < height / 2)
- path.addLineTo(FloatPoint(x + width, y + height - nry));
-
- path.addBezierCurveTo(FloatPoint(x + width, y + height - nry * (1 - 0.552)), FloatPoint(x + width - nrx * (1 - 0.552), y + height), FloatPoint(x + width - nrx, y + height));
-
- if (nrx < width / 2)
- path.addLineTo(FloatPoint(x + nrx, y + height));
-
- path.addBezierCurveTo(FloatPoint(x + nrx * (1 - 0.552), y + height), FloatPoint(x, y + height - nry * (1 - 0.552)), FloatPoint(x, y + height - nry));
-
- if (nry < height / 2)
- path.addLineTo(FloatPoint(x, y + nry));
-
- path.addBezierCurveTo(FloatPoint(x, y + nry * (1 - 0.552)), FloatPoint(x + nrx * (1 - 0.552), y), FloatPoint(x + nrx, y));
-
- path.closeSubpath();
-
- return path;
-}
-
-Path KCanvasCreator::createRectangle(const FloatRect& box) const
-{
- Path path;
- float x = box.x();
- float y = box.y();
- float width = box.width();
- float height = box.height();
- if (width < 0.0f || height < 0.0f)
- return path;
-
- path.moveTo(FloatPoint(x, y));
- path.addLineTo(FloatPoint(x + width, y));
- path.addLineTo(FloatPoint(x + width, y + height));
- path.addLineTo(FloatPoint(x, y + height));
- path.closeSubpath();
-
- return path;
-}
-
-Path KCanvasCreator::createEllipse(const FloatPoint&c, float rx, float ry) const
-{
- float cx = c.x();
- float cy = c.y();
- Path path;
- if (rx <= 0.0f || ry <= 0.0f)
- return path;
-
- // Ellipse creation - nice & clean agg2 code
- double x = cx, y = cy;
-
- unsigned step = 0, num = 100;
- bool running = true;
- while(running)
- {
- if(step == num)
- {
- running = false;
- break;
- }
-
- double angle = double(step) / double(num) * 2.0 * M_PI;
- x = cx + cos(angle) * rx;
- y = cy + sin(angle) * ry;
-
- step++;
- if(step == 1)
- path.moveTo(FloatPoint(x, y));
- else
- path.addLineTo(FloatPoint(x, y));
- }
-
- path.closeSubpath();
-
- return path;
-}
-
-Path KCanvasCreator::createCircle(const FloatPoint& c, float r) const
-{
- return createEllipse(c, r, r);
-}
-
-Path KCanvasCreator::createLine(const FloatPoint& start, const FloatPoint& end) const
-{
- Path path;
- if (start.x() == end.x() && start.y() == end.y())
- return path;
-
- path.moveTo(start);
- path.addLineTo(end);
-
- return path;
-}
-
-}
-
-// vim:ts=4:noet
-#endif // SVG_SUPPORT
-
-/*
- Copyright (C) 2004, 2005 Nikolas Zimmermann <wildfox@kde.org>
- 2004, 2005 Rob Buis <buis@kde.org>
-
- This file is part of the KDE project
-
- 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
- aint with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
-
-#ifndef KCanvasCreator_H
-#define KCanvasCreator_H
-#ifdef SVG_SUPPORT
-
-namespace WebCore {
-
-class Path;
-class FloatPoint;
-class FloatRect;
-class FloatSize;
-
-class KCanvasCreator
-{
-public:
- KCanvasCreator();
- virtual ~KCanvasCreator();
-
- static KCanvasCreator *self();
-
- // Canvas path creation
- Path createRoundedRectangle(const FloatRect&, const FloatSize&) const;
- Path createRectangle(const FloatRect&) const;
- Path createEllipse(const FloatPoint&, float rx, float ry) const;
- Path createCircle(const FloatPoint&, float r) const;
- Path createLine(const FloatPoint&, const FloatPoint&) const;
-
-private:
- static KCanvasCreator *s_creator;
-};
-
-}
-
-#endif // SVG_SUPPORT
-#endif
-
-// vim:ts=4:noet
#ifdef SVG_SUPPORT
#include "RenderPath.h"
+#include <math.h>
+
#include "GraphicsContext.h"
#include "RenderSVGContainer.h"
#include "KRenderingDevice.h"
return false;
}
+enum MarkerType {
+ Start,
+ Mid,
+ End
+};
+
+struct MarkerData {
+ FloatPoint origin;
+ double strokeWidth;
+ FloatPoint inslopePoints[2];
+ FloatPoint outslopePoints[2];
+ MarkerType type;
+ KCanvasMarker *marker;
+};
+
+struct DrawMarkersData {
+ DrawMarkersData(GraphicsContext*, KCanvasMarker* startMarker, KCanvasMarker* midMarker, double strokeWidth);
+ GraphicsContext* context;
+ int elementIndex;
+ MarkerData previousMarkerData;
+ KCanvasMarker* midMarker;
+};
+
+DrawMarkersData::DrawMarkersData(GraphicsContext* c, KCanvasMarker *start, KCanvasMarker *mid, double strokeWidth)
+ : context(c)
+ , elementIndex(0)
+ , midMarker(mid)
+{
+ previousMarkerData.origin = FloatPoint();
+ previousMarkerData.strokeWidth = strokeWidth;
+ previousMarkerData.marker = start;
+ previousMarkerData.type = Start;
}
-// vim:ts=4:noet
-#endif // SVG_SUPPORT
+static void drawMarkerWithData(GraphicsContext* context, MarkerData &data)
+{
+ if (!data.marker)
+ return;
+
+ FloatPoint inslopeChange = data.inslopePoints[1] - FloatSize(data.inslopePoints[0].x(), data.inslopePoints[0].y());
+ FloatPoint outslopeChange = data.outslopePoints[1] - FloatSize(data.outslopePoints[0].x(), data.outslopePoints[0].y());
+
+ static const double deg2rad = M_PI/180.0;
+ double inslope = atan2(inslopeChange.y(), inslopeChange.x()) / deg2rad;
+ double outslope = atan2(outslopeChange.y(), outslopeChange.x()) / deg2rad;
+
+ double angle = 0.0;
+ switch (data.type) {
+ case Start:
+ angle = outslope;
+ break;
+ case Mid:
+ angle = (inslope + outslope) / 2;
+ break;
+ case End:
+ angle = inslope;
+ }
+
+ data.marker->draw(context, FloatRect(), data.origin.x(), data.origin.y(), data.strokeWidth, angle);
+}
+
+static inline void updateMarkerDataForElement(MarkerData &previousMarkerData, const PathElement *element)
+{
+ FloatPoint *points = element->points;
+
+ switch (element->type) {
+ case PathElementAddQuadCurveToPoint:
+ // TODO
+ previousMarkerData.origin = points[1];
+ break;
+ case PathElementAddCurveToPoint:
+ previousMarkerData.inslopePoints[0] = points[1];
+ previousMarkerData.inslopePoints[1] = points[2];
+ previousMarkerData.origin = points[2];
+ break;
+ case PathElementMoveToPoint:
+ case PathElementAddLineToPoint:
+ case PathElementCloseSubpath:
+ previousMarkerData.inslopePoints[0] = previousMarkerData.origin;
+ previousMarkerData.inslopePoints[1] = points[0];
+ previousMarkerData.origin = points[0];
+ }
+}
+
+static void drawStartAndMidMarkers(void *info, const PathElement *element)
+{
+ DrawMarkersData &data = *(DrawMarkersData *)info;
+
+ int elementIndex = data.elementIndex;
+ MarkerData &previousMarkerData = data.previousMarkerData;
+ FloatPoint *points = element->points;
+
+ // First update the outslope for the previous element
+ previousMarkerData.outslopePoints[0] = previousMarkerData.origin;
+ previousMarkerData.outslopePoints[1] = points[0];
+
+ // Draw the marker for the previous element
+ if (elementIndex != 0)
+ drawMarkerWithData(data.context, previousMarkerData);
+
+ // Update our marker data for this element
+ updateMarkerDataForElement(previousMarkerData, element);
+
+ if (elementIndex == 1) {
+ // After drawing the start marker, switch to drawing mid markers
+ previousMarkerData.marker = data.midMarker;
+ previousMarkerData.type = Mid;
+ }
+
+ data.elementIndex++;
+}
+
+void RenderPath::drawMarkersIfNeeded(GraphicsContext* context, const FloatRect& rect, const Path& path) const
+{
+ Document *doc = document();
+ const SVGRenderStyle *svgStyle = style()->svgStyle();
+
+ KCanvasMarker *startMarker = getMarkerById(doc, svgStyle->startMarker().mid(1));
+ KCanvasMarker *midMarker = getMarkerById(doc, svgStyle->midMarker().mid(1));
+ KCanvasMarker *endMarker = getMarkerById(doc, svgStyle->endMarker().mid(1));
+
+ if (!startMarker && !midMarker && !endMarker)
+ return;
+
+ double strokeWidth = KSVGPainterFactory::cssPrimitiveToLength(this, style()->svgStyle()->strokeWidth(), 1.0);
+
+ DrawMarkersData data(context, startMarker, midMarker, strokeWidth);
+
+ path.apply(&data, drawStartAndMidMarkers);
+
+ data.previousMarkerData.marker = endMarker;
+ data.previousMarkerData.type = End;
+ drawMarkerWithData(context, data.previousMarkerData);
+}
+
+}
+
+#endif // SVG_SUPPORT
Boston, MA 02111-1307, USA.
*/
-#ifndef KCanvasItem_H
-#define KCanvasItem_H
+#ifndef RenderPath_H
+#define RenderPath_H
#ifdef SVG_SUPPORT
#include "DeprecatedValueList.h"
// Hit-detection seperated for the fill and the stroke
virtual bool fillContains(const FloatPoint&, bool requiresFill = true) const;
- virtual bool strokeContains(const FloatPoint&, bool requiresStroke = true) const = 0;
+ virtual bool strokeContains(const FloatPoint&, bool requiresStroke = true) const;
// Returns an unscaled bounding box (not even including localTransform()) for this vector path
virtual FloatRect relativeBBox(bool includeStroke = true) const;
bool canHitFill;
};
-protected:
- virtual void drawMarkersIfNeeded(GraphicsContext*, const FloatRect&, const Path&) const = 0;
- virtual FloatRect strokeBBox() const = 0;
+ virtual void drawMarkersIfNeeded(GraphicsContext*, const FloatRect&, const Path&) const;
+ virtual FloatRect strokeBBox() const;
private:
FloatPoint mapAbsolutePointToLocal(const FloatPoint&) const;
virtual KCanvasFilterEffect *createFilterEffect(const KCFilterEffectType &type) const = 0;
virtual KRenderingPaintServer *createPaintServer(const KCPaintServerType &type) const = 0;
- virtual RenderPath *createItem(RenderArena *arena, RenderStyle *style, SVGStyledElement *node, const Path& path) const = 0;
-
private:
Vector<KRenderingDeviceContext*> m_contextStack;
};
return 0;
}
-// item creation
-RenderPath* KRenderingDeviceQt::createItem(RenderArena* arena, RenderStyle* style, SVGStyledElement* node, const Path& path) const
-{
- RenderPath* item = new (arena) RenderPathQt(style, node);
- item->setPath(path);
- return item;
-}
-
KRenderingDevice* renderingDevice()
{
static KRenderingDevice *sharedRenderingDevice = new KRenderingDeviceQt();
virtual KCanvasResource* createResource(const KCResourceType&) const;
virtual KRenderingPaintServer* createPaintServer(const KCPaintServerType&) const;
virtual KCanvasFilterEffect* createFilterEffect(const KCFilterEffectType&) const;
-
- // item creation
- virtual RenderPath* createItem(RenderArena*, RenderStyle*, SVGStyledElement*, const Path&) const;
};
}
*/
#include "config.h"
-#include "RenderPathQt.h"
+#include "RenderPath.h"
#include "KCanvasRenderingStyle.h"
#include "KRenderingStrokePainter.h"
namespace WebCore {
-RenderPathQt::RenderPathQt(RenderStyle* style, SVGStyledElement* node)
- : RenderPath(style, node)
-{
-}
-
-void RenderPathQt::drawMarkersIfNeeded(GraphicsContext*, const FloatRect&, const Path&) const
-{
- qDebug("RenderPathQt::drawMarkersIfNeeded() TODO!");
-}
-
-bool RenderPathQt::strokeContains(const FloatPoint& point, bool requiresStroke) const
+bool RenderPath::strokeContains(const FloatPoint& point, bool requiresStroke) const
{
if (path().isEmpty())
return false;
return s.createStroke(path);
}
-FloatRect RenderPathQt::strokeBBox() const
+FloatRect RenderPath::strokeBBox() const
{
KRenderingStrokePainter strokePainter = KSVGPainterFactory::strokePainter(style(), this);
QPainterPath outline = getPathStroke(*(path().platformPath()), strokePainter);
-/*
- Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org>
- 2004, 2005, 2006 Rob Buis <buis@kde.org>
- 2005 Eric Seidel <eric.seidel@kdemail.net>
-
- This file is part of the KDE project
-
- 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
- aint with this library; see the file COPYING.LIB. If not, write to
- the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
-
-#ifndef RenderPathQt_H
-#define RenderPathQt_H
-
-#include "RenderPath.h"
-
-namespace WebCore {
-
-class RenderPathQt : public RenderPath
-{
-public:
- RenderPathQt(RenderStyle*, SVGStyledElement*);
-
- virtual bool strokeContains(const FloatPoint&, bool requiresStroke) const;
- virtual FloatRect strokeBBox() const;
-
-protected:
- virtual void drawMarkersIfNeeded(GraphicsContext*, const FloatRect&, const Path&) const;
-};
-
-}
-
-#endif
-
-// vim:ts=4:noet
-/*
- * Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef KCanvasItemQuartz_h
-#define KCanvasItemQuartz_h
-
-#import "kcanvas/RenderPath.h"
-
-#include "AffineTransform.h"
-
-namespace WebCore {
-
-class KCanvasItemQuartz : public RenderPath {
-public:
- KCanvasItemQuartz(RenderStyle*, SVGStyledElement*);
- virtual ~KCanvasItemQuartz() { }
-
- virtual bool strokeContains(const FloatPoint& point, bool = true) const;
- virtual void drawMarkersIfNeeded(GraphicsContext*, const FloatRect&, const Path&) const;
- virtual FloatRect strokeBBox() const;
-};
-
-}
-
-#endif
#include "config.h"
#ifdef SVG_SUPPORT
-#import "KCanvasItemQuartz.h"
#import <wtf/Assertions.h>
namespace WebCore {
-KCanvasItemQuartz::KCanvasItemQuartz(RenderStyle *style, SVGStyledElement *node) : RenderPath(style, node)
-{
-}
-
-typedef enum {
- Start,
- Mid,
- End
-} MarkerType;
-
-struct MarkerData {
- CGPoint origin;
- double strokeWidth;
- CGPoint inslopePoints[2];
- CGPoint outslopePoints[2];
- MarkerType type;
- KCanvasMarker *marker;
-};
-
-struct DrawMarkersData {
- DrawMarkersData(GraphicsContext*, KCanvasMarker* startMarker, KCanvasMarker* midMarker, double strokeWidth);
- GraphicsContext* context;
- int elementIndex;
- MarkerData previousMarkerData;
- KCanvasMarker* midMarker;
-};
-
-DrawMarkersData::DrawMarkersData(GraphicsContext* c, KCanvasMarker *start, KCanvasMarker *mid, double strokeWidth)
- : context(c)
-{
- elementIndex = 0;
- midMarker = mid;
-
- previousMarkerData.origin = CGPointZero;
- previousMarkerData.strokeWidth = strokeWidth;
- previousMarkerData.marker = start;
- previousMarkerData.type = Start;
-}
-
-static void drawMarkerWithData(GraphicsContext* context, MarkerData &data)
-{
- if (!data.marker)
- return;
-
- CGPoint inslopeChange = CGPointSubtractPoints(data.inslopePoints[1], data.inslopePoints[0]);
- CGPoint outslopeChange = CGPointSubtractPoints(data.outslopePoints[1], data.outslopePoints[0]);
-
- static const double deg2rad = M_PI/180.0;
- double inslope = atan2(inslopeChange.y, inslopeChange.x) / deg2rad;
- double outslope = atan2(outslopeChange.y, outslopeChange.x) / deg2rad;
-
- double angle;
- if (data.type == Start)
- angle = outslope;
- else if (data.type == Mid)
- angle = (inslope + outslope) / 2;
- else // (data.type == End)
- angle = inslope;
-
- data.marker->draw(context, FloatRect(), data.origin.x, data.origin.y, data.strokeWidth, angle);
-}
-
-static inline void updateMarkerDataForElement(MarkerData &previousMarkerData, const CGPathElement *element)
-{
- CGPoint *points = element->points;
-
- switch (element->type) {
- case kCGPathElementAddQuadCurveToPoint:
- // TODO
- previousMarkerData.origin = points[1];
- break;
- case kCGPathElementAddCurveToPoint:
- previousMarkerData.inslopePoints[0] = points[1];
- previousMarkerData.inslopePoints[1] = points[2];
- previousMarkerData.origin = points[2];
- break;
- default:
- previousMarkerData.inslopePoints[0] = previousMarkerData.origin;
- previousMarkerData.inslopePoints[1] = points[0];
- previousMarkerData.origin = points[0];
- break;
- }
-}
-
-static void drawStartAndMidMarkers(void *info, const CGPathElement *element)
-{
- DrawMarkersData &data = *(DrawMarkersData *)info;
-
- int elementIndex = data.elementIndex;
- MarkerData &previousMarkerData = data.previousMarkerData;
-
- CGPoint *points = element->points;
-
- // First update the outslope for the previous element
- previousMarkerData.outslopePoints[0] = previousMarkerData.origin;
- previousMarkerData.outslopePoints[1] = points[0];
-
- // Draw the marker for the previous element
- if (elementIndex != 0)
- drawMarkerWithData(data.context, previousMarkerData);
-
- // Update our marker data for this element
- updateMarkerDataForElement(previousMarkerData, element);
-
- if (elementIndex == 1) {
- // After drawing the start marker, switch to drawing mid markers
- previousMarkerData.marker = data.midMarker;
- previousMarkerData.type = Mid;
- }
-
- data.elementIndex++;
-}
-
-void KCanvasItemQuartz::drawMarkersIfNeeded(GraphicsContext* context, const FloatRect& rect, const Path& path) const
-{
- Document *doc = document();
- const SVGRenderStyle *svgStyle = style()->svgStyle();
-
- KCanvasMarker *startMarker = getMarkerById(doc, svgStyle->startMarker().mid(1));
- KCanvasMarker *midMarker = getMarkerById(doc, svgStyle->midMarker().mid(1));
- KCanvasMarker *endMarker = getMarkerById(doc, svgStyle->endMarker().mid(1));
-
- if (!startMarker && !midMarker && !endMarker)
- return;
-
- double strokeWidth = KSVGPainterFactory::cssPrimitiveToLength(this, style()->svgStyle()->strokeWidth(), 1.0);
-
- DrawMarkersData data(context, startMarker, midMarker, strokeWidth);
-
- CGPathRef cgPath = path.platformPath();
- CGPathApply(cgPath, &data, drawStartAndMidMarkers);
-
- data.previousMarkerData.marker = endMarker;
- data.previousMarkerData.type = End;
- drawMarkerWithData(context, data.previousMarkerData);
-}
-
-FloatRect KCanvasItemQuartz::strokeBBox() const
+FloatRect RenderPath::strokeBBox() const
{
if (KSVGPainterFactory::isStroked(style())) {
KRenderingStrokePainter strokePainter = KSVGPainterFactory::strokePainter(style(), this);
}
-bool KCanvasItemQuartz::strokeContains(const FloatPoint& point, bool requiresStroke) const
+bool RenderPath::strokeContains(const FloatPoint& point, bool requiresStroke) const
{
if (path().isEmpty())
return false;
virtual KRenderingPaintServer *createPaintServer(const KCPaintServerType &type) const;
virtual KCanvasFilterEffect *createFilterEffect(const KCFilterEffectType &type) const;
- // item creation
- virtual RenderPath *createItem(RenderArena *arena, RenderStyle *style, SVGStyledElement *node, const Path& path) const;
-
// filters (mostly debugging)
static bool filtersEnabled();
static void setFiltersEnabled(bool enabled);
#import "FoundationExtras.h"
#import "GraphicsContext.h"
#import "KCanvasFilterQuartz.h"
-#import "KCanvasItemQuartz.h"
#import "KCanvasMaskerQuartz.h"
#import "KCanvasResourcesQuartz.h"
#import "KRenderingFillPainter.h"
return newServer;
}
-RenderPath *KRenderingDeviceQuartz::createItem(RenderArena *arena, RenderStyle *style, SVGStyledElement *node, const Path& path) const
-{
- RenderPath *item = new (arena) KCanvasItemQuartz(style, node);
- item->setPath(path);
- return item;
-}
-
KCanvasResource *KRenderingDeviceQuartz::createResource(const KCResourceType &type) const
{
switch (type) {
return kCGLineJoinMiter;
}
-static inline CGPoint CGPointSubtractPoints(CGPoint a, CGPoint b)
-{
- return CGPointMake(a.x - b.x, a.y - b.y);
-}
-
}
#endif // SVG_SUPPORT
#include "SVGNames.h"
#include "csshelper.h"
#include <kcanvas/RenderSVGContainer.h>
-#include <kcanvas/KCanvasCreator.h>
#include <kcanvas/device/KRenderingDevice.h>
namespace WebCore {
#include "SVGCircleElement.h"
#include "SVGAnimatedLength.h"
-#include <kcanvas/KCanvasCreator.h>
-
using namespace WebCore;
SVGCircleElement::SVGCircleElement(const QualifiedName& tagName, Document *doc)
float _cx = cx()->baseVal()->value(), _cy = cy()->baseVal()->value();
float _r = r()->baseVal()->value();
- return KCanvasCreator::self()->createCircle(FloatPoint(_cx, _cy), _r);
+ return Path::createCircle(FloatPoint(_cx, _cy), _r);
}
const SVGStyledElement *SVGCircleElement::pushAttributeContext(const SVGStyledElement *context)
#include "SVGEllipseElement.h"
#include "SVGAnimatedLength.h"
-#include <kcanvas/KCanvasCreator.h>
-
namespace WebCore {
SVGEllipseElement::SVGEllipseElement(const QualifiedName& tagName, Document *doc)
float _cx = cx()->baseVal()->value(), _cy = cy()->baseVal()->value();
float _rx = rx()->baseVal()->value(), _ry = ry()->baseVal()->value();
- return KCanvasCreator::self()->createEllipse(FloatPoint(_cx, _cy), _rx, _ry);
+ return Path::createEllipse(FloatPoint(_cx, _cy), _rx, _ry);
}
const SVGStyledElement *SVGEllipseElement::pushAttributeContext(const SVGStyledElement *context)
#include "SVGAnimatedString.h"
#include "SVGHelper.h"
#include "SVGNames.h"
-#include <kcanvas/KCanvasCreator.h>
#include <kcanvas/KCanvasImage.h>
#include <kcanvas/device/KRenderingDevice.h>
#include <kcanvas/device/KRenderingFillPainter.h>
#ifdef SVG_SUPPORT
#include "SVGGElement.h"
-#include <kcanvas/KCanvasCreator.h>
#include <kcanvas/RenderSVGContainer.h>
#include <kcanvas/device/KRenderingDevice.h>
#include "SVGSVGElement.h"
#include "XLinkNames.h"
#include <kcanvas/RenderSVGContainer.h>
-#include <kcanvas/KCanvasCreator.h>
#include <kcanvas/KCanvasImage.h>
#include <wtf/Assertions.h>
#include "SVGLineElement.h"
#include "SVGAnimatedLength.h"
-#include <kcanvas/KCanvasCreator.h>
-
using namespace WebCore;
SVGLineElement::SVGLineElement(const QualifiedName& tagName, Document *doc)
float _x1 = x1()->baseVal()->value(), _y1 = y1()->baseVal()->value();
float _x2 = x2()->baseVal()->value(), _y2 = y2()->baseVal()->value();
- return KCanvasCreator::self()->createLine(FloatPoint(_x1, _y1), FloatPoint(_x2, _y2));
+ return Path::createLine(FloatPoint(_x1, _y1), FloatPoint(_x2, _y2));
}
const SVGStyledElement *SVGLineElement::pushAttributeContext(const SVGStyledElement *context)
#include "SVGSVGElement.h"
#include "ksvg.h"
#include <kcanvas/RenderSVGContainer.h>
-#include <kcanvas/KCanvasCreator.h>
#include <kcanvas/device/KRenderingDevice.h>
namespace WebCore {
#include "SVGPathSegCurvetoCubicSmooth.h"
#include "SVGPathSegCurvetoQuadraticSmooth.h"
-#include <kcanvas/KCanvasCreator.h>
#include <kcanvas/device/KRenderingDevice.h>
namespace WebCore {
#include "Document.h"
#include "GraphicsContext.h"
#include "RenderSVGContainer.h"
-#include "KCanvasCreator.h"
#include "KCanvasImage.h"
#include "KCanvasRenderingStyle.h"
#include "KRenderingDevice.h"
#include "SVGPointList.h"
#include "SVGPolygonElement.h"
-#include <kcanvas/KCanvasCreator.h>
#include <kcanvas/device/KRenderingDevice.h>
using namespace WebCore;
#include "SVGPointList.h"
#include "SVGPolylineElement.h"
-#include <kcanvas/KCanvasCreator.h>
#include <kcanvas/device/KRenderingDevice.h>
using namespace WebCore;
#include <kcanvas/device/KRenderingDevice.h>
#include <kcanvas/device/KRenderingFillPainter.h>
#include <kcanvas/device/KRenderingPaintServerSolid.h>
-#include <kcanvas/KCanvasCreator.h>
namespace WebCore {
{
float _rx = hasRx ? rx()->baseVal()->value() : ry()->baseVal()->value();
float _ry = hasRy ? ry()->baseVal()->value() : rx()->baseVal()->value();
- return KCanvasCreator::self()->createRoundedRectangle(FloatRect(_x, _y, _width, _height), FloatSize(_rx, _ry));
+ return Path::createRoundedRectangle(FloatRect(_x, _y, _width, _height), FloatSize(_rx, _ry));
}
- return KCanvasCreator::self()->createRectangle(FloatRect(_x, _y, _width, _height));
+ return Path::createRectangle(FloatRect(_x, _y, _width, _height));
}
const SVGStyledElement *SVGRectElement::pushAttributeContext(const SVGStyledElement *context)
#include "SVGZoomEvent.h"
#include "ksvg.h"
#include <kcanvas/RenderSVGContainer.h>
-#include <kcanvas/KCanvasCreator.h>
#include <kcanvas/device/KRenderingDevice.h>
#include "TextStream.h"
#include "Attr.h"
#include "Document.h"
-#include "KCanvasCreator.h"
#include "KCanvasRenderingStyle.h"
#include "KRenderingDevice.h"
#include "PlatformString.h"
Path pathData = toPathData();
if (pathData.isEmpty())
return 0;
- return renderingDevice()->createItem(arena, style, this, pathData);
+
+ RenderPath *item = new (arena) RenderPath(style, this);
+ item->setPath(pathData);
+ return item;
}
void SVGStyledElement::parseMappedAttribute(MappedAttribute* attr)
#ifdef SVG_SUPPORT
#include "Attr.h"
-#include <kcanvas/KCanvasCreator.h>
#include <kcanvas/RenderSVGContainer.h>
#include <kcanvas/device/KRenderingDevice.h>
#include "SVGRenderStyle.h"
#include "SVGTSpanElement.h"
#include "RenderStyle.h"
-#include <kcanvas/KCanvasCreator.h>
#include <kcanvas/RenderSVGText.h>
#include "FloatRect.h"
#include "SVGSymbolElement.h"
#include "ksvg.h"
#include <kcanvas/RenderSVGContainer.h>
-#include <kcanvas/KCanvasCreator.h>
#include <kcanvas/device/KRenderingDevice.h>
using namespace WebCore;
namespace WebCore {
+ class AffineTransform;
+ class FloatPoint;
+ class FloatSize;
+ class FloatRect;
+ class String;
+
enum WindRule {
RULE_NONZERO = 0,
RULE_EVENODD = 1
};
- class FloatPoint;
- class FloatSize;
- class FloatRect;
- class String;
+ enum PathElementType {
+ PathElementMoveToPoint,
+ PathElementAddLineToPoint,
+ PathElementAddQuadCurveToPoint,
+ PathElementAddCurveToPoint,
+ PathElementCloseSubpath
+ };
+
+ struct PathElement {
+ PathElementType type;
+ FloatPoint* points;
+ };
+
+ typedef void (*PathApplierFunction) (void* info, const PathElement*);
class Path {
public:
PlatformPath* platformPath() const { return m_path; }
+ static Path createRoundedRectangle(const FloatRect&, const FloatSize& roundingRadii);
+ static Path createRectangle(const FloatRect&);
+ static Path createEllipse(const FloatPoint& center, float rx, float ry);
+ static Path createCircle(const FloatPoint& center, float r);
+ static Path createLine(const FloatPoint&, const FloatPoint&);
+
+ void apply(void* info, PathApplierFunction) const;
+ void transform(const AffineTransform&);
+
private:
PlatformPath* m_path;
WindRule m_rule;
#include "FloatRect.h"
#include "PlatformString.h"
+#include "AffineTransform.h"
#include <ApplicationServices/ApplicationServices.h>
namespace WebCore {
return CGPathIsEmpty(m_path);
}
-void CGPathToCFStringApplierFunction(void *info, const CGPathElement *element)
+void CGPathToCFStringApplierFunction(void* info, const CGPathElement *element)
{
CFMutableStringRef string = (CFMutableStringRef)info;
CFStringRef typeString = CFSTR("");
- CGPoint *points = element->points;
- switch(element->type) {
+ CGPoint* points = element->points;
+ switch (element->type) {
case kCGPathElementMoveToPoint:
CFStringAppendFormat(string, 0, CFSTR("M%.2f,%.2f"), points[0].x, points[0].y);
break;
return result;
}
+struct PathApplierInfo {
+ void* info;
+ PathApplierFunction function;
+};
+
+void CGPathApplierToPathApplier(void *info, const CGPathElement *element)
+{
+ PathApplierInfo* pinfo = (PathApplierInfo*)info;
+ FloatPoint points[2];
+ PathElement pelement;
+ pelement.type = (PathElementType)element->type;
+ pelement.points = points;
+ CGPoint* cgPoints = element->points;
+ switch (element->type) {
+ case kCGPathElementMoveToPoint:
+ case kCGPathElementAddLineToPoint:
+ points[0] = cgPoints[0];
+ break;
+ case kCGPathElementAddQuadCurveToPoint:
+ points[0] = cgPoints[0];
+ points[1] = cgPoints[1];
+ break;
+ case kCGPathElementAddCurveToPoint:
+ points[0] = cgPoints[0];
+ points[1] = cgPoints[1];
+ points[2] = cgPoints[2];
+ break;
+ case kCGPathElementCloseSubpath:
+ break;
+ }
+ pinfo->function(pinfo->info, &pelement);
+}
+
+void Path::apply(void* info, PathApplierFunction function) const
+{
+ PathApplierInfo pinfo;
+ pinfo.info = info;
+ pinfo.function = function;
+ CGPathApply(m_path, &pinfo, CGPathApplierToPathApplier);
+}
+
+void Path::transform(const AffineTransform& transform)
+{
+ CGMutablePathRef path = CGPathCreateMutable();
+ CGAffineTransform transformCG = transform;
+ CGPathAddPath(path, &transformCG, m_path);
+ CGPathRelease(m_path);
+ m_path = path;
+}
+
}
#endif // PLATFORM(CG)
return ret;
}
+void Path::apply(void* info, PathApplierFunction function) const
+{
+ PathElement pelement;
+ FloatPoint points[2];
+ pelement.points = points;
+ for (int i = 0; i < m_path->elementCount(); ++i) {
+ const QPainterPath::Element& cur = m_path->elementAt(i);
+
+ switch (cur.type) {
+ case QPainterPath::MoveToElement:
+ pelement.type = PathElementMoveToPoint;
+ pelement.points[0] = cur;
+ function(info, &pelement);
+ break;
+ case QPainterPath::LineToElement:
+ pelement.type = PathElementAddLineToPoint;
+ pelement.points[0] = cur;
+ function(info, &pelement);
+ break;
+ case QPainterPath::CurveToElement:
+ {
+ const QPainterPath::Element& c1 = m_path->elementAt(i + 1);
+ const QPainterPath::Element& c2 = m_path->elementAt(i + 2);
+
+ Q_ASSERT(c1.type == QPainterPath::CurveToDataElement);
+ Q_ASSERT(c2.type == QPainterPath::CurveToDataElement);
+
+ pelement.type = PathElementAddCurveToPoint;
+ pelement.points[0] = cur;
+ pelement.points[1] = c1;
+ pelement.points[2] = c2;
+ function(info, &pelement);
+
+ i += 2;
+ break;
+ }
+ case QPainterPath::CurveToDataElement:
+ Q_ASSERT(false);
+ }
+ }
+}
+
}
// vim: ts=4 sw=4 et