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
41Q_AUTOTEST_EXPORT QList<qreal> parseNumbersList(const QChar *&str);
42
43class Q_SVG_EXPORT QSvgHandler
44{
45public:
46 QSvgHandler(QIODevice *device, QtSvg::Options options = {},
47 QtSvg::AnimatorType type = QtSvg::AnimatorType::Automatic);
48 QSvgHandler(const QByteArray &data, QtSvg::Options options = {},
49 QtSvg::AnimatorType type = QtSvg::AnimatorType::Automatic);
50 QSvgHandler(QXmlStreamReader *const data, QtSvg::Options options = {},
51 QtSvg::AnimatorType type = QtSvg::AnimatorType::Automatic);
52 ~QSvgHandler();
53
54 QIODevice *device() const;
55 QSvgDocument *document() const;
56
57 inline bool ok() const {
58 return document() != 0 && !xml->hasError();
59 }
60
61 inline QString errorString() const { return xml->errorString(); }
62 inline int lineNumber() const { return xml->lineNumber(); }
63
64 void setDefaultCoordinateSystem(QSvgUtils::LengthType type);
65 QSvgUtils::LengthType defaultCoordinateSystem() const;
66
67 void pushColor(const QColor &color);
68 void pushColorCopy();
69 void popColor();
70 QColor currentColor() const;
71
72#ifndef QT_NO_CSSPARSER
73 void setInStyle(bool b);
74 bool inStyle() const;
75
76 QSvgCssHandler &cssHandler();
77#endif
78
79 void setAnimPeriod(int start, int end);
80 int animationDuration() const;
81
82 inline QPen defaultPen() const
83 { return m_defaultPen; }
84
85 QtSvg::Options options() const;
86 QtSvg::AnimatorType animatorType() const;
87 bool trustedSourceMode() const;
88
89public:
90 bool startElement(const QStringView localName, const QXmlStreamAttributes &attributes);
91 bool endElement(const QStringView localName);
92 bool characters(const QStringView str);
93 bool processingInstruction(const QStringView target, const QStringView data);
94
95private:
96 void init();
97
98 QSvgDocument *m_doc;
99 QStack<QSvgNode *> m_nodes;
100 // TODO: This is only needed during parsing, so it unnecessarily takes up space after that.
101 // Temporary container for :
102 // - <use> nodes which haven't been resolved yet.
103 // - <filter> nodes to be checked for unsupported filter primitives.
104 QList<QSvgNode *> m_toBeResolved;
105
106 enum CurrentNode
107 {
108 Unknown,
109 Graphics,
110 Style,
111 Doc
112 };
113 QStack<CurrentNode> m_skipNodes;
114
115 /*!
116 Follows the depths of elements. The top is current xml:space
117 value that applies for a given element.
118 */
119 QStack<QSvgText::WhitespaceMode> m_whitespaceMode;
120
121 QSvgRefCounter<QSvgStyleProperty> m_style;
122
123 QSvgUtils::LengthType m_defaultCoords;
124
125 QStack<QColor> m_colorStack;
126 QStack<int> m_colorTagCount;
127
128 int m_animEnd;
129
130 QXmlStreamReader *const xml;
131#ifndef QT_NO_CSSPARSER
132 bool m_inStyle;
133 QSvgCssHandler m_cssHandler;
134#endif
135 void parse();
136 void resolvePaintServers(QSvgNode *node, int nestedDepth = 0);
137 void resolveNodes();
138
139 QPen m_defaultPen;
140 /**
141 * Whether we own the variable xml, and hence whether
142 * we need to delete it.
143 */
144 const bool m_ownsReader;
145
146 const QtSvg::Options m_options;
147 const QtSvg::AnimatorType m_animatorType;
148};
149
150Q_DECLARE_LOGGING_CATEGORY(lcSvgHandler)
151
152QT_END_NAMESPACE
153
154#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)
std::optional< int > calculateSizeValue(bool isPercent, int sizeValue, qreal viewBoxSizeValue)