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++
Allow using width, slant and fontaxes for svg text label.
Wolthera van Hövell tot Westerflier57bb10cf7b40
diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPalette.qml b/plugins/tools/svgtexttool/glyphpalette/GlyphPalette.qmlindex abdf9e8dd0..3f87c1a245 100644--- a/plugins/tools/svgtexttool/glyphpalette/GlyphPalette.qml+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPalette.qml@@ -22,6 +22,7 @@ Rectangle {property double fontWidth : 100;property int fontStyle: 0;property double fontSlant: 0.0;+ property var fontAxesValues: ({});property string language: "";SystemPalette {id: sysPalette;@@ -61,6 +62,7 @@ Rectangle {fontStyle: root.fontStyle;fontWidth: root.fontWidth;fontSlant: root.fontSlant;+ fontAxesValues: root.fontAxesValues;language: root.language;replace: true;Layout.fillHeight: true;@@ -142,6 +144,9 @@ Rectangle {fontStyle: root.fontStyle;fontWeight: root.fontWeight;language: root.language;+ fontWidth: root.fontWidth;+ fontSlant: root.fontSlant;+ fontAxesValues: root.fontAxesValues === undefined? {}: root.fontAxesValues;onGlyphDoubleClicked: (index, mouse)=> {mainWindow.slotInsertRichText(index)};diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteAltPopup.cpp b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteAltPopup.cppindex c92d6cafbc..09280b6276 100644--- a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteAltPopup.cpp+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteAltPopup.cpp@@ -82,7 +82,7 @@ void GlyphPaletteAltPopup::setModel(QAbstractItemModel *model)}}-void GlyphPaletteAltPopup::setMarkup(const QStringList &families, const int size, const int weight, const int width, const QFont::Style style, const QString &language)+void GlyphPaletteAltPopup::setMarkup(const QStringList &families, const int size, const int weight, const int width, const QFont::Style style, const QVariantMap &axes, const QString &language){if (m_quickWidget->rootObject()) {m_quickWidget->rootObject()->setProperty("fontFamilies", QVariant::fromValue(families));@@ -90,6 +90,7 @@ void GlyphPaletteAltPopup::setMarkup(const QStringList &families, const int sizem_quickWidget->rootObject()->setProperty("fontWeight", QVariant::fromValue(weight));m_quickWidget->rootObject()->setProperty("fontWidth", QVariant::fromValue(width));m_quickWidget->rootObject()->setProperty("fontStyle", QVariant::fromValue(style));+ m_quickWidget->rootObject()->setProperty("fontAxesValues", QVariant::fromValue(axes));m_quickWidget->rootObject()->setProperty("language", QVariant::fromValue(language));}}diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteAltPopup.h b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteAltPopup.hindex 9483fb4954..52c35aea62 100644--- a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteAltPopup.h+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteAltPopup.h@@ -46,7 +46,7 @@ public:* @brief setMarkup* Set the css font markup to be used inside the palette.*/- void setMarkup(const QStringList &families, const int size, const int weight, const int width, const QFont::Style style, const QString &language);+ void setMarkup(const QStringList &families, const int size, const int weight, const int width, const QFont::Style style, const QVariantMap &axes, const QString &language);public Q_SLOTS:diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteAlts.qml b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteAlts.qmlindex 879728107a..0d63caf0a4 100644--- a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteAlts.qml+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteAlts.qml@@ -16,6 +16,7 @@ Rectangle {property double fontWidth: 100;property int fontStyle: 0;property double fontSlant: 0.0;+ property var fontAxesValues;property string language: "";SystemPalette {id: sysPalette;@@ -45,6 +46,9 @@ Rectangle {fontSize: root.fontSize;fontStyle: root.fontStyle;fontWeight: root.fontWeight;+ fontWidth: root.fontWidth;+ fontSlant: root.fontSlant;+ fontAxesValues: root.fontAxesValues === undefined? {}: root.fontAxesValues;language: root.language;onGlyphClicked: (index, mouse)=> {if (!root.replace) {diff --git a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cppindex 2219fafb94..f27a564d34 100644--- a/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp+++ b/plugins/tools/svgtexttool/glyphpalette/GlyphPaletteDialog.cpp@@ -117,6 +117,12 @@ void GlyphPaletteDialog::setGlyphModelFromProperties(const QPair<KoSvgTextProperif (faces.empty()) return;m_model->setFace(faces.front(), QLatin1String(language.toLatin1()));+ QVariantMap map;+ QVariantHash axes = properties.second.propertyOrDefault(KoSvgTextProperties::FontVariationSettingsId).toHash();+ Q_FOREACH(const QString key, axes.keys()) {+ map.insert(key, axes.value(key));+ }+QModelIndex idx = m_model->indexForString(text);if (m_quickWidget->rootObject()) {m_quickWidget->rootObject()->setProperty("fontFamilies", QVariant::fromValue(families));@@ -124,13 +130,14 @@ void GlyphPaletteDialog::setGlyphModelFromProperties(const QPair<KoSvgTextProperm_quickWidget->rootObject()->setProperty("fontWeight", QVariant::fromValue(weight));m_quickWidget->rootObject()->setProperty("fontWidth", QVariant::fromValue(width));m_quickWidget->rootObject()->setProperty("fontStyle", QVariant::fromValue(style.style));+ m_quickWidget->rootObject()->setProperty("fontAxesValues", QVariant::fromValue(axes));m_quickWidget->rootObject()->setProperty("language", QVariant::fromValue(language));if (idx.isValid()) {m_quickWidget->rootObject()->setProperty("currentIndex", QVariant::fromValue(idx.row()));}}if (m_altPopup) {- m_altPopup->setMarkup(families, size, weight, width, style.style, language);+ m_altPopup->setMarkup(families, size, weight, width, style.style, map, language);}m_lastUsedProperties = properties.first;}diff --git a/plugins/tools/svgtexttool/glyphpalette/SvgTextLabel.cpp b/plugins/tools/svgtexttool/glyphpalette/SvgTextLabel.cppindex b16541cdf1..88c9195cd2 100644--- a/plugins/tools/svgtexttool/glyphpalette/SvgTextLabel.cpp+++ b/plugins/tools/svgtexttool/glyphpalette/SvgTextLabel.cpp@@ -21,13 +21,13 @@ struct Q_DECL_HIDDEN SvgTextLabel::Private {shape->setResolution(72, 72);// Hack to avoid the textshape having 0 bounds and the KoRTree complaining about it.shape->insertText(0, "a");- shape->relayout();shapePainter->setShapes({shape.data()});}~Private() {}QScopedPointer<KoSvgTextShape> shape;QScopedPointer<KoShapePainter> shapePainter;+ KoSvgTextProperties props;int padding = 2;};@@ -46,6 +46,9 @@ SvgTextLabel::~SvgTextLabel()void SvgTextLabel::paint(QPainter *painter){+ if (d->shape->textProperties() != d->props) {+ updateShape();+ }if (!painter->isActive()) return;painter->save();painter->fillRect(0, 0, width(), height(), fillColor());@@ -68,14 +71,35 @@ QStringList SvgTextLabel::fontFamilies() constreturn d->shape->textProperties().property(KoSvgTextProperties::FontFamiliesId).value<QStringList>();}-int SvgTextLabel::fontWeight() const+qreal SvgTextLabel::fontWeight() const{- return d->shape->textProperties().property(KoSvgTextProperties::FontWeightId).toInt();+ return d->shape->textProperties().property(KoSvgTextProperties::FontWeightId).toReal();+}++qreal SvgTextLabel::fontWidth() const+{+ return d->shape->textProperties().property(KoSvgTextProperties::FontStretchId).toReal();}QFont::Style SvgTextLabel::fontStyle() const{- return d->shape->textProperties().property(KoSvgTextProperties::FontStyleId).value<QFont::Style>();+ return d->shape->textProperties().property(KoSvgTextProperties::FontStyleId).value<KoSvgText::CssFontStyleData>().style;+}++qreal SvgTextLabel::fontSlant() const+{+ KoSvgText::CssFontStyleData style = d->shape->textProperties().property(KoSvgTextProperties::FontStyleId).value<KoSvgText::CssFontStyleData>();+ return style.slantValue.isAuto? 14.0: style.slantValue.customValue;+}++QVariantMap SvgTextLabel::fontAxesValues() const+{+ QVariantMap map;+ QVariantHash axes = d->props.propertyOrDefault(KoSvgTextProperties::FontVariationSettingsId).toHash();+ Q_FOREACH(const QString key, axes.keys()) {+ map.insert(key, axes.value(key));+ }+ return map;}qreal SvgTextLabel::fontSize() const@@ -114,57 +138,86 @@ QString SvgTextLabel::language() constvoid SvgTextLabel::setFontFamilies(QStringList fontFamilies){- KoSvgTextProperties props = d->shape->textProperties();- QStringList current = props.property(KoSvgTextProperties::FontFamiliesId).value<QStringList>();+ QStringList current = d->props.property(KoSvgTextProperties::FontFamiliesId).value<QStringList>();if (current == fontFamilies)return;- props.setProperty(KoSvgTextProperties::FontFamiliesId, fontFamilies);- d->shape->setPropertiesAtPos(-1, props);+ d->props.setProperty(KoSvgTextProperties::FontFamiliesId, fontFamilies);emit fontFamiliesChanged(fontFamilies);}-void SvgTextLabel::setFontWeight(int fontWeight)+void SvgTextLabel::setFontWeight(qreal fontWeight){- KoSvgTextProperties props = d->shape->textProperties();- int current = props.property(KoSvgTextProperties::FontWeightId).toInt();- if (current == fontWeight)+ qreal current = d->props.property(KoSvgTextProperties::FontWeightId).toReal();+ if (qFuzzyCompare(current, fontWeight))return;- props.setProperty(KoSvgTextProperties::FontWeightId, fontWeight);- d->shape->setPropertiesAtPos(-1, props);+ d->props.setProperty(KoSvgTextProperties::FontWeightId, fontWeight);emit fontWeightChanged(fontWeight);}+void SvgTextLabel::setFontWidth(qreal fontWidth)+{+ qreal current = d->props.property(KoSvgTextProperties::FontStretchId).toReal();+ if (qFuzzyCompare(current, fontWidth))+ return;++ d->props.setProperty(KoSvgTextProperties::FontStretchId, fontWidth);+ emit fontWidthChanged(fontWidth);+}+void SvgTextLabel::setFontStyle(QFont::Style fontStyle){- KoSvgTextProperties props = d->shape->textProperties();- QFont::Style current = props.property(KoSvgTextProperties::FontStyleId).value<QFont::Style>();- if (current == fontStyle)+ KoSvgText::CssFontStyleData current = d->props.property(KoSvgTextProperties::FontStyleId).value<KoSvgText::CssFontStyleData>();+ if (current.style == fontStyle)return;- props.setProperty(KoSvgTextProperties::FontStyleId, fontStyle);- d->shape->setPropertiesAtPos(-1, props);- updateShape();+ current.style = fontStyle;+ d->props.setProperty(KoSvgTextProperties::FontStyleId, QVariant::fromValue(current));emit fontStyleChanged(fontStyle);}+void SvgTextLabel::setFontSlant(qreal fontSlant)+{+ KoSvgText::CssFontStyleData current = d->props.property(KoSvgTextProperties::FontStyleId).value<KoSvgText::CssFontStyleData>();+ if (current.slantValue.isAuto && qFuzzyCompare(fontSlant, 14))+ return;+ if (!current.slantValue.isAuto && qFuzzyCompare(fontSlant, current.slantValue.customValue))+ return;++ current.slantValue.customValue = fontSlant;+ current.slantValue.isAuto = false;+ d->props.setProperty(KoSvgTextProperties::FontStyleId, QVariant::fromValue(current));+ emit fontSlantChanged(fontSlant);+}++void SvgTextLabel::setFontAxesValues(QVariantMap fontAxesValues)+{+ QVariantHash compare;+ Q_FOREACH (const QString key, fontAxesValues.keys()) {+ compare.insert(key, fontAxesValues.value(key));+ }+ QVariantHash current = d->props.property(KoSvgTextProperties::FontVariationSettingsId).toHash();+ if (current == compare)+ return;++ d->props.setProperty(KoSvgTextProperties::FontVariationSettingsId, QVariant::fromValue(compare));+ emit fontAxesValuesChanged(fontAxesValues);+}+void SvgTextLabel::setFontSize(qreal fontSize){- KoSvgTextProperties props = d->shape->textProperties();- qreal current = props.property(KoSvgTextProperties::FontSizeId).toReal();+ qreal current = d->props.property(KoSvgTextProperties::FontSizeId).toReal();if (qFuzzyCompare(current, fontSize))return;- props.setProperty(KoSvgTextProperties::FontSizeId, fontSize);- d->shape->setPropertiesAtPos(-1, props);+ d->props.setProperty(KoSvgTextProperties::FontSizeId, fontSize);emit fontSizeChanged(fontSize);}void SvgTextLabel::setTextColor(QColor textColor){- KoSvgTextProperties props = d->shape->textProperties();- if (props.hasProperty(KoSvgTextProperties::FillId)) {+ if (d->props.hasProperty(KoSvgTextProperties::FillId)) {KoColorBackground *bg = dynamic_cast<KoColorBackground*>(d->shape->background().data());if (bg) {if (bg->color() == textColor)@@ -173,6 +226,7 @@ void SvgTextLabel::setTextColor(QColor textColor)}d->shape->setBackground(QSharedPointer<KoColorBackground>(new KoColorBackground(textColor)));+ d->props.setProperty(KoSvgTextProperties::FillId, d->shape->textProperties().property(KoSvgTextProperties::FillId));if (this->window()) {const qreal pixelRatio = this->window()->effectiveDevicePixelRatio();d->shape->setResolution(pixelRatio*72, pixelRatio*72);@@ -182,13 +236,11 @@ void SvgTextLabel::setTextColor(QColor textColor)void SvgTextLabel::setOpenTypeFeatures(QStringList openTypeFeatures){- KoSvgTextProperties props = d->shape->textProperties();- QStringList otf = props.property(KoSvgTextProperties::FontFeatureSettingsId).value<QStringList>();+ QStringList otf = d->props.property(KoSvgTextProperties::FontFeatureSettingsId).value<QStringList>();if (otf == openTypeFeatures)return;- props.setProperty(KoSvgTextProperties::FontFeatureSettingsId, openTypeFeatures);- d->shape->setPropertiesAtPos(-1, props);+ d->props.setProperty(KoSvgTextProperties::FontFeatureSettingsId, openTypeFeatures);emit openTypeFeaturesChanged(openTypeFeatures);}@@ -201,7 +253,6 @@ void SvgTextLabel::setText(QString text)int start = 0;d->shape->removeText(start, length);d->shape->insertText(0, text);- updateShape();emit textChanged(d->shape->plainText());}@@ -216,19 +267,23 @@ void SvgTextLabel::setPadding(int padding)void SvgTextLabel::setLanguage(QString language){- KoSvgTextProperties props = d->shape->textProperties();- const QString lang = props.property(KoSvgTextProperties::TextLanguage).toString();+ const QString lang = d->props.property(KoSvgTextProperties::TextLanguage).toString();if (lang == language) {return;}- props.setProperty(KoSvgTextProperties::TextLanguage, language);- d->shape->setPropertiesAtPos(-1, props);+ d->props.setProperty(KoSvgTextProperties::TextLanguage, language);emit languageChanged(language);}+void SvgTextLabel::componentComplete()+{+ QQuickPaintedItem::componentComplete();+ updateShape();+}+void SvgTextLabel::updateShape(){+ d->shape->setPropertiesAtPos(-1, d->props);d->shape->relayout();setImplicitSize(d->shape->boundingRect().width(), d->shape->boundingRect().height());- update();}diff --git a/plugins/tools/svgtexttool/glyphpalette/SvgTextLabel.h b/plugins/tools/svgtexttool/glyphpalette/SvgTextLabel.hindex bd93303dc1..8a8a045dae 100644--- a/plugins/tools/svgtexttool/glyphpalette/SvgTextLabel.h+++ b/plugins/tools/svgtexttool/glyphpalette/SvgTextLabel.h@@ -22,8 +22,11 @@ class SvgTextLabel : public QQuickPaintedItem{Q_OBJECTQ_PROPERTY(QStringList fontFamilies READ fontFamilies WRITE setFontFamilies NOTIFY fontFamiliesChanged)- Q_PROPERTY(int fontWeight READ fontWeight WRITE setFontWeight NOTIFY fontWeightChanged)+ Q_PROPERTY(qreal fontWeight READ fontWeight WRITE setFontWeight NOTIFY fontWeightChanged)+ Q_PROPERTY(qreal fontWidth READ fontWidth WRITE setFontWidth NOTIFY fontWidthChanged)Q_PROPERTY(QFont::Style fontStyle READ fontStyle WRITE setFontStyle NOTIFY fontStyleChanged)+ Q_PROPERTY(qreal fontSlant READ fontSlant WRITE setFontSlant NOTIFY fontSlantChanged)+ Q_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)@@ -39,10 +42,16 @@ public:QStringList fontFamilies() const;- int fontWeight() const;+ qreal fontWeight() const;++ qreal fontWidth() const;QFont::Style fontStyle() const;+ qreal fontSlant() const;++ QVariantMap fontAxesValues() const;+qreal fontSize() const;QColor textColor() const;@@ -58,10 +67,16 @@ public:public Q_SLOTS:void setFontFamilies(QStringList fontFamilies);- void setFontWeight(int fontWeight);+ void setFontWeight(qreal fontWeight);++ void setFontWidth(qreal fontWidth);void setFontStyle(QFont::Style fontStyle);+ void setFontSlant(qreal fontSlant);++ void setFontAxesValues(QVariantMap fontAxesValues);+void setFontSize(qreal fontSize);void setTextColor(QColor textColor);@@ -77,10 +92,16 @@ public Q_SLOTS:Q_SIGNALS:void fontFamiliesChanged(QStringList);- void fontWeightChanged(int fontWeight);+ void fontWeightChanged(qreal fontWeight);++ void fontWidthChanged(qreal fontWidth);void fontStyleChanged(QFont::Style fontStyle);+ void fontSlantChanged(qreal fontSlant);++ void fontAxesValuesChanged(QVariantMap fontAxesValues);+void fontSizeChanged(qreal fontSize);void textColorChanged(QColor textColor);@@ -92,6 +113,13 @@ Q_SIGNALS:void paddingChanged(int padding);void languageChanged(QString language);+protected:+ /**+ * @brief componentComplete+ * called when all properties have been set.+ * used to avoid relayout being called time and time again when the properties change.+ */+ void componentComplete() override;private: