解析svg图片时,允许不带属性的<style>的节点
根据https://www.w3.org/TR/SVG/styling.html#StyleElement,`type`属性可以省略。 Signed-off-by: tangjie02 <tangjie02@kylinsec.com.cn>
This commit is contained in:
parent
b26725b99f
commit
10fde67353
76
0001-Allow-style-without-type-attribute.patch
Normal file
76
0001-Allow-style-without-type-attribute.patch
Normal file
@ -0,0 +1,76 @@
|
||||
From cb6fce016d88622cc361a9f609518db753502e46 Mon Sep 17 00:00:00 2001
|
||||
From: Chih-Hsuan Yen <yen@chyen.cc>
|
||||
Date: Wed, 23 Jan 2019 16:41:35 +0800
|
||||
Subject: [PATCH] Allow <style> without type attribute
|
||||
|
||||
According to https://www.w3.org/TR/SVG/styling.html#StyleElement, `type`
|
||||
can be omitted.
|
||||
|
||||
> If the attribute is not specified, then the style sheet language is assumed to be CSS.
|
||||
|
||||
Original-Author: Christoph Feck
|
||||
Fixes: QTBUG-58326
|
||||
Fixes: QTBUG-69378
|
||||
Change-Id: Ic3d0e8db99da8c81e5a01c0dda33fb38428e38d5
|
||||
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
|
||||
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
|
||||
---
|
||||
src/svg/qsvghandler.cpp | 2 +-
|
||||
tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp | 22 ++++++++++++++++++++
|
||||
2 files changed, 23 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp
|
||||
index 6d2e279..132c4ec 100644
|
||||
--- a/src/svg/qsvghandler.cpp
|
||||
+++ b/src/svg/qsvghandler.cpp
|
||||
@@ -3203,7 +3203,7 @@ static bool parseStyleNode(QSvgNode *parent,
|
||||
Q_UNUSED(handler)
|
||||
#else
|
||||
const QStringRef type = attributes.value(QLatin1String("type"));
|
||||
- if (type.compare(QLatin1String("text/css"), Qt::CaseInsensitive) == 0)
|
||||
+ if (type.compare(QLatin1String("text/css"), Qt::CaseInsensitive) == 0 || type.isNull())
|
||||
handler->setInStyle(true);
|
||||
#endif
|
||||
|
||||
diff --git a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
|
||||
index 87d24c7..1bc8b94 100644
|
||||
--- a/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
|
||||
+++ b/tests/auto/qsvgrenderer/tst_qsvgrenderer.cpp
|
||||
@@ -74,6 +74,7 @@ private slots:
|
||||
void testStopOffsetOpacity();
|
||||
void testUseElement();
|
||||
void smallFont();
|
||||
+ void styleSheet();
|
||||
|
||||
#ifndef QT_NO_COMPRESS
|
||||
void testGzLoading();
|
||||
@@ -1376,5 +1377,26 @@ void tst_QSvgRenderer::smallFont()
|
||||
QVERIFY(images[0] != images[1]);
|
||||
}
|
||||
|
||||
+void tst_QSvgRenderer::styleSheet()
|
||||
+{
|
||||
+ static const char *svgs[] = { "<svg><style type=\"text/css\">.cls {fill:#ff0000;}</style><rect class=\"cls\" x = \"10\" y = \"10\" width = \"30\" height = \"30\"/></svg>",
|
||||
+ "<svg><style>.cls {fill:#ff0000;}</style><rect class=\"cls\" x = \"10\" y = \"10\" width = \"30\" height = \"30\"/></svg>",
|
||||
+ };
|
||||
+ const int COUNT = sizeof(svgs) / sizeof(svgs[0]);
|
||||
+ QImage images[COUNT];
|
||||
+ QPainter p;
|
||||
+
|
||||
+ for (int i = 0; i < COUNT; ++i) {
|
||||
+ QByteArray data(svgs[i]);
|
||||
+ QSvgRenderer renderer(data);
|
||||
+ images[i] = QImage(50, 50, QImage::Format_ARGB32_Premultiplied);
|
||||
+ images[i].fill(-1);
|
||||
+ p.begin(&images[i]);
|
||||
+ renderer.render(&p);
|
||||
+ p.end();
|
||||
+ }
|
||||
+ QCOMPARE(images[0], images[1]);
|
||||
+}
|
||||
+
|
||||
QTEST_MAIN(tst_QSvgRenderer)
|
||||
#include "tst_qsvgrenderer.moc"
|
||||
--
|
||||
2.18.1
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
Name: qt5-qtsvg
|
||||
Version: 5.11.1
|
||||
Release: 5
|
||||
Release: 6
|
||||
Summary: Qt GUI toolkit for rendering and displaying SVG
|
||||
License: LGPLv2 with exceptions or GPLv3 with exceptions
|
||||
Url: http://www.qt.io
|
||||
Source0: https://download.qt.io/new_archive/qt/5.11/%{version}/submodules/qtsvg-everywhere-src-%{version}.tar.xz
|
||||
Patch0001: qtsvg-opensource-src-5.6.0-beta1-example-install.patch
|
||||
Patch0002: 0001-Allow-style-without-type-attribute.patch
|
||||
BuildRequires: qt5-qtbase-devel >= %{version} pkgconfig(zlib) qt5-qtbase-private-devel
|
||||
%{?_qt5:Requires: %{_qt5} = %{_qt5_version}}
|
||||
|
||||
@ -60,6 +61,9 @@ popd
|
||||
%{_qt5_archdatadir}/mkspecs/modules/qt_lib_svg*.pri
|
||||
|
||||
%changelog
|
||||
* Wed Dec 08 2021 liuxinhao <liuxinhao@kylinos.com.cn> - 5.11.1-6
|
||||
- Allow style without type attribute
|
||||
|
||||
* Mon Sep 14 2020 liuweibo <liuweibo10@huawei.com> - 5.11.1-5
|
||||
- Fix Source0
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user