Class: QgsFontUtils¶
- class qgis.core.QgsFontUtils¶
- class qgis.core.QgsFontUtils(QgsFontUtils)
Bases:
sip.wrapper
Methods
Adds a font
family
to the list of recently used font families.Returns a CSS string representing the specified font as closely as possible.
Creates a font with the specified
family
.Check whether font family on system has specific style
Check whether font family is on system
Check whether font family is on system in a quick manner, which does not compare [foundry]
Check whether exact font is on system
Attempts to parse the provided mime
data
as a QFont.Gets standard test font with specific style
Loads standard test fonts from filesystem or qrc resource
Returns a list of recently used font families.
Attempts to resolve the style name corresponding to the specified
font
object.Sets the
family
for afont
object.Sets the properties of a font to match the properties stored in an XML child node.
Sets the properties of a font to match the properties stored in an XML element.
Gets standard test font family
Returns new mime data representing the specified
font
settings.Returns a DOM element containing the properties of the font.
Returns the localized named style of a font, if such a translation is available.
Returns the english named style of a font, if possible.
Updates font with named style and retain all font properties
- addRecentFontFamily(family: str)¶
Adds a font
family
to the list of recently used font families.See also
- Parameters:
family (str)
- asCSS(font: QFont, pointToPixelMultiplier: float = 1) str ¶
Returns a CSS string representing the specified font as closely as possible.
- Parameters:
font (QFont) – QFont to convert
pointToPixelMultiplier (float = 1) – 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)
- Return type:
str
- Returns:
partial CSS string, e.g., “font-family: Comic Sans; font-size: 12px;”
- createFont(family: str, pointSize: int = -1, weight: int = -1, italic: bool = False) QFont ¶
Creates a font with the specified
family
.Applies some workarounds for specific font quirks.
Added in version 3.34.
- Parameters:
family (str)
pointSize (int = -1)
weight (int = -1)
italic (bool = False)
- Return type:
QFont
- fontFamilyHasStyle(family: str, style: str) bool ¶
Check whether font family on system has specific style
- Parameters:
family (str) – The family to test
style (str) – The style to test for
- Return type:
bool
- Returns:
Whether family has style
- fontFamilyMatchOnSystem(family: str, chosen: str = '') Tuple[bool, bool] ¶
Check whether font family is on system
- Parameters:
family (str) – The family to test
chosen (str = '') – The actual family (possibly from different foundry) returned by system
match – Whether the family [foundry] returned by system is a match
- Return type:
Tuple[bool, bool]
- 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 (str) – The family to test
- Return type:
bool
- 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 (QFont) – The font to test for match
- Return type:
bool
- 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 toTrue
.See also
- Parameters:
data (QMimeData)
- Return type:
Tuple[QFont, bool]
- getStandardTestFont(style: str = '', pointsize: int = 12) QFont ¶
Gets standard test font with specific style
- Parameters:
style (str = '') – Style to load, e.g. Roman, Oblique, Bold, Bold Oblique
pointsize (int = 12) – Font point size to set
- Return type:
QFont
- Returns:
QFont
- loadStandardTestFonts(loadstyles: Iterable[str]) bool ¶
Loads standard test fonts from filesystem or qrc resource
- Parameters:
loadstyles (Iterable[str]) – List of styles to load, e.g. All, Roman, Oblique, Bold, Bold Oblique
- Return type:
bool
- 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)
- recentFontFamilies() List[str] ¶
Returns a list of recently used font families.
See also
- Return type:
List[str]
- resolveFontStyleName(font: QFont) str ¶
Attempts to resolve the style name corresponding to the specified
font
object.If a font has been modified by calling QFont.setBold or QFont.setItalic, then its QFont.styleName may return an empty string. This method attempts to determine the correct style name which corresponds to the font’s bold and italic settings.
Returns an empty string if a matching style name could not be found.
Added in version 3.26.
- Parameters:
font (QFont)
- Return type:
str
- setFontFamily(font: QFont, family: str)¶
Sets the
family
for afont
object.Applies some workarounds for specific font quirks.
Added in version 3.34.
- Parameters:
font (QFont)
family (str)
- 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 (QFont) – font to update
element (QDomElement) – DOM element
childNode (str) – name of child node
- Return type:
bool
- Returns:
True
if child node exists and properties were successfully read from node
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 (QFont) – font to update
element (QDomElement) – DOM element
- Return type:
bool
- Returns:
True
if properties were successfully read from element
See also
See also
- standardTestFontFamily() str ¶
Gets standard test font family
- Return type:
str
- toMimeData(font: QFont) QMimeData ¶
Returns new mime data representing the specified
font
settings. Caller takes responsibility for deleting the returned object.See also
- Parameters:
font (QFont)
- Return type:
QMimeData
- toXmlElement(font: QFont, document: QDomDocument, elementName: str) QDomElement ¶
Returns a DOM element containing the properties of the font.
- Parameters:
font (QFont) – font
document (QDomDocument) – DOM document
elementName (str) – name for DOM element
- Return type:
QDomElement
- Returns:
DOM element containing font settings
See also
- translateNamedStyle(namedStyle: str) str ¶
Returns the localized named style of a font, if such a translation is available.
- Parameters:
namedStyle (str) – a named style, i.e. “Bold”, “Italic”, etc
- Return type:
str
- Returns:
The localized named style
See also
- untranslateNamedStyle(namedStyle: str) str ¶
Returns the english named style of a font, if possible.
- Parameters:
namedStyle (str) – a localized named style, i.e. “Fett”, “Kursiv”, etc
- Return type:
str
- Returns:
The english named style
See also
- updateFontViaStyle(f: QFont, fontstyle: str, fallback: bool = False) bool ¶
Updates font with named style and retain all font properties
- Parameters:
f (QFont) – The font to update
fontstyle (str) – The style to try and switch the font to
fallback (bool = False) – If no matching fontstyle found for font, assign most similar or first style found to font
- Return type:
bool
- 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 )