1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QSVGHELPER_P_H
#define QSVGHELPER_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include "qtsvgglobal_p.h"
#include <QRectF>
QT_BEGIN_NAMESPACE
class Q_SVG_EXPORT QSvgRectF : public QRectF
{
public:
QSvgRectF(const QRectF &r = QRectF(),
QtSvg::UnitTypes unitX = QtSvg::UnitTypes::userSpaceOnUse,
QtSvg::UnitTypes unitY = QtSvg::UnitTypes::userSpaceOnUse,
QtSvg::UnitTypes unitW = QtSvg::UnitTypes::userSpaceOnUse,
QtSvg::UnitTypes unitH = QtSvg::UnitTypes::userSpaceOnUse)
: QRectF(r)
, m_unitX(unitX)
, m_unitY(unitY)
, m_unitW(unitW)
, m_unitH(unitH)
{}
QPointF translationRelativeToBoundingBox(const QRectF &boundingBox) const {
QPointF result;
if (m_unitX == QtSvg::UnitTypes::objectBoundingBox)
result.setX(x() * boundingBox.width());
else
result.setX(x());
if (m_unitY == QtSvg::UnitTypes::objectBoundingBox)
result.setY(y() * boundingBox.height());
else
result.setY(y());
return result;
}
QRectF resolveRelativeLengths(const QRectF &localRect) const {
QRectF result;
if (m_unitX == QtSvg::UnitTypes::objectBoundingBox)
result.setX(localRect.x() + x() * localRect.width());
else
result.setX(x());
if (m_unitY == QtSvg::UnitTypes::objectBoundingBox)
result.setY(localRect.y() + y() * localRect.height());
else
result.setY(y());
if (m_unitW == QtSvg::UnitTypes::objectBoundingBox)
result.setWidth(localRect.width() * width());
else
result.setWidth(width());
if (m_unitH == QtSvg::UnitTypes::objectBoundingBox)
result.setHeight(localRect.height() * height());
else
result.setHeight(height());
return result;
}
QRectF resolveRelativeLengths(const QRectF &localRect, QtSvg::UnitTypes units) const {
QRectF result;
if (units == QtSvg::UnitTypes::objectBoundingBox ||
m_unitX == QtSvg::UnitTypes::objectBoundingBox)
result.setX(localRect.x() + x() * localRect.width());
else
result.setX(x());
if (units == QtSvg::UnitTypes::objectBoundingBox ||
m_unitY == QtSvg::UnitTypes::objectBoundingBox)
result.setY(localRect.y() + y() * localRect.height());
else
result.setY(y());
if (units == QtSvg::UnitTypes::objectBoundingBox ||
m_unitW == QtSvg::UnitTypes::objectBoundingBox)
result.setWidth(localRect.width() * width());
else
result.setWidth(width());
if (units == QtSvg::UnitTypes::objectBoundingBox ||
m_unitH == QtSvg::UnitTypes::objectBoundingBox)
result.setHeight(localRect.height() * height());
else
result.setHeight(height());
return result;
}
QtSvg::UnitTypes unitX() const {return m_unitX;}
QtSvg::UnitTypes unitY() const {return m_unitY;}
QtSvg::UnitTypes unitW() const {return m_unitW;}
QtSvg::UnitTypes unitH() const {return m_unitH;}
void setUnitX(QtSvg::UnitTypes unit) {m_unitX = unit;}
void setUnitY(QtSvg::UnitTypes unit) {m_unitY = unit;}
void setUnitW(QtSvg::UnitTypes unit) {m_unitW = unit;}
void setUnitH(QtSvg::UnitTypes unit) {m_unitH = unit;}
#ifndef QT_NO_DEBUG_STREAM
friend QDebug operator<<(QDebug debug, const QSvgRectF &r)
{
debug.space();
debug.nospace() << "QSvgRectF(" << r.x()
<< (r.unitX() == QtSvg::UnitTypes::unknown ? "(?)" :
(r.unitX() == QtSvg::UnitTypes::objectBoundingBox ? "(%)" : ""))
<< "," << r.y()
<< (r.unitY() == QtSvg::UnitTypes::unknown ? "(?)" :
(r.unitY() == QtSvg::UnitTypes::objectBoundingBox ? "(%)" : ""))
<< " " << r.width()
<< (r.unitW() == QtSvg::UnitTypes::unknown ? "(?)" :
(r.unitW() == QtSvg::UnitTypes::objectBoundingBox ? "(%)" : ""))
<< "x" << r.height()
<< (r.unitH() == QtSvg::UnitTypes::unknown ? "(?)" :
(r.unitH() == QtSvg::UnitTypes::objectBoundingBox ? "(%)" : ""))
<< ")";
return debug;
}
#endif
protected:
QtSvg::UnitTypes m_unitX,
m_unitY,
m_unitW,
m_unitH;
};
QT_END_NAMESPACE
#endif // QSVGHELPER_P_H
|