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++
Enable editing font-size adjust, fix some small issues there.
Wolthera van Hövell tot Westerflier02a91cc6287d
diff --git a/libs/flake/text/KoCSSFontInfo.h b/libs/flake/text/KoCSSFontInfo.hindex 483a928d14..264cc1d40a 100644--- a/libs/flake/text/KoCSSFontInfo.h+++ b/libs/flake/text/KoCSSFontInfo.h@@ -24,7 +24,7 @@ struct KRITAFLAKE_EXPORT KoCSSFontInfo: public boost::equality_comparable<KoCSSFdouble size = -1; /// < Size in Pt.bool automaticOpticalSizing = true;- double fontSizeAdjust = 1.0;+ double fontSizeAdjust = 0.0; // 1.0 would mean that the x-height is the same as the specified font-size, allowing scaling by x-height.double weight = 400;double width = 100;diff --git a/libs/flake/text/KoFontRegistry.cpp b/libs/flake/text/KoFontRegistry.cppindex 34a9c9a813..b8de026e98 100644--- a/libs/flake/text/KoFontRegistry.cpp+++ b/libs/flake/text/KoFontRegistry.cpp@@ -594,6 +594,8 @@ bool KoFontRegistry::configureFaces(const std::vector<FT_FaceSP> &faces,FT_Set_Charmap(face.data(), map);}+ qreal adjustedSize = size;+if (!FT_IS_SCALABLE(face)) {const qreal fontSizePixels = size * ftFontUnit * scaleToPixel;qreal sizeDelta = 0;@@ -626,10 +628,11 @@ bool KoFontRegistry::configureFaces(const std::vector<FT_FaceSP> &faces,hb_font_t_sp font(hb_ft_font_create_referenced(face.data()));hb_position_t xHeight = 0;hb_ot_metrics_get_position(font.data(), HB_OT_METRICS_TAG_X_HEIGHT, &xHeight);- if (xHeight > 0 && fontSizeAdjust > 0 && fontSizeAdjust < 1.0) {+ if (xHeight > 0 && fontSizeAdjust > 0) {qreal aspect = xHeight / (size * ftFontUnit * scaleToPixel);+ adjustedSize = (fontSizeAdjust / aspect) * (size);errorCode = FT_Set_Char_Size(face.data(),- static_cast<FT_F26Dot6>((fontSizeAdjust / aspect) * (size * ftFontUnit)),+ static_cast<FT_F26Dot6>(adjustedSize * ftFontUnit),0,xRes,yRes);@@ -641,7 +644,19 @@ bool KoFontRegistry::configureFaces(const std::vector<FT_FaceSP> &faces,if (tagName.size() == 4) {const QByteArray utfData = tagName.toUtf8();const char *tag = utfData.data();- tags.insert(FT_MAKE_TAG(tag[0], tag[1], tag[2], tag[3]), axisSettings.value(tagName));+ if (tagName == "opsz" && !qFuzzyCompare(adjustedSize, size)) {+ /**+ * There's something peculiar about this:+ * Var fonts can change their x-height depending+ * on the optical size selected. Meaning that the x-height adjusted size+ * could be wrong depending on the font and its x-height choices.+ * There's no reasonable way to fix this beyond cycling, and it is questionable+ * whether the font-size-adjust property is even meant to be that specific.+ */+ tags.insert(FT_MAKE_TAG(tag[0], tag[1], tag[2], tag[3]), adjustedSize);+ } else {+ tags.insert(FT_MAKE_TAG(tag[0], tag[1], tag[2], tag[3]), axisSettings.value(tagName));+ }}}const FT_Tag ITALIC_TAG = FT_MAKE_TAG('i', 't', 'a', 'l');diff --git a/libs/flake/text/KoSvgTextProperties.cpp b/libs/flake/text/KoSvgTextProperties.cppindex 8b0653c18d..7fb04d5d46 100644--- a/libs/flake/text/KoSvgTextProperties.cpp+++ b/libs/flake/text/KoSvgTextProperties.cpp@@ -1131,7 +1131,7 @@ KoCSSFontInfo KoSvgTextProperties::cssFontInfo() constinfo.families = propertyOrDefault(FontFamiliesId).toStringList();const KoSvgText::AutoValue fontSizeAdjust = propertyOrDefault(FontSizeAdjustId).value<KoSvgText::AutoValue>();if (property(KraTextVersionId).toInt() >= 3) {- info.fontSizeAdjust = fontSizeAdjust.isAuto? 1.0: fontSizeAdjust.customValue;+ info.fontSizeAdjust = fontSizeAdjust.isAuto? 0.0: fontSizeAdjust.customValue;}const KoSvgText::CssFontStyleData style = propertyOrDefault(FontStyleId).value<KoSvgText::CssFontStyleData>();diff --git a/libs/flake/text/lager/KoSvgTextPropertiesModel.cpp b/libs/flake/text/lager/KoSvgTextPropertiesModel.cppindex 16a8ba960e..28dabbef74 100644--- a/libs/flake/text/lager/KoSvgTextPropertiesModel.cpp+++ b/libs/flake/text/lager/KoSvgTextPropertiesModel.cpp@@ -80,6 +80,20 @@ auto autoValueToBoolImpl = lager::lenses::getset(auto autoValueToBool = variant_to<KoSvgText::AutoValue> | autoValueToBoolImpl;+// Used for font-size-adjust.+auto autoValueSimplifiedImpl = lager::lenses::getset(+ [](const KoSvgText::AutoValue &value) -> qreal {+ return value.isAuto? 0.0: value.customValue;+ },+ [](KoSvgText::AutoValue value, const qreal &val){+ value.customValue = val;+ value.isAuto = value.customValue > 0? false: true;+ return value;+ }+ );++auto autoValueSimplified = variant_to<KoSvgText::AutoValue> | autoValueSimplifiedImpl;+auto textDecorLinePropImpl = [](KoSvgText::TextDecoration flag) {return lager::lenses::getset([flag] (const KoSvgText::TextDecorations &value) -> bool {@@ -252,6 +266,8 @@ KoSvgTextPropertiesModel::KoSvgTextPropertiesModel(lager::cursor<KoSvgTextProper, LAGER_QT(fontKerningState) {textData.zoom(propertyModifyState(KoSvgTextProperties::KerningId))}, LAGER_QT(language) {textData.zoom(createTextProperty(KoSvgTextProperties::TextLanguage)).zoom(variant_to<QString>)}, LAGER_QT(languageState) {textData.zoom(propertyModifyState(KoSvgTextProperties::TextLanguage))}+ , LAGER_QT(fontSizeAdjust) {textData.zoom(createTextProperty(KoSvgTextProperties::FontSizeAdjustId)).zoom(autoValueSimplified)}+ , LAGER_QT(fontSizeAdjustState) {textData.zoom(propertyModifyState(KoSvgTextProperties::FontSizeAdjustId))}, 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 65b8a30eeb..0b132c683c 100644--- a/libs/flake/text/lager/KoSvgTextPropertiesModel.h+++ b/libs/flake/text/lager/KoSvgTextPropertiesModel.h@@ -202,6 +202,9 @@ public:LAGER_QT_CURSOR(QString, language);LAGER_QT_CURSOR(PropertyState, languageState);+ LAGER_QT_CURSOR(qreal, fontSizeAdjust);+ LAGER_QT_CURSOR(PropertyState, fontSizeAdjustState);+/// We're selecting a span of text instead of the whole paragraph.LAGER_QT_CURSOR(bool, spanSelection);diff --git a/plugins/dockers/textproperties/qml/FontSizeAdjust.qml b/plugins/dockers/textproperties/qml/FontSizeAdjust.qmlnew file mode 100644index 0000000000..e5a621eacb--- /dev/null+++ b/plugins/dockers/textproperties/qml/FontSizeAdjust.qml@@ -0,0 +1,71 @@+/*+ * 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 {+ propertyName: i18nc("@label:spinbox", "Font Size Adjust");+ propertyType: TextPropertyBase.Character;+ toolTip: i18nc("@info:tooltip",+ "Font size adjust allows setting a ratio that the x-height must be matched by.");+ searchTerms: i18nc("comma separated search terms for the fontsize adjust property, matching is case-insensitive",+ "size, small, big, medium, font-size-adjust");++ property alias fontSizeAdjust: fontSizeAdjustSpn.value;++ onPropertiesUpdated: {+ blockSignals = true;+ fontSizeAdjust = properties.fontSizeAdjust * fontSizeAdjustSpn.multiplier;+ visible = properties.fontSizeAdjustState !== KoSvgTextPropertiesModel.PropertyUnset;+ blockSignals = false;+ }+ onFontSizeAdjustChanged: {+ if (!blockSignals) {+ properties.fontSizeAdjust = fontSizeAdjust/fontSizeAdjustSpn.multiplier;+ }+ }++ onEnableProperty: properties.fontSizeAdjustState = KoSvgTextPropertiesModel.PropertySet;++ RowLayout {+ spacing: columnSpacing;+ width: parent.width;+++ RevertPropertyButton {+ revertState: properties.fontSizeAdjustState;+ onClicked: properties.fontSizeAdjustState = KoSvgTextPropertiesModel.PropertyUnset;+ }++ Label {+ text: propertyName;+ elide: Text.ElideRight;+ Layout.fillWidth: true;+ font.italic: properties.fontSizeAdjustState === KoSvgTextPropertiesModel.PropertyTriState;+ }++ DoubleSpinBox {+ id: fontSizeAdjustSpn;+ editable: true;+ Layout.fillWidth: true;++ from: 0;+ to: 999 * multiplier;+ stepSize: 100;+ }++ Button {+ text: i18nc("@label:button", "Calculate");+ ToolTip.text: i18nc("@info:tooltip", "Calculate the x-height to font size ratio for the first font family.");+ onClicked: {+ let ratio = properties.resolvedXHeight(true)/properties.resolvedFontSize(true);+ fontSizeAdjust = ratio * fontSizeAdjustSpn.multiplier;+ }+ }+ }+}diff --git a/plugins/dockers/textproperties/qml/TextPropertyBaseList.qml b/plugins/dockers/textproperties/qml/TextPropertyBaseList.qmlindex 0dfb6cb08c..e146c1c25d 100644--- a/plugins/dockers/textproperties/qml/TextPropertyBaseList.qml+++ b/plugins/dockers/textproperties/qml/TextPropertyBaseList.qml@@ -112,6 +112,9 @@ ColumnLayout {}FontSize {}+ FontSizeAdjust {+ }+FontFamily {}FontStyle {diff --git a/plugins/dockers/textproperties/textproperties.qrc b/plugins/dockers/textproperties/textproperties.qrcindex 4262f2fb11..0319e40312 100644--- a/plugins/dockers/textproperties/textproperties.qrc+++ b/plugins/dockers/textproperties/textproperties.qrc@@ -58,5 +58,6 @@<file alias="baseline-ideo-embox-bottom.svg">icons/baseline-ideo-embox-bottom.svg</file><file alias="baseline-ideo-embox-horizontal-center.svg">icons/baseline-ideo-embox-horizontal-center.svg</file><file alias="16_light_format-text-overline.svg">icons/16_light_format-text-overline.svg</file>+ <file alias="FontSizeAdjust.qml">qml/FontSizeAdjust.qml</file></qresource></RCC>