From 441e0b41bf5b700cdaa3b0ba2393c487ed4b9de5 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Fri, 30 Jun 2017 10:07:29 +0200 Subject: Expose "kerning" property for fonts For text where the content is known, it can be handy to be able to disable the kerning feature in OpenType to improve performance. [ChangeLog][Qt Quick][Text] Added "kerning" property to the font type to support disabling kerning on text. Task-number: QTBUG-56728 Change-Id: I2e447587a066a7e12c5d38967e0845eaad021014 Reviewed-by: Simon Hausmann --- src/quick/doc/src/qmltypereference.qdoc | 1 + src/quick/items/qquicktext.cpp | 13 +++++++++++++ src/quick/items/qquicktextedit.cpp | 13 +++++++++++++ src/quick/items/qquicktextinput.cpp | 13 +++++++++++++ src/quick/util/qquickglobal.cpp | 5 +++++ src/quick/util/qquickvaluetypes.cpp | 10 ++++++++++ src/quick/util/qquickvaluetypes_p.h | 4 ++++ 7 files changed, 59 insertions(+) (limited to 'src/quick') diff --git a/src/quick/doc/src/qmltypereference.qdoc b/src/quick/doc/src/qmltypereference.qdoc index 2406722dbc..cbcf945a11 100644 --- a/src/quick/doc/src/qmltypereference.qdoc +++ b/src/quick/doc/src/qmltypereference.qdoc @@ -170,6 +170,7 @@ available when you import \c QtQuick. \li \l enumeration \c font.capitalization \li \l real \c font.letterSpacing \li \l real \c font.wordSpacing + \li \l bool \c font.kerning \endlist Example: diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp index 080cc9412e..1bcfbd41f7 100644 --- a/src/quick/items/qquicktext.cpp +++ b/src/quick/items/qquicktext.cpp @@ -1499,6 +1499,19 @@ QQuickText::~QQuickText() Text { text: "Hello"; renderType: Text.NativeRendering; font.hintingPreference: Font.PreferVerticalHinting } \endqml */ + +/*! + \qmlproperty bool QtQuick::Text::font.kerning + \since 5.10 + + Enables or disables the kerning OpenType feature when shaping the text. This may improve performance + when creating or changing the text, at the expense of some cosmetic features. The default value + is true. + + \qml + Text { text: "OATS FLAVOUR WAY"; font.kerning: false } + \endqml +*/ QFont QQuickText::font() const { Q_D(const QQuickText); diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp index 61d610520f..aad380ca30 100644 --- a/src/quick/items/qquicktextedit.cpp +++ b/src/quick/items/qquicktextedit.cpp @@ -355,6 +355,19 @@ QString QQuickTextEdit::text() const \endqml */ +/*! + \qmlproperty bool QtQuick::TextEdit::font.kerning + \since 5.10 + + Enables or disables the kerning OpenType feature when shaping the text. This may improve performance + when creating or changing the text, at the expense of some cosmetic features. The default value + is true. + + \qml + Text { text: "OATS FLAVOUR WAY"; kerning: font.false } + \endqml +*/ + /*! \qmlproperty string QtQuick::TextEdit::text diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index a378359c95..d485083820 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -378,6 +378,19 @@ QString QQuickTextInputPrivate::realText() const TextInput { text: "Hello"; renderType: TextInput.NativeRendering; font.hintingPreference: Font.PreferVerticalHinting } \endqml */ + +/*! + \qmlproperty bool QtQuick::TextInput::font.kerning + \since 5.10 + + Enables or disables the kerning OpenType feature when shaping the text. This may improve performance + when creating or changing the text, at the expense of some cosmetic features. The default value + is true. + + \qml + Text { text: "OATS FLAVOUR WAY"; font.kerning: false } + \endqml +*/ QFont QQuickTextInput::font() const { Q_D(const QQuickTextInput); diff --git a/src/quick/util/qquickglobal.cpp b/src/quick/util/qquickglobal.cpp index 1d2f3de1df..6df23cdff5 100644 --- a/src/quick/util/qquickglobal.cpp +++ b/src/quick/util/qquickglobal.cpp @@ -302,6 +302,7 @@ public: QV4::ScopedValue vweight(scope, obj->get((s = v4->newString(QStringLiteral("weight"))))); QV4::ScopedValue vwspac(scope, obj->get((s = v4->newString(QStringLiteral("wordSpacing"))))); QV4::ScopedValue vhint(scope, obj->get((s = v4->newString(QStringLiteral("hintingPreference"))))); + QV4::ScopedValue vkerning(scope, obj->get((s = v4->newString(QStringLiteral("kerning"))))); // pull out the values, set ok to true if at least one valid field is given. if (vbold->isBoolean()) { @@ -356,6 +357,10 @@ public: retn.setHintingPreference(static_cast(vhint->integerValue())); if (ok) *ok = true; } + if (vkerning->isBoolean()) { + retn.setKerning(vkerning->booleanValue()); + if (ok) *ok = true; + } return retn; } diff --git a/src/quick/util/qquickvaluetypes.cpp b/src/quick/util/qquickvaluetypes.cpp index 4d34c6d661..bc4a72b6ea 100644 --- a/src/quick/util/qquickvaluetypes.cpp +++ b/src/quick/util/qquickvaluetypes.cpp @@ -757,6 +757,16 @@ void QQuickFontValueType::setHintingPreference(QQuickFontValueType::HintingPrefe v.setHintingPreference(QFont::HintingPreference(hintingPreference)); } +bool QQuickFontValueType::kerning() const +{ + return v.kerning(); +} + +void QQuickFontValueType::setKerning(bool b) +{ + v.setKerning(b); +} + QT_END_NAMESPACE #include "moc_qquickvaluetypes_p.cpp" diff --git a/src/quick/util/qquickvaluetypes_p.h b/src/quick/util/qquickvaluetypes_p.h index 4a1598ec5c..a3f35a84ec 100644 --- a/src/quick/util/qquickvaluetypes_p.h +++ b/src/quick/util/qquickvaluetypes_p.h @@ -323,6 +323,7 @@ class QQuickFontValueType Q_PROPERTY(qreal letterSpacing READ letterSpacing WRITE setLetterSpacing FINAL) Q_PROPERTY(qreal wordSpacing READ wordSpacing WRITE setWordSpacing FINAL) Q_PROPERTY(HintingPreference hintingPreference READ hintingPreference WRITE setHintingPreference FINAL) + Q_PROPERTY(bool kerning READ kerning WRITE setKerning FINAL) public: enum FontWeight { Thin = QFont::Thin, @@ -393,6 +394,9 @@ public: HintingPreference hintingPreference() const; void setHintingPreference(HintingPreference); + + bool kerning() const; + void setKerning(bool b); }; QT_END_NAMESPACE -- cgit v1.2.3