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 better timestamps to fontfamily resource, add special updateThumbnail check.
Wolthera van Hövell tot Westerflier51759ba1fd62
diff --git a/libs/flake/resources/KoFontFamily.cpp b/libs/flake/resources/KoFontFamily.cppindex 33c3e385e8..4486d62a57 100644--- a/libs/flake/resources/KoFontFamily.cpp+++ b/libs/flake/resources/KoFontFamily.cpp@@ -25,6 +25,7 @@ const QString COLOR_CLRV1 = "color_clrv1";const QString COLOR_SVG = "color_svg";const QString SAMPLE_STRING = "sample_string";const QString SAMPLE_SVG = "sample_svg";+const QString LAST_MODIFIED = "last_modified";struct KoFontFamily::Private {};@@ -99,6 +100,8 @@ KoFontFamily::KoFontFamily(KoFontFamilyWWSRepresentation representation)addMetaData(LOCALIZED_TYPOGRAPHIC_NAME, localeHashtoVariantMap(representation.localizedTypographicFamily));addMetaData(LOCALIZED_TYPOGRAPHIC_STYLE, localeHashtoVariantMap(representation.localizedTypographicStyles));+ addMetaData(LAST_MODIFIED, representation.lastModified);+QMap<QString, QVariant> samples;Q_FOREACH(const QString key, representation.sampleStrings.keys()) {samples.insert(key, QVariant::fromValue(representation.sampleStrings.value(key)));@@ -254,3 +257,8 @@ QList<KoSvgText::FontFamilyStyleInfo> KoFontFamily::styles() const}return converted;}++QDateTime KoFontFamily::lastModified() const+{+ return metadata().value(LAST_MODIFIED).toDateTime();+}diff --git a/libs/flake/resources/KoFontFamily.h b/libs/flake/resources/KoFontFamily.hindex df440b57d0..64454ed532 100644--- a/libs/flake/resources/KoFontFamily.h+++ b/libs/flake/resources/KoFontFamily.h@@ -55,6 +55,8 @@ public:QList<KoSvgText::FontFamilyAxis> axes() const;QList<KoSvgText::FontFamilyStyleInfo> styles() const;+ QDateTime lastModified() const;+private:struct Private;QScopedPointer<Private> d;diff --git a/libs/flake/resources/KoFontStorage.cpp b/libs/flake/resources/KoFontStorage.cppindex 12018d5264..97de49fd1c 100644--- a/libs/flake/resources/KoFontStorage.cpp+++ b/libs/flake/resources/KoFontStorage.cpp@@ -52,7 +52,7 @@ public:}QDateTime lastModified() const override {- return QDateTime::fromMSecsSinceEpoch(0);+ return m_currentResource->lastModified();}bool hasNext() const override {@@ -68,7 +68,6 @@ public:void next() override {KoFontFamilyWWSRepresentation rep = m_representationIterator->next();m_currentResource = KoFontFamilySP (new KoFontFamily(rep));- m_currentResource->updateThumbnail();}QString url() const override {@@ -133,7 +132,8 @@ QString KoFontStorage::resourceMd5(const QString &url)bool KoFontStorage::supportsVersioning() const{- return false;+ // Even though it doesn't make sense, this needs to support versioning, otherwise the thumbnail is never updated...+ return true;}QSharedPointer<KisResourceStorage::ResourceIterator> KoFontStorage::resources(const QString &resourceType)@@ -153,6 +153,7 @@ bool KoFontStorage::isValid() constbool KoFontStorage::loadVersionedResource(KoResourceSP resource){- Q_UNUSED(resource);- return false;+ //Q_UNUSED(resource);+ resource->updateThumbnail();+ return true;}diff --git a/libs/flake/text/KoFFWWSConverter.cpp b/libs/flake/text/KoFFWWSConverter.cppindex 35de609087..cd73d1faa0 100644--- a/libs/flake/text/KoFFWWSConverter.cpp+++ b/libs/flake/text/KoFFWWSConverter.cpp@@ -59,6 +59,7 @@ struct FontFamilyNode {QList<QLocale> supportedLanguages;QStringList otherFiles;+ QDateTime lastModified;QHash<QLocale, QString> localizedFontFamilies;QHash<QLocale, QString> localizedFontStyle;@@ -258,6 +259,7 @@ bool KoFFWWSConverter::addFontFromFile(const QString &filename, const int index,fontFamily.fontFamily = face->family_name;fontFamily.fontStyle = face->style_name;+ fontFamily.lastModified = QFileInfo(fontFamily.fileName).lastModified();FontFamilyNode typographicFamily;FontFamilyNode wwsFamily;bool isWWSFamilyWithoutName = false;@@ -748,6 +750,9 @@ void KoFFWWSConverter::sortIntoWWSFamilies()wwsChild->otherFiles.append(font->fileName);wwsChild->otherFiles.append(font->otherFiles);}+ if (wwsChild->lastModified < font->lastModified) {+ wwsChild->lastModified = font->lastModified;+ }break;} else {continue;@@ -787,6 +792,10 @@ KoFontFamilyWWSRepresentation createRepresentation(KisForest<FontFamilyNode>::chfor (auto subFamily = childBegin(wws); subFamily != childEnd(wws); subFamily++) {KoSvgText::FontFamilyStyleInfo style;+ if (subFamily == childBegin(wws)+ || representation.lastModified < subFamily->lastModified) {+ representation.lastModified = subFamily->lastModified;+ }representation.sampleStrings.insert(subFamily->sampleStrings);Q_FOREACH(const QLocale &locale, subFamily->supportedLanguages) {if (!representation.supportedLanguages.contains(locale)) {diff --git a/libs/flake/text/KoFFWWSConverter.h b/libs/flake/text/KoFFWWSConverter.hindex d83f16f790..7b6165017a 100644--- a/libs/flake/text/KoFFWWSConverter.h+++ b/libs/flake/text/KoFFWWSConverter.h@@ -12,6 +12,7 @@#include <KoSvgText.h>#include <QLocale>+#include <QDateTime>/// This struct represents a CSS-compatible font family, containing all/// sorts of info useful for the GUI.@@ -23,6 +24,8 @@ struct KoFontFamilyWWSRepresentation {QHash<QLocale, QString> localizedTypographicFamily;QHash<QLocale, QString> localizedTypographicStyles;+ QDateTime lastModified; ///< Value of the most recently modified font family. Used for updates.+QHash<QString, QString> sampleStrings; /// sample string used to generate the preview;QList<QLocale> supportedLanguages;diff --git a/libs/resources/KisResourceCacheDb.cpp b/libs/resources/KisResourceCacheDb.cppindex a6f7b2a230..377cc94361 100644--- a/libs/resources/KisResourceCacheDb.cpp+++ b/libs/resources/KisResourceCacheDb.cpp@@ -1073,6 +1073,13 @@ bool KisResourceCacheDb::addResources(KisResourceStorageSP storage, QString resoif (resource && resource->valid()) {resource->setVersion(verIt->guessedVersion());resource->setMD5Sum(storage->resourceMd5(verIt->url()));+ if (resourceType == ResourceType::FontFamilies) {+ // because the iterator shouldn't be updating the thumbnail, but we still need a thumbnail+ // before adding to the resource db, we're updating the thumbnail for font families here.+ // arguably we could replace this resource check by adding a "synthesized thumbnail" check,+ // so this could be generalized for other resources like layer styles.+ resource->updateThumbnail();+ }if (resourceId < 0) {if (addResource(storage, iter->lastModified(), resource, iter->type())) {