QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsfontutils.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsfontutils.h
3 ---------------------
4 begin : June 5, 2013
5 copyright : (C) 2013 by Larry Shaffer
6 email : larrys at dakotacarto 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 QGSFONTUTILS_H
17#define QGSFONTUTILS_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
21
22#include <QDomElement>
23#include <QFont>
24#include <QString>
25
26class QMimeData;
27
33class CORE_EXPORT QgsFontUtils
34{
35 public:
36
41 static bool fontMatchOnSystem( const QFont &f );
42
49 static bool fontFamilyOnSystem( const QString &family );
50
57 static bool fontFamilyHasStyle( const QString &family, const QString &style );
58
70 static QString resolveFontStyleName( const QFont &font );
71
79 static bool fontFamilyMatchOnSystem( const QString &family, QString *chosen = nullptr, bool *match = nullptr );
80
89 static bool updateFontViaStyle( QFont &f, const QString &fontstyle, bool fallback = false );
90
94 static QString standardTestFontFamily();
95
102 static bool loadStandardTestFonts( const QStringList &loadstyles );
103
110 static QFont getStandardTestFont( const QString &style = "Roman", int pointsize = 12 );
111
120 static QDomElement toXmlElement( const QFont &font, QDomDocument &document, const QString &elementName );
121
131 static bool setFromXmlElement( QFont &font, const QDomElement &element );
132
143 static bool setFromXmlChildNode( QFont &font, const QDomElement &element, const QString &childNode );
144
150 static QMimeData *toMimeData( const QFont &font ) SIP_FACTORY;
151
157 static QFont fromMimeData( const QMimeData *data, bool *ok SIP_OUT = nullptr );
158
165 static QString translateNamedStyle( const QString &namedStyle );
166
173 static QString untranslateNamedStyle( const QString &namedStyle );
174
184 static QString asCSS( const QFont &font, double pointToPixelMultiplier = 1.0 );
185
190 static void addRecentFontFamily( const QString &family );
191
196 static QStringList recentFontFamilies();
197
205 static void setFontFamily( QFont &font, const QString &family );
206
214 static QFont createFont( const QString &family, int pointSize = -1, int weight = -1, bool italic = false );
215};
216
217// clazy:excludeall=qstring-allocations
218
219#endif // QGSFONTUTILS_H
Contains utility functions for working with fonts.
static QString resolveFontStyleName(const QFont &font)
Attempts to resolve the style name corresponding to the specified font object.
static QString asCSS(const QFont &font, double pointToPixelMultiplier=1.0)
Returns a CSS string representing the specified font as closely as possible.
static QString translateNamedStyle(const QString &namedStyle)
Returns the localized named style of a font, if such a translation is available.
static QString untranslateNamedStyle(const QString &namedStyle)
Returns the english named style of a font, if possible.
static bool setFromXmlElement(QFont &font, const QDomElement &element)
Sets the properties of a font to match the properties stored in an XML element.
static bool setFromXmlChildNode(QFont &font, const QDomElement &element, const QString &childNode)
Sets the properties of a font to match the properties stored in an XML child node.
static QFont createFont(const QString &family, int pointSize=-1, int weight=-1, bool italic=false)
Creates a font with the specified family.
static QMimeData * toMimeData(const QFont &font)
Returns new mime data representing the specified font settings.
static bool fontFamilyMatchOnSystem(const QString &family, QString *chosen=nullptr, bool *match=nullptr)
Check whether font family is on system.
static bool fontFamilyOnSystem(const QString &family)
Check whether font family is on system in a quick manner, which does not compare [foundry].
static bool updateFontViaStyle(QFont &f, const QString &fontstyle, bool fallback=false)
Updates font with named style and retain all font properties.
static bool fontMatchOnSystem(const QFont &f)
Check whether exact font is on system.
static bool loadStandardTestFonts(const QStringList &loadstyles)
Loads standard test fonts from filesystem or qrc resource.
static QFont getStandardTestFont(const QString &style="Roman", int pointsize=12)
Gets standard test font with specific style.
static void setFontFamily(QFont &font, const QString &family)
Sets the family for a font object.
static QDomElement toXmlElement(const QFont &font, QDomDocument &document, const QString &elementName)
Returns a DOM element containing the properties of the font.
static void addRecentFontFamily(const QString &family)
Adds a font family to the list of recently used font families.
static QString standardTestFontFamily()
Gets standard test font family.
static QFont fromMimeData(const QMimeData *data, bool *ok=nullptr)
Attempts to parse the provided mime data as a QFont.
static bool fontFamilyHasStyle(const QString &family, const QString &style)
Check whether font family on system has specific style.
static QStringList recentFontFamilies()
Returns a list of recently used font families.
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_FACTORY
Definition qgis_sip.h:84