Krita Source Code Documentation
Loading...
Searching...
No Matches
KoFontStorage.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2024 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6#include "KoFontStorage.h"
7#include "KoFontFamily.h"
8#include "KoFontRegistry.h"
10#include <KoMD5Generator.h>
11#include <optional>
12
15}
16
18{
19public:
20
21 FontTagIterator(QVector<KisTagSP> /*tags*/, const QString &resourceType)
22 : m_resourceType(resourceType)
23 {
24 }
25
26 bool hasNext() const override
27 {
28 return false;
29 }
30
31 void next() override
32 {
33 }
34
35 KisTagSP tag() const override
36 {
37 return nullptr;
38 }
39
40private:
42};
43
45{
46public:
47 FontIterator(const QString resourceType): m_isLoaded(false), m_resourceType(resourceType) {
48
49 }
50
51 QString type() const override {
53 }
54
55 QDateTime lastModified() const override {
56 return m_currentResource->lastModified();
57 }
58
59 bool hasNext() const override {
60 if (m_resourceType != ResourceType::FontFamilies) return false;
61 if (!m_isLoaded) {
62 const_cast<FontIterator*>(this)->m_representationIterator.reset(new QListIterator<KoFontFamilyWWSRepresentation>(KoFontRegistry::instance()->collectRepresentations()));
63 const_cast<FontIterator*>(this)->m_isLoaded = true;
64 }
65
67 }
68
73
74 QString url() const override {
75 if (m_currentResource.isNull()) {
76 return QString();
77 }
78 return m_currentResource->filename();
79 }
80
81 KoResourceSP resourceImpl() const override {
82 m_currentResource->updateThumbnail();
83 return m_currentResource;
84 }
85private:
89 QScopedPointer<QListIterator<KoFontFamilyWWSRepresentation>> m_representationIterator;
90};
91
92KoFontStorage::KoFontStorage(const QString &location)
93 : KisStoragePlugin(location)
94{
95}
96
100
102{
105 item.url = url;
106 item.folder = location();
107 item.lastModified = QDateTime::fromMSecsSinceEpoch(0);
108 return item;
109}
110
112{
113 KoFontFamilySP fam;
114 QString familyName = url;
115 QString prefix (ResourceType::FontFamilies+"/");
116 if (familyName.startsWith(prefix)) {
117 familyName.remove(0, prefix.size());
118 }
119
120 std::optional<KoFontFamilyWWSRepresentation> rep = KoFontRegistry::instance()->representationByFamilyName(familyName);
121 if (rep) {
122 fam.reset(new KoFontFamily(rep.value()));
123 fam->updateThumbnail();
124 }
125
126 return fam;
127}
128
130{
131 // Even though it doesn't make sense, this needs to support versioning, otherwise the thumbnail is never updated...
132 return true;
133}
134
139
144
146{
147 return true;
148}
149
151{
152 //Q_UNUSED(resource);
153 resource->updateThumbnail();
154 return true;
155}
QSharedPointer< KoFontFamily > KoFontFamilySP
KIS_DECLARE_STATIC_INITIALIZER
bool hasNext() const override
void next() override
The iterator is only valid if next() has been called at least once.
KoResourceSP resourceImpl() const override
This only loads the resource when called.
QString m_resourceType
QScopedPointer< QListIterator< KoFontFamilyWWSRepresentation > > m_representationIterator
QString type() const override
KoFontFamilySP m_currentResource
QDateTime lastModified() const override
FontIterator(const QString resourceType)
QString url() const override
KisTagSP tag() const override
A tag object on which we can set properties and which we can save.
FontTagIterator(QVector< KisTagSP >, const QString &resourceType)
bool hasNext() const override
void next() override
The iterator is only valid if next() has been called at least once.
void addStoragePluginFactory(KisResourceStorage::StorageType storageType, KisStoragePluginFactoryBase *factory)
static KisStoragePluginRegistry * instance()
QString location() const
The KoFontFamily class Abstract representation of a Weight/Width/Slant font family,...
std::optional< KoFontFamilyWWSRepresentation > representationByFamilyName(const QString &familyName) const
representationByFamilyName This simplifies retrieving the representation for a given font family.
QList< KoFontFamilyWWSRepresentation > collectRepresentations() const
collectRepresentations
static KoFontRegistry * instance()
bool isValid() const override
bool loadVersionedResource(KoResourceSP resource) override
KoResourceSP resource(const QString &url) override
KoFontStorage(const QString &location="fontregistry")
KisResourceStorage::ResourceItem resourceItem(const QString &url) override
bool supportsVersioning() const override
virtual ~KoFontStorage()
QSharedPointer< KisResourceStorage::TagIterator > tags(const QString &resourceType) override
QSharedPointer< KisResourceStorage::ResourceIterator > resources(const QString &resourceType) override
const QString FontFamilies
A resource item is simply an entry in the storage,.