QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgsfontmanager.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsfontmanager.h
3 ------------------
4 Date : June 2022
5 Copyright : (C) 2022 Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSFONTMANAGER_H
17#define QGSFONTMANAGER_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
22#include <QObject>
23#include <QMap>
24#include <QReadWriteLock>
25#include <QSet>
26
37class CORE_EXPORT QgsFontManager : public QObject
38{
39 Q_OBJECT
40
41 public:
42
43#ifndef SIP_RUN
45 static const inline QgsSettingsEntryStringList settingsFontFamilyReplacements = QgsSettingsEntryStringList( QStringLiteral( "fontFamilyReplacements" ), QgsSettings::Prefix::FONTS, QStringList(), QStringLiteral( "Automatic font family replacements" ) );
46
48 static const inline QgsSettingsEntryBool settingsDownloadMissingFonts = QgsSettingsEntryBool( QStringLiteral( "downloadMissingFonts" ), QgsSettings::Prefix::FONTS, true, QStringLiteral( "Automatically download missing fonts whenever possible" ) );
49#endif
50
56 explicit QgsFontManager( QObject *parent SIP_TRANSFERTHIS = nullptr );
57
73 QMap< QString, QString > fontFamilyReplacements() const;
74
92 void addFontFamilyReplacement( const QString &original, const QString &replacement );
93
111 void setFontFamilyReplacements( const QMap< QString, QString> &replacements );
112
119 QString processFontFamilyName( const QString &name ) const;
120
126 void installUserFonts() SIP_SKIP;
127
149 bool tryToDownloadFontFamily( const QString &family, QString &matchedFamily SIP_OUT );
150
156 void enableFontDownloadsForSession();
157
168 QString urlForFontDownload( const QString &family, QString &matchedFamily SIP_OUT ) const;
169
181 void downloadAndInstallFont( const QUrl &url, const QString &identifier = QString() );
182
197 bool installFontsFromData( const QByteArray &data, QString &errorMessage SIP_OUT, QStringList &families SIP_OUT, QString &licenseDetails SIP_OUT, const QString &filename = QString() );
198
208 void addUserFontDirectory( const QString &directory );
209
215 QMap< QString, QStringList > userFontToFamilyMap() const;
216
220 bool removeUserFont( const QString &path );
221
222 signals:
223
234 void fontDownloaded( const QStringList &families, const QString &licenseDetails );
235
242 void fontDownloadErrorOccurred( const QUrl &url, const QString &identifier, const QString &error );
243
244 private:
245
246 QMap< QString, QString > mFamilyReplacements;
247 QMap< QString, QString > mLowerCaseFamilyReplacements;
248 QMap< QString, QStringList > mUserFontToFamilyMap;
249 QMap< QString, int > mUserFontToIdMap;
250 mutable QReadWriteLock mReplacementLock;
251 QStringList mUserFontDirectories;
252
253 bool mEnableFontDownloads = false;
254 QMap< QString, QString > mPendingFontDownloads;
255 QMap< QString, QString > mDeferredFontDownloads;
256
257 void storeFamilyReplacements();
258 void installFontsFromDirectory( const QString &dir );
259};
260
261#endif // QGSFONTMANAGER_H
Manages available fonts and font installation for a QGIS instance.
A boolean settings entry.
A string list settings entry.
static const char * FONTS
Definition: qgssettings.h:109
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_OUT
Definition: qgis_sip.h:58