Change QFont::fontFeatures() -> QFont::features()

The 'font' is redundant here, and we don't prefix any other
properties like that.

Change-Id: Iee1f492b232e5bbcae399b472d7478406d8a81ef
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Eskil Abrahamsen Blomfeldt 2023-05-24 11:20:03 +02:00
parent 413e74e9a5
commit baba1f1b39
6 changed files with 72 additions and 72 deletions

View File

@ -213,7 +213,7 @@ QFontPrivate::QFontPrivate(const QFontPrivate &other)
strikeOut(other.strikeOut), kerning(other.kerning), strikeOut(other.strikeOut), kerning(other.kerning),
capital(other.capital), letterSpacingIsAbsolute(other.letterSpacingIsAbsolute), capital(other.capital), letterSpacingIsAbsolute(other.letterSpacingIsAbsolute),
letterSpacing(other.letterSpacing), wordSpacing(other.wordSpacing), letterSpacing(other.letterSpacing), wordSpacing(other.wordSpacing),
fontFeatures(other.fontFeatures), scFont(other.scFont) features(other.features), scFont(other.scFont)
{ {
if (scFont && scFont != this) if (scFont && scFont != this)
scFont->ref.ref(); scFont->ref.ref();
@ -344,18 +344,18 @@ void QFontPrivate::resolve(uint mask, const QFontPrivate *other)
if (! (mask & QFont::CapitalizationResolved)) if (! (mask & QFont::CapitalizationResolved))
capital = other->capital; capital = other->capital;
if (!(mask & QFont::FontFeaturesResolved)) if (!(mask & QFont::FeaturesResolved))
fontFeatures = other->fontFeatures; features = other->features;
} }
void QFontPrivate::setFontFeature(quint32 tag, quint32 value) void QFontPrivate::setFeature(quint32 tag, quint32 value)
{ {
fontFeatures.insert(tag, value); features.insert(tag, value);
} }
void QFontPrivate::unsetFontFeature(quint32 tag) void QFontPrivate::unsetFeature(quint32 tag)
{ {
fontFeatures.remove(tag); features.remove(tag);
} }
@ -1759,7 +1759,7 @@ bool QFont::operator==(const QFont &f) const
&& f.d->letterSpacingIsAbsolute == d->letterSpacingIsAbsolute && f.d->letterSpacingIsAbsolute == d->letterSpacingIsAbsolute
&& f.d->letterSpacing == d->letterSpacing && f.d->letterSpacing == d->letterSpacing
&& f.d->wordSpacing == d->wordSpacing && f.d->wordSpacing == d->wordSpacing
&& f.d->fontFeatures == d->fontFeatures && f.d->features == d->features
)); ));
} }
@ -1799,12 +1799,12 @@ bool QFont::operator<(const QFont &f) const
int f2attrs = (d->underline << 3) + (d->overline << 2) + (d->strikeOut<<1) + d->kerning; int f2attrs = (d->underline << 3) + (d->overline << 2) + (d->strikeOut<<1) + d->kerning;
if (f1attrs != f2attrs) return f1attrs < f2attrs; if (f1attrs != f2attrs) return f1attrs < f2attrs;
if (d->fontFeatures.size() != f.d->fontFeatures.size()) if (d->features.size() != f.d->features.size())
return f.d->fontFeatures.size() < d->fontFeatures.size(); return f.d->features.size() < d->features.size();
auto it = d->fontFeatures.constBegin(); auto it = d->features.constBegin();
auto jt = f.d->fontFeatures.constBegin(); auto jt = f.d->features.constBegin();
for (; it != d->fontFeatures.constEnd(); ++it, ++jt) { for (; it != d->features.constEnd(); ++it, ++jt) {
if (it.key() != jt.key()) if (it.key() != jt.key())
return jt.key() < it.key(); return jt.key() < it.key();
if (it.value() != jt.value()) if (it.value() != jt.value())
@ -2236,7 +2236,7 @@ void QFont::cacheStatistics()
\since 6.6 \since 6.6
Applies integer values to specific OpenType features when shaping the text based on the contents Applies integer values to specific OpenType features when shaping the text based on the contents
in \a fontFeatures. This provides advanced access to the font shaping process, and can be used in \a features. This provides advanced access to the font shaping process, and can be used
to support font features that are otherwise not covered in the API. to support font features that are otherwise not covered in the API.
An OpenType feature is defined by a 32-bit tag (encoded from the four-character name of the An OpenType feature is defined by a 32-bit tag (encoded from the four-character name of the
@ -2252,10 +2252,10 @@ void QFont::cacheStatistics()
fraction into a single character width (such as \c ½). fraction into a single character width (such as \c ½).
If a font supports the \c frac feature, then it can be enabled in the shaper by setting If a font supports the \c frac feature, then it can be enabled in the shaper by setting
\c{fontFeatures[stringToTag("frac")] = 1} in the font feature map. \c{features[stringToTag("frac")] = 1} in the font feature map.
This function will overwrite the current list of explicit font features. Use setFontFeature() or This function will overwrite the current list of explicit font features. Use setFeature() or
unsetFontFeature() to set or unset individual features. unsetFeature() to set or unset individual features.
\note By default, Qt will enable and disable certain font features based on other font \note By default, Qt will enable and disable certain font features based on other font
properties. In particular, the \c kern feature will be enabled/disabled depending on the properties. In particular, the \c kern feature will be enabled/disabled depending on the
@ -2263,19 +2263,19 @@ void QFont::cacheStatistics()
(\c liga, \c clig, \c dlig, \c hlig) will be disabled if a \l letterSpacing() is applied, (\c liga, \c clig, \c dlig, \c hlig) will be disabled if a \l letterSpacing() is applied,
but only for writing systems where the use of ligature is cosmetic. For writing systems where but only for writing systems where the use of ligature is cosmetic. For writing systems where
ligatures are required, the features will remain in their default state. The values set using ligatures are required, the features will remain in their default state. The values set using
setFontFeatures() and related functions will override the default behavior. If, for instance, setFeatures() and related functions will override the default behavior. If, for instance,
the \c{fontFeatures[stringToTag("kern")]} is set to 1, then kerning will always be enabled, the \c{features[stringToTag("kern")]} is set to 1, then kerning will always be enabled,
regardless of whether the kerning property is set to false. Similarly, if it is set to 0, then regardless of whether the kerning property is set to false. Similarly, if it is set to 0, then
it will always be disabled. To reset a font feature to its default behavior, you can unset it it will always be disabled. To reset a font feature to its default behavior, you can unset it
in the fontFeatures hash, for example by using unsetFontFeature(). in the features hash, for example by using unsetFeature().
\sa setFontFeature(), unsetFontFeature(), fontFeatures() \sa setFeature(), unsetFeature(), features()
*/ */
void QFont::setFontFeatures(const QHash<quint32, quint32> &fontFeatures) void QFont::setFeatures(const QHash<quint32, quint32> &features)
{ {
d->detachButKeepEngineData(this); d->detachButKeepEngineData(this);
d->fontFeatures = fontFeatures; d->features = features;
resolve_mask |= QFont::FontFeaturesResolved; resolve_mask |= QFont::FeaturesResolved;
} }
/*! /*!
@ -2284,74 +2284,74 @@ void QFont::setFontFeatures(const QHash<quint32, quint32> &fontFeatures)
Sets the \a value for a specific font feature \a tag. This is an advanced feature which can be Sets the \a value for a specific font feature \a tag. This is an advanced feature which can be
used to enable or disable specific OpenType features if they are available in the font. See used to enable or disable specific OpenType features if they are available in the font. See
\l setFontFeatures() for more details. \l setFeatures() for more details.
\sa setFontFeatures(), unsetFontFeature(), fontFeatures() \sa setFeatures(), unsetFeature(), features()
*/ */
void QFont::setFontFeature(quint32 tag, quint32 value) void QFont::setFeature(quint32 tag, quint32 value)
{ {
d->detachButKeepEngineData(this); d->detachButKeepEngineData(this);
d->setFontFeature(tag, value); d->setFeature(tag, value);
resolve_mask |= QFont::FontFeaturesResolved; resolve_mask |= QFont::FeaturesResolved;
} }
/*! /*!
\since 6.6 \since 6.6
\overload \overload
Sets the \a value of a specific \a fontFeature. This is an advanced feature which can be used to Sets the \a value of a specific \a feature. This is an advanced feature which can be used to
enable or disable specific OpenType features if they are available in the font. See enable or disable specific OpenType features if they are available in the font. See
\l setFontFeatures() for more details. \l setFeatures() for more details.
\note This is equivalent to calling setFontFeature(stringToTag(fontFeature), value). \note This is equivalent to calling setFeature(stringToTag(feature), value).
\sa setFontFeatures(), unsetFontFeature(), fontFeatures() \sa setFeatures(), unsetFeature(), features()
*/ */
void QFont::setFontFeature(const char *fontFeature, quint32 value) void QFont::setFeature(const char *feature, quint32 value)
{ {
setFontFeature(stringToTag(fontFeature), value); setFeature(stringToTag(feature), value);
} }
/*! /*!
\since 6.6 \since 6.6
\overload \overload
Unsets the \a fontFeature from the map of explicitly enabled/disabled features. Unsets the \a tag from the map of explicitly enabled/disabled features.
\note Even if the feature has not previously been added, this will mark the font features map \note Even if the feature has not previously been added, this will mark the font features map
as modified in this QFont, so that it will take precedence when resolving against other fonts. as modified in this QFont, so that it will take precedence when resolving against other fonts.
Unsetting an existing feature on the QFont reverts behavior to the default. See Unsetting an existing feature on the QFont reverts behavior to the default. See
\l setFontFeatures() for more details. \l setFeatures() for more details.
\sa setFontFeatures(), setFontFeature(), fontFeatures() \sa setFeatures(), setFeature(), features()
*/ */
void QFont::unsetFontFeature(quint32 fontFeature) void QFont::unsetFeature(quint32 tag)
{ {
d->detachButKeepEngineData(this); d->detachButKeepEngineData(this);
d->unsetFontFeature(fontFeature); d->unsetFeature(tag);
resolve_mask |= QFont::FontFeaturesResolved; resolve_mask |= QFont::FeaturesResolved;
} }
/*! /*!
\since 6.6 \since 6.6
\overload \overload
Unsets the \a fontFeature from the map of explicitly enabled/disabled features. Unsets the \a feature from the map of explicitly enabled/disabled features.
\note Even if the feature has not previously been added, this will mark the font features map \note Even if the feature has not previously been added, this will mark the font features map
as modified in this QFont, so that it will take precedence when resolving against other fonts. as modified in this QFont, so that it will take precedence when resolving against other fonts.
Unsetting an existing feature on the QFont reverts behavior to the default. See Unsetting an existing feature on the QFont reverts behavior to the default. See
\l setFontFeatures() for more details. \l setFeatures() for more details.
\note This is equivalent to calling unsetFontFeature(stringToTag(fontFeature)). \note This is equivalent to calling unsetFeature(stringToTag(feature)).
\sa setFontFeatures(), setFontFeature(), fontFeatures() \sa setFeatures(), setFeature(), features()
*/ */
void QFont::unsetFontFeature(const char *fontFeature) void QFont::unsetFeature(const char *feature)
{ {
unsetFontFeature(stringToTag(fontFeature)); unsetFeature(stringToTag(feature));
} }
/*! /*!
@ -2361,16 +2361,16 @@ void QFont::unsetFontFeature(const char *fontFeature)
the shaping process will use default features based on other font or text properties. the shaping process will use default features based on other font or text properties.
Unsetting an existing feature on the QFont reverts behavior to the default. See Unsetting an existing feature on the QFont reverts behavior to the default. See
\l setFontFeatures() for more details. \l setFeatures() for more details.
The key of the returned QHash refers to the font table tag as it's encoded in the font The key of the returned QHash refers to the font table tag as it's encoded in the font
file. It can be converted to a QByteArray using the tagToString() function. file. It can be converted to a QByteArray using the tagToString() function.
\sa setFontFeatures(), setFontFeature(), unsetFontFeature() \sa setFeatures(), setFeature(), unsetFeature()
*/ */
QHash<quint32, quint32> QFont::fontFeatures() const QHash<quint32, quint32> QFont::features() const
{ {
return d->fontFeatures; return d->features;
} }
/*! /*!
@ -2378,7 +2378,7 @@ QHash<quint32, quint32> QFont::fontFeatures() const
Returns the decoded name for \a tag. Returns the decoded name for \a tag.
\sa setFontFeatures(), setFontFeature(), unsetFontFeature(), stringToTag() \sa setFeatures(), setFeature(), unsetFeature(), stringToTag()
*/ */
QByteArray QFont::tagToString(quint32 tag) QByteArray QFont::tagToString(quint32 tag)
{ {
@ -2396,7 +2396,7 @@ QByteArray QFont::tagToString(quint32 tag)
Returns the encoded tag for \a name. The \a name must be a null-terminated string of exactly Returns the encoded tag for \a name. The \a name must be a null-terminated string of exactly
four characters. Returns 0 on error. four characters. Returns 0 on error.
\sa setFontFeatures(), setFontFeature(), unsetFontFeature(), tagToString() \sa setFeatures(), setFeature(), unsetFeature(), tagToString()
*/ */
quint32 QFont::stringToTag(const char *name) quint32 QFont::stringToTag(const char *name)
{ {
@ -2543,7 +2543,7 @@ QDataStream &operator<<(QDataStream &s, const QFont &font)
s << font.d->request.families; s << font.d->request.families;
} }
if (s.version() >= QDataStream::Qt_6_6) if (s.version() >= QDataStream::Qt_6_6)
s << font.d->fontFeatures; s << font.d->features;
return s; return s;
} }
@ -2659,8 +2659,8 @@ QDataStream &operator>>(QDataStream &s, QFont &font)
font.d->request.families = value; font.d->request.families = value;
} }
if (s.version() >= QDataStream::Qt_6_6) { if (s.version() >= QDataStream::Qt_6_6) {
font.d->fontFeatures.clear(); font.d->features.clear();
s >> font.d->fontFeatures; s >> font.d->features;
} }
return s; return s;

View File

@ -126,7 +126,7 @@ public:
HintingPreferenceResolved = 0x8000, HintingPreferenceResolved = 0x8000,
StyleNameResolved = 0x10000, StyleNameResolved = 0x10000,
FamiliesResolved = 0x20000, FamiliesResolved = 0x20000,
FontFeaturesResolved = 0x40000, FeaturesResolved = 0x40000,
AllPropertiesResolved = 0x7ffff AllPropertiesResolved = 0x7ffff
}; };
Q_ENUM(ResolveProperties) Q_ENUM(ResolveProperties)
@ -207,12 +207,12 @@ public:
void setHintingPreference(HintingPreference hintingPreference); void setHintingPreference(HintingPreference hintingPreference);
HintingPreference hintingPreference() const; HintingPreference hintingPreference() const;
void setFontFeature(const char *fontFeature, quint32 value); void setFeature(const char *feature, quint32 value);
void setFontFeature(quint32 tag, quint32 value); void setFeature(quint32 tag, quint32 value);
void setFontFeatures(const QHash<quint32, quint32> &fontFeatures); void setFeatures(const QHash<quint32, quint32> &features);
void unsetFontFeature(quint32 tag); void unsetFeature(quint32 tag);
void unsetFontFeature(const char *tag); void unsetFeature(const char *feature);
QHash<quint32, quint32> fontFeatures() const; QHash<quint32, quint32> features() const;
static QByteArray tagToString(quint32 tag); static QByteArray tagToString(quint32 tag);
static quint32 stringToTag(const char *tagString); static quint32 stringToTag(const char *tagString);

View File

@ -164,7 +164,7 @@ public:
QFixed letterSpacing; QFixed letterSpacing;
QFixed wordSpacing; QFixed wordSpacing;
QHash<quint32, quint32> fontFeatures; QHash<quint32, quint32> features;
mutable QFontPrivate *scFont; mutable QFontPrivate *scFont;
QFont smallCapsFont() const { return QFont(smallCapsFontPrivate()); } QFont smallCapsFont() const { return QFont(smallCapsFontPrivate()); }
@ -179,8 +179,8 @@ public:
static void detachButKeepEngineData(QFont *font); static void detachButKeepEngineData(QFont *font);
void setFontFeature(quint32 tag, quint32 value); void setFeature(quint32 tag, quint32 value);
void unsetFontFeature(quint32 tag); void unsetFeature(quint32 tag);
private: private:
QFontPrivate &operator=(const QFontPrivate &) { return *this; } QFontPrivate &operator=(const QFontPrivate &) { return *this; }

View File

@ -1404,7 +1404,7 @@ void QTextEngine::shapeText(int item) const
bool kerningEnabled; bool kerningEnabled;
bool letterSpacingIsAbsolute; bool letterSpacingIsAbsolute;
bool shapingEnabled = false; bool shapingEnabled = false;
QHash<quint32, quint32> fontFeatures; QHash<quint32, quint32> features;
QFixed letterSpacing, wordSpacing; QFixed letterSpacing, wordSpacing;
#ifndef QT_NO_RAWFONT #ifndef QT_NO_RAWFONT
if (useRawFont) { if (useRawFont) {
@ -1418,7 +1418,7 @@ void QTextEngine::shapeText(int item) const
wordSpacing = QFixed::fromReal(font.wordSpacing()); wordSpacing = QFixed::fromReal(font.wordSpacing());
letterSpacing = QFixed::fromReal(font.letterSpacing()); letterSpacing = QFixed::fromReal(font.letterSpacing());
letterSpacingIsAbsolute = true; letterSpacingIsAbsolute = true;
fontFeatures = font.d->fontFeatures; features = font.d->features;
} else } else
#endif #endif
{ {
@ -1431,7 +1431,7 @@ void QTextEngine::shapeText(int item) const
letterSpacingIsAbsolute = font.d->letterSpacingIsAbsolute; letterSpacingIsAbsolute = font.d->letterSpacingIsAbsolute;
letterSpacing = font.d->letterSpacing; letterSpacing = font.d->letterSpacing;
wordSpacing = font.d->wordSpacing; wordSpacing = font.d->wordSpacing;
fontFeatures = font.d->fontFeatures; features = font.d->features;
if (letterSpacingIsAbsolute && letterSpacing.value()) if (letterSpacingIsAbsolute && letterSpacing.value())
letterSpacing *= font.d->dpi / qt_defaultDpiY(); letterSpacing *= font.d->dpi / qt_defaultDpiY();
@ -1492,7 +1492,7 @@ void QTextEngine::shapeText(int item) const
itemBoundaries, itemBoundaries,
kerningEnabled, kerningEnabled,
letterSpacing != 0, letterSpacing != 0,
fontFeatures); features);
} else } else
#endif #endif
{ {

View File

@ -628,7 +628,7 @@ private:
const QList<uint> &itemBoundaries, const QList<uint> &itemBoundaries,
bool kerningEnabled, bool kerningEnabled,
bool hasLetterSpacing, bool hasLetterSpacing,
const QHash<quint32, quint32> &fontFeatures) const; const QHash<quint32, quint32> &features) const;
#endif #endif
int endOfLine(int lineNum); int endOfLine(int lineNum);

View File

@ -28,7 +28,7 @@ void MainWindow::updateSampleText()
QListWidgetItem *it = ui->lwFeatures->item(i); QListWidgetItem *it = ui->lwFeatures->item(i);
if (it->checkState() != Qt::PartiallyChecked) { if (it->checkState() != Qt::PartiallyChecked) {
QByteArray ba = it->text().toLatin1(); QByteArray ba = it->text().toLatin1();
font.setFontFeature(ba, !!it->checkState()); font.setFeature(ba, !!it->checkState());
} }
} }