Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Implement basic font-feature-settings widget.
Wolthera van Hövell tot Westerflier80342dc4396a
diff --git a/libs/flake/text/KoFontGlyphModel.cpp b/libs/flake/text/KoFontGlyphModel.cppindex 2867d12c56..f57cfc6ace 100644--- a/libs/flake/text/KoFontGlyphModel.cpp+++ b/libs/flake/text/KoFontGlyphModel.cpp@@ -170,19 +170,24 @@ struct KoFontGlyphModel::Private {continue;}- hb_ot_name_id_t labelId;- hb_ot_name_id_t toolTipId;- hb_ot_name_id_t sampleId;+ hb_ot_name_id_t labelId = HB_OT_NAME_ID_INVALID;+ hb_ot_name_id_t toolTipId = HB_OT_NAME_ID_INVALID;+ hb_ot_name_id_t sampleId = HB_OT_NAME_ID_INVALID;uint namedParameters;- hb_ot_name_id_t firstParamId;+ hb_ot_name_id_t firstParamId = HB_OT_NAME_ID_INVALID;KoOpenTypeFeatureInfo info = factory.infoByTag(tagName);if (hb_ot_layout_feature_get_name_ids(hbFace.data(), table, featureIndex, &labelId, &toolTipId, &sampleId, &namedParameters, &firstParamId)) {QVector<hb_ot_name_id_t> nameIds = {labelId, toolTipId, sampleId};- for (uint i = 0; i < namedParameters; i++) {- nameIds += firstParamId + i;+ if (firstParamId != HB_OT_NAME_ID_INVALID) {+ for (uint i = 0; i < namedParameters; i++) {+ nameIds += firstParamId + i;+ }}for(auto nameId = nameIds.begin(); nameId != nameIds.end(); nameId++) {+ if (*nameId == HB_OT_NAME_ID_INVALID) {+ continue;+ }QVector<hb_language_t> testLang;uint length = 0;if (*nameId == sampleId) {@@ -221,6 +226,7 @@ struct KoFontGlyphModel::Private {continue;}+ QStringList samples;int lookupCount = hb_ot_layout_feature_get_lookups (hbFace.data(), table,featureIndex,0,@@ -262,6 +268,7 @@ struct KoFontGlyphModel::Private {for(auto it = charMap.begin(); it != charMap.end(); it++) {gci.ucs = it->ucs;hb_codepoint_t glyphIndex = it->glyphIndex;+ bool addSample = false;uint alt_count = hb_ot_layout_lookup_get_glyph_alternates (hbFace.data(),lookUpIndex, glyphIndex,@@ -274,12 +281,22 @@ struct KoFontGlyphModel::Private {gci.featureIndex = j;it->glyphs.append(gci);}+ info.maxValue = qMax(int(alt_count), info.maxValue);+ addSample = true;} else if (hb_set_has(glyphsInput.data(), glyphIndex)) {gci.featureIndex = 1;it->glyphs.append(gci);+ addSample = true;+ }+ if (samples.size() < 6 && addSample) {+ samples.append(QString::fromUcs4(&gci.ucs, 1));}}lookUpsProcessed.append(lookUpIndex);+ if (info.sample.isEmpty() && !samples.isEmpty()) {+ info.sample = samples.join(" ");+ }+ featureInfo.insert(tagName, info);}@@ -357,15 +374,14 @@ QVariant KoFontGlyphModel::data(const QModelIndex &index, int role) const}}} else if (role == OpenTypeFeatures) {- QStringList features;+ QVariantMap features;if (index.parent().isValid()) {Private::CodePointInfo codePoint = d->codePoints.value(index.parent().row());Private::GlyphInfo glyph = codePoint.glyphs.value(index.row());//qDebug () << index.parent().row() << index.row() << codePoint.utfString << codePoint.ucs;if (glyph.type == OpenType) {- features.append(QString("'%1' %2").arg(glyph.baseString).arg(glyph.featureIndex));+ features.insert(glyph.baseString, glyph.featureIndex);}-}return features;} else if (role == GlyphLabel) {@@ -509,3 +525,8 @@ QVector<KoUnicodeBlockData> KoFontGlyphModel::blocks() const{return d->blocks;}++QMap<QString, KoOpenTypeFeatureInfo> KoFontGlyphModel::featureInfo() const+{+ return d->featureData;+}diff --git a/libs/flake/text/KoFontGlyphModel.h b/libs/flake/text/KoFontGlyphModel.hindex 297aacf5cf..6ae5ce02d9 100644--- a/libs/flake/text/KoFontGlyphModel.h+++ b/libs/flake/text/KoFontGlyphModel.h@@ -12,6 +12,7 @@#include "data/KoUnicodeBlockData.h"#include "kritaflake_export.h"+class KoOpenTypeFeatureInfo;/*** @brief The KoFontGlyphModel class* Creates a tree model of all the glyphs in a given face.@@ -51,8 +52,18 @@ public:QHash<int, QByteArray> roleNames() const override;+ /**+ * @brief blocks+ * @return list of Unicode blocks available in the font.+ */QVector<KoUnicodeBlockData> blocks() const;+ /**+ * @brief featureInfo+ * @return list of OpenTypeFeatures available in the font.+ */+ QMap<QString, KoOpenTypeFeatureInfo> featureInfo() const;+private:struct Private;QScopedPointer<Private> d;diff --git a/libs/flake/text/KoOpenTypeFeatureInfoFactory.cpp b/libs/flake/text/KoOpenTypeFeatureInfoFactory.cppindex af9d6a05f6..aed6dc0fdf 100644--- a/libs/flake/text/KoOpenTypeFeatureInfoFactory.cpp+++ b/libs/flake/text/KoOpenTypeFeatureInfoFactory.cpp@@ -560,8 +560,13 @@ KoOpenTypeFeatureInfoFactory::~KoOpenTypeFeatureInfoFactory(){}-KoOpenTypeFeatureInfo KoOpenTypeFeatureInfoFactory::infoByTag(const QLatin1String &tag)+KoOpenTypeFeatureInfo KoOpenTypeFeatureInfoFactory::infoByTag(const QLatin1String &tag) const{KoOpenTypeFeatureInfo def(tag, QString(), QString(), {});return d->infoMap.value(tag, def);}++QList<QString> KoOpenTypeFeatureInfoFactory::tags() const+{+ return d->infoMap.keys();+}diff --git a/libs/flake/text/KoOpenTypeFeatureInfoFactory.h b/libs/flake/text/KoOpenTypeFeatureInfoFactory.hindex 8f2fe24ab5..4975713c34 100644--- a/libs/flake/text/KoOpenTypeFeatureInfoFactory.h+++ b/libs/flake/text/KoOpenTypeFeatureInfoFactory.h@@ -7,6 +7,7 @@#include <QStringList>#include <QVector>#include <QScopedPointer>+#include <kritaflake_export.h>/** KoOpenTypeFeatureInfo provides basic info about@@ -38,12 +39,14 @@ struct KoOpenTypeFeatureInfoconst QString &name,const QString &description,const QVector<OpenTypeTable> &tables,- const bool glyphPalette = false)+ const bool glyphPalette = false,+ const int maxValue = 1): tag(tag), name(name), description(description), tables(tables), glyphPalette(glyphPalette)+ , maxValue(maxValue){}@@ -58,8 +61,10 @@ struct KoOpenTypeFeatureInfoQStringList namedParameters;/// Named parameters. Only used by CVXX features and retrieved from the font.QVector<OpenTypeTable> tables; ///< Which table type(s) are recommended for this feature in the official registery.-+bool glyphPalette{false}; ///< Whether the feature should be visible in the glyph palette.++ int maxValue; ///< The maximum value possible, this is by default 1 (on), but for alternate substitution(gsub 3), it can have more inside the font.};@@ -69,13 +74,26 @@ struct KoOpenTypeFeatureInfo* This returns KoOpenTypeFeatureInfo's for the given tag.*/-class KoOpenTypeFeatureInfoFactory+class KRITAFLAKE_EXPORT KoOpenTypeFeatureInfoFactory{public:KoOpenTypeFeatureInfoFactory();~KoOpenTypeFeatureInfoFactory();- KoOpenTypeFeatureInfo infoByTag(const QLatin1String &tag);+ /**+ * @brief infoByTag+ * @param tag -- the opentype tag for a given feature.+ * Note that it is possible for Fonts to have custom features,+ * in this case a generic KoOpenTypeFeatureInfo will be returned.+ * @return KoOpenTypeFeatureInfo for a given tag.+ */+ KoOpenTypeFeatureInfo infoByTag(const QLatin1String &tag) const;++ /**+ * @brief tags+ * @return all the tags we have prepared KoOpenTypeFeatureInfo for.+ */+ QList<QString> tags() const;private:struct Private;diff --git a/libs/flake/text/KoSvgTextProperties.cpp b/libs/flake/text/KoSvgTextProperties.cppindex 5943e2a4fb..ac77773e32 100644--- a/libs/flake/text/KoSvgTextProperties.cpp+++ b/libs/flake/text/KoSvgTextProperties.cpp@@ -214,6 +214,15 @@ inline qreal roundToStraightAngle(qreal value)return normalizeAngle(int((value + M_PI_4) / M_PI_2) * M_PI_2);}+QPair<QString, QString> parseTag(QString taggedValue) {+ QPair<QString, QString> tag;+ tag.first = taggedValue.mid(1, 4);+ if (taggedValue.length() > 6) {+ tag.second = taggedValue.remove(0, 6).trimmed();+ }+ return tag;+}+QVariantMap parseVariantStringList(const QStringList features) {QVariantMap settings;for (int i = 0; i < features.size(); i++) {@@ -221,14 +230,40 @@ QVariantMap parseVariantStringList(const QStringList features) {if ((!feature.startsWith('\'') && !feature.startsWith('\"')) || feature.isEmpty()) {continue;}- QString tag = feature.mid(1, 4);- feature = feature.remove(0, 6).trimmed();+ QPair<QString, QString> tag = parseTag(feature);bool ok = false;- double featureVal = feature.toDouble(&ok);+ double featureVal = tag.second.toDouble(&ok);- if (ok && !tag.isEmpty()) {- settings.insert(tag, QVariant(featureVal));- tag = QString();+ if (ok && !tag.first.isEmpty()) {+ settings.insert(tag.first, QVariant(featureVal));+ }+ }+ return settings;+}++QVariantMap parseFeatureSettingsStringList(const QStringList features) {+ QVariantMap settings;+ for (int i = 0; i < features.size(); i++) {+ QString feature = features.at(i).trimmed();+ if ((!feature.startsWith('\'') && !feature.startsWith('\"')) || feature.isEmpty()) {+ continue;+ }+ QPair<QString, QString> tag = parseTag(feature);+ if (tag.second.isEmpty()) {+ settings.insert(tag.first, QVariant(1));+ } else {+ bool ok = false;+ int featureVal = tag.second.toInt(&ok);+ if (tag.second.toLower() == "on") {+ featureVal = 1;+ ok = true;+ } else if (tag.second.toLower() == "off") {+ featureVal = 0;+ ok = true;+ }+ if (ok && !tag.first.isEmpty()) {+ settings.insert(tag.first, QVariant(featureVal));+ }}}return settings;@@ -354,7 +389,7 @@ void KoSvgTextProperties::parseSvgTextAttribute(const SvgLoadingContext &context}} else if (command == "font-feature-settings") {- setProperty(FontFeatureSettingsId, value.split(","));+ setProperty(FontFeatureSettingsId, QVariant::fromValue(parseFeatureSettingsStringList(value.split(","))));} else if (command == "font-stretch") {int newStretch = 100;@@ -675,7 +710,12 @@ QMap<QString, QString> KoSvgTextProperties::convertToSvgTextAttributes() constresult.insert("font-variant-east-asian", writeFontFeatureEastAsian(feat));}if (hasProperty(FontFeatureSettingsId)) {- result.insert("font-feature-settings", property(FontFeatureSettingsId).toStringList().join(", "));+ QStringList settings;+ QVariantMap vals = property(FontFeatureSettingsId).toMap();+ for(auto it = vals.begin(); it != vals.end(); it++) {+ settings.append(QString("'%1' %2").arg(it.key()).arg(it.value().toDouble()));+ }+ result.insert("font-feature-settings", settings.join(", "));}if (hasProperty(FontOpticalSizingId)) {@@ -1028,29 +1068,10 @@ QStringList KoSvgTextProperties::fontFeaturesForText(int start, int length) cons}if (hasProperty(FontFeatureSettingsId)) {- QStringList features = property(FontFeatureSettingsId).toStringList();- for (int i = 0; i < features.size(); i++) {- QString feature = features.at(i).trimmed();- if ((!feature.startsWith('\'') && !feature.startsWith('\"')) || feature.isEmpty()) {- continue;- }- QString openTypeTag = feature.mid(1, 4);- if (feature.size() == 6) {- openTypeTag += QString("[%1:%2]=1").arg(start).arg(start + length);- } else {- feature = feature.remove(0, 6).trimmed();- bool ok = false;- int featureVal = feature.toInt(&ok);- if (feature == "on") {- openTypeTag += QString("[%1:%2]=1").arg(start).arg(start + length);- } else if (feature == "off") {- openTypeTag += QString("[%1:%2]=0").arg(start).arg(start + length);- } else if (ok) {- openTypeTag += QString("[%1:%2]=%3").arg(start).arg(start + length).arg(featureVal);- } else {- continue;- }- }+ QVariantMap features = property(FontFeatureSettingsId).toMap();+ for (int i = 0; i < features.keys().size(); i++) {+ const QString key = features.keys().at(i);+ QString openTypeTag = QString("%1[%2:%3]=%4").arg(key).arg(start).arg(start + length).arg(features.value(key).toInt());fontFeatures.append(openTypeTag);}}diff --git a/libs/flake/text/lager/KoSvgTextPropertiesModel.cpp b/libs/flake/text/lager/KoSvgTextPropertiesModel.cppindex 457c4a3526..b5740ab0fb 100644--- a/libs/flake/text/lager/KoSvgTextPropertiesModel.cpp+++ b/libs/flake/text/lager/KoSvgTextPropertiesModel.cpp@@ -228,6 +228,8 @@ KoSvgTextPropertiesModel::KoSvgTextPropertiesModel(lager::cursor<KoSvgTextProper, LAGER_QT(fontVariantLigaturesState) {textData.zoom(propertyModifyState(KoSvgTextProperties::FontVariantLigatureId))}, LAGER_QT(fontVariantNumericState) {textData.zoom(propertyModifyState(KoSvgTextProperties::FontVariantNumericId))}, LAGER_QT(fontVariantEastAsianState) {textData.zoom(propertyModifyState(KoSvgTextProperties::FontVariantEastAsianId))}+ , LAGER_QT(fontFeatureSettings) {textData.zoom(createTextProperty(KoSvgTextProperties::FontFeatureSettingsId)).zoom(variant_to<QVariantMap>)}+ , LAGER_QT(fontFeatureSettingsState) {textData.zoom(propertyModifyState(KoSvgTextProperties::FontFeatureSettingsId))}, LAGER_QT(spanSelection) {textData[&KoSvgTextPropertyData::spanSelection]}{lager::watch(textData, std::bind(&KoSvgTextPropertiesModel::textPropertyChanged, this));diff --git a/libs/flake/text/lager/KoSvgTextPropertiesModel.h b/libs/flake/text/lager/KoSvgTextPropertiesModel.hindex 989335e2b6..9fa652e995 100644--- a/libs/flake/text/lager/KoSvgTextPropertiesModel.h+++ b/libs/flake/text/lager/KoSvgTextPropertiesModel.h@@ -178,8 +178,6 @@ public:LAGER_QT_CURSOR(bool, fontSynthesisStyle);LAGER_QT_CURSOR(PropertyState, fontSynthesisStyleState);- /// We're selecting a span of text instead of the whole paragraph.- LAGER_QT_CURSOR(bool, spanSelection);LAGER_QT_CURSOR(int, fontVariantPosition);LAGER_QT_CURSOR(PropertyState, fontVariantPositionState);@@ -193,6 +191,12 @@ public:FontVariantEastAsianModel *fontVariantEastAsian();LAGER_QT_CURSOR(PropertyState, fontVariantEastAsianState);+ LAGER_QT_CURSOR(QVariantMap, fontFeatureSettings);+ LAGER_QT_CURSOR(PropertyState, fontFeatureSettingsState);++ /// We're selecting a span of text instead of the whole paragraph.+ LAGER_QT_CURSOR(bool, spanSelection);+/*** @brief resolvedFontSize* this returns the resolved font (em) size, needed for unit conversion for em.diff --git a/plugins/dockers/textproperties/CMakeLists.txt b/plugins/dockers/textproperties/CMakeLists.txtindex 83db9d5096..d2e389967b 100644--- a/plugins/dockers/textproperties/CMakeLists.txt+++ b/plugins/dockers/textproperties/CMakeLists.txt@@ -5,6 +5,7 @@ set(KRITA_TEXTPROPERTIES_SOURCESFontAxesModel.cppKoShapeQtQuickLabel.cppTagFilterProxyModelQmlWrapper.cpp+ OpenTypeFeatureModel.cpp)qt_add_resources(KRITA_TEXTPROPERTIES_SOURCES textproperties.qrc)diff --git a/plugins/dockers/textproperties/OpenTypeFeatureModel.cpp b/plugins/dockers/textproperties/OpenTypeFeatureModel.cppnew file mode 100644index 0000000000..6f9785488f--- /dev/null+++ b/plugins/dockers/textproperties/OpenTypeFeatureModel.cpp@@ -0,0 +1,242 @@+/*+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#include "OpenTypeFeatureModel.h"+#include <KoFontGlyphModel.h>+#include <KoCSSFontInfo.h>+#include <KoOpenTypeFeatureInfoFactory.h>+#include <KoFontLibraryResourceUtils.h>+#include <KoSvgTextProperties.h>+#include <KoFontRegistry.h>++struct OpenTypeFeatureModel::Private {+ Private(QObject *parent)+ : glyphModel(new KoFontGlyphModel(parent)) {+ }++ QList<KoOpenTypeFeatureInfo> availableFeatures() const {+ if (glyphModel) {+ return glyphModel->featureInfo().values();+ }+ return QList<KoOpenTypeFeatureInfo>();+ }++ KoOpenTypeFeatureInfo featureByTag(QLatin1String tag) const {+ KoOpenTypeFeatureInfo info = factory.infoByTag(tag);+ if (glyphModel) {+ info = glyphModel->featureInfo().value(tag, info);+ }+ return info;+ }++ KoFontGlyphModel *glyphModel {nullptr};+ KoOpenTypeFeatureInfoFactory factory;+ KoCSSFontInfo fontInfo;+ QVariantMap currentFeatures;+};++OpenTypeFeatureModel::OpenTypeFeatureModel(QObject *parent)+ : QAbstractItemModel(parent)+ , d(new Private(this))+{+}++OpenTypeFeatureModel::~OpenTypeFeatureModel()+{+}++QModelIndex OpenTypeFeatureModel::index(int row, int column, const QModelIndex &parent) const+{+ Q_UNUSED(parent)+ if (column != 0) return QModelIndex();+ if (row >= 0 && row < d->currentFeatures.size()) return createIndex(row, column, &row);+ return QModelIndex();+}++QModelIndex OpenTypeFeatureModel::parent(const QModelIndex &index) const+{+ Q_UNUSED(index)+ return QModelIndex();+}++int OpenTypeFeatureModel::rowCount(const QModelIndex &parent) const+{+ Q_UNUSED(parent)+ return d->currentFeatures.size();+}++int OpenTypeFeatureModel::columnCount(const QModelIndex &parent) const+{+ Q_UNUSED(parent)+ return 1;+}++QVariant OpenTypeFeatureModel::data(const QModelIndex &index, int role) const+{+ if (!index.isValid())+ return QVariant();++ const QString feature = d->currentFeatures.keys().at(index.row());+ KoOpenTypeFeatureInfo info = d->featureByTag(QLatin1String(feature.toLatin1()));+ if (role == Qt::DisplayRole) {+ return info.name;+ } else if (role == Qt::ToolTipRole) {+ return info.description;+ } else if (role == Qt::EditRole) {+ return d->currentFeatures.value(feature, QVariant(0)).toInt();+ } else if (role == Tag) {+ return feature;+ } else if (role == Sample) {+ return info.sample;+ } else if (role == Parameters) {+ QVariantList features;+ for (int i = 0; i <= info.maxValue; i++) {+ QVariantMap map;+ map.insert("value", QVariant(i));+ QString entry = i > 0? info.namedParameters.value(i-1): QString();+ if (entry.isEmpty()) {+ if (i == 1 && info.maxValue == 1) {+ entry = info.name + ": " + i18nc("Feature value toggle", "On");+ } else if (i == 0) {+ entry = info.name + ": " + i18nc("Feature value toggle", "Off");+ } else {+ entry = info.name + ": " + QString::number(i);+ }+ }+ map.insert("display", entry);+ features.append(map);+ }+ return features;+ } else if (role == Max) {+ return info.maxValue;+ }+ return QVariant();+}++bool OpenTypeFeatureModel::setData(const QModelIndex &index, const QVariant &value, int role)+{+ if (data(index, role) != value) {+ // FIXME: Implement me!++ if (index.isValid() && role == Qt::EditRole) {+ const QString feature = d->currentFeatures.keys().at(index.row());+ d->currentFeatures.insert(feature, value.toInt());+ emit openTypeFeaturesChanged();+ emit dataChanged(index, index, {role});+ return true;+ }+ return false;+ }++ return false;+}++Qt::ItemFlags OpenTypeFeatureModel::flags(const QModelIndex &index) const+{+ Qt::ItemFlags flags = QAbstractItemModel::flags(index) | Qt::ItemNeverHasChildren | Qt::ItemIsEditable;++ return flags;+}++QHash<int, QByteArray> OpenTypeFeatureModel::roleNames() const+{+ QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();+ roles[Tag] = "tag";+ roles[Sample] = "sample";+ roles[Parameters] = "parameters";+ roles[Max] = "max";+ return roles;+}++void OpenTypeFeatureModel::setFromTextProperties(const KoSvgTextProperties &props)+{+ const bool changeFont = props.cssFontInfo() != d->fontInfo;+ const QVariantMap newFeatures = props.propertyOrDefault(KoSvgTextProperties::FontFeatureSettingsId).toMap();+ const bool changeFeatures = d->currentFeatures != newFeatures;++ if (!changeFont && !changeFeatures) return;++ beginResetModel();+ if (changeFont) {+ const qreal res = 72.0;+ QVector<int> lengths;+ const KoCSSFontInfo info = props.cssFontInfo();+ const std::vector<FT_FaceSP> faces = KoFontRegistry::instance()->facesForCSSValues(+ lengths,+ info,+ QString(),+ static_cast<quint32>(res),+ static_cast<quint32>(res));++ if (!faces.empty()) {+ QString language = props.propertyOrDefault(KoSvgTextProperties::TextLanguage).toString();+ d->glyphModel->setFace(faces.front(), QLatin1String(language.toLatin1()));+ emit availableFeaturesChanged();+ }+ }++ if (changeFeatures) {+ d->currentFeatures = newFeatures;+ emit openTypeFeaturesChanged();+ }+ endResetModel();+}++QVariantMap OpenTypeFeatureModel::openTypeFeatures() const+{+ return d->currentFeatures;+}++void OpenTypeFeatureModel::setOpenTypeFeatures(const QVariantMap &newOpenTypeFeatures)+{+ if (d->currentFeatures == newOpenTypeFeatures)+ return;+ beginResetModel();+ d->currentFeatures = newOpenTypeFeatures;+ endResetModel();+ emit openTypeFeaturesChanged();+}++QVariantList OpenTypeFeatureModel::availableFeatures() const+{+ QVariantList features;+ Q_FOREACH(const KoOpenTypeFeatureInfo info, d->availableFeatures()) {+ QVariantMap feat;++ feat.insert("tag", info.tag);+ feat.insert("display", info.name);+ feat.insert("toolTip", info.description);+ feat.insert("sample", info.sample);+ features.append(feat);+ }+ return features;+}++void OpenTypeFeatureModel::addFeature(const QString &tag)+{+ if (tag.isEmpty()) return;+ if (d->currentFeatures.keys().contains(tag)) return;++ QVariantMap dummy = d->currentFeatures;+ dummy.insert(tag, QVariant(1));+ const int index = dummy.keys().indexOf(tag);++ beginInsertRows(QModelIndex(), index, index);+ d->currentFeatures.insert(tag, QVariant(1));+ endInsertRows();+ emit openTypeFeaturesChanged();+}++void OpenTypeFeatureModel::removeFeature(const QString &tag)+{+ if (tag.isEmpty()) return;+ const int index = d->currentFeatures.keys().indexOf(tag);+ if (index < 0) return;++ beginRemoveRows(QModelIndex(), index, index);+ d->currentFeatures.remove(tag);+ endRemoveRows();+ emit openTypeFeaturesChanged();+}diff --git a/plugins/dockers/textproperties/OpenTypeFeatureModel.h b/plugins/dockers/textproperties/OpenTypeFeatureModel.hnew file mode 100644index 0000000000..97b5d6e7f2--- /dev/null+++ b/plugins/dockers/textproperties/OpenTypeFeatureModel.h@@ -0,0 +1,69 @@+/*+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#ifndef OPENTYPEFEATUREMODEL_H+#define OPENTYPEFEATUREMODEL_H++#include <QAbstractItemModel>++class KoSvgTextProperties;++class OpenTypeFeatureModel : public QAbstractItemModel+{+ Q_OBJECT++ Q_PROPERTY(QVariantMap openTypeFeatures READ openTypeFeatures WRITE setOpenTypeFeatures NOTIFY openTypeFeaturesChanged)+ Q_PROPERTY(QVariantList availableFeatures READ availableFeatures NOTIFY availableFeaturesChanged)++public:+ OpenTypeFeatureModel(QObject *parent = nullptr);++ ~OpenTypeFeatureModel();++ enum Roles {+ Tag = Qt::UserRole + 1, ///< QString, opentype tag.+ Sample, ///< QString, the sample for this feature, may be empty.+ Parameters, ///< QVariantList, indices with names of the feature count.+ Max ///< int, max count, default is 1, but can be larger depending on the font.+ };+ // Basic functionality:+ QModelIndex index(int row, int column,+ const QModelIndex &parent = QModelIndex()) const override;+ QModelIndex parent(const QModelIndex &index) const override;++ int rowCount(const QModelIndex &parent = QModelIndex()) const override;+ int columnCount(const QModelIndex &parent = QModelIndex()) const override;++ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;++ // Editable:+ bool setData(const QModelIndex &index, const QVariant &value,+ int role = Qt::EditRole) override;++ Qt::ItemFlags flags(const QModelIndex& index) const override;++ QHash<int, QByteArray> roleNames() const override;++ void setFromTextProperties(const KoSvgTextProperties &props);++ QVariantMap openTypeFeatures() const;+ void setOpenTypeFeatures(const QVariantMap &newOpenTypeFeatures);++ QVariantList availableFeatures() const;++ Q_INVOKABLE void addFeature(const QString &tag);+ Q_INVOKABLE void removeFeature(const QString &tag);++Q_SIGNALS:+ void openTypeFeaturesChanged();+ void availableFeaturesChanged();++private:++ struct Private;+ const QScopedPointer<Private> d;+};++#endif // OPENTYPEFEATUREMODEL_Hdiff --git a/plugins/dockers/textproperties/TextPropertiesDock.cpp b/plugins/dockers/textproperties/TextPropertiesDock.cppindex 1145a4653a..06ee90468c 100644--- a/plugins/dockers/textproperties/TextPropertiesDock.cpp+++ b/plugins/dockers/textproperties/TextPropertiesDock.cpp@@ -45,6 +45,7 @@#include "FontStyleModel.h"#include "FontAxesModel.h"#include "KoShapeQtQuickLabel.h"+#include "OpenTypeFeatureModel.h"#include "TagFilterProxyModelQmlWrapper.h"/// Strange place to put this, do we have a better spot?@@ -63,6 +64,7 @@ KIS_DECLARE_STATIC_INITIALIZER {qmlRegisterType<FontStyleModel>("org.krita.flake.text", 1, 0, "FontStyleModel");qmlRegisterType<FontAxesModel>("org.krita.flake.text", 1, 0, "FontAxesModel");+ qmlRegisterType<OpenTypeFeatureModel>("org.krita.flake.text", 1, 0, "OpenTypeFeatureModel");qmlRegisterType<KoShapeQtQuickLabel>("org.krita.flake.text", 1, 0, "KoShapeQtQuickLabel");qmlRegisterType<TagFilterProxyModelQmlWrapper>("org.krita.flake.text", 1, 0, "TagFilterProxyModelQmlWrapper");}@@ -103,6 +105,7 @@ struct TextPropertiesDock::PrivateFontAxesModel axesModel;KisResourceModel *fontModel{nullptr};KisCanvasResourceProvider *provider{nullptr};+ OpenTypeFeatureModel featureModel;};TextPropertiesDock::TextPropertiesDock()@@ -141,11 +144,12 @@ TextPropertiesDock::TextPropertiesDock()d->stylesModel.setLocales(locales);connect(&d->axesModel, SIGNAL(axisValuesChanged()), this, SLOT(slotUpdateAxesValues()));-+ connect(&d->featureModel, SIGNAL(openTypeFeaturesChanged()), this, SLOT(slotUpdateFeatureSettings()));m_quickWidget->rootContext()->setContextProperty("textPropertiesModel", d->textModel);m_quickWidget->rootContext()->setContextProperty("fontStylesModel", QVariant::fromValue(&d->stylesModel));m_quickWidget->rootContext()->setContextProperty("fontAxesModel", QVariant::fromValue(&d->axesModel));+ m_quickWidget->rootContext()->setContextProperty("fontFeatureModel", QVariant::fromValue(&d->featureModel));m_quickWidget->rootContext()->setContextProperty("locales", QVariant::fromValue(wellFormedBCPNames));connect(d->textModel, SIGNAL(textPropertyChanged()),this, SLOT(slotTextPropertiesChanged()));@@ -210,6 +214,11 @@ void TextPropertiesDock::slotCanvasTextPropertiesChanged()KoSvgTextPropertyData data = d->provider->textPropertyData();if (d->textModel->textData.get() != data) {d->textModel->textData.set(data);++ KoSvgTextProperties main = data.commonProperties;+ main.inheritFrom(data.inheritedProperties);+ d->featureModel.setFromTextProperties(main);+QMetaObject::invokeMethod(m_quickWidget->rootObject(), "setProperties");}}@@ -258,6 +267,13 @@ void TextPropertiesDock::slotUpdateAxesValues()d->textModel->setaxisValues(d->axesModel.axisValues());}+void TextPropertiesDock::slotUpdateFeatureSettings()+{+ if (d->featureModel.openTypeFeatures() == d->textModel->fontFeatureSettings())+ return;+ d->textModel->setfontFeatureSettings(d->featureModel.openTypeFeatures());+}+#include <KoFontRegistry.h>QString TextPropertiesDock::wwsFontFamilyName(QString familyName){diff --git a/plugins/dockers/textproperties/TextPropertiesDock.h b/plugins/dockers/textproperties/TextPropertiesDock.hindex d757d3c567..112dca3102 100644--- a/plugins/dockers/textproperties/TextPropertiesDock.h+++ b/plugins/dockers/textproperties/TextPropertiesDock.h@@ -16,6 +16,7 @@class KoDialog;class QQuickWidget;+class KoSvgTextProperties;class TextPropertiesDock : public QDockWidget, public KisMainwindowObserver {Q_OBJECT@@ -27,13 +28,12 @@ public:void setCanvas(KoCanvasBase *canvas) override;void unsetCanvas() override;--public Q_SLOTS:void slotCanvasTextPropertiesChanged();void slotTextPropertiesChanged();void slotUpdateStylesModel();void slotUpdateAxesValues();+ void slotUpdateFeatureSettings();QString wwsFontFamilyName(QString familyName);void connectAutoEnabler(QObject *watched);diff --git a/plugins/dockers/textproperties/qml/OpenTypeFeatureDelegate.qml b/plugins/dockers/textproperties/qml/OpenTypeFeatureDelegate.qmlnew file mode 100644index 0000000000..52834f58c8--- /dev/null+++ b/plugins/dockers/textproperties/qml/OpenTypeFeatureDelegate.qml@@ -0,0 +1,74 @@+/*+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+import QtQuick 2.15+import QtQuick.Controls 2.15+import QtQuick.Layouts 1.15+import org.krita.flake.text 1.0++Control {+ id: root;++ height: childrenRect.height;+ property string display;+ property string tag;+ property string sample;+ property string toolTip;++ property alias containsMouse: mouseArea.containsMouse;++ background: Rectangle {+ color: containsMouse? sysPalette.highlight: "transparent";+ }++ signal featureClicked (QtObject mouse);++ RowLayout {+ height: childrenRect.height;+ width: parent.width;++ Label {+ Layout.alignment: Qt.AlignCenter | Qt.AlignVCenter+ textFormat: Text.MarkdownText;+ // This is somehow the easiest way I've found it to require monospace...+ text: "`"+root.tag+"`";+ Layout.fillHeight: true;+ Layout.maximumWidth: contentWidth;+ }+ ToolSeparator {+ Layout.fillHeight: true;+ }++ ColumnLayout {+ Layout.fillWidth: true;+ Layout.fillHeight: true;+ Label {+ text: root.display;+ Layout.alignment: Qt.AlignRight | Qt.AlignVCenter+ elide: Text.ElideRight;+ Layout.fillWidth: true;+ }++ Label {+ text: root.sample;+ Layout.alignment: Qt.AlignRight | Qt.AlignVCenter+ elide: Text.ElideRight;+ Layout.fillWidth: true;+ }+ }+ }+ MouseArea {+ id: mouseArea;+ anchors.fill: parent;+ hoverEnabled: true;+ onClicked: (mouse)=>{+ featureClicked(mouse);+ }++ ToolTip.text: root.toolTip;+ ToolTip.visible: containsMouse;+ ToolTip.delay: 1000;+ }+}diff --git a/plugins/dockers/textproperties/qml/OpenTypeFeatureSettings.qml b/plugins/dockers/textproperties/qml/OpenTypeFeatureSettings.qmlnew file mode 100644index 0000000000..7df013e1e8--- /dev/null+++ b/plugins/dockers/textproperties/qml/OpenTypeFeatureSettings.qml@@ -0,0 +1,143 @@+/*+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+import QtQuick 2.15+import QtQuick.Controls 2.15+import QtQuick.Layouts 1.12+import org.krita.flake.text 1.0++TextPropertyBase {+ id: root;+ propertyName: i18nc("@label", "OpenType features");+ propertyType: TextPropertyBase.Character;+ toolTip: i18nc("@info:tooltip",+ "Configure Open Type features.");+ searchTerms: i18nc("comma separated search terms for the font-feature-settings property, matching is case-insensitive",+ "font-feature-settings, OpenType");++ onPropertiesUpdated: {+ blockSignals = true;+ visible = properties.fontFeatureSettingsState !== KoSvgTextPropertiesModel.PropertyUnset;+ blockSignals = false;+ }++ onEnableProperty: properties.fontFeatureSettingsState = KoSvgTextPropertiesModel.PropertySet;+ GridLayout {+ columns: 2;+ columnSpacing: columnSpacing;+ rowSpacing: columnSpacing;+ width: parent.width;++ RevertPropertyButton {+ revertState: properties.fontFeatureSettingsState;+ onClicked: properties.fontFeatureSettingsState = KoSvgTextPropertiesModel.PropertyUnset;+ }++ Label {+ text: propertyName;+ Layout.fillWidth: true;+ }++ Item {+ width: firstColumnWidth;+ height: 1;+ }++ ListView {+ id: featureView;+ Layout.fillWidth: true;+ Layout.preferredHeight: contentHeight;+ Layout.minimumHeight: noContentLabel.contentHeight;+ spacing: columnSpacing;++ Label {+ id: noContentLabel;+ text: i18n("No OpenType features are currently set.");+ wrapMode: Text.WordWrap;+ anchors.fill: parent;+ anchors.horizontalCenter: parent.horizontalCenter;+ visible: parent.count === 0;+ padding: columnSpacing+ }++ model: fontFeatureModel;+ delegate: RowLayout {+ id: activeFeatureDelegate;+ required property var model;+ required property int index;+ property string display: model.display;+ property string toolTip: model.toolTip;+ property string sample: model.sample;+ property string tag: model.tag;+ property var parameters: model.parameters;+ width: featureView.width;++ ComboBox {+ id: activeFeatureControl;+ Layout.fillWidth: true;+ model: activeFeatureDelegate.parameters;+ valueRole: "value";+ textRole: "display";++ currentIndex: activeFeatureDelegate.model.edit;++ delegate: OpenTypeFeatureDelegate {+ display: modelData.display;+ width: activeFeatureControl.width;+ toolTip: activeFeatureDelegate.display;+ sample: activeFeatureDelegate.sample;+ tag: activeFeatureDelegate.tag;+ onFeatureClicked: {+ activeFeatureControl.currentIndex = index;+ activeFeatureControl.popup.close();+ }+ }++ onCurrentValueChanged: {+ activeFeatureDelegate.model.edit = currentValue;+ }+ }+++ ToolButton {+ id: removeFeature;+ icon.width: 22;+ icon.height: 22;+ icon.source: "qrc:///22_light_list-remove.svg"+ onClicked: fontFeatureModel.removeFeature(parent.tag);+ ToolTip.text: i18n("Remove feature");+ ToolTip.delay: Qt.styleHints.mousePressAndHoldInterval;+ ToolTip.visible: hovered;+ }+ }+ }++ Item {+ width: firstColumnWidth;+ height: 1;+ }+ ComboBox {+ id: cmbAvailableFeatures;+ model: fontFeatureModel.availableFeatures;+ textRole: "display";+ valueRole: "tag";+ Layout.fillWidth: true;++ delegate: OpenTypeFeatureDelegate {+ display: modelData.display;+ toolTip: modelData.toolTip;+ sample: modelData.sample;+ tag: modelData.tag;+ width: cmbAvailableFeatures.width;+ onFeatureClicked: (mouse) => {+ cmbAvailableFeatures.currentIndex = index;+ fontFeatureModel.addFeature(tag);+ cmbAvailableFeatures.popup.close();+ }+ }+ }+ }+}+diff --git a/plugins/dockers/textproperties/qml/TextPropertyBaseList.qml b/plugins/dockers/textproperties/qml/TextPropertyBaseList.qmlindex 0109e2f045..7e0c99441f 100644--- a/plugins/dockers/textproperties/qml/TextPropertyBaseList.qml+++ b/plugins/dockers/textproperties/qml/TextPropertyBaseList.qml@@ -140,6 +140,8 @@ ColumnLayout {}OTEastAsian {}+ OpenTypeFeatureSettings {+ }BaselineShift {}AlignmentBaseline {diff --git a/plugins/dockers/textproperties/textproperties.qrc b/plugins/dockers/textproperties/textproperties.qrcindex e37c3e84e2..f553d1a0d0 100644--- a/plugins/dockers/textproperties/textproperties.qrc+++ b/plugins/dockers/textproperties/textproperties.qrc@@ -45,5 +45,7 @@<file alias="font-type-opentype-variable.svg">icons/font-type-opentype-variable.svg</file><file alias="PaletteControl.qml">qml/PaletteControl.qml</file><file alias="SqueezedComboBox.qml">qml/SqueezedComboBox.qml</file>+ <file alias="OpenTypeFeatureSettings.qml">qml/OpenTypeFeatureSettings.qml</file>+ <file alias="OpenTypeFeatureDelegate.qml">qml/OpenTypeFeatureDelegate.qml</file></qresource></RCC>diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cppindex 25728cf61b..388857fbeb 100644--- a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp@@ -127,18 +127,19 @@ void GlyphPaletteDialog::slotInsertRichText(const int charRow, const int glyphRoQModelIndex idx = model->index(charRow, 0);QString text = idx.isValid()? model->data(idx, Qt::DisplayRole).toString(): QString();KoSvgTextProperties props = m_lastUsedProperties.first;- QStringList otf;+ QVariantMap otf;if (glyphRow > -1) {idx = model->index(glyphRow, 0, idx);text = model->data(idx, Qt::DisplayRole).toString();- otf.append(model->data(idx, KoFontGlyphModel::OpenTypeFeatures).value<QStringList>());+ otf = model->data(idx, KoFontGlyphModel::OpenTypeFeatures).toMap();}if (!text.isEmpty()) {KoSvgTextShape *richText = new KoSvgTextShape();+if (!otf.isEmpty()) {- props.setProperty(KoSvgTextProperties::FontFeatureSettingsId, otf);+ props.setProperty(KoSvgTextProperties::FontFeatureSettingsId, QVariant::fromValue(otf));}richText->setPropertiesAtPos(-1, props);diff --git a/plugins/tools/svgtexttool/glyphpalette/SvgTextLabel.cpp b/plugins/tools/svgtexttool/glyphpalette/SvgTextLabel.cppindex 573e00e295..556f49e7f1 100644--- a/plugins/tools/svgtexttool/glyphpalette/SvgTextLabel.cpp+++ b/plugins/tools/svgtexttool/glyphpalette/SvgTextLabel.cpp@@ -120,9 +120,9 @@ QColor SvgTextLabel::textColor() constreturn Qt::black;}-QStringList SvgTextLabel::openTypeFeatures() const+QVariantMap SvgTextLabel::openTypeFeatures() const{- return d->shape->textProperties().property(KoSvgTextProperties::FontFeatureSettingsId).value<QStringList>();+ return d->shape->textProperties().property(KoSvgTextProperties::FontFeatureSettingsId).toMap();}QString SvgTextLabel::text() const@@ -235,13 +235,13 @@ void SvgTextLabel::setTextColor(QColor textColor)emit textColorChanged(textColor);}-void SvgTextLabel::setOpenTypeFeatures(QStringList openTypeFeatures)+void SvgTextLabel::setOpenTypeFeatures(QVariantMap openTypeFeatures){- QStringList otf = d->props.property(KoSvgTextProperties::FontFeatureSettingsId).value<QStringList>();+ QVariantMap otf = d->props.property(KoSvgTextProperties::FontFeatureSettingsId).toMap();if (otf == openTypeFeatures)return;- d->props.setProperty(KoSvgTextProperties::FontFeatureSettingsId, openTypeFeatures);+ d->props.setProperty(KoSvgTextProperties::FontFeatureSettingsId, QVariant::fromValue(openTypeFeatures));emit openTypeFeaturesChanged(openTypeFeatures);}diff --git a/plugins/tools/svgtexttool/glyphpalette/SvgTextLabel.h b/plugins/tools/svgtexttool/glyphpalette/SvgTextLabel.hindex 8a8a045dae..526a27e4b5 100644--- a/plugins/tools/svgtexttool/glyphpalette/SvgTextLabel.h+++ b/plugins/tools/svgtexttool/glyphpalette/SvgTextLabel.h@@ -29,7 +29,7 @@ class SvgTextLabel : public QQuickPaintedItemQ_PROPERTY(QVariantMap fontAxesValues READ fontAxesValues WRITE setFontAxesValues NOTIFY fontAxesValuesChanged)Q_PROPERTY(qreal fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor NOTIFY textColorChanged)- Q_PROPERTY(QStringList openTypeFeatures READ openTypeFeatures WRITE setOpenTypeFeatures NOTIFY openTypeFeaturesChanged)+ Q_PROPERTY(QVariantMap openTypeFeatures READ openTypeFeatures WRITE setOpenTypeFeatures NOTIFY openTypeFeaturesChanged)Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)Q_PROPERTY(int padding READ padding WRITE setPadding NOTIFY paddingChanged)Q_PROPERTY(QString language READ language WRITE setLanguage NOTIFY languageChanged)@@ -56,7 +56,7 @@ public:QColor textColor() const;- QStringList openTypeFeatures() const;+ QVariantMap openTypeFeatures() const;QString text() const;@@ -81,7 +81,7 @@ public Q_SLOTS:void setTextColor(QColor textColor);- void setOpenTypeFeatures(QStringList openTypeFeatures);+ void setOpenTypeFeatures(QVariantMap openTypeFeatures);void setText(QString text);@@ -106,7 +106,7 @@ Q_SIGNALS:void textColorChanged(QColor textColor);- void openTypeFeaturesChanged(QStringList openTypeFeatures);+ void openTypeFeaturesChanged(QVariantMap openTypeFeatures);void textChanged(QString text);