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/qstringview.h"
23#include <QtCore/QLoggingCategory>
24#include "qsvgstyle_p.h"
25#if QT_CONFIG(cssparser)
26#include <QtSvg/private/qsvgcsshandler_p.h>
27#include <QtSvg/private/qsvgcssproperties_p.h>
28#include <QtSvg/private/qsvgcssvalues_p.h>
29#endif
30#include "qsvggraphics_p.h"
31#include "qtsvgglobal_p.h"
32#include "qsvgutils_p.h"
33#include "qtsvgglobal.h"
34#include <QtSvg/private/qsvgpaintserver_p.h>
35
36#include <memory>
37
39
40class QSvgNode;
41class QSvgDocument;
42class QSvgHandler;
43class QColor;
44
45Q_AUTOTEST_EXPORT QList<qreal> parseNumbersList(QStringView *str);
46Q_AUTOTEST_EXPORT bool resolveColor(QStringView colorStr, QColor &color, QSvgHandler *handler);
47
48class Q_SVG_EXPORT QSvgHandler
49{
50public:
51 QSvgHandler(QIODevice *device, QtSvg::Options options = {},
52 QtSvg::AnimatorType type = QtSvg::AnimatorType::Automatic);
53 QSvgHandler(const QByteArray &data, QtSvg::Options options = {},
54 QtSvg::AnimatorType type = QtSvg::AnimatorType::Automatic);
55 QSvgHandler(QXmlStreamReader *const data, QtSvg::Options options = {},
56 QtSvg::AnimatorType type = QtSvg::AnimatorType::Automatic);
57 ~QSvgHandler();
58
59 QIODevice *device() const;
60 QSvgDocument *document() const;
61 // resets the stored document: afterwards document() == nullptr and ok() == false
62 [[nodiscard]] std::unique_ptr<QSvgDocument> takeDocument();
63
64 inline bool ok() const {
65 return document() != 0 && !xml->hasError();
66 }
67
68 inline QString errorString() const { return xml->errorString(); }
69 inline int lineNumber() const { return xml->lineNumber(); }
70
71 void setDefaultCoordinateSystem(QSvgUtils::LengthType type);
72 QSvgUtils::LengthType defaultCoordinateSystem() const;
73
74 void pushColor(const QColor &color);
75 void pushColorCopy();
76 void popColor();
77 QColor currentColor() const;
78
79 void pushUnresolvedStyle(QSvgStyleProperty *prop);
80
81#ifndef QT_NO_CSSPARSER
82 void setInStyle(bool b);
83 bool inStyle() const;
84
85 QSvgCssHandler &cssHandler();
86#endif
87
88 void setAnimPeriod(int start, int end);
89 int animationDuration() const;
90
91 inline QPen defaultPen() const
92 { return m_defaultPen; }
93
94 QtSvg::Options options() const;
95 QtSvg::AnimatorType animatorType() const;
96 bool trustedSourceMode() const;
97
98public:
99 bool startElement(const QStringView localName, const QXmlStreamAttributes &attributes);
100 bool endElement(const QStringView localName);
101 bool characters(const QStringView str);
102 bool processingInstruction(const QStringView target, const QStringView data);
103
104private:
105 void init();
106
107 std::unique_ptr<QSvgDocument> m_doc;
108 QStack<QSvgNode *> m_nodes;
109 // TODO: This is only needed during parsing, so it unnecessarily takes up space after that.
110 // Temporary container for :
111 // - <use> nodes which haven't been resolved yet.
112 // - <filter> nodes to be checked for unsupported filter primitives.
113 QList<QSvgNode *> m_toBeResolved;
114 QList<QSvgStyleProperty *> m_unresolvedStyles;
115
116 enum CurrentNode
117 {
118 Unknown,
119 Graphics,
120 Style,
121 Doc
122 };
123 QStack<CurrentNode> m_skipNodes;
124
125 /*!
126 Follows the depths of elements. The top is current xml:space
127 value that applies for a given element.
128 */
129 QStack<QSvgText::WhitespaceMode> m_whitespaceMode;
130
131 QSvgStyleProperty *m_style{nullptr};
132 QSvgPaintServerSharedPtr m_paintServer;
133
134 QSvgUtils::LengthType m_defaultCoords;
135
136 QStack<QColor> m_colorStack;
137 QStack<int> m_colorTagCount;
138
139 int m_animEnd;
140
141 QXmlStreamReader *const xml;
142#ifndef QT_NO_CSSPARSER
143 bool m_inStyle;
144 QSvgCssHandler m_cssHandler;
145#endif
146 void parse();
147 void resolvePaintServers();
148 void resolveNodes();
149
150 QPen m_defaultPen;
151 /**
152 * Whether we own the variable xml, and hence whether
153 * we need to delete it.
154 */
155 const bool m_ownsReader;
156
157 const QtSvg::Options m_options;
158 const QtSvg::AnimatorType m_animatorType;
159};
160
161Q_AUTOTEST_EXPORT QSvgNode *createAnimateTransformNode(QSvgNode *parent,
162 const QXmlStreamAttributes &attributes,
163 QSvgHandler *handler);
164
165Q_DECLARE_LOGGING_CATEGORY(lcSvgHandler)
166
167QT_END_NAMESPACE
168
169#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:2618
#define qPrintable(string)
Definition qstring.h:1705
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)
Q_AUTOTEST_EXPORT bool resolveColor(QStringView colorStr, QColor &color, QSvgHandler *handler)