44 static std::unique_ptr<QSvgDocument> load(
const QString &file, QtSvg::Options options = {},
45 QtSvg::AnimatorType type = QtSvg::AnimatorType::Automatic);
46 static std::unique_ptr<QSvgDocument> load(
const QByteArray &contents, QtSvg::Options options = {},
47 QtSvg::AnimatorType type = QtSvg::AnimatorType::Automatic);
48 static std::unique_ptr<QSvgDocument> load(QXmlStreamReader *contents, QtSvg::Options options = {},
49 QtSvg::AnimatorType type = QtSvg::AnimatorType::Automatic);
50 static bool isLikelySvg(QIODevice *device,
bool *isCompressed =
nullptr);
52 QSvgDocument(QtSvg::Options options, QtSvg::AnimatorType type);
53 ~QSvgDocument() override;
55 Type type()
const override;
57 inline QSize size()
const;
58 void setWidth(
int len,
bool percent);
59 void setHeight(
int len,
bool percent);
60 inline int width()
const;
61 inline int height()
const;
62 inline bool widthPercent()
const;
63 inline bool heightPercent()
const;
65 inline bool preserveAspectRatio()
const;
66 void setPreserveAspectRatio(
bool on);
68 inline QRectF viewBox()
const;
69 void setViewBox(
const QRectF &rect);
70 bool isCalculatingImplicitViewBox() {
return m_calculatingImplicitViewBox; }
72 QtSvg::Options options()
const;
74 void drawCommand(QPainter *, QSvgExtraStates &) override;
76 void draw(QPainter *p);
77 void draw(QPainter *p,
const QRectF &bounds);
78 void draw(QPainter *p,
const QString &id,
79 const QRectF &bounds=QRectF());
81 QTransform transformForElement(
const QString &id)
const;
82 QRectF boundsOnElement(
const QString &id)
const;
83 bool elementExists(
const QString &id)
const;
85 void addSvgFont(QSvgFont *);
86 QSvgFont *svgFont(
const QString &family)
const;
87 void addNamedNode(
const QString &id, QSvgNode *node);
88 QSvgNode *namedNode(
const QString &id)
const;
89 void addPaintServer(QSvgPaintServerSharedPtr paintServer,
const QString &id);
90 QSvgPaintServerSharedPtr paintServer(QStringView id)
const;
92 void restartAnimation();
93 inline qint64 currentElapsed()
const;
94 bool animated()
const;
95 void setAnimated(
bool a);
96 inline int animationDuration()
const;
97 int currentFrame()
const;
98 void setCurrentFrame(
int);
99 void setFramesPerSecond(
int num);
101 QSharedPointer<QSvgAbstractAnimator> animator()
const;
104 void mapSourceToTarget(QPainter *p,
const QRectF &targetRect,
const QRectF &sourceRect = QRectF());
108 bool m_heightPercent;
110 mutable bool m_calculatingImplicitViewBox =
false;
111 mutable bool m_implicitViewBox =
true;
112 mutable QRectF m_viewBox;
113 bool m_preserveAspectRatio =
false;
115 QHash<QString, QSvgRefCounter<QSvgFont> > m_fonts;
116 QHash<QString, QSvgNode *> m_namedNodes;
117 std::unordered_map<QString, QSvgPaintServerSharedPtr> m_paintServers;
122 QSvgExtraStates m_states;
124 const QtSvg::Options m_options;
125 QSharedPointer<QSvgAbstractAnimator> m_animator;
141inline QSize QSvgDocument::size()
const
143 if (m_size.isEmpty())
144 return viewBox().size().toSize();
145 if (m_widthPercent || m_heightPercent) {
146 const std::optional<
int> width = calculateSizeValue(m_widthPercent, m_size.width(), viewBox().size().width());
147 const std::optional<
int> height = calculateSizeValue(m_heightPercent, m_size.height(), viewBox().size().height());
148 if (!width || !height)
151 return QSize(*width, *height);