diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2022-11-07 14:36:06 +0100 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2022-11-29 09:10:44 +0000 |
commit | 5019037adf38f7b7fd299949af3f8f46c07e574d (patch) | |
tree | d10d4ba97560b7df6b5d26be25c2e20376ed1b1b /src | |
parent | 4df3e31a72c9a3524870c8953b9ae6e9192dcc0d (diff) | |
download | qtsvg-5019037adf38f7b7fd299949af3f8f46c07e574d.tar.gz |
QSvgGenerator: introduce a way to make it output SVG 1.1
Add an opt-in measure for QSvgGenerator to request SVG 1.1 output.
This will enable the generator to honor non-Tiny features, such as
clip paths, introduced in the next commits.
[ChangeLog][QtSvg][QSvgGenerator] QSvgGenerator is now prepared to
produce SVG 1.1 documents. This will enable QSvgGenerator to support
more SVG features in the future, such as SVG clip paths.
Please note that the actual feature set supported by QSvgGenerator is
still very limited; extensive testing is recommended.
Change-Id: Ief133953e4eb25bf9bde344320fadfb49b65fd31
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/svg/qsvggenerator.cpp | 61 | ||||
-rw-r--r-- | src/svg/qsvggenerator.h | 13 |
2 files changed, 67 insertions, 7 deletions
diff --git a/src/svg/qsvggenerator.cpp b/src/svg/qsvggenerator.cpp index d452670..7514275 100644 --- a/src/svg/qsvggenerator.cpp +++ b/src/svg/qsvggenerator.cpp @@ -50,7 +50,8 @@ static void translate_dashPattern(const QList<qreal> &pattern, qreal width, QStr class QSvgPaintEnginePrivate : public QPaintEnginePrivate { public: - QSvgPaintEnginePrivate() + explicit QSvgPaintEnginePrivate(QSvgGenerator::SvgVersion version) + : svgVersion(version) { size = QSize(); viewBox = QRectF(); @@ -68,6 +69,7 @@ public: numGradients = 0; } + QSvgGenerator::SvgVersion svgVersion; QSize size; QRectF viewBox; QIODevice *outputDevice; @@ -125,8 +127,8 @@ class QSvgPaintEngine : public QPaintEngine Q_DECLARE_PRIVATE(QSvgPaintEngine) public: - QSvgPaintEngine() - : QPaintEngine(*new QSvgPaintEnginePrivate, + explicit QSvgPaintEngine(QSvgGenerator::SvgVersion version) + : QPaintEngine(*new QSvgPaintEnginePrivate(version), svgEngineFeatures()) { } @@ -182,6 +184,8 @@ public: d_func()->resolution = resolution; } + QSvgGenerator::SvgVersion svgVersion() const { return d_func()->svgVersion; } + QString savePatternMask(Qt::BrushStyle style) { QString maskId = QString(QStringLiteral("patternmask%1")).arg(style); @@ -545,14 +549,37 @@ public: */ /*! - Constructs a new generator. + \enum QSvgGenerator::SvgVersion + \since 6.5 + + This enumeration describes the version of the SVG output of the + generator. + + \value SvgTiny12 The generated document follows the SVG Tiny 1.2 specification. + \value Svg11 The generated document follows the SVG 1.1 specification. +*/ + +#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) +/*! + Constructs a new generator using the SVG Tiny 1.2 profile. */ QSvgGenerator::QSvgGenerator() + : QSvgGenerator(SvgVersion::SvgTiny12) +{ +} +#endif + +/*! + \since 6.5 + + Constructs a new generator that uses the SVG version \a version. +*/ +QSvgGenerator::QSvgGenerator(SvgVersion version) : d_ptr(new QSvgGeneratorPrivate) { Q_D(QSvgGenerator); - d->engine = new QSvgPaintEngine; + d->engine = new QSvgPaintEngine(version); d->owns_iodevice = false; } @@ -767,6 +794,18 @@ void QSvgGenerator::setResolution(int dpi) } /*! + \since 6.5 + + Returns the version of the SVG document that this generator is + producing. +*/ +QSvgGenerator::SvgVersion QSvgGenerator::svgVersion() const +{ + Q_D(const QSvgGenerator); + return d->engine->svgVersion(); +} + +/*! Returns the paint engine used to render graphics to be converted to SVG format information. */ @@ -855,8 +894,16 @@ bool QSvgPaintEngine::begin(QPaintDevice *) } *d->stream << " xmlns=\"http://www.w3.org/2000/svg\"" - " xmlns:xlink=\"http://www.w3.org/1999/xlink\" " - " version=\"1.2\" baseProfile=\"tiny\">" << Qt::endl; + " xmlns:xlink=\"http://www.w3.org/1999/xlink\""; + switch (d->svgVersion) { + case QSvgGenerator::SvgVersion::SvgTiny12: + *d->stream << " version=\"1.2\" baseProfile=\"tiny\">"; + break; + case QSvgGenerator::SvgVersion::Svg11: + *d->stream << " version=\"1.1\">"; + break; + } + *d->stream << Qt::endl; if (!d->attributes.document_title.isEmpty()) { *d->stream << "<title>" << d->attributes.document_title.toHtmlEscaped() << "</title>" << Qt::endl; diff --git a/src/svg/qsvggenerator.h b/src/svg/qsvggenerator.h index 9aac47f..2121eb9 100644 --- a/src/svg/qsvggenerator.h +++ b/src/svg/qsvggenerator.h @@ -32,7 +32,18 @@ class Q_SVG_EXPORT QSvgGenerator : public QPaintDevice Q_PROPERTY(QIODevice* outputDevice READ outputDevice WRITE setOutputDevice) Q_PROPERTY(int resolution READ resolution WRITE setResolution) public: + enum class SvgVersion { + SvgTiny12, + Svg11, + }; + + // ### Qt 7: unify overloads +#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) QSvgGenerator(); + explicit QSvgGenerator(SvgVersion version); +#else + explicit QSvgGenerator(SvgVersion version = SvgVersion::SvgTiny12); +#endif ~QSvgGenerator(); QString title() const; @@ -57,6 +68,8 @@ public: void setResolution(int dpi); int resolution() const; + + SvgVersion svgVersion() const; protected: QPaintEngine *paintEngine() const override; int metric(QPaintDevice::PaintDeviceMetric metric) const override; |