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 QSvgVisitorImpl loader(m_fileName, this, m_flags.testFlag(QQuickVectorImageGenerator::AssumeTrustedSource));
45 return loader.traverse();
46}
47
48void QQuickGenerator::optimizePaths(const PathNodeInfo &info, const QRectF &overrideBoundingRect)
49{
50 QPainterPath pathCopy = info.painterPath;
51 pathCopy.setFillRule(info.fillRule);
52
53 const QRectF &boundingRect = overrideBoundingRect.isNull() ? pathCopy.boundingRect() : overrideBoundingRect;
54 if (m_flags.testFlag(QQuickVectorImageGenerator::GeneratorFlag::OptimizePaths)) {
55 QQuadPath strokePath = QQuadPath::fromPainterPath(pathCopy);
56 bool fillPathNeededClose;
57 QQuadPath fillPath = strokePath.subPathsClosed(&fillPathNeededClose);
58 const bool intersectionsFound = QSGCurveProcessor::solveIntersections(fillPath, false);
59 fillPath.addCurvatureData();
60 QSGCurveProcessor::solveOverlaps(fillPath);
61 const bool compatibleStrokeAndFill = !fillPathNeededClose && !intersectionsFound;
62
63 if (compatibleStrokeAndFill || m_flags.testFlag(QQuickVectorImageGenerator::GeneratorFlag::OutlineStrokeMode)) {
64 outputShapePath(info, nullptr, &fillPath, QQuickVectorImageGenerator::FillAndStroke, boundingRect);
65 } else {
66 outputShapePath(info, nullptr, &fillPath, QQuickVectorImageGenerator::FillPath, boundingRect);
67 outputShapePath(info, nullptr, &strokePath, QQuickVectorImageGenerator::StrokePath, boundingRect);
68 }
69 } else {
70 outputShapePath(info, &pathCopy, nullptr, QQuickVectorImageGenerator::FillAndStroke, boundingRect);
71 }
72}
73
74bool QQuickGenerator::isNodeVisible(const NodeInfo &info)
75{
76 if (!info.isVisible || !info.isDisplayed)
77 return false;
78
79 return true;
80}
81
82QT_END_NAMESPACE