Ejemplo n.º 1
0
bool PictureShape::saveSvg(SvgSavingContext &context)
{
    KoImageData *imageData = qobject_cast<KoImageData*>(userData());
    if (!imageData) {
        qWarning() << "Picture has no image data. Omitting.";
        return false;
    }

    context.shapeWriter().startElement("image");
    context.shapeWriter().addAttribute("id", context.getID(this));

    QTransform m = transformation();
    if (m.type() == QTransform::TxTranslate) {
        const QPointF pos = position();
        context.shapeWriter().addAttributePt("x", pos.x());
        context.shapeWriter().addAttributePt("y", pos.y());
    } else {
        context.shapeWriter().addAttribute("transform", SvgUtil::transformToString(m));
    }

    const QSizeF s = size();
    context.shapeWriter().addAttributePt("width", s.width());
    context.shapeWriter().addAttributePt("height", s.height());
    context.shapeWriter().addAttribute("xlink:href", context.saveImage(imageData));
    context.shapeWriter().endElement();

    return true;
}
Ejemplo n.º 2
0
bool RectangleShape::saveSvg(SvgSavingContext &context)
{
    context.shapeWriter().startElement("rect");
    context.shapeWriter().addAttribute("id", context.getID(this));
    context.shapeWriter().addAttribute("transform", SvgUtil::transformToString(transformation()));

    SvgStyleWriter::saveSvgStyle(this, context);

    const QSizeF size = this->size();
    context.shapeWriter().addAttributePt("width", size.width());
    context.shapeWriter().addAttributePt("height", size.height());

    double rx = cornerRadiusX();
    if (rx > 0.0)
        context.shapeWriter().addAttributePt("rx", 0.01 * rx * 0.5 * size.width());
    double ry = cornerRadiusY();
    if (ry > 0.0)
        context.shapeWriter().addAttributePt("ry", 0.01 * ry * 0.5 * size.height());

    context.shapeWriter().endElement();

    return true;
}