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
qfontvariableaxis.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
5
6#include <QtCore/qdebug.h>
7
8QT_BEGIN_NAMESPACE
9
10class QFontVariableAxisPrivate : public QSharedData
11{
12public:
13 QFont::Tag tag;
14 QString name;
15 qreal minimumValue = 0.0;
16 qreal maximumValue = 0.0;
17 qreal defaultValue = 0.0;
18};
19
20/*!
21 \class QFontVariableAxis
22 \reentrant
23 \inmodule QtGui
24 \ingroup shared
25 \since 6.9
26
27 \brief The QFontVariableAxis class represents a variable axis in a font.
28
29 Variable fonts provide a way to store multiple variations (with different weights, widths
30 or styles) in the same font file. The variations are given as floating point values for
31 a pre-defined set of parameters, called "variable axes".
32
33 Specific parameterizations (sets of values for the axes in a font) can be selected using
34 the properties in QFont, same as with traditional subfamilies that are defined as stand-alone
35 font files. But with variable fonts, arbitrary values can be provided for each axis to gain a
36 fine-grained customization of the font's appearance.
37
38 QFontVariableAxis contains information of one axis. Use \l{QFontInfo::variableAxes()}
39 to retrieve a list of the variable axes defined for a given font. Specific values can be
40 provided for an axis by using \l{QFont::setVariableAxis()} and passing in the \l{tag()}.
41
42 \note On Windows, variable axes are not supported if the optional GDI font backend is in use.
43*/
44QFontVariableAxis::QFontVariableAxis()
45 : d_ptr(new QFontVariableAxisPrivate)
46{
47}
48
49/*!
50 Destroys this QFontVariableAxis object.
51*/
53QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QFontVariableAxisPrivate)
54
55/*!
56 Creates a QFontVariableAxis object that is a copy of the given \a axis.
57
58 \sa operator=()
59*/
60QFontVariableAxis::QFontVariableAxis(const QFontVariableAxis &axis) = default;
61
62/*!
63 Returns the tag of the axis. This is a four-character sequence which identifies the axis.
64 Certain tags have standardized meanings, such as "wght" (weight) and "wdth" (width), but any
65 sequence of four latin-1 characters is a valid tag. By convention, non-standard/custom axes
66 are denoted by tags in all uppercase.
67
68 \sa QFont::setVariableAxis(), name()
69 */
70QFont::Tag QFontVariableAxis::tag() const
71{
72 Q_D(const QFontVariableAxis);
73 return d->tag;
74}
75
76/*!
77 Sets the tag of QFontVariableAxis to \a tag.
78
79 \note Typically, there will be no need to call this function as it will not affect the font
80 itself, only this particular representation.
81
82 \sa tag()
83 */
84void QFontVariableAxis::setTag(QFont::Tag tag)
85{
86 if (d_func()->tag == tag)
87 return;
88 detach();
89 Q_D(QFontVariableAxis);
90 d->tag = tag;
91}
92
93/*!
94 Returns the name of the axis, if provided by the font.
95
96 \sa tag()
97*/
98QString QFontVariableAxis::name() const
99{
100 Q_D(const QFontVariableAxis);
101 return d->name;
102}
103
104/*!
105 Sets the name of this QFontVariableAxis to \a name.
106
107 \note Typically, there will be no need to call this function as it will not affect the font
108 itself, only this particular representation.
109
110 \sa name()
111 */
112void QFontVariableAxis::setName(const QString &name)
113{
114 if (d_func()->name == name)
115 return;
116 detach();
117 Q_D(QFontVariableAxis);
118 d->name = name;
119}
120
121/*!
122 \property QFontVariableAxis::minimumValue
123 \brief the minimum value of the axis.
124*/
125
126/*!
127 Returns the minimum value of the axis. Setting the axis to a value which is lower than this
128 is not supported.
129
130 \sa maximumValue(), defaultValue()
131*/
132qreal QFontVariableAxis::minimumValue() const
133{
134 Q_D(const QFontVariableAxis);
135 return d->minimumValue;
136}
137
138/*!
139 Sets the minimum value of this QFontVariableAxis to \a minimumValue.
140
141 \note Typically, there will be no need to call this function as it will not affect the font
142 itself, only this particular representation.
143
144 \sa minimumValue()
145*/
146void QFontVariableAxis::setMinimumValue(qreal minimumValue)
147{
148 if (d_func()->minimumValue == minimumValue)
149 return;
150 detach();
151 Q_D(QFontVariableAxis);
152 d->minimumValue = minimumValue;
153}
154
155/*!
156 Returns the maximum value of the axis. Setting the axis to a value which is higher than this
157 is not supported.
158
159 \sa minimumValue(), defaultValue()
160*/
161qreal QFontVariableAxis::maximumValue() const
162{
163 Q_D(const QFontVariableAxis);
164 return d->maximumValue;
165}
166
167/*!
168 Sets the maximum value of this QFontVariableAxis to \a maximumValue.
169
170 \note Typically, there will be no need to call this function as it will not affect the font
171 itself, only this particular representation.
172
173 \sa maximumValue()
174*/
175void QFontVariableAxis::setMaximumValue(qreal maximumValue)
176{
177 if (d_func()->maximumValue == maximumValue)
178 return;
179 detach();
180 Q_D(QFontVariableAxis);
181 d->maximumValue = maximumValue;
182}
183
184/*!
185 Returns the default value of the axis. This is the value the axis will have if none has been
186 provided in the QFont query.
187
188 \sa minimumValue(), maximumValue()
189*/
190qreal QFontVariableAxis::defaultValue() const
191{
192 Q_D(const QFontVariableAxis);
193 return d->defaultValue;
194}
195
196/*!
197 Sets the default value of this QFontVariableAxis to \a defaultValue.
198
199 \note Typically, there will be no need to call this function as it will not affect the font
200 itself, only this particular representation.
201
202 \sa defaultValue()
203*/
204void QFontVariableAxis::setDefaultValue(qreal defaultValue)
205{
206 if (d_func()->defaultValue == defaultValue)
207 return;
208 detach();
209 Q_D(QFontVariableAxis);
210 d->defaultValue = defaultValue;
211}
212
213/*!
214 Assigns the given \a axis to this QFontVariableAxis.
215
216 \sa QFontVariableAxis()
217*/
219{
220 QFontVariableAxis copy(axis);
221 swap(copy);
222 return *this;
223}
224
225/*!
226 \internal
227 */
228void QFontVariableAxis::detach()
229{
230 d_ptr.detach();
231}
232
233#ifndef QT_NO_DEBUG_STREAM
234QDebug operator<<(QDebug debug, const QFontVariableAxis &axis)
235{
236 QDebugStateSaver save(debug);
237
238 debug.nospace().noquote();
239 const QString name = axis.name();
240 if (!name.isEmpty())
241 debug << name << '(';
242
243 debug << axis.tag();
244 if (!name.isEmpty())
245 debug << ')';
246 debug << '[' << axis.minimumValue() << "..." << axis.maximumValue()
247 << "; default=" << axis.defaultValue() << ']';
248
249 return debug;
250}
251#endif
252
253QT_END_NAMESPACE
\reentrant \inmodule QtGui
Q_GUI_EXPORT void setDefaultValue(qreal defaultValue)
Sets the default value of this QFontVariableAxis to defaultValue.
Q_GUI_EXPORT void setMinimumValue(qreal minimumValue)
Sets the minimum value of this QFontVariableAxis to minimumValue.
Q_GUI_EXPORT void setMaximumValue(qreal maximumValue)
Sets the maximum value of this QFontVariableAxis to maximumValue.
Q_GUI_EXPORT void setName(const QString &name)
Sets the name of this QFontVariableAxis to name.
Q_GUI_EXPORT ~QFontVariableAxis()
Destroys this QFontVariableAxis object.
QDebug operator<<(QDebug debug, const QFontVariableAxis &axis)