Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qsvgutils_p.h
Go to the documentation of this file.
1
// Copyright (C) 2026 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
QSVGUTILS_P_H
7
#
define
QSVGUTILS_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
<
QtSvg
/
qtsvgglobal
.
h
>
21
#
include
<
QtCore
/
qrect
.
h
>
22
#
include
<
cmath
>
23
24
QT_BEGIN_NAMESPACE
25
26
namespace
QSvgUtils
{
27
// Safely casts a qreal value to int while validating the range
28
// before casting to avoid UB.
29
inline
int
castToInt
(qreal v)
30
{
31
if
(
std
::isnan(v))
32
return
0;
33
34
const
qreal boundedValue = std::clamp(v,
35
qreal(std::numeric_limits<
int
>::min()),
36
qreal(std::numeric_limits<
int
>::max()));
37
return
int
(
std
::round(boundedValue));
38
}
39
40
// Same as QRectF::toAlignedRect but safely cast to int
41
inline
QRect
toAlignedRect
(
const
QRectF &r) {
42
const
qreal xmin =
std
::floor(r.x());
43
const
qreal xmax =
std
::ceil(r.x() + r.width());
44
const
qreal ymin =
std
::floor(r.y());
45
const
qreal ymax =
std
::ceil(r.y() + r.height());
46
return
QRect(castToInt(xmin), castToInt(ymin),
47
castToInt(xmax - xmin), castToInt(ymax - ymin));
48
}
49
}
// namespace QSvgUtils
50
51
QT_END_NAMESPACE
52
#
endif
//QSVGUTILS_P_H
QSvgUtils
Definition
qsvgutils_p.h:26
QSvgUtils::toAlignedRect
QRect toAlignedRect(const QRectF &r)
Definition
qsvgutils_p.h:41
QSvgUtils::castToInt
int castToInt(qreal v)
Definition
qsvgutils_p.h:29
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
qtsvg
src
svg
qsvgutils_p.h
Generated on
for Qt by
1.18.0