Subgroup: Font
Class: QgsFontUtils¶
-
class
qgis.core.
QgsFontUtils
¶ Bases:
sip.wrapper
QgsFontUtils(QgsFontUtils)
Methods
addRecentFontFamily
Adds a font family
to the list of recently used font families.asCSS
Returns a CSS string representing the specified font as closely as possible. fontFamilyHasStyle
Check whether font family on system has specific style fontFamilyMatchOnSystem
Check whether font family is on system fontFamilyOnSystem
Check whether font family is on system in a quick manner, which does not compare [foundry] fontMatchOnSystem
Check whether exact font is on system fromMimeData
Attempts to parse the provided mime data
as a QFont.getStandardTestFont
Get standard test font with specific style loadStandardTestFonts
Loads standard test fonts from filesystem or qrc resource recentFontFamilies
Returns a list of recently used font families. setFromXmlChildNode
Sets the properties of a font to match the properties stored in an XML child node. setFromXmlElement
Sets the properties of a font to match the properties stored in an XML element. standardTestFontFamily
Get standard test font family toMimeData
Returns new mime data representing the specified font
settings.toXmlElement
Returns a DOM element containing the properties of the font. translateNamedStyle
Returns the localized named style of a font, if such a translation is available. untranslateNamedStyle
Returns the english named style of a font, if possible. updateFontViaStyle
Updates font with named style and retain all font properties Attributes
-
addRecentFontFamily
(family: str)¶ Adds a font
family
to the list of recently used font families.New in version 3.0.
See also
-
asCSS
(font: QFont, pointToPixelMultiplier: float = 1) → str¶ Returns a CSS string representing the specified font as closely as possible.
Parameters: - font – QFont to convert
- pointToPixelMultiplier – scaling 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;” New in version 2.16.
-
fontFamilyHasStyle
(family: str, style: str) → bool¶ Check whether font family on system has specific style
Parameters: - family – The family to test
- style – The style to test for
Returns: Whether family has style
New in version 2.1.
-
fontFamilyMatchOnSystem
(family: str, chosen: str = '') → Tuple[bool, bool]¶ Check whether font family is on system
Parameters: - family – The family to test
- chosen – The actual family (possibly from different foundry) returned by system
- match – Whether the family [foundry] returned by system is a match
Returns: Whether family was found on system
-
fontFamilyOnSystem
(family: str) → bool¶ Check whether font family is on system in a quick manner, which does not compare [foundry]
Parameters: family – The 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
-
fontMatchOnSystem
(f: QFont) → bool¶ Check whether exact font is on system
Parameters: f – The font to test for match
-
fromMimeData
(data: QMimeData) → Tuple[QFont, bool]¶ 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
New in version 3.0.
-
getStandardTestFont
(style: str = '', pointsize: int = 12) → QFont¶ Get standard test font with specific style
Parameters: - style – Style to load, e.g. Roman, Oblique, Bold, Bold Oblique
- pointsize – Font point size to set
Returns: QFont
New in version 2.1.
-
loadStandardTestFonts
(loadstyles: Iterable[str]) → bool¶ Loads standard test fonts from filesystem or qrc resource
Parameters: loadstyles – List 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)
New in version 2.1.
-
recentFontFamilies
() → List[str]¶ Returns a list of recently used font families.
See also
New in version 3.0.
-
setFromXmlChildNode
(font: QFont, element: QDomElement, childNode: str) → bool¶ 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: - font – font to update
- element – DOM element
- childNode – name of child node
Returns: true if child node exists and properties were successfully read from node
New in version 2.10.
See also
See also
-
setFromXmlElement
(font: QFont, element: QDomElement) → bool¶ 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: - font – font to update
- element – DOM element
Returns: true if properties were successfully read from element
New in version 2.10.
See also
See also
-
standardTestFontFamily
() → str¶ Get standard test font family
New in version 2.1.
-
toMimeData
(font: QFont) → QMimeData¶ Returns new mime data representing the specified
font
settings. Caller takes responsibility for deleting the returned object.See also
New in version 3.0.
-
toXmlElement
(font: QFont, document: QDomDocument, elementName: str) → QDomElement¶ Returns a DOM element containing the properties of the font.
Parameters: - font – font
- document – DOM document
- elementName – name for DOM element
Returns: DOM element containing font settings
New in version 2.10.
See also
-
translateNamedStyle
(namedStyle: str) → str¶ Returns the localized named style of a font, if such a translation is available.
Parameters: namedStyle – a named style, i.e. “Bold”, “Italic”, etc Returns: The localized named style New in version 2.12.
See also
-
untranslateNamedStyle
(namedStyle: str) → str¶ Returns the english named style of a font, if possible.
Parameters: namedStyle – a localized named style, i.e. “Fett”, “Kursiv”, etc Returns: The english named style New in version 2.12.
See also
-
updateFontViaStyle
(f: QFont, fontstyle: str, fallback: bool = False) → bool¶ Updates font with named style and retain all font properties
Parameters: - f – The font to update
- fontstyle – The style to try and switch the font to
- fallback – If 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 )
-