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 \property QFontVariableAxis::tag
64 \brief the tag of the axis
65
66 This is a four-character sequence which identifies the axis. Certain tags
67 have standardized meanings, such as "wght" (weight) and "wdth" (width),
68 but any sequence of four latin-1 characters is a valid tag. By convention,
69 non-standard/custom axes are denoted by tags in all uppercase.
70
71 \sa QFont::setVariableAxis(), name()
72*/
73
74/*!
75 Returns the tag of the axis. This is a four-character sequence which identifies the axis.
76 Certain tags have standardized meanings, such as "wght" (weight) and "wdth" (width), but any
77 sequence of four latin-1 characters is a valid tag. By convention, non-standard/custom axes
78 are denoted by tags in all uppercase.
79
80 \sa QFont::setVariableAxis(), name()
81 */
82QFont::Tag QFontVariableAxis::tag() const
83{
84 Q_D(const QFontVariableAxis);
85 return d->tag;
86}
87
88/*!
89 Sets the tag of QFontVariableAxis to \a tag.
90
91 \note Typically, there will be no need to call this function as it will not affect the font
92 itself, only this particular representation.
93
94 \sa tag()
95 */
96void QFontVariableAxis::setTag(QFont::Tag tag)
97{
98 if (d_func()->tag == tag)
99 return;
100 detach();
101 Q_D(QFontVariableAxis);
102 d->tag = tag;
103}
104
105/*!
106 \property QFontVariableAxis::name
107 \brief the name of the axis, if provided by the font
108
109 \sa tag()
110*/
111
112/*!
113 Returns the name of the axis, if provided by the font.
114
115 \sa tag()
116*/
117QString QFontVariableAxis::name() const
118{
119 Q_D(const QFontVariableAxis);
120 return d->name;
121}
122
123/*!
124 Sets the name of this QFontVariableAxis to \a name.
125
126 \note Typically, there will be no need to call this function as it will not affect the font
127 itself, only this particular representation.
128
129 \sa name()
130 */
131void QFontVariableAxis::setName(const QString &name)
132{
133 if (d_func()->name == name)
134 return;
135 detach();
136 Q_D(QFontVariableAxis);
137 d->name = name;
138}
139
140/*!
141 \property QFontVariableAxis::minimumValue
142 \brief the minimum value of the axis.
143*/
144
145/*!
146 Returns the minimum value of the axis. Setting the axis to a value which is lower than this
147 is not supported.
148
149 \sa maximumValue(), defaultValue()
150*/
151qreal QFontVariableAxis::minimumValue() const
152{
153 Q_D(const QFontVariableAxis);
154 return d->minimumValue;
155}
156
157/*!
158 Sets the minimum value of this QFontVariableAxis to \a minimumValue.
159
160 \note Typically, there will be no need to call this function as it will not affect the font
161 itself, only this particular representation.
162
163 \sa minimumValue()
164*/
165void QFontVariableAxis::setMinimumValue(qreal minimumValue)
166{
167 if (d_func()->minimumValue == minimumValue)
168 return;
169 detach();
170 Q_D(QFontVariableAxis);
171 d->minimumValue = minimumValue;
172}
173
174/*!
175 \property QFontVariableAxis::maximumValue
176 \brief the maximum value of the axis
177
178 Setting the axis to a value which is higher than this is not supported.
179
180 \sa minimumValue(), defaultValue()
181*/
182
183/*!
184 Returns the maximum value of the axis. Setting the axis to a value which is higher than this
185 is not supported.
186
187 \sa minimumValue(), defaultValue()
188*/
189qreal QFontVariableAxis::maximumValue() const
190{
191 Q_D(const QFontVariableAxis);
192 return d->maximumValue;
193}
194
195/*!
196 Sets the maximum value of this QFontVariableAxis to \a maximumValue.
197
198 \note Typically, there will be no need to call this function as it will not affect the font
199 itself, only this particular representation.
200
201 \sa maximumValue()
202*/
203void QFontVariableAxis::setMaximumValue(qreal maximumValue)
204{
205 if (d_func()->maximumValue == maximumValue)
206 return;
207 detach();
208 Q_D(QFontVariableAxis);
209 d->maximumValue = maximumValue;
210}
211
212/*!
213 \property QFontVariableAxis::defaultValue
214 \brief the default value of the axis
215
216 This is the value the axis will have if none has been provided in the
217 QFont query.
218
219 \sa minimumValue(), maximumValue()
220*/
221
222/*!
223 Returns the default value of the axis. This is the value the axis will have if none has been
224 provided in the QFont query.
225
226 \sa minimumValue(), maximumValue()
227*/
228qreal QFontVariableAxis::defaultValue() const
229{
230 Q_D(const QFontVariableAxis);
231 return d->defaultValue;
232}
233
234/*!
235 Sets the default value of this QFontVariableAxis to \a defaultValue.
236
237 \note Typically, there will be no need to call this function as it will not affect the font
238 itself, only this particular representation.
239
240 \sa defaultValue()
241*/
242void QFontVariableAxis::setDefaultValue(qreal defaultValue)
243{
244 if (d_func()->defaultValue == defaultValue)
245 return;
246 detach();
247 Q_D(QFontVariableAxis);
248 d->defaultValue = defaultValue;
249}
250
251/*!
252 Assigns the given \a axis to this QFontVariableAxis.
253
254 \sa QFontVariableAxis()
255*/
257{
258 QFontVariableAxis copy(axis);
259 swap(copy);
260 return *this;
261}
262
263/*!
264 \internal
265 */
266void QFontVariableAxis::detach()
267{
268 d_ptr.detach();
269}
270
271#ifndef QT_NO_DEBUG_STREAM
272QDebug operator<<(QDebug debug, const QFontVariableAxis &axis)
273{
274 QDebugStateSaver save(debug);
275
276 debug.nospace().noquote();
277 const QString name = axis.name();
278 if (!name.isEmpty())
279 debug << name << '(';
280
281 debug << axis.tag();
282 if (!name.isEmpty())
283 debug << ')';
284 debug << '[' << axis.minimumValue() << "..." << axis.maximumValue()
285 << "; default=" << axis.defaultValue() << ']';
286
287 return debug;
288}
289#endif
290
291QT_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)