/src/qtbase/src/gui/text/qfontvariableaxis.cpp
Line | Count | Source |
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 | | |
4 | | #include "qfontvariableaxis.h" |
5 | | |
6 | | #include <QtCore/qdebug.h> |
7 | | |
8 | | QT_BEGIN_NAMESPACE |
9 | | |
10 | | class QFontVariableAxisPrivate : public QSharedData |
11 | | { |
12 | | public: |
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 | | */ |
44 | | QFontVariableAxis::QFontVariableAxis() |
45 | 0 | : d_ptr(new QFontVariableAxisPrivate) |
46 | 0 | { |
47 | 0 | } |
48 | | |
49 | | /*! |
50 | | Destroys this QFontVariableAxis object. |
51 | | */ |
52 | 0 | QFontVariableAxis::~QFontVariableAxis() = default; |
53 | | QT_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 | | */ |
60 | 0 | QFontVariableAxis::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 | | */ |
82 | | QFont::Tag QFontVariableAxis::tag() const |
83 | 0 | { |
84 | 0 | Q_D(const QFontVariableAxis); |
85 | 0 | return d->tag; |
86 | 0 | } |
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 | | */ |
96 | | void QFontVariableAxis::setTag(QFont::Tag tag) |
97 | 0 | { |
98 | 0 | if (d_func()->tag == tag) |
99 | 0 | return; |
100 | 0 | detach(); |
101 | 0 | Q_D(QFontVariableAxis); |
102 | 0 | d->tag = tag; |
103 | 0 | } |
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 | | */ |
117 | | QString QFontVariableAxis::name() const |
118 | 0 | { |
119 | 0 | Q_D(const QFontVariableAxis); |
120 | 0 | return d->name; |
121 | 0 | } |
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 | | */ |
131 | | void QFontVariableAxis::setName(const QString &name) |
132 | 0 | { |
133 | 0 | if (d_func()->name == name) |
134 | 0 | return; |
135 | 0 | detach(); |
136 | 0 | Q_D(QFontVariableAxis); |
137 | 0 | d->name = name; |
138 | 0 | } |
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 | | */ |
151 | | qreal QFontVariableAxis::minimumValue() const |
152 | 0 | { |
153 | 0 | Q_D(const QFontVariableAxis); |
154 | 0 | return d->minimumValue; |
155 | 0 | } |
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 | | */ |
165 | | void QFontVariableAxis::setMinimumValue(qreal minimumValue) |
166 | 0 | { |
167 | 0 | if (d_func()->minimumValue == minimumValue) |
168 | 0 | return; |
169 | 0 | detach(); |
170 | 0 | Q_D(QFontVariableAxis); |
171 | 0 | d->minimumValue = minimumValue; |
172 | 0 | } |
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 | | */ |
189 | | qreal QFontVariableAxis::maximumValue() const |
190 | 0 | { |
191 | 0 | Q_D(const QFontVariableAxis); |
192 | 0 | return d->maximumValue; |
193 | 0 | } |
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 | | */ |
203 | | void QFontVariableAxis::setMaximumValue(qreal maximumValue) |
204 | 0 | { |
205 | 0 | if (d_func()->maximumValue == maximumValue) |
206 | 0 | return; |
207 | 0 | detach(); |
208 | 0 | Q_D(QFontVariableAxis); |
209 | 0 | d->maximumValue = maximumValue; |
210 | 0 | } |
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 | | */ |
228 | | qreal QFontVariableAxis::defaultValue() const |
229 | 0 | { |
230 | 0 | Q_D(const QFontVariableAxis); |
231 | 0 | return d->defaultValue; |
232 | 0 | } |
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 | | */ |
242 | | void QFontVariableAxis::setDefaultValue(qreal defaultValue) |
243 | 0 | { |
244 | 0 | if (d_func()->defaultValue == defaultValue) |
245 | 0 | return; |
246 | 0 | detach(); |
247 | 0 | Q_D(QFontVariableAxis); |
248 | 0 | d->defaultValue = defaultValue; |
249 | 0 | } |
250 | | |
251 | | /*! |
252 | | Assigns the given \a axis to this QFontVariableAxis. |
253 | | |
254 | | \sa QFontVariableAxis() |
255 | | */ |
256 | | QFontVariableAxis &QFontVariableAxis::operator=(const QFontVariableAxis &axis) |
257 | 0 | { |
258 | 0 | QFontVariableAxis copy(axis); |
259 | 0 | swap(copy); |
260 | 0 | return *this; |
261 | 0 | } |
262 | | |
263 | | /*! |
264 | | \internal |
265 | | */ |
266 | | void QFontVariableAxis::detach() |
267 | 0 | { |
268 | 0 | d_ptr.detach(); |
269 | 0 | } |
270 | | |
271 | | #ifndef QT_NO_DEBUG_STREAM |
272 | | QDebug operator<<(QDebug debug, const QFontVariableAxis &axis) |
273 | 0 | { |
274 | 0 | QDebugStateSaver save(debug); |
275 | |
|
276 | 0 | debug.nospace().noquote(); |
277 | 0 | const QString name = axis.name(); |
278 | 0 | if (!name.isEmpty()) |
279 | 0 | debug << name << '('; |
280 | |
|
281 | 0 | debug << axis.tag(); |
282 | 0 | if (!name.isEmpty()) |
283 | 0 | debug << ')'; |
284 | 0 | debug << '[' << axis.minimumValue() << "..." << axis.maximumValue() |
285 | 0 | << "; default=" << axis.defaultValue() << ']'; |
286 | |
|
287 | 0 | return debug; |
288 | 0 | } |
289 | | #endif |
290 | | |
291 | | QT_END_NAMESPACE |