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