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++
Fix issues with md5 sums and use std::optional in KoFontStorage related API.
Wolthera van Hövell tot Westerflier37fbba89733a
diff --git a/libs/flake/resources/KoFontStorage.cpp b/libs/flake/resources/KoFontStorage.cppindex 97de49fd1c..c28cbbbc36 100644--- a/libs/flake/resources/KoFontStorage.cpp+++ b/libs/flake/resources/KoFontStorage.cpp@@ -8,6 +8,7 @@#include "KoFontRegistry.h"#include "KisStaticInitializer.h"#include <KoMD5Generator.h>+#include <optional>KIS_DECLARE_STATIC_INITIALIZER {KisStoragePluginRegistry::instance()->addStoragePluginFactory(KisResourceStorage::StorageType::FontStorage, new KisStoragePluginFactory<KoFontStorage>());@@ -115,21 +116,15 @@ KoResourceSP KoFontStorage::resource(const QString &url)familyName.remove(0, prefix.size());}- bool found = false;- KoFontFamilyWWSRepresentation rep = KoFontRegistry::instance()->representationByFamilyName(familyName, &found);- if (found) {- fam.reset(new KoFontFamily(rep));+ std::optional<KoFontFamilyWWSRepresentation> rep = KoFontRegistry::instance()->representationByFamilyName(familyName);+ if (rep) {+ fam.reset(new KoFontFamily(rep.value()));fam->updateThumbnail();}return fam;}-QString KoFontStorage::resourceMd5(const QString &url)-{- return KoMD5Generator::generateHash(QString("fontregistery:"+url).toUtf8());-}-bool KoFontStorage::supportsVersioning() const{// Even though it doesn't make sense, this needs to support versioning, otherwise the thumbnail is never updated...diff --git a/libs/flake/resources/KoFontStorage.h b/libs/flake/resources/KoFontStorage.hindex 896560bf20..98b1025418 100644--- a/libs/flake/resources/KoFontStorage.h+++ b/libs/flake/resources/KoFontStorage.h@@ -18,7 +18,6 @@ public:KisResourceStorage::ResourceItem resourceItem(const QString &url) override;KoResourceSP resource(const QString &url) override;- QString resourceMd5(const QString &url) override;bool supportsVersioning() const override;QSharedPointer<KisResourceStorage::ResourceIterator> resources(const QString &resourceType) override;diff --git a/libs/flake/text/KoFFWWSConverter.cpp b/libs/flake/text/KoFFWWSConverter.cppindex 3ab0434488..92876ace40 100644--- a/libs/flake/text/KoFFWWSConverter.cpp+++ b/libs/flake/text/KoFFWWSConverter.cpp@@ -919,12 +919,8 @@ KisForest<FontFamilyNode>::composition_iterator searchNodes (KisForest<FontFamilreturn it;}-KoFontFamilyWWSRepresentation KoFFWWSConverter::representationByFamilyName(const QString &familyName, bool *found) const+std::optional<KoFontFamilyWWSRepresentation> KoFFWWSConverter::representationByFamilyName(const QString &familyName) const{- KoFontFamilyWWSRepresentation representation;- if (found) {- *found = false;- }for (auto typographic = d->fontFamilyCollection.childBegin(); typographic != d->fontFamilyCollection.childEnd(); typographic++) {auto counter = childBegin(typographic);counter++;@@ -932,15 +928,11 @@ KoFontFamilyWWSRepresentation KoFFWWSConverter::representationByFamilyName(constfor (auto wws = childBegin(typographic); wws != childEnd(typographic); wws++) {if (wws->fontFamily == familyName) {- representation = createRepresentation(wws, typographic, singleFamily);- if (found) {- *found = true;- }- return representation;+ return std::make_optional(createRepresentation(wws, typographic, singleFamily));}}}- return representation;+ return std::nullopt;}QString KoFFWWSConverter::wwsNameByFamilyName(const QString familyName, bool *found) constdiff --git a/libs/flake/text/KoFFWWSConverter.h b/libs/flake/text/KoFFWWSConverter.hindex a4c49be529..c8c44c7ea2 100644--- a/libs/flake/text/KoFFWWSConverter.h+++ b/libs/flake/text/KoFFWWSConverter.h@@ -14,6 +14,8 @@#include <QLocale>#include <QDateTime>+#include <optional>+/// This struct represents a CSS-compatible font family, containing all/// sorts of info useful for the GUI.struct KoFontFamilyWWSRepresentation {@@ -72,7 +74,7 @@ public:QList<KoFontFamilyWWSRepresentation> collectFamilies() const;/// Gets a single WWSFamily representation for a given CSS Family Name, used by KoFontStorage.- KoFontFamilyWWSRepresentation representationByFamilyName(const QString &familyName, bool *found = nullptr) const;+ std::optional<KoFontFamilyWWSRepresentation> representationByFamilyName(const QString &familyName) const;/// Used to find the closest corresponding resource when the family name doesn't match.QString wwsNameByFamilyName(const QString familyName, bool *found = nullptr) const;diff --git a/libs/flake/text/KoFontRegistry.cpp b/libs/flake/text/KoFontRegistry.cppindex 03522c96ae..ccdba96c34 100644--- a/libs/flake/text/KoFontRegistry.cpp+++ b/libs/flake/text/KoFontRegistry.cpp@@ -643,9 +643,9 @@ QList<KoFontFamilyWWSRepresentation> KoFontRegistry::collectRepresentations() coreturn d->converter()->collectFamilies();}-KoFontFamilyWWSRepresentation KoFontRegistry::representationByFamilyName(const QString &familyName, bool *found) const+std::optional<KoFontFamilyWWSRepresentation> KoFontRegistry::representationByFamilyName(const QString &familyName) const{- return d->converter()->representationByFamilyName(familyName, found);+ return d->converter()->representationByFamilyName(familyName);}QString KoFontRegistry::wwsNameByFamilyName(const QString familyName, bool *found) constdiff --git a/libs/flake/text/KoFontRegistry.h b/libs/flake/text/KoFontRegistry.hindex ea2bee8d12..33504746c8 100644--- a/libs/flake/text/KoFontRegistry.h+++ b/libs/flake/text/KoFontRegistry.h@@ -87,7 +87,7 @@ public:* @param found - bool to check for success.* @return the font family.*/- KoFontFamilyWWSRepresentation representationByFamilyName(const QString &familyName, bool *found = nullptr) const;+ std::optional<KoFontFamilyWWSRepresentation> representationByFamilyName(const QString &familyName) const;// Get the closest font family resource name for a given font family name, used by the selectors.QString wwsNameByFamilyName(const QString familyName, bool *found = nullptr) const;