Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsvghandler_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5
6#ifndef QSVGHANDLER_P_H
7#define QSVGHANDLER_P_H
8
9//
10// W A R N I N G
11// -------------
12//
13// This file is not part of the Qt API. It exists purely as an
14// implementation detail. This header file may change from version to
15// version without notice, or even be removed.
16//
17// We mean it.
18//
19
20#include "QtCore/qxmlstream.h"
21#include "QtCore/qstack.h"
22#include <QtCore/QLoggingCategory>
23#include "qsvgstyle_p.h"
24#if QT_CONFIG(cssparser)
25#include <QtSvg/private/qsvgcsshandler_p.h>
26#include <QtSvg/private/qsvgcssproperties_p.h>
27#include <QtSvg/private/qsvgcssvalues_p.h>
28#endif
29#include "qsvggraphics_p.h"
30#include "qtsvgglobal_p.h"
31#include "qsvgutils_p.h"
32#include "qtsvgglobal.h"
33
35
36class QSvgNode;
37class QSvgDocument;
38class QSvgHandler;
39class QColor;
40
41class Q_SVG_EXPORT QSvgHandler
42{
43public:
44 QSvgHandler(QIODevice *device, QtSvg::Options options = {},
45 QtSvg::AnimatorType type = QtSvg::AnimatorType::Automatic);
46 QSvgHandler(const QByteArray &data, QtSvg::Options options = {},
47 QtSvg::AnimatorType type = QtSvg::AnimatorType::Automatic);
48 QSvgHandler(QXmlStreamReader *const data, QtSvg::Options options = {},
49 QtSvg::AnimatorType type = QtSvg::AnimatorType::Automatic);
50 ~QSvgHandler();
51
52 QIODevice *device() const;
53 QSvgDocument *document() const;
54
55 inline bool ok() const {
56 return document() != 0 && !xml->hasError();
57 }
58
59 inline QString errorString() const { return xml->errorString(); }
60 inline int lineNumber() const { return xml->lineNumber(); }
61
62 void setDefaultCoordinateSystem(QSvgUtils::LengthType type);
63 QSvgUtils::LengthType defaultCoordinateSystem() const;
64
65 void pushColor(const QColor &color);
66 void pushColorCopy();
67 void popColor();
68 QColor currentColor() const;
69
70#ifndef QT_NO_CSSPARSER
71 void setInStyle(bool b);
72 bool inStyle() const;
73
74 QSvgCssHandler &cssHandler();
75#endif
76
77 void setAnimPeriod(int start, int end);
78 int animationDuration() const;
79
80 inline QPen defaultPen() const
81 { return m_defaultPen; }
82
83 QtSvg::Options options() const;
84 QtSvg::AnimatorType animatorType() const;
85 bool trustedSourceMode() const;
86
87public:
88 bool startElement(const QStringView localName, const QXmlStreamAttributes &attributes);
89 bool endElement(const QStringView localName);
90 bool characters(const QStringView str);
91 bool processingInstruction(const QStringView target, const QStringView data);
92
93private:
94 void init();
95
96 QSvgDocument *m_doc;
97 QStack<QSvgNode *> m_nodes;
98 // TODO: This is only needed during parsing, so it unnecessarily takes up space after that.
99 // Temporary container for :
100 // - <use> nodes which haven't been resolved yet.
101 // - <filter> nodes to be checked for unsupported filter primitives.
102 QList<QSvgNode *> m_toBeResolved;
103
104 enum CurrentNode
105 {
106 Unknown,
107 Graphics,
108 Style,
109 Doc
110 };
111 QStack<CurrentNode> m_skipNodes;
112
113 /*!
114 Follows the depths of elements. The top is current xml:space
115 value that applies for a given element.
116 */
117 QStack<QSvgText::WhitespaceMode> m_whitespaceMode;
118
119 QSvgRefCounter<QSvgStyleProperty> m_style;
120
121 QSvgUtils::LengthType m_defaultCoords;
122
123 QStack<QColor> m_colorStack;
124 QStack<int> m_colorTagCount;
125
126 int m_animEnd;
127
128 QXmlStreamReader *const xml;
129#ifndef QT_NO_CSSPARSER
130 bool m_inStyle;
131 QSvgCssHandler m_cssHandler;
132#endif
133 void parse();
134 void resolvePaintServers(QSvgNode *node, int nestedDepth = 0);
135 void resolveNodes();
136
137 QPen m_defaultPen;
138 /**
139 * Whether we own the variable xml, and hence whether
140 * we need to delete it.
141 */
142 const bool m_ownsReader;
143
144 const QtSvg::Options m_options;
145 const QtSvg::AnimatorType m_animatorType;
146};
147
148Q_DECLARE_LOGGING_CATEGORY(lcSvgHandler)
149
150QT_END_NAMESPACE
151
152#endif // QSVGHANDLER_P_H
friend class QPainter
Combined button and popup list for selecting options.
@ AssumeTrustedSource
Definition qtsvgglobal.h:20
@ DisableSMILAnimations
Definition qtsvgglobal.h:23
@ DisableCSSAnimations
Definition qtsvgglobal.h:24
@ Tiny12FeaturesOnly
Definition qtsvgglobal.h:19
@ NoOption
Definition qtsvgglobal.h:18
@ DisableAnimations
Definition qtsvgglobal.h:27
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2582
#define qPrintable(string)
Definition qstring.h:1683
static QByteArray qt_inflateSvgzDataFrom(QIODevice *device, bool doCheckContent=true)
static bool isValidMatrix(const QTransform &transform)
static bool hasSvgHeader(const QByteArray &buf)