Skip to content

armgit / krita

Public Imported from GitHub
0

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++

Add font-kerning to text property docker.

Wolthera van Hövell tot Westerflierea849b8bc56c
diff --git a/libs/flake/svg/SvgStyleParser.cpp b/libs/flake/svg/SvgStyleParser.cpp
index 5fb8823ce1..6225334015 100644
--- a/libs/flake/svg/SvgStyleParser.cpp
+++ b/libs/flake/svg/SvgStyleParser.cpp
@@ -62,6 +62,7 @@ public:
<< "text-decoration-style"
<< "text-decoration-color"
<< "text-decoration-position"
+ << "font-kerning"
<< "letter-spacing"
<< "word-spacing"
<< "baseline-shift"
@@ -336,7 +337,7 @@ void SvgStyleParser::parsePA(SvgGraphicsContext *gc, const QString &command, con
gc->markerMidId = gc->markerStartId;
gc->markerEndId = gc->markerStartId;
}
- } else if (command == "line-height" || command == "white-space" || command == "xml:space" || command == "text-transform" || command == "text-indent"
+ } else if (command == "font-kerning" || command == "line-height" || command == "white-space" || command == "xml:space" || command == "text-transform" || command == "text-indent"
|| command == "word-break" || command == "line-break" || command == "hanging-punctuation" || command == "text-align"
|| command == "text-align-all" || command == "text-align-last" || command == "inline-size" || command == "overflow" || command == "text-overflow"
|| command == "tab-size" || command == "overflow-wrap" || command == "word-wrap" || command == "vertical-align"
diff --git a/libs/flake/text/KoSvgTextProperties.cpp b/libs/flake/text/KoSvgTextProperties.cpp
index ac77773e32..c7c60d06b7 100644
--- a/libs/flake/text/KoSvgTextProperties.cpp
+++ b/libs/flake/text/KoSvgTextProperties.cpp
@@ -325,7 +325,7 @@ void KoSvgTextProperties::parseSvgTextAttribute(const SvgLoadingContext &context
parseSvgTextAttribute(context, "alignment-baseline", param);
}
}
- } else if (command == "kerning") {
+ } else if (command == "kerning" || command == "font-kerning") {
KoSvgText::AutoValue kerning;
if (value == "none") {
kerning.isAuto = false;
@@ -662,11 +662,11 @@ QMap<QString, QString> KoSvgTextProperties::convertToSvgTextAttributes() const
} else {
AutoValue kerning = property(KerningId).value<AutoValue>();
if (kerning.isAuto) {
- result.insert("kerning", "auto");
+ result.insert("font-kerning", "auto");
} else if (kerning.customValue == 0) {
- result.insert("kerning", "none");
+ result.insert("font-kerning", "none");
} else {
- result.insert("kerning", "normal");
+ result.insert("font-kerning", "normal");
}
}
}
diff --git a/libs/flake/text/lager/KoSvgTextPropertiesModel.cpp b/libs/flake/text/lager/KoSvgTextPropertiesModel.cpp
index b5740ab0fb..0f1a6ed6c9 100644
--- a/libs/flake/text/lager/KoSvgTextPropertiesModel.cpp
+++ b/libs/flake/text/lager/KoSvgTextPropertiesModel.cpp
@@ -64,6 +64,22 @@ auto simplifiedAutoLengthPropertyImpl = lager::lenses::getset(
auto simplifiedAutoLengthProperty = variant_to<KoSvgText::AutoLengthPercentage> | simplifiedAutoLengthPropertyImpl;
+// Used for font-kerning.
+auto autoValueToBoolImpl = lager::lenses::getset(
+ [](const KoSvgText::AutoValue &value) -> bool {
+ return value.isAuto;
+ },
+ [](KoSvgText::AutoValue value, const bool &val){
+ value.isAuto = val;
+ if (!val) {
+ value.customValue = 0;
+ }
+ return value;
+ }
+ );
+
+auto autoValueToBool = variant_to<KoSvgText::AutoValue> | autoValueToBoolImpl;
+
auto textDecorLinePropImpl = [](KoSvgText::TextDecoration flag) {
return lager::lenses::getset(
[flag] (const KoSvgText::TextDecorations &value) -> bool {
@@ -230,6 +246,8 @@ KoSvgTextPropertiesModel::KoSvgTextPropertiesModel(lager::cursor<KoSvgTextProper
, 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(fontKerning) {textData.zoom(createTextProperty(KoSvgTextProperties::KerningId)).zoom(autoValueToBool)}
+ , LAGER_QT(fontKerningState) {textData.zoom(propertyModifyState(KoSvgTextProperties::KerningId))}
, 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.h
index 9fa652e995..570a2b2deb 100644
--- a/libs/flake/text/lager/KoSvgTextPropertiesModel.h
+++ b/libs/flake/text/lager/KoSvgTextPropertiesModel.h
@@ -194,6 +194,9 @@ public:
LAGER_QT_CURSOR(QVariantMap, fontFeatureSettings);
LAGER_QT_CURSOR(PropertyState, fontFeatureSettingsState);
+ LAGER_QT_CURSOR(bool, fontKerning);
+ LAGER_QT_CURSOR(PropertyState, fontKerningState);
+
/// We're selecting a span of text instead of the whole paragraph.
LAGER_QT_CURSOR(bool, spanSelection);
diff --git a/plugins/dockers/textproperties/qml/FontKerning.qml b/plugins/dockers/textproperties/qml/FontKerning.qml
new file mode 100644
index 0000000000..21abc6e0d5
--- /dev/null
+++ b/plugins/dockers/textproperties/qml/FontKerning.qml
@@ -0,0 +1,54 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Wolthera van Hövell tot Westerflier <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+import QtQuick 2.0
+import QtQuick.Controls 2.0
+import QtQuick.Layouts 1.12
+import org.krita.flake.text 1.0
+
+/**
+ CSS font-kerning is formally a three-way state between auto, normal and none. SVG 1.1 had it as an
+ auto-length, but this has been deprecated in SVG 2.0. Because of this, we only really support auto and none.
+ */
+TextPropertyBase {
+ propertyName: i18nc("@label", "Font Kerning");
+ propertyType: TextPropertyBase.Character;
+ toolTip: i18nc("@info:tooltip",
+ "Turn font kerning on or off. Font kerning enables per-glyph spacing adjustments.");
+ searchTerms: i18nc("comma separated search terms for the font-kerning property, matching is case-insensitive",
+ "font-kerning, tracking");
+
+ property alias kerning: fontKerningCbx.checked;
+ onPropertiesUpdated: {
+ blockSignals = true;
+ kerning = properties.fontKerning;
+ visible = properties.fontKerningState !== KoSvgTextPropertiesModel.PropertyUnset;
+ blockSignals = false;
+ }
+
+ onKerningChanged: {
+ if (!blockSignals) {
+ properties.fontKerning = kerning;
+ }
+ }
+
+ onEnableProperty: properties.fontKerningState = KoSvgTextPropertiesModel.PropertySet;
+ GridLayout {
+ columns: 2;
+ columnSpacing: columnSpacing;
+ width: parent.width;
+
+ RevertPropertyButton {
+ revertState: properties.fontKerningState;
+ onClicked: properties.fontKerningState = KoSvgTextPropertiesModel.PropertyUnset;
+ }
+
+ CheckBox {
+ id: fontKerningCbx;
+ text: propertyName;
+ Layout.fillWidth: true;
+ }
+ }
+}
diff --git a/plugins/dockers/textproperties/qml/TextPropertyBaseList.qml b/plugins/dockers/textproperties/qml/TextPropertyBaseList.qml
index 7e0c99441f..3a2dae768e 100644
--- a/plugins/dockers/textproperties/qml/TextPropertyBaseList.qml
+++ b/plugins/dockers/textproperties/qml/TextPropertyBaseList.qml
@@ -142,6 +142,8 @@ ColumnLayout {
}
OpenTypeFeatureSettings {
}
+ FontKerning {
+ }
BaselineShift {
}
AlignmentBaseline {
diff --git a/plugins/dockers/textproperties/textproperties.qrc b/plugins/dockers/textproperties/textproperties.qrc
index f553d1a0d0..7d5177522b 100644
--- a/plugins/dockers/textproperties/textproperties.qrc
+++ b/plugins/dockers/textproperties/textproperties.qrc
@@ -47,5 +47,6 @@
<file alias="SqueezedComboBox.qml">qml/SqueezedComboBox.qml</file>
<file alias="OpenTypeFeatureSettings.qml">qml/OpenTypeFeatureSettings.qml</file>
<file alias="OpenTypeFeatureDelegate.qml">qml/OpenTypeFeatureDelegate.qml</file>
+ <file alias="FontKerning.qml">qml/FontKerning.qml</file>
</qresource>
</RCC>