diff options
Diffstat (limited to 'src/gui/text')
| -rw-r--r-- | src/gui/text/qfont.cpp | 13 | ||||
| -rw-r--r-- | src/gui/text/qfont_p.h | 7 | ||||
| -rw-r--r-- | src/gui/text/qfontmetrics.cpp | 44 | ||||
| -rw-r--r-- | src/gui/text/qfontvariableaxis.cpp | 38 |
4 files changed, 65 insertions, 37 deletions
diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp index b50dc4a43bf..7bbc9cf63db 100644 --- a/src/gui/text/qfont.cpp +++ b/src/gui/text/qfont.cpp @@ -257,6 +257,19 @@ QFontEngine *QFontPrivate::engineForScript(int script) const return QT_FONT_ENGINE_FROM_DATA(engineData, script); } +QFontEngine *QFontPrivate::engineForCharacter(char32_t c, EngineQueryOptions opt) const +{ + const bool smallCaps = !(opt & EngineQueryOption::IgnoreSmallCapsEngine); + const auto script = QChar::script(c); + QFontEngine *engine; + if (smallCaps && capital == QFont::SmallCaps && QChar::isLower(c)) + engine = smallCapsFontPrivate()->engineForScript(script); + else + engine = engineForScript(script); + Q_ASSERT(engine != nullptr); + return engine; +} + void QFontPrivate::alterCharForCapitalization(QChar &c) const { switch (capital) { case QFont::AllUppercase: diff --git a/src/gui/text/qfont_p.h b/src/gui/text/qfont_p.h index 75550439521..27bc2a6a7cc 100644 --- a/src/gui/text/qfont_p.h +++ b/src/gui/text/qfont_p.h @@ -163,6 +163,11 @@ private: class Q_GUI_EXPORT QFontPrivate { public: + enum class EngineQueryOption { + Default = 0, + IgnoreSmallCapsEngine = 0x1, + }; + Q_DECLARE_FLAGS(EngineQueryOptions, EngineQueryOption) QFontPrivate(); QFontPrivate(const QFontPrivate &other); @@ -170,6 +175,7 @@ public: ~QFontPrivate(); QFontEngine *engineForScript(int script) const; + QFontEngine *engineForCharacter(char32_t c, EngineQueryOptions opt = {}) const; void alterCharForCapitalization(QChar &c) const; QAtomicInt ref; @@ -208,6 +214,7 @@ public: void unsetVariableAxis(QFont::Tag tag); bool hasVariableAxis(QFont::Tag tag, float value) const; }; +Q_DECLARE_OPERATORS_FOR_FLAGS(QFontPrivate::EngineQueryOptions) class Q_GUI_EXPORT QFontCache : public QObject diff --git a/src/gui/text/qfontmetrics.cpp b/src/gui/text/qfontmetrics.cpp index 4ea21c9f0f3..c4403a16c6d 100644 --- a/src/gui/text/qfontmetrics.cpp +++ b/src/gui/text/qfontmetrics.cpp @@ -410,9 +410,8 @@ bool QFontMetrics::inFont(QChar ch) const */ bool QFontMetrics::inFontUcs4(uint ucs4) const { - const int script = QChar::script(ucs4); - QFontEngine *engine = d->engineForScript(script); - Q_ASSERT(engine != nullptr); + constexpr auto Ignore = QFontPrivate::EngineQueryOption::IgnoreSmallCapsEngine; + QFontEngine *engine = d->engineForCharacter(ucs4, Ignore); if (engine->type() == QFontEngine::Box) return false; return engine->canRender(ucs4); @@ -432,13 +431,7 @@ bool QFontMetrics::inFontUcs4(uint ucs4) const */ int QFontMetrics::leftBearing(QChar ch) const { - const int script = ch.script(); - QFontEngine *engine; - if (d->capital == QFont::SmallCaps && ch.isLower()) - engine = d->smallCapsFontPrivate()->engineForScript(script); - else - engine = d->engineForScript(script); - Q_ASSERT(engine != nullptr); + QFontEngine *engine = d->engineForCharacter(ch.unicode()); if (engine->type() == QFontEngine::Box) return 0; @@ -465,12 +458,7 @@ int QFontMetrics::leftBearing(QChar ch) const */ int QFontMetrics::rightBearing(QChar ch) const { - const int script = ch.script(); - QFontEngine *engine; - if (d->capital == QFont::SmallCaps && ch.isLower()) - engine = d->smallCapsFontPrivate()->engineForScript(script); - else - engine = d->engineForScript(script); + QFontEngine *engine = d->engineForCharacter(ch.unicode()); Q_ASSERT(engine != nullptr); if (engine->type() == QFontEngine::Box) return 0; @@ -574,13 +562,7 @@ int QFontMetrics::horizontalAdvance(QChar ch) const if (QChar::category(ch.unicode()) == QChar::Mark_NonSpacing) return 0; - const int script = ch.script(); - QFontEngine *engine; - if (d->capital == QFont::SmallCaps && ch.isLower()) - engine = d->smallCapsFontPrivate()->engineForScript(script); - else - engine = d->engineForScript(script); - Q_ASSERT(engine != nullptr); + QFontEngine *engine = d->engineForCharacter(ch.unicode()); d->alterCharForCapitalization(ch); @@ -684,13 +666,7 @@ QRect QFontMetrics::boundingRect(const QString &text, const QTextOption &option) */ QRect QFontMetrics::boundingRect(QChar ch) const { - const int script = ch.script(); - QFontEngine *engine; - if (d->capital == QFont::SmallCaps && ch.isLower()) - engine = d->smallCapsFontPrivate()->engineForScript(script); - else - engine = d->engineForScript(script); - Q_ASSERT(engine != nullptr); + QFontEngine *engine = d->engineForCharacter(ch.unicode()); d->alterCharForCapitalization(ch); @@ -1345,13 +1321,7 @@ bool QFontMetricsF::inFontUcs4(uint ucs4) const */ qreal QFontMetricsF::leftBearing(QChar ch) const { - const int script = ch.script(); - QFontEngine *engine; - if (d->capital == QFont::SmallCaps && ch.isLower()) - engine = d->smallCapsFontPrivate()->engineForScript(script); - else - engine = d->engineForScript(script); - Q_ASSERT(engine != nullptr); + QFontEngine *engine = d->engineForCharacter(ch.unicode()); if (engine->type() == QFontEngine::Box) return 0; diff --git a/src/gui/text/qfontvariableaxis.cpp b/src/gui/text/qfontvariableaxis.cpp index be83a3e02ce..bbc14f4cd11 100644 --- a/src/gui/text/qfontvariableaxis.cpp +++ b/src/gui/text/qfontvariableaxis.cpp @@ -60,6 +60,18 @@ QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QFontVariableAxisPrivate) QFontVariableAxis::QFontVariableAxis(const QFontVariableAxis &axis) = default; /*! + \property QFontVariableAxis::tag + \brief the tag of the axis + + This is a four-character sequence which identifies the axis. Certain tags + have standardized meanings, such as "wght" (weight) and "wdth" (width), + but any sequence of four latin-1 characters is a valid tag. By convention, + non-standard/custom axes are denoted by tags in all uppercase. + + \sa QFont::setVariableAxis(), name() +*/ + +/*! Returns the tag of the axis. This is a four-character sequence which identifies the axis. Certain tags have standardized meanings, such as "wght" (weight) and "wdth" (width), but any sequence of four latin-1 characters is a valid tag. By convention, non-standard/custom axes @@ -91,6 +103,13 @@ void QFontVariableAxis::setTag(QFont::Tag tag) } /*! + \property QFontVariableAxis::name + \brief the name of the axis, if provided by the font + + \sa tag() +*/ + +/*! Returns the name of the axis, if provided by the font. \sa tag() @@ -153,6 +172,15 @@ void QFontVariableAxis::setMinimumValue(qreal minimumValue) } /*! + \property QFontVariableAxis::maximumValue + \brief the maximum value of the axis + + Setting the axis to a value which is higher than this is not supported. + + \sa minimumValue(), defaultValue() +*/ + +/*! Returns the maximum value of the axis. Setting the axis to a value which is higher than this is not supported. @@ -182,6 +210,16 @@ void QFontVariableAxis::setMaximumValue(qreal maximumValue) } /*! + \property QFontVariableAxis::defaultValue + \brief the default value of the axis + + This is the value the axis will have if none has been provided in the + QFont query. + + \sa minimumValue(), maximumValue() +*/ + +/*! Returns the default value of the axis. This is the value the axis will have if none has been provided in the QFont query. |
