diff options
Diffstat (limited to 'src/gui/text')
| -rw-r--r-- | src/gui/text/qfont_p.h | 4 | ||||
| -rw-r--r-- | src/gui/text/qfontvariableaxis.cpp | 38 | ||||
| -rw-r--r-- | src/gui/text/qtextengine.cpp | 61 | ||||
| -rw-r--r-- | src/gui/text/qtextengine_p.h | 4 |
4 files changed, 76 insertions, 31 deletions
diff --git a/src/gui/text/qfont_p.h b/src/gui/text/qfont_p.h index d1509e4a251..75550439521 100644 --- a/src/gui/text/qfont_p.h +++ b/src/gui/text/qfont_p.h @@ -166,6 +166,7 @@ public: QFontPrivate(); QFontPrivate(const QFontPrivate &other); + QFontPrivate &operator=(const QFontPrivate &) = delete; ~QFontPrivate(); QFontEngine *engineForScript(int script) const; @@ -206,9 +207,6 @@ public: void setVariableAxis(QFont::Tag tag, float value); void unsetVariableAxis(QFont::Tag tag); bool hasVariableAxis(QFont::Tag tag, float value) const; - -private: - QFontPrivate &operator=(const QFontPrivate &) { return *this; } }; 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. diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index 11c79f23d25..29fda652ef6 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only // Qt-Security score:critical reason:data-parser +#include <QtCore/private/qflatmap_p.h> #include <QtGui/private/qtguiglobal_p.h> #include "qdebug.h" #include "qtextformat.h" @@ -1613,11 +1614,15 @@ int QTextEngine::shapeTextWithHarfbuzzNG(const QScriptItem &si, const ushort *st { uint glyphs_shaped = 0; - hb_buffer_t *buffer = hb_buffer_create(); - hb_buffer_set_unicode_funcs(buffer, hb_qt_get_unicode_funcs()); + if (!buffer) { + buffer = hb_buffer_create(); + hb_buffer_set_unicode_funcs(buffer, hb_qt_get_unicode_funcs()); + } + hb_buffer_pre_allocate(buffer, itemLength); if (Q_UNLIKELY(!hb_buffer_allocation_successful(buffer))) { hb_buffer_destroy(buffer); + buffer = nullptr; return 0; } @@ -1671,26 +1676,26 @@ int QTextEngine::shapeTextWithHarfbuzzNG(const QScriptItem &si, const ushort *st bool dontLigate = hasLetterSpacing && !scriptRequiresOpenType; - QHash<QFont::Tag, quint32> features; - features.insert(QFont::Tag("kern"), !!kerningEnabled); + QVarLengthFlatMap<QFont::Tag, hb_feature_t, 16> features; + auto insertFeature = [&features](QFont::Tag tag, quint32 value) { + features.insert(tag, { tag.value(), + value, + HB_FEATURE_GLOBAL_START, + HB_FEATURE_GLOBAL_END }); + }; + // fontFeatures have precedence + for (const auto &[tag, value]: fontFeatures.asKeyValueRange()) + insertFeature(tag, value); + insertFeature(QFont::Tag("kern"), !!kerningEnabled); if (dontLigate) { - features.insert(QFont::Tag("liga"), false); - features.insert(QFont::Tag("clig"), false); - features.insert(QFont::Tag("dlig"), false); - features.insert(QFont::Tag("hlig"), false); - } - features.insert(fontFeatures); - - QVarLengthArray<hb_feature_t, 16> featureArray; - for (auto it = features.constBegin(); it != features.constEnd(); ++it) { - featureArray.append({ it.key().value(), - it.value(), - HB_FEATURE_GLOBAL_START, - HB_FEATURE_GLOBAL_END }); + insertFeature(QFont::Tag("liga"), false); + insertFeature(QFont::Tag("clig"), false); + insertFeature(QFont::Tag("dlig"), false); + insertFeature(QFont::Tag("hlig"), false); } // whitelist cross-platforms shapers only - static const char *shaper_list[] = { + constexpr const char *shaper_list[] = { "graphite2", "ot", "fallback", @@ -1699,13 +1704,11 @@ int QTextEngine::shapeTextWithHarfbuzzNG(const QScriptItem &si, const ushort *st bool shapedOk = hb_shape_full(hb_font, buffer, - featureArray.constData(), - features.size(), + features.values().constData(), + features.values().size(), shaper_list); - if (Q_UNLIKELY(!shapedOk)) { - hb_buffer_destroy(buffer); + if (Q_UNLIKELY(!shapedOk)) return 0; - } if (Q_UNLIKELY(HB_DIRECTION_IS_BACKWARD(props.direction))) hb_buffer_reverse(buffer); @@ -1718,10 +1721,8 @@ int QTextEngine::shapeTextWithHarfbuzzNG(const QScriptItem &si, const ushort *st num_glyphs = 1; // ensure we have enough space for shaped glyphs and metrics - if (Q_UNLIKELY(!ensureSpace(glyphs_shaped + num_glyphs))) { - hb_buffer_destroy(buffer); + if (Q_UNLIKELY(!ensureSpace(glyphs_shaped + num_glyphs))) return 0; - } // fetch the shaped glyphs and metrics QGlyphLayout g = availableGlyphs(&si).mid(glyphs_shaped, num_glyphs); @@ -1781,8 +1782,6 @@ int QTextEngine::shapeTextWithHarfbuzzNG(const QScriptItem &si, const ushort *st glyphs_shaped += num_glyphs; } - hb_buffer_destroy(buffer); - return glyphs_shaped; } @@ -1826,6 +1825,12 @@ QTextEngine::~QTextEngine() delete layoutData; delete specialData; resetFontEngineCache(); +#if QT_CONFIG(harfbuzz) + if (buffer) { + hb_buffer_destroy(buffer); + buffer = nullptr; + } +#endif } const QCharAttributes *QTextEngine::attributes() const diff --git a/src/gui/text/qtextengine_p.h b/src/gui/text/qtextengine_p.h index dffbc129b3a..e513fd598ba 100644 --- a/src/gui/text/qtextengine_p.h +++ b/src/gui/text/qtextengine_p.h @@ -40,6 +40,8 @@ #include <stdlib.h> #include <vector> +struct hb_buffer_t; + QT_BEGIN_NAMESPACE class QFontPrivate; @@ -583,6 +585,8 @@ private: void indexFormats(); void resolveFormats() const; + mutable hb_buffer_t *buffer = nullptr; + public: bool atWordSeparator(int position) const; |
