Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_svg_import.cc
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#include "kis_svg_import.h"
8
9#include <kpluginfactory.h>
10#include <QFileInfo>
11#include "kis_config.h"
12
13#include <QInputDialog>
14#include <KisDocument.h>
15#include <kis_image.h>
16
17#include <SvgParser.h>
19#include "kis_shape_layer.h"
21
22K_PLUGIN_FACTORY_WITH_JSON(SVGImportFactory, "krita_svg_import.json", registerPlugin<KisSVGImport>();)
23
24KisSVGImport::KisSVGImport(QObject *parent, const QVariantList &) : KisImportExportFilter(parent)
25{
26}
27
31
33{
34 Q_UNUSED(configuration);
35
36 KisDocument * doc = document;
37
38 const QString baseXmlDir = QFileInfo(filename()).canonicalPath();
39
40 KisConfig cfg(false);
41
42 qreal resolutionPPI = cfg.preferredVectorImportResolutionPPI(true);
43
44 if (!batchMode()) {
45 bool okay = false;
46 const QString name = QFileInfo(filename()).fileName();
47 resolutionPPI = QInputDialog::getInt(0,
48 i18n("Import SVG"),
49 i18n("Enter preferred resolution (PPI) for \"%1\"", name),
51 0, 100000, 1, &okay);
52
53 if (!okay) {
55 }
56
58 }
59
60 const qreal resolution = resolutionPPI;
61
62 QStringList warnings;
63 QStringList errors;
64
65 QSizeF fragmentSize;
66 QList<KoShape*> shapes =
68 QRectF(0,0,1200,800), resolutionPPI,
70 false,
71 &fragmentSize,
72 &warnings, &errors);
73
74 if (!warnings.isEmpty()) {
75 doc->setWarningMessage(warnings.join('\n'));
76 }
77 if (!errors.isEmpty()) {
78 doc->setErrorMessage(errors.join('\n'));
80 }
81
82
83 QRectF rawImageRect(QPointF(), fragmentSize);
84 QRect imageRect(rawImageRect.toAlignedRect());
85
87 KisImageSP image = new KisImage(doc->createUndoStore(), imageRect.width(), imageRect.height(), cs, "svg image");
88 image->setResolution(resolution / 72.0, resolution / 72.0);
89 doc->setCurrentImage(image);
90
91 KisShapeLayerSP shapeLayer =
92 new KisShapeLayer(doc->shapeController(), image,
93 i18n("Vector Layer"),
95
96 Q_FOREACH (KoShape *shape, shapes) {
97 shapeLayer->addShape(shape);
98 }
99
100 image->addNode(shapeLayer);
102}
103
104#include <kis_svg_import.moc>
const quint8 OPACITY_OPAQUE_U8
void setPreferredVectorImportResolutionPPI(int value) const
int preferredVectorImportResolutionPPI(bool defaultValue=false) const
KisUndoStore * createUndoStore()
KisShapeController * shapeController
void setErrorMessage(const QString &errMsg)
void setWarningMessage(const QString &warningMsg)
void setCurrentImage(KisImageSP image, bool forceInitialUpdate=true, KisNodeSP preActivatedNode=nullptr)
void setResolution(double xres, double yres)
The base class for import and export filters.
KisImportExportErrorCode convert(KisDocument *document, QIODevice *io, KisPropertiesConfigurationSP configuration) override
KisSVGImport(QObject *parent, const QVariantList &)
~KisSVGImport() override
static QList< KoShape * > createShapesFromSvg(QIODevice *device, const QString &baseXmlDir, const QRectF &rectInPixels, qreal resolutionPPI, KoDocumentResourceManager *resourceManager, bool loadingFromKra, QSizeF *fragmentSize, QStringList *warnings=0, QStringList *errors=0)
void addShape(KoShape *shape)
virtual KoDocumentResourceManager * resourceManager() const
K_PLUGIN_FACTORY_WITH_JSON(KritaASCCDLFactory, "kritaasccdl.json", registerPlugin< KritaASCCDL >();) KritaASCCDL
bool addNode(KisNodeSP node, KisNodeSP parent=KisNodeSP(), KisNodeAdditionFlags flags=KisNodeAdditionFlag::None)
static KoColorSpaceRegistry * instance()
const KoColorSpace * rgb8(const QString &profileName=QString())