/src/qtsvg/src/svg/qsvghelper_p.h
Line | Count | Source |
1 | | // Copyright (C) 2023 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 QSVGHELPER_P_H |
7 | | #define QSVGHELPER_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 "qtsvgglobal_p.h" |
21 | | #include <QtCore/qdebug.h> |
22 | | #include <QRectF> |
23 | | |
24 | | QT_BEGIN_NAMESPACE |
25 | | |
26 | | class Q_SVG_EXPORT QSvgRectF : public QRectF |
27 | | { |
28 | | public: |
29 | | QSvgRectF(const QRectF &r = QRectF(), |
30 | | QtSvg::UnitTypes unitX = QtSvg::UnitTypes::userSpaceOnUse, |
31 | | QtSvg::UnitTypes unitY = QtSvg::UnitTypes::userSpaceOnUse, |
32 | | QtSvg::UnitTypes unitW = QtSvg::UnitTypes::userSpaceOnUse, |
33 | | QtSvg::UnitTypes unitH = QtSvg::UnitTypes::userSpaceOnUse) |
34 | 1.94k | : QRectF(r) |
35 | 1.94k | , m_unitX(unitX) |
36 | 1.94k | , m_unitY(unitY) |
37 | 1.94k | , m_unitW(unitW) |
38 | 1.94k | , m_unitH(unitH) |
39 | 1.94k | {} |
40 | | |
41 | 0 | QPointF translationRelativeToBoundingBox(const QRectF &boundingBox) const { |
42 | 0 | QPointF result; |
43 | |
|
44 | 0 | if (m_unitX == QtSvg::UnitTypes::objectBoundingBox) |
45 | 0 | result.setX(x() * boundingBox.width()); |
46 | 0 | else |
47 | 0 | result.setX(x()); |
48 | 0 | if (m_unitY == QtSvg::UnitTypes::objectBoundingBox) |
49 | 0 | result.setY(y() * boundingBox.height()); |
50 | 0 | else |
51 | 0 | result.setY(y()); |
52 | 0 | return result; |
53 | 0 | } |
54 | | |
55 | 0 | QRectF resolveRelativeLengths(const QRectF &localRect) const { |
56 | 0 | QRectF result; |
57 | 0 | if (m_unitX == QtSvg::UnitTypes::objectBoundingBox) |
58 | 0 | result.setX(localRect.x() + x() * localRect.width()); |
59 | 0 | else |
60 | 0 | result.setX(x()); |
61 | 0 | if (m_unitY == QtSvg::UnitTypes::objectBoundingBox) |
62 | 0 | result.setY(localRect.y() + y() * localRect.height()); |
63 | 0 | else |
64 | 0 | result.setY(y()); |
65 | 0 | if (m_unitW == QtSvg::UnitTypes::objectBoundingBox) |
66 | 0 | result.setWidth(localRect.width() * width()); |
67 | 0 | else |
68 | 0 | result.setWidth(width()); |
69 | 0 | if (m_unitH == QtSvg::UnitTypes::objectBoundingBox) |
70 | 0 | result.setHeight(localRect.height() * height()); |
71 | 0 | else |
72 | 0 | result.setHeight(height()); |
73 | 0 | return result; |
74 | 0 | } |
75 | | |
76 | 0 | QRectF resolveRelativeLengths(const QRectF &localRect, QtSvg::UnitTypes units) const { |
77 | 0 | QRectF result; |
78 | 0 | if (units == QtSvg::UnitTypes::objectBoundingBox || |
79 | 0 | m_unitX == QtSvg::UnitTypes::objectBoundingBox) |
80 | 0 | result.setX(localRect.x() + x() * localRect.width()); |
81 | 0 | else |
82 | 0 | result.setX(x()); |
83 | 0 | if (units == QtSvg::UnitTypes::objectBoundingBox || |
84 | 0 | m_unitY == QtSvg::UnitTypes::objectBoundingBox) |
85 | 0 | result.setY(localRect.y() + y() * localRect.height()); |
86 | 0 | else |
87 | 0 | result.setY(y()); |
88 | 0 | if (units == QtSvg::UnitTypes::objectBoundingBox || |
89 | 0 | m_unitW == QtSvg::UnitTypes::objectBoundingBox) |
90 | 0 | result.setWidth(localRect.width() * width()); |
91 | 0 | else |
92 | 0 | result.setWidth(width()); |
93 | 0 | if (units == QtSvg::UnitTypes::objectBoundingBox || |
94 | 0 | m_unitH == QtSvg::UnitTypes::objectBoundingBox) |
95 | 0 | result.setHeight(localRect.height() * height()); |
96 | 0 | else |
97 | 0 | result.setHeight(height()); |
98 | |
|
99 | 0 | return result; |
100 | 0 | } |
101 | | |
102 | 0 | QtSvg::UnitTypes unitX() const {return m_unitX;} |
103 | 0 | QtSvg::UnitTypes unitY() const {return m_unitY;} |
104 | 0 | QtSvg::UnitTypes unitW() const {return m_unitW;} |
105 | 0 | QtSvg::UnitTypes unitH() const {return m_unitH;} |
106 | | |
107 | 0 | void setUnitX(QtSvg::UnitTypes unit) {m_unitX = unit;} |
108 | 0 | void setUnitY(QtSvg::UnitTypes unit) {m_unitY = unit;} |
109 | 0 | void setUnitW(QtSvg::UnitTypes unit) {m_unitW = unit;} |
110 | 0 | void setUnitH(QtSvg::UnitTypes unit) {m_unitH = unit;} |
111 | | |
112 | | |
113 | | #ifndef QT_NO_DEBUG_STREAM |
114 | | friend QDebug operator<<(QDebug debug, const QSvgRectF &r) |
115 | 0 | { |
116 | 0 | debug.space(); |
117 | 0 | debug.nospace() << "QSvgRectF(" << r.x() |
118 | 0 | << (r.unitX() == QtSvg::UnitTypes::unknown ? "(?)" : |
119 | 0 | (r.unitX() == QtSvg::UnitTypes::objectBoundingBox ? "(%)" : "")) |
120 | 0 | << "," << r.y() |
121 | 0 | << (r.unitY() == QtSvg::UnitTypes::unknown ? "(?)" : |
122 | 0 | (r.unitY() == QtSvg::UnitTypes::objectBoundingBox ? "(%)" : "")) |
123 | 0 | << " " << r.width() |
124 | 0 | << (r.unitW() == QtSvg::UnitTypes::unknown ? "(?)" : |
125 | 0 | (r.unitW() == QtSvg::UnitTypes::objectBoundingBox ? "(%)" : "")) |
126 | 0 | << "x" << r.height() |
127 | 0 | << (r.unitH() == QtSvg::UnitTypes::unknown ? "(?)" : |
128 | 0 | (r.unitH() == QtSvg::UnitTypes::objectBoundingBox ? "(%)" : "")) |
129 | 0 | << ")"; |
130 | 0 | return debug; |
131 | 0 | } |
132 | | #endif |
133 | | |
134 | | protected: |
135 | | QtSvg::UnitTypes m_unitX, |
136 | | m_unitY, |
137 | | m_unitW, |
138 | | m_unitH; |
139 | | }; |
140 | | |
141 | | QT_END_NAMESPACE |
142 | | |
143 | | #endif // QSVGHELPER_P_H |