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
qquickgenerator.cpp
Go to the documentation of this file.
1// Copyright (C) 2024 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
4#include <QVarLengthArray>
5
9
10#include <private/qsgcurveprocessor_p.h>
11#include <private/qquickshape_p.h>
12#include <private/qquadpath_p.h>
13#include <private/qquickitem_p.h>
14#include <private/qquickimagebase_p_p.h>
15
16#include <QtCore/qloggingcategory.h>
17
19
20Q_LOGGING_CATEGORY(lcQuickVectorImage, "qt.quick.vectorimage", QtWarningMsg)
21
22QQuickGenerator::QQuickGenerator(const QString fileName, QQuickVectorImageGenerator::GeneratorFlags flags)
23 : m_flags(flags)
24 , m_fileName(fileName)
25{
26}
27
28QQuickGenerator::~QQuickGenerator()
29{
30}
31
32void QQuickGenerator::setGeneratorFlags(QQuickVectorImageGenerator::GeneratorFlags flags)
33{
34 m_flags = flags;
35}
36
37QQuickVectorImageGenerator::GeneratorFlags QQuickGenerator::generatorFlags()
38{
39 return m_flags;
40}
41
42bool QQuickGenerator::generate()
43{
44 m_errorState = QQuickVectorImageGenerator::NoError;
45 QSvgVisitorImpl loader(m_fileName, this, m_flags.testFlag(QQuickVectorImageGenerator::AssumeTrustedSource));
46 return loader.doTraversal();
47}
48
49void QQuickGenerator::optimizePaths(const PathNodeInfo &info, const QRectF &overrideBoundingRect)
50{
51 if (Q_UNLIKELY(errorState()))
52 return;
53
54 QPainterPath pathCopy = info.path.defaultValue().value<QPainterPath>();
55 pathCopy.setFillRule(info.fillRule);
56
57 const QRectF &boundingRect = overrideBoundingRect.isNull() ? pathCopy.boundingRect() : overrideBoundingRect;
58 if (m_flags.testFlag(QQuickVectorImageGenerator::GeneratorFlag::OptimizePaths) && !info.path.isAnimated()) {
59 QQuadPath strokePath = QQuadPath::fromPainterPath(pathCopy);
60 bool fillPathNeededClose;
61 QQuadPath fillPath = strokePath.subPathsClosed(&fillPathNeededClose);
62 const bool intersectionsFound = QSGCurveProcessor::solveIntersections(fillPath, false);
63 fillPath.addCurvatureData();
64 QSGCurveProcessor::solveOverlaps(fillPath);
65 const bool compatibleStrokeAndFill = !fillPathNeededClose && !intersectionsFound;
66
67 if (compatibleStrokeAndFill || m_flags.testFlag(QQuickVectorImageGenerator::GeneratorFlag::OutlineStrokeMode)) {
68 outputShapePath(info, nullptr, &fillPath, QQuickVectorImageGenerator::FillAndStroke, boundingRect);
69 } else {
70 outputShapePath(info, nullptr, &fillPath, QQuickVectorImageGenerator::FillPath, boundingRect);
71 outputShapePath(info, nullptr, &strokePath, QQuickVectorImageGenerator::StrokePath, boundingRect);
72 }
73 } else {
74 outputShapePath(info, &pathCopy, nullptr, QQuickVectorImageGenerator::FillAndStroke, boundingRect);
75 }
76}
77
78bool QQuickGenerator::isNodeVisible(const NodeInfo &info)
79{
80 if (!info.isVisible || !info.isDisplayed)
81 return false;
82
83 return true;
84}
85
86void QQuickGenerator::checkSanityLimit_helper(quint64 limit, QLatin1StringView limitObject)
87{
88 qCWarning(lcQuickVectorImage) << "QML generation of untrusted source" << m_fileName
89 << "failed: exceeded sanity limit of" << limit << limitObject;
90 m_errorState = QQuickVectorImageGenerator::SanityLimitsExceeded;
91}
92
93QT_END_NAMESPACE
Combined button and popup list for selecting options.