QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
|
Manages available fonts and font installation for a QGIS instance. More...
#include <qgsfontmanager.h>
Signals | |
void | fontDownloaded (const QStringList &families, const QString &licenseDetails) |
Emitted when a font has downloaded and been locally loaded. More... | |
void | fontDownloadErrorOccurred (const QUrl &url, const QString &identifier, const QString &error) |
Emitted when an error occurs during font downloading. More... | |
Public Member Functions | |
QgsFontManager (QObject *parent=nullptr) | |
Constructor for QgsFontManager, with the specified parent object. More... | |
void | addFontFamilyReplacement (const QString &original, const QString &replacement) |
Adds a new font replacement from the original font family to a replacement font family. More... | |
void | addUserFontDirectory (const QString &directory) |
Adds a directory to use for user fonts. More... | |
void | downloadAndInstallFont (const QUrl &url, const QString &identifier=QString()) |
Downloads a font and installs in the user's profile/fonts directory as an application font. More... | |
void | enableFontDownloadsForSession () |
Enables font downloads the the current QGIS session. More... | |
QMap< QString, QString > | fontFamilyReplacements () const |
Returns the map of automatic font family replacements. More... | |
bool | installFontsFromData (const QByteArray &data, QString &errorMessage, QStringList &families, QString &licenseDetails, const QString &filename=QString()) |
Installs local user fonts from the specified raw data. More... | |
void | installUserFonts () |
Installs user fonts from the profile/fonts directory as application fonts. More... | |
QString | processFontFamilyName (const QString &name) const |
Processes a font family name, applying any matching fontFamilyReplacements() to the name. More... | |
bool | removeUserFont (const QString &path) |
Removes the user font at the specified path. More... | |
void | setFontFamilyReplacements (const QMap< QString, QString > &replacements) |
Sets the map of automatic font family replacements. More... | |
bool | tryToDownloadFontFamily (const QString &family, QString &matchedFamily) |
Tries to download and install the specified font family. More... | |
QString | urlForFontDownload (const QString &family, QString &matchedFamily) const |
Returns the URL at which the font family can be downloaded. More... | |
QMap< QString, QStringList > | userFontToFamilyMap () const |
Returns the mapping of installed user fonts to font families. More... | |
Static Public Attributes | |
static const QgsSettingsEntryBool * | settingsDownloadMissingFonts = new QgsSettingsEntryBool( QStringLiteral( "downloadMissingFonts" ), QgsSettingsTree::sTreeFonts, true, QStringLiteral( "Automatically download missing fonts whenever possible" ) ) |
Settings entry for font family replacements. More... | |
static const QgsSettingsEntryStringList * | settingsFontFamilyReplacements = new QgsSettingsEntryStringList( QStringLiteral( "fontFamilyReplacements" ), QgsSettingsTree::sTreeFonts, QStringList(), QStringLiteral( "Automatic font family replacements" ) ) |
Settings entry for font family replacements. More... | |
Manages available fonts and font installation for a QGIS instance.
Definition at line 37 of file qgsfontmanager.h.
|
explicit |
Constructor for QgsFontManager, with the specified parent object.
Definition at line 35 of file qgsfontmanager.cpp.
void QgsFontManager::addFontFamilyReplacement | ( | const QString & | original, |
const QString & | replacement | ||
) |
Adds a new font replacement from the original font family to a replacement font family.
This is used to transparently map an original font family to an alternative font family, e.g. to permit graceful handling of opening projects which reference fonts which are not available on the system.
The replacement map is stored locally and persists across QGIS sessions.
If replacement is an empty string then any existing mapping for the original family will be removed.
Definition at line 57 of file qgsfontmanager.cpp.
void QgsFontManager::addUserFontDirectory | ( | const QString & | directory | ) |
Adds a directory to use for user fonts.
This directory will be scanned for any TTF or OTF font files, which will automatically be added and made available for use in the QGIS session.
Additionally, if this is the first user font directory added, any fonts downloaded via downloadAndInstallFont() will be installed into this directory.
Definition at line 1125 of file qgsfontmanager.cpp.
void QgsFontManager::downloadAndInstallFont | ( | const QUrl & | url, |
const QString & | identifier = QString() |
||
) |
Downloads a font and installs in the user's profile/fonts directory as an application font.
The download will proceed in a background task.
The optional identifier string can be used to specify a user-friendly name for the download tasks, e.g. the font family name if known.
Definition at line 953 of file qgsfontmanager.cpp.
void QgsFontManager::enableFontDownloadsForSession | ( | ) |
Enables font downloads the the current QGIS session.
Definition at line 183 of file qgsfontmanager.cpp.
|
signal |
Emitted when a font has downloaded and been locally loaded.
The families list specifies the font families contained in the downloaded font.
If found, the licenseDetails string will be populated with corresponding font license details.
|
signal |
Emitted when an error occurs during font downloading.
QMap< QString, QString > QgsFontManager::fontFamilyReplacements | ( | ) | const |
Returns the map of automatic font family replacements.
This map is used to transparently map an original font family to an alternative font family, e.g. to permit graceful handling of opening projects which reference fonts which are not available on the system.
The map keys are the original font family names, and the values are the alternative replacement family to use for the font.
Definition at line 51 of file qgsfontmanager.cpp.
bool QgsFontManager::installFontsFromData | ( | const QByteArray & | data, |
QString & | errorMessage, | ||
QStringList & | families, | ||
QString & | licenseDetails, | ||
const QString & | filename = QString() |
||
) |
Installs local user fonts from the specified raw data.
The data array may correspond to the contents of a TTF or OTF font file, or a zipped archive of font files.
data | raw font data or zipped font data |
errorMessage | will be set to a descriptive error message if the installation fails |
families | will be populated with a list of font families installed from the data |
licenseDetails | will be populated with font license details, if found |
filename | filename hint for destination file. Will be ignored for archived content (e.g. zip file data) |
true
if installation was successful. Definition at line 998 of file qgsfontmanager.cpp.
void QgsFontManager::installUserFonts | ( | ) |
Installs user fonts from the profile/fonts directory as application fonts.
Definition at line 102 of file qgsfontmanager.cpp.
QString QgsFontManager::processFontFamilyName | ( | const QString & | name | ) | const |
Processes a font family name, applying any matching fontFamilyReplacements() to the name.
Definition at line 84 of file qgsfontmanager.cpp.
bool QgsFontManager::removeUserFont | ( | const QString & | path | ) |
Removes the user font at the specified path.
Definition at line 1150 of file qgsfontmanager.cpp.
void QgsFontManager::setFontFamilyReplacements | ( | const QMap< QString, QString > & | replacements | ) |
Sets the map of automatic font family replacements.
This map is used to transparently map an original font family to an alternative font family, e.g. to permit graceful handling of opening projects which reference fonts which are not available on the system.
The map keys are the original font family names, and the values are the alternative replacement family to use for the font.
The replacement map is stored locally and persists across QGIS sessions.
Definition at line 73 of file qgsfontmanager.cpp.
bool QgsFontManager::tryToDownloadFontFamily | ( | const QString & | family, |
QString & | matchedFamily | ||
) |
Tries to download and install the specified font family.
This method will attempt to download missing fonts, if the font download URL is known and the font is freely licensed.
Returns true
if a download link for the family is known and the download has commenced, or false
if the family is not known and cannot be automatically downloaded.
The actual download operation occurs in a background task, and this method returns immediately. Connect to fontDownloaded() in order to respond when the font is installed and available for use.
family | input font family name to try to match to known fonts |
matchedFamily | will be set to found font family if a match was successful |
true
if match was successful and the download will occur Definition at line 143 of file qgsfontmanager.cpp.
QString QgsFontManager::urlForFontDownload | ( | const QString & | family, |
QString & | matchedFamily | ||
) | const |
Returns the URL at which the font family can be downloaded.
This method relies on a hardcoded list of available freely licensed fonts, and will return an empty string for any font families not present in this list.
family | input font family name to try to match to known fonts |
matchedFamily | will be set to found font family if a match was successful |
Definition at line 201 of file qgsfontmanager.cpp.
QMap< QString, QStringList > QgsFontManager::userFontToFamilyMap | ( | ) | const |
Returns the mapping of installed user fonts to font families.
The map keys are the file names, the values are a list of families provided by the file.
Definition at line 1144 of file qgsfontmanager.cpp.
|
static |
Settings entry for font family replacements.
Definition at line 48 of file qgsfontmanager.h.
|
static |
Settings entry for font family replacements.
Definition at line 45 of file qgsfontmanager.h.