28 , m_widthPercent(
false)
29 , m_heightPercent(
false)
32 , m_animationDuration(0)
48 if (th.startsWith(
"<svg"_L1) || th.startsWith(
"<!DOCTYPE svg"_L1))
50 else if (th.startsWith(
"<?xml"_L1) || th.startsWith(
"<!--"_L1))
51 matched = th.
contains(
"<!DOCTYPE svg"_L1) || th.contains(
"<svg"_L1);
57# ifdef QT_BUILD_INTERNAL
75 int zlibResult = Z_OK;
82 zlibStream.next_in = Z_NULL;
83 zlibStream.avail_in = 0;
84 zlibStream.avail_out = 0;
85 zlibStream.zalloc = Z_NULL;
86 zlibStream.zfree = Z_NULL;
87 zlibStream.opaque = Z_NULL;
90 if (inflateInit2(&zlibStream, MAX_WBITS + 16) != Z_OK) {
91 qCWarning(lcSvgHandler,
"Cannot initialize zlib, because: %s",
92 (zlibStream.msg != NULL ? zlibStream.msg :
"Unknown error"));
96 bool stillMoreWorkToDo =
true;
97 while (stillMoreWorkToDo) {
99 if (!zlibStream.avail_in) {
105 zlibStream.avail_in =
source.size();
106 zlibStream.next_in =
reinterpret_cast<Bytef*
>(
source.data());
113 inflateEnd(&zlibStream);
114 qCWarning(lcSvgHandler,
"Error while inflating gzip file: integer size overflow");
119 zlibStream.next_out =
reinterpret_cast<Bytef*
>(
120 destination.data() + oldSize - zlibStream.avail_out);
123 zlibResult =
inflate(&zlibStream, Z_NO_FLUSH);
124 switch (zlibResult) {
129 inflateEnd(&zlibStream);
130 qCWarning(lcSvgHandler,
"Error while inflating gzip file: %s",
131 (zlibStream.msg != NULL ? zlibStream.msg :
"Unknown error"));
138 }
while (!zlibStream.avail_out);
140 if (doCheckContent) {
143 inflateEnd(&zlibStream);
144 qCWarning(lcSvgHandler,
"Error while inflating gzip file: SVG format check failed");
147 doCheckContent =
false;
150 if (zlibResult == Z_STREAM_END) {
152 if (!(zlibStream.avail_in && inflateReset(&zlibStream) == Z_OK))
153 stillMoreWorkToDo =
false;
160 inflateEnd(&zlibStream);
174 qCWarning(lcSvgHandler,
"Cannot open file '%s', because: %s",
190 qCWarning(lcSvgHandler,
"Cannot read file '%s', because: %s (line %d)",
201 if (
contents.startsWith(
"\x1f\x8b")) {
258 node->
draw(
p, m_states);
272 qCDebug(lcSvgHandler,
"Couldn't find node %s. Skipping rendering.",
qPrintable(
id));
285 mapSourceToTarget(
p,
bounds, elementBounds);
286 QTransform originalTransform =
p->worldTransform();
296 QStack<QSvgNode*> parentApplyStack;
299 parentApplyStack.push(
parent);
303 for (
int i = parentApplyStack.size() - 1;
i >= 0; --
i)
309 p->setWorldTransform(originalTransform);
311 node->
draw(
p, m_states);
313 p->setWorldTransform(currentTransform);
315 for (
int i = 0;
i < parentApplyStack.size(); ++
i)
331 m_widthPercent = percent;
337 m_heightPercent = percent;
342 m_preserveAspectRatio = on;
348 m_implicitViewBox =
rect.isNull();
363 return m_fonts[family];
368 m_namedNodes.
insert(
id, node);
373 return m_namedNodes.
value(
id);
381 qCWarning(lcSvgHandler) <<
"Duplicate unique style id:" <<
id;
386 return m_namedStyles.
value(
id);
411 qCDebug(lcSvgHandler) <<
"SVG Tiny does not support nested <svg> elements: ignored.";
421void QSvgTinyDocument::mapSourceToTarget(
QPainter *
p,
const QRectF &targetRect,
const QRectF &sourceRect)
463 p->translate(
target.x() + (
target.width() - viewBoxSize.width()) / 2,
464 target.y() + (
target.height() - viewBoxSize.height()) / 2);
466 p->scale(viewBoxSize.width() /
source.width(),
467 viewBoxSize.height() /
source.height());
475 p->setWorldTransform(oldTransform);
498 qCDebug(lcSvgHandler,
"Couldn't find node %s. Skipping rendering.",
qPrintable(
id));
518 int totalFrames = m_fps * m_animationDuration;
520 return int(runningPercentage * totalFrames);
525 int totalFrames = m_fps * m_animationDuration;
526 double framePercentage =
frame/double(totalFrames);
527 double timeForFrame = m_animationDuration * framePercentage;
528 timeForFrame *= 1000;
543 bool useInflateBuf =
false;
547#ifndef QT_NO_COMPRESS
551 zlibStream.avail_in = readLen;
552 zlibStream.next_out =
reinterpret_cast<Bytef *
>(inflateBuf);
553 zlibStream.avail_out =
bufSize;
554 zlibStream.next_in =
reinterpret_cast<Bytef *
>(
buf);
555 zlibStream.zalloc = Z_NULL;
556 zlibStream.zfree = Z_NULL;
557 zlibStream.opaque = Z_NULL;
558 if (inflateInit2(&zlibStream, MAX_WBITS + 16) != Z_OK)
560 int zlibResult =
inflate(&zlibStream, Z_NO_FLUSH);
561 inflateEnd(&zlibStream);
562 if ((zlibResult != Z_OK && zlibResult != Z_STREAM_END) || zlibStream.total_out < 8)
564 readLen = zlibStream.total_out;
566 *isCompressed =
true;
567 useInflateBuf =
true;
IOBluetoothDevice * device
\inmodule QtCore \reentrant
void setData(const QByteArray &data)
Sets the contents of the internal buffer to be data.
static QByteArray fromRawData(const char *data, qsizetype size)
Constructs a QByteArray that uses the first size bytes of the data array.
static qint64 currentMSecsSinceEpoch() noexcept
QFILE_MAYBE_NODISCARD bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
bool contains(const Key &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
T value(const Key &key) const noexcept
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
\inmodule QtCore \reentrant
QString errorString() const
Returns a human-readable description of the last device error that occurred.
The QPainter class performs low-level painting on widgets and other paint devices.
void setMiterLimit(qreal limit)
Sets the miter limit of this pen to the given limit.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr bool isEmpty() const noexcept
Returns true if the rectangle is empty, otherwise returns false.
constexpr QSizeF size() const noexcept
Returns the size of the rectangle.
constexpr bool isEmpty() const noexcept
Returns true if the rectangle is empty, otherwise returns false.
void scale(qreal w, qreal h, Qt::AspectRatioMode mode) noexcept
Scales the size to a rectangle with the given width and height, according to the specified mode.
constexpr void setWidth(int w) noexcept
Sets the width to the given width.
constexpr void setHeight(int h) noexcept
Sets the height to the given height.
bool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
QStringView trimmed() const noexcept
Strips leading and trailing whitespace and returns the result.
\macro QT_RESTRICTED_CAST_FROM_ASCII
QSvgTinyDocument * document() const
int animationDuration() const
QString errorString() const
friend class QSvgTinyDocument
void revertStyle(QPainter *p, QSvgExtraStates &states) const
virtual QRectF transformedBounds(QPainter *p, QSvgExtraStates &states) const
QSvgNode * parent() const
void applyStyle(QPainter *p, QSvgExtraStates &states) const
DisplayMode displayMode() const
void draw(QPainter *p, QSvgExtraStates &states)
const QSvgStyle & style() const
static void initPainter(QPainter *p)
QRectF bounds(QPainter *p, QSvgExtraStates &states) const override
QSvgNode * scopeNode(const QString &id) const
QList< QSvgNode * > m_renderers
QSvgRefCounter< QSvgTransformStyle > transform
bool elementExists(const QString &id) const
static bool isLikelySvg(QIODevice *device, bool *isCompressed=nullptr)
QSvgNode * namedNode(const QString &id) const
void setFramesPerSecond(int num)
Type type() const override
void setViewBox(const QRectF &rect)
void addNamedStyle(const QString &id, QSvgPaintStyleProperty *style)
void setWidth(int len, bool percent)
QtSvg::Options options() const
QRectF boundsOnElement(const QString &id) const
bool preserveAspectRatio() const
void addNamedNode(const QString &id, QSvgNode *node)
static QSvgTinyDocument * load(const QString &file, QtSvg::Options options={})
QSvgFont * svgFont(const QString &family) const
int currentElapsed() const
void setPreserveAspectRatio(bool on)
void drawCommand(QPainter *, QSvgExtraStates &) override
QSvgPaintStyleProperty * namedStyle(const QString &id) const
void addSvgFont(QSvgFont *)
QTransform transformForElement(const QString &id) const
void setCurrentFrame(int)
void setHeight(int len, bool percent)
Combined button and popup list for selecting options.
SharedPointerFileDialogOptions m_options
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char * destination
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
bool qIsFinite(qfloat16 f) noexcept
bool qFuzzyIsNull(qfloat16 f) noexcept
#define qCWarning(category,...)
#define qCDebug(category,...)
constexpr const T & qMin(const T &a, const T &b)
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLenum GLsizei const GLchar * buf
GLfloat GLfloat GLfloat GLfloat h
GLsizei GLsizei GLchar * source
GLuint GLenum GLenum transform
#define qPrintable(string)
static QByteArray qt_inflateSvgzDataFrom(QIODevice *device, bool doCheckContent=true)
static bool isValidMatrix(const QTransform &transform)
static bool hasSvgHeader(const QByteArray &buf)
#define Q_AUTOTEST_EXPORT
static int inflate(Bytef *dest, ulong *destLen, const Bytef *source, ulong sourceLen)