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

Cache the primary font family name for style presets and show when it is missing.

Wolthera van Hövell tot Westerflier90a0532cf593
diff --git a/libs/flake/resources/KoCssStylePreset.cpp b/libs/flake/resources/KoCssStylePreset.cpp
index f5b67a80ff..7be013568b 100644
--- a/libs/flake/resources/KoCssStylePreset.cpp
+++ b/libs/flake/resources/KoCssStylePreset.cpp
@@ -25,6 +25,7 @@ const QString SAMPLE_SVG = "sample_svg";
const QString SAMPLE_ALIGN = "sample_align";
const QString STYLE_TYPE = "style_type";
const QString STORED_PPI = "stored_ppi";
+const QString PRIMARY_FONT_FAMILY = "primary_font_family";
const QString STYLE_TYPE_PARAGRAPH = "paragraph";
const QString STYLE_TYPE_CHARACTER = "character";
@@ -83,6 +84,13 @@ KoSvgTextProperties KoCssStylePreset::properties(int ppi, bool removeKraProps) c
props.removeProperty(KoSvgTextProperties::KraTextStyleResolution);
props.removeProperty(KoSvgTextProperties::KraTextVersionId);
}
+ // remove fill and stroke for now.
+ props.removeProperty(KoSvgTextProperties::FillId);
+ props.removeProperty(KoSvgTextProperties::StrokeId);
+ props.removeProperty(KoSvgTextProperties::Opacity);
+ props.removeProperty(KoSvgTextProperties::Visiblity);
+ props.removeProperty(KoSvgTextProperties::TextOrientationId);
+ props.removeProperty(KoSvgTextProperties::PaintOrder);
return props;
}
@@ -173,9 +181,17 @@ void KoCssStylePreset::setSampleText(const QString &sample, const KoSvgTextPrope
// Remove fill and stroke for now as we have no widgets for them.
modifiedProps.removeProperty(KoSvgTextProperties::FillId);
modifiedProps.removeProperty(KoSvgTextProperties::StrokeId);
+ modifiedProps.removeProperty(KoSvgTextProperties::PaintOrder);
+ modifiedProps.removeProperty(KoSvgTextProperties::Opacity);
+ modifiedProps.removeProperty(KoSvgTextProperties::Visiblity);
+ modifiedProps.removeProperty(KoSvgTextProperties::TextOrientationId);
sampleText->setPropertiesAtPos(-1, modifiedProps);
+ QStringList fonts = modifiedProps.property(KoSvgTextProperties::FontFamiliesId).toStringList();
+ //TODO: Apparantly we cannot remove metadata, only set it to nothing...
+ addMetaData(PRIMARY_FONT_FAMILY, fonts.value(0));
+
if (type == STYLE_TYPE_PARAGRAPH) {
// For paragraph we'll add a shape, as those will allow wrapping,
// without being part of the properties like inline-size is.
@@ -225,6 +241,12 @@ Qt::Alignment KoCssStylePreset::alignSample() const
return static_cast<Qt::Alignment>(v.value<Qt::Alignment::Int>());
}
+QString KoCssStylePreset::primaryFontFamily() const
+{
+ QMap<QString, QVariant> m = metadata();
+ return m.value(PRIMARY_FONT_FAMILY).toString();
+}
+
void KoCssStylePreset::updateAlignSample()
{
Qt::AlignmentFlag hComponent = Qt::AlignHCenter;
@@ -408,6 +430,10 @@ bool KoCssStylePreset::loadFromDevice(QIODevice *dev, KisResourcesInterfaceSP re
if (props.hasProperty(KoSvgTextProperties::KraTextStyleResolution)) {
addMetaData(STORED_PPI, props.property(KoSvgTextProperties::KraTextStyleResolution));
}
+ if (props.hasProperty(KoSvgTextProperties::FontFamiliesId)) {
+ QStringList fonts = props.property(KoSvgTextProperties::FontFamiliesId).toStringList();
+ addMetaData(PRIMARY_FONT_FAMILY, fonts.value(0));
+ }
}
addMetaData(STYLE_TYPE, styleType);
diff --git a/libs/flake/resources/KoCssStylePreset.h b/libs/flake/resources/KoCssStylePreset.h
index d46f277b5f..697880cbeb 100644
--- a/libs/flake/resources/KoCssStylePreset.h
+++ b/libs/flake/resources/KoCssStylePreset.h
@@ -76,6 +76,16 @@ public:
/// the alignment anchor of the text is shown.
Qt::Alignment alignSample() const;
+ /**
+ * @brief primaryFontFamily
+ * If a style uses a FontFamily, it may not look as expected when that
+ * font family is missing. Typically, we'd use linked resources for this,
+ * however, embedding fonts is really complex.
+ * @return the primary font family for this style, will return empty if
+ * the style does not require a font family.
+ */
+ QString primaryFontFamily() const;
+
void updateAlignSample();
// KoResource interface
public:
diff --git a/plugins/dockers/textproperties/TextPropertiesDock.cpp b/plugins/dockers/textproperties/TextPropertiesDock.cpp
index 21c51c5a39..19162a28cb 100644
--- a/plugins/dockers/textproperties/TextPropertiesDock.cpp
+++ b/plugins/dockers/textproperties/TextPropertiesDock.cpp
@@ -251,11 +251,11 @@ void TextPropertiesDock::slotTextPropertiesChanged()
}
#include <KoFontRegistry.h>
-QString TextPropertiesDock::wwsFontFamilyName(QString familyName)
+QString TextPropertiesDock::wwsFontFamilyName(QString familyName, bool returnEmptyWhenMissing)
{
std::optional<QString> name = KoFontRegistry::instance()->wwsNameByFamilyName(familyName);
if (!name) {
- return familyName;
+ return returnEmptyWhenMissing? QString(): familyName;
}
return name.value();
}
diff --git a/plugins/dockers/textproperties/TextPropertiesDock.h b/plugins/dockers/textproperties/TextPropertiesDock.h
index 96e2796b2b..756de33cad 100644
--- a/plugins/dockers/textproperties/TextPropertiesDock.h
+++ b/plugins/dockers/textproperties/TextPropertiesDock.h
@@ -31,7 +31,7 @@ public:
public Q_SLOTS:
void slotCanvasTextPropertiesChanged();
void slotTextPropertiesChanged();
- QString wwsFontFamilyName(QString familyName);
+ QString wwsFontFamilyName(QString familyName, bool returnEmptyWhenMissing = false);
QColor modalColorDialog(QColor oldColor);
diff --git a/plugins/dockers/textproperties/qml/TextProperties.qml b/plugins/dockers/textproperties/qml/TextProperties.qml
index 74981a2982..9c38362f6a 100644
--- a/plugins/dockers/textproperties/qml/TextProperties.qml
+++ b/plugins/dockers/textproperties/qml/TextProperties.qml
@@ -112,6 +112,21 @@ Rectangle {
elide: Text.ElideRight;
color: presetDelegate.highlighted? palette.highlightedText: palette.text;
}
+
+ Row {
+ anchors.bottom: parent.bottom;
+ anchors.left: parent.left;
+ anchors.right: parent.right;
+ ToolButton {
+ id: missingFamily;
+ visible: typeof presetDelegate.meta.primary_font_family !== 'undefined'?
+ presetDelegate.meta.primary_font_family !== ""
+ && mainWindow.wwsFontFamilyName(presetDelegate.meta.primary_font_family, true) === "": false;
+ icon.source: palette.window.hslLightness < 0.5? "qrc:///16_light_warning.svg": "qrc:///16_dark_warning.svg";
+ icon.height: 8;
+ icon.width: 8;
+ }
+ }
}
background: Rectangle {
color: presetDelegate.highlighted? presetDelegate.palette.highlight: "transparent";