QGIS API Documentation  3.4.15-Madeira (e83d02e274)
Static Public Member Functions | List of all members
QgsFontUtils Class Reference

#include <qgsfontutils.h>

Static Public Member Functions

static void addRecentFontFamily (const QString &family)
 Adds a font family to the list of recently used font families. More...
 
static QString asCSS (const QFont &font, double pointToPixelMultiplier=1.0)
 Returns a CSS string representing the specified font as closely as possible. More...
 
static bool fontFamilyHasStyle (const QString &family, const QString &style)
 Check whether font family on system has specific style. More...
 
static bool fontFamilyMatchOnSystem (const QString &family, QString *chosen=nullptr, bool *match=nullptr)
 Check whether font family is on system. More...
 
static bool fontFamilyOnSystem (const QString &family)
 Check whether font family is on system in a quick manner, which does not compare [foundry]. More...
 
static bool fontMatchOnSystem (const QFont &f)
 Check whether exact font is on system. More...
 
static QFont fromMimeData (const QMimeData *data, bool *ok=nullptr)
 Attempts to parse the provided mime data as a QFont. More...
 
static QFont getStandardTestFont (const QString &style="Roman", int pointsize=12)
 Gets standard test font with specific style. More...
 
static bool loadStandardTestFonts (const QStringList &loadstyles)
 Loads standard test fonts from filesystem or qrc resource. More...
 
static QStringList recentFontFamilies ()
 Returns a list of recently used font families. More...
 
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. More...
 
static bool setFromXmlElement (QFont &font, const QDomElement &element)
 Sets the properties of a font to match the properties stored in an XML element. More...
 
static QString standardTestFontFamily ()
 Gets standard test font family. More...
 
static QMimeData * toMimeData (const QFont &font)
 Returns new mime data representing the specified font settings. More...
 
static QDomElement toXmlElement (const QFont &font, QDomDocument &document, const QString &elementName)
 Returns a DOM element containing the properties of the font. More...
 
static QString translateNamedStyle (const QString &namedStyle)
 Returns the localized named style of a font, if such a translation is available. More...
 
static QString untranslateNamedStyle (const QString &namedStyle)
 Returns the english named style of a font, if possible. More...
 
static bool updateFontViaStyle (QFont &f, const QString &fontstyle, bool fallback=false)
 Updates font with named style and retain all font properties. More...
 

Detailed Description

Definition at line 32 of file qgsfontutils.h.

Member Function Documentation

void QgsFontUtils::addRecentFontFamily ( const QString &  family)
static

Adds a font family to the list of recently used font families.

See also
recentFontFamilies()
Since
QGIS 3.0

Definition at line 519 of file qgsfontutils.cpp.

QString QgsFontUtils::asCSS ( const QFont &  font,
double  pointToPixelMultiplier = 1.0 
)
static

Returns a CSS string representing the specified font as closely as possible.

Parameters
fontQFont to convert
pointToPixelMultiplierscaling factor to apply to convert point sizes to pixel font sizes. The CSS returned by this function will always use pixels for font sizes, so this parameter should be set to a suitable value to convert point sizes to pixels (e.g., taking into account destination DPI)
Returns
partial CSS string, e.g., "font-family: Comic Sans; font-size: 12px;"
Since
QGIS 2.16

Definition at line 457 of file qgsfontutils.cpp.

bool QgsFontUtils::fontFamilyHasStyle ( const QString &  family,
const QString &  style 
)
static

Check whether font family on system has specific style.

Parameters
familyThe family to test
styleThe style to test for
Returns
Whether family has style
Since
QGIS 2.1

Definition at line 44 of file qgsfontutils.cpp.

bool QgsFontUtils::fontFamilyMatchOnSystem ( const QString &  family,
QString *  chosen = nullptr,
bool *  match = nullptr 
)
static

Check whether font family is on system.

Parameters
familyThe family to test
chosenThe actual family (possibly from different foundry) returned by system
matchWhether the family [foundry] returned by system is a match
Returns
Whether family was found on system

Definition at line 68 of file qgsfontutils.cpp.

bool QgsFontUtils::fontFamilyOnSystem ( const QString &  family)
static

Check whether font family is on system in a quick manner, which does not compare [foundry].

Parameters
familyThe family to test
Returns
Whether family was found on system
Note
This is good for use in loops of large lists, e.g. registering many features for labeling

Definition at line 37 of file qgsfontutils.cpp.

bool QgsFontUtils::fontMatchOnSystem ( const QFont &  f)
static

Check whether exact font is on system.

Parameters
fThe font to test for match

Definition at line 31 of file qgsfontutils.cpp.

QFont QgsFontUtils::fromMimeData ( const QMimeData *  data,
bool *  ok = nullptr 
)
static

Attempts to parse the provided mime data as a QFont.

If data can be parsed as a QFont, ok will be set to true.

See also
toMimeData()
Since
QGIS 3.0

Definition at line 377 of file qgsfontutils.cpp.

QFont QgsFontUtils::getStandardTestFont ( const QString &  style = "Roman",
int  pointsize = 12 
)
static

Gets standard test font with specific style.

Parameters
styleStyle to load, e.g. Roman, Oblique, Bold, Bold Oblique
pointsizeFont point size to set
Returns
QFont
Since
QGIS 2.1

Definition at line 285 of file qgsfontutils.cpp.

bool QgsFontUtils::loadStandardTestFonts ( const QStringList &  loadstyles)
static

Loads standard test fonts from filesystem or qrc resource.

Parameters
loadstylesList of styles to load, e.g. All, Roman, Oblique, Bold, Bold Oblique
Returns
Whether any font was loaded
Note
Done by default on debug app/server startup to ensure fonts available for unit tests (Roman and Bold)
Since
QGIS 2.1

Definition at line 223 of file qgsfontutils.cpp.

QStringList QgsFontUtils::recentFontFamilies ( )
static

Returns a list of recently used font families.

See also
addRecentFontFamily()
Since
QGIS 3.0

Definition at line 541 of file qgsfontutils.cpp.

bool QgsFontUtils::setFromXmlChildNode ( QFont &  font,
const QDomElement &  element,
const QString &  childNode 
)
static

Sets the properties of a font to match the properties stored in an XML child node.

Calling this will overwrite the current properties of the font.

Parameters
fontfont to update
elementDOM element
childNodename of child node
Returns
true if child node exists and properties were successfully read from node
See also
setFromXmlElement
toXmlElement
Since
QGIS 2.10

Definition at line 346 of file qgsfontutils.cpp.

bool QgsFontUtils::setFromXmlElement ( QFont &  font,
const QDomElement &  element 
)
static

Sets the properties of a font to match the properties stored in an XML element.

Calling this will overwrite the current properties of the font.

Parameters
fontfont to update
elementDOM element
Returns
true if properties were successfully read from element
See also
toXmlElement
setFromXmlChildNode
Since
QGIS 2.10

Definition at line 330 of file qgsfontutils.cpp.

QString QgsFontUtils::standardTestFontFamily ( )
static

Gets standard test font family.

Since
QGIS 2.1

Definition at line 218 of file qgsfontutils.cpp.

QMimeData * QgsFontUtils::toMimeData ( const QFont &  font)
static

Returns new mime data representing the specified font settings.

Caller takes responsibility for deleting the returned object.

See also
fromMimeData()
Since
QGIS 3.0

Definition at line 365 of file qgsfontutils.cpp.

QDomElement QgsFontUtils::toXmlElement ( const QFont &  font,
QDomDocument &  document,
const QString &  elementName 
)
static

Returns a DOM element containing the properties of the font.

Parameters
fontfont
documentDOM document
elementNamename for DOM element
Returns
DOM element containing font settings
See also
setFromXmlElement
Since
QGIS 2.10

Definition at line 322 of file qgsfontutils.cpp.

QString QgsFontUtils::translateNamedStyle ( const QString &  namedStyle)
static

Returns the localized named style of a font, if such a translation is available.

Parameters
namedStylea named style, i.e. "Bold", "Italic", etc
Returns
The localized named style
See also
untranslateNamedStyle
Since
QGIS 2.12

Definition at line 429 of file qgsfontutils.cpp.

QString QgsFontUtils::untranslateNamedStyle ( const QString &  namedStyle)
static

Returns the english named style of a font, if possible.

Parameters
namedStylea localized named style, i.e. "Fett", "Kursiv", etc
Returns
The english named style
See also
translateNamedStyle
Since
QGIS 2.12

Definition at line 439 of file qgsfontutils.cpp.

bool QgsFontUtils::updateFontViaStyle ( QFont &  f,
const QString &  fontstyle,
bool  fallback = false 
)
static

Updates font with named style and retain all font properties.

Parameters
fThe font to update
fontstyleThe style to try and switch the font to
fallbackIf no matching fontstyle found for font, assign most similar or first style found to font
Returns
Whether the font was updated (also returns true if the requested style matches font's current style)
Note
This is a more featured replacement for a Qt 4.8+ function: void QFont::setStyleName ( const QString & styleName )

Definition at line 121 of file qgsfontutils.cpp.


The documentation for this class was generated from the following files: