diff options
Diffstat (limited to 'Source/WebCore/rendering/svg/SVGPathData.cpp')
-rw-r--r-- | Source/WebCore/rendering/svg/SVGPathData.cpp | 77 |
1 files changed, 46 insertions, 31 deletions
diff --git a/Source/WebCore/rendering/svg/SVGPathData.cpp b/Source/WebCore/rendering/svg/SVGPathData.cpp index 01ef871f7..6eeb5476c 100644 --- a/Source/WebCore/rendering/svg/SVGPathData.cpp +++ b/Source/WebCore/rendering/svg/SVGPathData.cpp @@ -20,14 +20,18 @@ #include "config.h" #include "SVGPathData.h" -#if ENABLE(SVG) #include "Path.h" +#include "RenderElement.h" +#include "RenderStyle.h" #include "SVGCircleElement.h" #include "SVGEllipseElement.h" +#include "SVGLengthContext.h" #include "SVGLineElement.h" #include "SVGNames.h" #include "SVGPathElement.h" #include "SVGPathUtilities.h" +#include "SVGPoint.h" +#include "SVGPointList.h" #include "SVGPolygonElement.h" #include "SVGPolylineElement.h" #include "SVGRectElement.h" @@ -37,32 +41,42 @@ namespace WebCore { static void updatePathFromCircleElement(SVGElement* element, Path& path) { - ASSERT(isSVGCircleElement(element)); - SVGCircleElement* circle = toSVGCircleElement(element); + ASSERT(is<SVGCircleElement>(element)); SVGLengthContext lengthContext(element); - float r = circle->r().value(lengthContext); - if (r > 0) - path.addEllipse(FloatRect(circle->cx().value(lengthContext) - r, circle->cy().value(lengthContext) - r, r * 2, r * 2)); + RenderElement* renderer = element->renderer(); + if (!renderer) + return; + auto& style = renderer->style(); + float r = lengthContext.valueForLength(style.svgStyle().r()); + if (r > 0) { + float cx = lengthContext.valueForLength(style.svgStyle().cx(), LengthModeWidth); + float cy = lengthContext.valueForLength(style.svgStyle().cy(), LengthModeHeight); + path.addEllipse(FloatRect(cx - r, cy - r, r * 2, r * 2)); + } } static void updatePathFromEllipseElement(SVGElement* element, Path& path) { - SVGEllipseElement* ellipse = toSVGEllipseElement(element); - + RenderElement* renderer = element->renderer(); + if (!renderer) + return; + auto& style = renderer->style(); SVGLengthContext lengthContext(element); - float rx = ellipse->rx().value(lengthContext); + float rx = lengthContext.valueForLength(style.svgStyle().rx(), LengthModeWidth); if (rx <= 0) return; - float ry = ellipse->ry().value(lengthContext); + float ry = lengthContext.valueForLength(style.svgStyle().ry(), LengthModeHeight); if (ry <= 0) return; - path.addEllipse(FloatRect(ellipse->cx().value(lengthContext) - rx, ellipse->cy().value(lengthContext) - ry, rx * 2, ry * 2)); + float cx = lengthContext.valueForLength(style.svgStyle().cx(), LengthModeWidth); + float cy = lengthContext.valueForLength(style.svgStyle().cy(), LengthModeHeight); + path.addEllipse(FloatRect(cx - rx, cy - ry, rx * 2, ry * 2)); } static void updatePathFromLineElement(SVGElement* element, Path& path) { - SVGLineElement* line = toSVGLineElement(element); + SVGLineElement* line = downcast<SVGLineElement>(element); SVGLengthContext lengthContext(element); path.moveTo(FloatPoint(line->x1().value(lengthContext), line->y1().value(lengthContext))); @@ -71,12 +85,12 @@ static void updatePathFromLineElement(SVGElement* element, Path& path) static void updatePathFromPathElement(SVGElement* element, Path& path) { - buildPathFromByteStream(toSVGPathElement(element)->pathByteStream(), path); + buildPathFromByteStream(downcast<SVGPathElement>(element)->pathByteStream(), path); } static void updatePathFromPolygonElement(SVGElement* element, Path& path) { - SVGPointList& points = toSVGPolygonElement(element)->animatedPoints()->values(); + auto& points = downcast<SVGPolygonElement>(element)->animatedPoints()->values(); if (points.isEmpty()) return; @@ -91,7 +105,7 @@ static void updatePathFromPolygonElement(SVGElement* element, Path& path) static void updatePathFromPolylineElement(SVGElement* element, Path& path) { - SVGPointList& points = toSVGPolylineElement(element)->animatedPoints()->values(); + auto& points = downcast<SVGPolylineElement>(element)->animatedPoints()->values(); if (points.isEmpty()) return; @@ -104,19 +118,22 @@ static void updatePathFromPolylineElement(SVGElement* element, Path& path) static void updatePathFromRectElement(SVGElement* element, Path& path) { - SVGRectElement* rect = toSVGRectElement(element); + RenderElement* renderer = element->renderer(); + if (!renderer) + return; + auto& style = renderer->style(); SVGLengthContext lengthContext(element); - float width = rect->width().value(lengthContext); + float width = lengthContext.valueForLength(style.width(), LengthModeWidth); if (width <= 0) return; - float height = rect->height().value(lengthContext); + float height = lengthContext.valueForLength(style.height(), LengthModeHeight); if (height <= 0) return; - float x = rect->x().value(lengthContext); - float y = rect->y().value(lengthContext); - float rx = rect->rx().value(lengthContext); - float ry = rect->ry().value(lengthContext); + float x = lengthContext.valueForLength(style.svgStyle().x(), LengthModeWidth); + float y = lengthContext.valueForLength(style.svgStyle().y(), LengthModeHeight); + float rx = lengthContext.valueForLength(style.svgStyle().rx(), LengthModeWidth); + float ry = lengthContext.valueForLength(style.svgStyle().ry(), LengthModeHeight); bool hasRx = rx > 0; bool hasRy = ry > 0; if (hasRx || hasRy) { @@ -143,13 +160,13 @@ void updatePathFromGraphicsElement(SVGElement* element, Path& path) static HashMap<AtomicStringImpl*, PathUpdateFunction>* map = 0; if (!map) { map = new HashMap<AtomicStringImpl*, PathUpdateFunction>; - map->set(SVGNames::circleTag.localName().impl(), &updatePathFromCircleElement); - map->set(SVGNames::ellipseTag.localName().impl(), &updatePathFromEllipseElement); - map->set(SVGNames::lineTag.localName().impl(), &updatePathFromLineElement); - map->set(SVGNames::pathTag.localName().impl(), &updatePathFromPathElement); - map->set(SVGNames::polygonTag.localName().impl(), &updatePathFromPolygonElement); - map->set(SVGNames::polylineTag.localName().impl(), &updatePathFromPolylineElement); - map->set(SVGNames::rectTag.localName().impl(), &updatePathFromRectElement); + map->set(SVGNames::circleTag.localName().impl(), updatePathFromCircleElement); + map->set(SVGNames::ellipseTag.localName().impl(), updatePathFromEllipseElement); + map->set(SVGNames::lineTag.localName().impl(), updatePathFromLineElement); + map->set(SVGNames::pathTag.localName().impl(), updatePathFromPathElement); + map->set(SVGNames::polygonTag.localName().impl(), updatePathFromPolygonElement); + map->set(SVGNames::polylineTag.localName().impl(), updatePathFromPolylineElement); + map->set(SVGNames::rectTag.localName().impl(), updatePathFromRectElement); } if (PathUpdateFunction pathUpdateFunction = map->get(element->localName().impl())) @@ -157,5 +174,3 @@ void updatePathFromGraphicsElement(SVGElement* element, Path& path) } } // namespace WebCore - -#endif // ENABLE(SVG) |