Пример #1
0
void RenderSVGEllipse::calculateRadiiAndCenter()
{
    ASSERT(element());
    if (element()->hasTagName(SVGNames::circleTag)) {
        SVGCircleElement* circle = toSVGCircleElement(element());

        SVGLengthContext lengthContext(circle);
        float radius = circle->rCurrentValue().value(lengthContext);
        m_radii = FloatSize(radius, radius);
        m_center = FloatPoint(circle->cxCurrentValue().value(lengthContext), circle->cyCurrentValue().value(lengthContext));
        return;
    }

    SVGEllipseElement* ellipse = toSVGEllipseElement(element());

    SVGLengthContext lengthContext(ellipse);
    m_radii = FloatSize(ellipse->rxCurrentValue().value(lengthContext), ellipse->ryCurrentValue().value(lengthContext));
    m_center = FloatPoint(ellipse->cxCurrentValue().value(lengthContext), ellipse->cyCurrentValue().value(lengthContext));
}
static TextStream& operator<<(TextStream& ts, const RenderSVGShape& shape)
{
    writePositionAndStyle(ts, shape);

    SVGElement* svgElement = shape.element();
    SVGLengthContext lengthContext(svgElement);

    if (svgElement->hasTagName(SVGNames::rectTag)) {
        SVGRectElement* element = toSVGRectElement(svgElement);
        writeNameValuePair(ts, "x", element->xCurrentValue().value(lengthContext));
        writeNameValuePair(ts, "y", element->yCurrentValue().value(lengthContext));
        writeNameValuePair(ts, "width", element->widthCurrentValue().value(lengthContext));
        writeNameValuePair(ts, "height", element->heightCurrentValue().value(lengthContext));
    } else if (svgElement->hasTagName(SVGNames::lineTag)) {
        SVGLineElement* element = toSVGLineElement(svgElement);
        writeNameValuePair(ts, "x1", element->x1CurrentValue().value(lengthContext));
        writeNameValuePair(ts, "y1", element->y1CurrentValue().value(lengthContext));
        writeNameValuePair(ts, "x2", element->x2CurrentValue().value(lengthContext));
        writeNameValuePair(ts, "y2", element->y2CurrentValue().value(lengthContext));
    } else if (svgElement->hasTagName(SVGNames::ellipseTag)) {
        SVGEllipseElement* element = toSVGEllipseElement(svgElement);
        writeNameValuePair(ts, "cx", element->cxCurrentValue().value(lengthContext));
        writeNameValuePair(ts, "cy", element->cyCurrentValue().value(lengthContext));
        writeNameValuePair(ts, "rx", element->rxCurrentValue().value(lengthContext));
        writeNameValuePair(ts, "ry", element->ryCurrentValue().value(lengthContext));
    } else if (svgElement->hasTagName(SVGNames::circleTag)) {
        SVGCircleElement* element = toSVGCircleElement(svgElement);
        writeNameValuePair(ts, "cx", element->cxCurrentValue().value(lengthContext));
        writeNameValuePair(ts, "cy", element->cyCurrentValue().value(lengthContext));
        writeNameValuePair(ts, "r", element->rCurrentValue().value(lengthContext));
    } else if (svgElement->hasTagName(SVGNames::polygonTag) || svgElement->hasTagName(SVGNames::polylineTag)) {
        writeNameAndQuotedValue(ts, "points", toSVGPolyElement(svgElement)->pointList().valueAsString());
    } else if (svgElement->hasTagName(SVGNames::pathTag)) {
        String pathString;
        // FIXME: We should switch to UnalteredParsing here - this will affect the path dumping output of dozens of tests.
        buildStringFromByteStream(toSVGPathElement(svgElement)->pathByteStream(), pathString, NormalizedParsing);
        writeNameAndQuotedValue(ts, "data", pathString);
    } else
        ASSERT_NOT_REACHED();
    return ts;
}