42#include <QSvgGenerator>
48 : m_writeInlineImages(true)
55 : m_toplevelShapes(toplevelShapes)
56 , m_writeInlineImages(true)
65bool SvgWriter::save(
const QString &filename,
const QSizeF &pageSize,
bool writeInlineImages)
67 QFile fileOut(filename);
68 if (!fileOut.open(QIODevice::WriteOnly))
73 const bool success =
save(fileOut, pageSize);
88 QTextStream svgStream(&outputDevice);
92 svgStream <<
"<?xml version=\"1.0\" standalone=\"no\"?>" << Qt::endl;
93 svgStream <<
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 20010904//EN\" ";
94 svgStream <<
"\"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd\">" << Qt::endl;
97 svgStream <<
"<!-- Created using Krita: https://krita.org -->" << Qt::endl;
99 svgStream <<
"<svg xmlns=\"http://www.w3.org/2000/svg\" \n";
100 svgStream <<
" xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n";
101 svgStream << QString(
" xmlns:krita=\"%1\"\n").arg(
KoXmlNS::krita);
102 svgStream <<
" xmlns:sodipodi=\"http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd\"\n";
103 svgStream <<
" width=\"" << pageSize.width() <<
"pt\"\n";
104 svgStream <<
" height=\"" << pageSize.height() <<
"pt\"\n";
105 svgStream <<
" viewBox=\"0 0 "
106 << pageSize.width() <<
" " << pageSize.height()
108 svgStream <<
">" << Qt::endl;
124 svgStream << Qt::endl <<
"</svg>" << Qt::endl;
153 Q_FOREACH (
KoShape *shape, shapes) {
175 Q_FOREACH (
KoShape * shape, sortedShapes) {
201 Q_FOREACH (
KoShape * shape, sortedShapes) {
215 if (svgShape && svgShape->
saveSvg(context))
238 context.
shapeWriter().addAttribute(
"sodipodi:nodetypes", path->nodeTypes());
254 QSvgGenerator svgGenerator;
255 svgGenerator.setOutputDevice(&svgBuffer);
266 if (shape->
shapeId() ==
"TextShapeID") {
267 svgGenerator.setResolution(54);
271 svgPainter.begin(&svgGenerator);
276 int startOfContent = svgBuffer.buffer().indexOf(
"<svg");
277 if(startOfContent>0) {
278 svgBuffer.buffer().remove(0, startOfContent);
282 if (svgBuffer.buffer().isEmpty()) {
284 QImage image(2*bbox.size().toSize(), QImage::Format_ARGB32);
286 painter.
paint(image);
292 context.
shapeWriter().addAttribute(
"width", bbox.width());
293 context.
shapeWriter().addAttribute(
"height", bbox.height());
298 context.
shapeWriter().addCompleteElement(&svgBuffer);
The position of a path point within a path shape.
QList< KoShape * > shapes() const
void setShapes(const QList< KoShape * > &shapes)
void paint(QPainter &painter)
static bool compareShapeZIndex(KoShape *s1, KoShape *s2)
virtual QRectF boundingRect() const
Get the bounding box of the shape.
QTransform transformation() const
Returns the shapes local transformation matrix.
static const QString krita
Context for saving svg files.
QTransform userSpaceTransform() const
Returns the transformation used to transform into user space.
QString saveImage(const QImage &image)
Saves given image and returns the href used.
QScopedPointer< KoXmlWriter > shapeWriter
QString getID(const KoShape *obj)
Returns the unique id for the given shape.
An interface providing svg loading and saving routines.
virtual bool saveSvg(SvgSavingContext &context)
Saves data utilizing specified svg saving context.
static void saveSvgStyle(KoShape *shape, SvgSavingContext &context)
Saves the style of the specified shape.
static void saveMetadata(const KoShape *shape, SvgSavingContext &context)
static double toUserSpace(double value)
static void writeTransformAttributeLazy(const QString &name, const QTransform &transform, KoXmlWriter &shapeWriter)
Writes a transform as an attribute name iff the transform is not empty.
void saveGroup(KoShapeGroup *group, SvgSavingContext &context)
SvgWriter(const QList< KoShapeLayer * > &layers)
Creates svg writer to export specified layers.
void saveGeneric(KoShape *shape, SvgSavingContext &context)
void saveShapes(const QList< KoShape * > shapes, SvgSavingContext &savingContext)
QString m_documentDescription
void saveShape(KoShape *shape, SvgSavingContext &context)
void savePath(KoPathShape *path, SvgSavingContext &context)
bool saveDetached(QIODevice &outputDevice)
void setDocumentDescription(QString description)
QList< KoShape * > m_toplevelShapes
bool save(QIODevice &outputDevice, const QSizeF &pageSize)
Writes svg to specified output device.
void saveLayer(KoShapeLayer *layer, SvgSavingContext &context)
virtual ~SvgWriter()
Destroys the svg writer.
void setDocumentTitle(QString title)
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
void setUtf8OnStream(QTextStream &stream)