Example #1
0
static void updatePathFromRectElement(SVGElement* element, Path& path)
{
    SVGRectElement* rect = toSVGRectElement(element);
    ASSERT(rect->layoutObject());

    SVGLengthContext lengthContext(element);
    const ComputedStyle& style = rect->layoutObject()->styleRef();
    float width = lengthContext.valueForLength(style.width(), style, SVGLengthMode::Width);
    if (width < 0)
        return;
    float height = lengthContext.valueForLength(style.height(), style, SVGLengthMode::Height);
    if (height < 0)
        return;
    if (!width && !height)
        return;

    float x = lengthContext.valueForLength(style.svgStyle().x(), style, SVGLengthMode::Width);
    float y = lengthContext.valueForLength(style.svgStyle().y(), style, SVGLengthMode::Height);
    float rx = lengthContext.valueForLength(style.svgStyle().rx(), style, SVGLengthMode::Width);
    float ry = lengthContext.valueForLength(style.svgStyle().ry(), style, SVGLengthMode::Height);
    bool hasRx = rx > 0;
    bool hasRy = ry > 0;
    if (hasRx || hasRy) {
        if (!hasRx)
            rx = ry;
        else if (!hasRy)
            ry = rx;

        path.addRoundedRect(FloatRect(x, y, width, height), FloatSize(rx, ry));
        return;
    }

    path.addRect(FloatRect(x, y, width, height));
}