QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
|
Container for all settings relating to text rendering. More...
#include <qgstextformat.h>
Public Member Functions | |
QgsTextFormat () | |
Default constructor for QgsTextFormat. More... | |
QgsTextFormat (const QgsTextFormat &other) | |
Copy constructor. More... | |
~QgsTextFormat () | |
bool | allowHtmlFormatting () const |
Returns true if text should be treated as a HTML document and HTML tags should be used for formatting the rendered text. More... | |
QgsTextBackgroundSettings & | background () |
Returns a reference to the text background settings. More... | |
QgsTextBackgroundSettings | background () const |
Returns a reference to the text background settings. More... | |
QPainter::CompositionMode | blendMode () const |
Returns the blending mode used for drawing the text. More... | |
QgsTextBufferSettings & | buffer () |
Returns a reference to the text buffer settings. More... | |
QgsTextBufferSettings | buffer () const |
Returns a reference to the text buffer settings. More... | |
Qgis::Capitalization | capitalization () const |
Returns the text capitalization style. More... | |
QColor | color () const |
Returns the color that text will be rendered in. More... | |
bool | containsAdvancedEffects () const |
Returns true if any component of the font format requires advanced effects such as blend modes, which require output in raster formats to be fully respected. More... | |
QgsPropertyCollection & | dataDefinedProperties () |
Returns a reference to the format's property collection, used for data defined overrides. More... | |
const QgsPropertyCollection & | dataDefinedProperties () const |
Returns a reference to the format's property collection, used for data defined overrides. More... | |
QStringList | families () const |
Returns the list of font families to use when restoring the text format, in order of precedence. More... | |
QFont | font () const |
Returns the font used for rendering text. More... | |
bool | fontFound () const |
Returns true if the specified font was found on the system, or false if the font was not found and a replacement was used instead. More... | |
bool | forcedBold () const |
Returns true if the format is set to force a bold style. More... | |
bool | forcedItalic () const |
Returns true if the format is set to force an italic style. More... | |
bool | isValid () const |
Returns true if the format is valid. More... | |
double | lineHeight () const |
Returns the line height for text. More... | |
QgsUnitTypes::RenderUnit | lineHeightUnit () const |
Returns the units for the line height for text. More... | |
QgsTextMaskSettings & | mask () |
Returns a reference to the masking settings. More... | |
QgsTextMaskSettings | mask () const |
Returns a reference to the masking settings. More... | |
QString | namedStyle () const |
Returns the named style for the font used for rendering text (e.g., "bold"). More... | |
double | opacity () const |
Returns the text's opacity. More... | |
bool | operator!= (const QgsTextFormat &other) const |
QgsTextFormat & | operator= (const QgsTextFormat &other) |
bool | operator== (const QgsTextFormat &other) const |
Qgis::TextOrientation | orientation () const |
Returns the orientation of the text. More... | |
QColor | previewBackgroundColor () const |
Returns the background color for text previews. More... | |
void | readFromLayer (QgsVectorLayer *layer) |
Reads settings from a layer's custom properties (for QGIS 2.x projects). More... | |
void | readXml (const QDomElement &elem, const QgsReadWriteContext &context) |
Read settings from a DOM element. More... | |
QSet< QString > | referencedFields (const QgsRenderContext &context) const |
Returns all field names referenced by the configuration (e.g. More... | |
QString | resolvedFontFamily () const |
Returns the family for the resolved font, ie if the specified font was not found on the system this will return the name of the replacement font. More... | |
QFont | scaledFont (const QgsRenderContext &context, double scaleFactor=1.0, bool *isZeroSize=nullptr) const |
Returns a font with the size scaled to match the format's size settings (including units and map unit scale) for a specified render context. More... | |
void | setAllowHtmlFormatting (bool allow) |
Sets whether text should be treated as a HTML document and HTML tags should be used for formatting the rendered text. More... | |
void | setBackground (const QgsTextBackgroundSettings &backgroundSettings) |
Sets the text's background settings.q. More... | |
void | setBlendMode (QPainter::CompositionMode mode) |
Sets the blending mode used for drawing the text. More... | |
void | setBuffer (const QgsTextBufferSettings &bufferSettings) |
Sets the text's buffer settings. More... | |
void | setCapitalization (Qgis::Capitalization capitalization) |
Sets the text capitalization style. More... | |
void | setColor (const QColor &color) |
Sets the color that text will be rendered in. More... | |
void | setDataDefinedProperties (const QgsPropertyCollection &collection) |
Sets the format's property collection, used for data defined overrides. More... | |
void | setFamilies (const QStringList &families) |
Sets a list of font families to use for the text format, in order of precedence. More... | |
void | setFont (const QFont &font) |
Sets the font used for rendering text. More... | |
void | setForcedBold (bool forced) |
Sets whether the format is set to force a bold style. More... | |
void | setForcedItalic (bool forced) |
Sets whether the format is set to force an italic style. More... | |
void | setLineHeight (double height) |
Sets the line height for text. More... | |
void | setLineHeightUnit (QgsUnitTypes::RenderUnit unit) |
Sets the unit for the line height for text. More... | |
void | setMask (const QgsTextMaskSettings &maskSettings) |
Sets the text's masking settings. More... | |
void | setNamedStyle (const QString &style) |
Sets the named style for the font used for rendering text. More... | |
void | setOpacity (double opacity) |
Sets the text's opacity. More... | |
void | setOrientation (Qgis::TextOrientation orientation) |
Sets the orientation for the text. More... | |
void | setPreviewBackgroundColor (const QColor &color) |
Sets the background color that text will be rendered on for previews. More... | |
void | setShadow (const QgsTextShadowSettings &shadowSettings) |
Sets the text's drop shadow settings. More... | |
void | setSize (double size) |
Sets the size for rendered text. More... | |
void | setSizeMapUnitScale (const QgsMapUnitScale &scale) |
Sets the map unit scale object for the size. More... | |
void | setSizeUnit (QgsUnitTypes::RenderUnit unit) |
Sets the units for the size of rendered text. More... | |
void | setStretchFactor (int factor) |
Sets the text's stretch factor. More... | |
void | setValid () |
Sets the format to a valid state, without changing any of the default format settings. More... | |
QgsTextShadowSettings & | shadow () |
Returns a reference to the text drop shadow settings. More... | |
QgsTextShadowSettings | shadow () const |
Returns a reference to the text drop shadow settings. More... | |
double | size () const |
Returns the size for rendered text. More... | |
QgsMapUnitScale | sizeMapUnitScale () const |
Returns the map unit scale object for the size. More... | |
QgsUnitTypes::RenderUnit | sizeUnit () const |
Returns the units for the size of rendered text. More... | |
int | stretchFactor () const |
Returns the text's stretch factor. More... | |
QMimeData * | toMimeData () const |
Returns new mime data representing the text format settings. More... | |
QFont | toQFont () const |
Returns a QFont matching the relevant settings from this text format. More... | |
void | updateDataDefinedProperties (QgsRenderContext &context) |
Updates the format by evaluating current values of data defined properties. More... | |
QDomElement | writeXml (QDomDocument &doc, const QgsReadWriteContext &context) const |
Write settings into a DOM element. More... | |
Static Public Member Functions | |
static QgsTextFormat | fromMimeData (const QMimeData *data, bool *ok=nullptr) |
Attempts to parse the provided mime data as a QgsTextFormat. More... | |
static QgsTextFormat | fromQFont (const QFont &font) |
Returns a text format matching the settings from an input font. More... | |
static QPixmap | textFormatPreviewPixmap (const QgsTextFormat &format, QSize size, const QString &previewText=QString(), int padding=0) |
Returns a pixmap preview for a text format. More... | |
Container for all settings relating to text rendering.
Definition at line 40 of file qgstextformat.h.
QgsTextFormat::QgsTextFormat | ( | ) |
Default constructor for QgsTextFormat.
Creates a text format initially set to an invalid state (see isValid()).
Definition at line 34 of file qgstextformat.cpp.
QgsTextFormat::QgsTextFormat | ( | const QgsTextFormat & | other | ) |
Copy constructor.
other | source QgsTextFormat |
Definition at line 39 of file qgstextformat.cpp.
QgsTextFormat::~QgsTextFormat | ( | ) |
Definition at line 63 of file qgstextformat.cpp.
bool QgsTextFormat::allowHtmlFormatting | ( | ) | const |
Returns true
if text should be treated as a HTML document and HTML tags should be used for formatting the rendered text.
Definition at line 394 of file qgstextformat.cpp.
QgsTextBackgroundSettings & QgsTextFormat::background | ( | ) |
Returns a reference to the text background settings.
Definition at line 125 of file qgstextformat.cpp.
|
inline |
Returns a reference to the text background settings.
Definition at line 114 of file qgstextformat.h.
QPainter::CompositionMode QgsTextFormat::blendMode | ( | ) | const |
Returns the blending mode used for drawing the text.
Definition at line 331 of file qgstextformat.cpp.
QgsTextBufferSettings & QgsTextFormat::buffer | ( | ) |
Returns a reference to the text buffer settings.
Definition at line 113 of file qgstextformat.cpp.
|
inline |
Returns a reference to the text buffer settings.
Definition at line 95 of file qgstextformat.h.
Qgis::Capitalization QgsTextFormat::capitalization | ( | ) | const |
Returns the text capitalization style.
Definition at line 375 of file qgstextformat.cpp.
QColor QgsTextFormat::color | ( | ) | const |
Returns the color that text will be rendered in.
Definition at line 298 of file qgstextformat.cpp.
bool QgsTextFormat::containsAdvancedEffects | ( | ) | const |
Returns true
if any component of the font format requires advanced effects such as blend modes, which require output in raster formats to be fully respected.
Definition at line 843 of file qgstextformat.cpp.
QgsPropertyCollection & QgsTextFormat::dataDefinedProperties | ( | ) |
Returns a reference to the format's property collection, used for data defined overrides.
Definition at line 860 of file qgstextformat.cpp.
const QgsPropertyCollection & QgsTextFormat::dataDefinedProperties | ( | ) | const |
Returns a reference to the format's property collection, used for data defined overrides.
Definition at line 866 of file qgstextformat.cpp.
QStringList QgsTextFormat::families | ( | ) | const |
Returns the list of font families to use when restoring the text format, in order of precedence.
Definition at line 254 of file qgstextformat.cpp.
QFont QgsTextFormat::font | ( | ) | const |
Returns the font used for rendering text.
Note that the size of the font is not used, and size() should be called instead to determine the size of rendered text.
Definition at line 161 of file qgstextformat.cpp.
|
inline |
Returns true
if the specified font was found on the system, or false
if the font was not found and a replacement was used instead.
Definition at line 593 of file qgstextformat.h.
bool QgsTextFormat::forcedBold | ( | ) | const |
Returns true
if the format is set to force a bold style.
Definition at line 230 of file qgstextformat.cpp.
bool QgsTextFormat::forcedItalic | ( | ) | const |
Returns true
if the format is set to force an italic style.
Definition at line 242 of file qgstextformat.cpp.
|
static |
Attempts to parse the provided mime data as a QgsTextFormat.
If data can be parsed as a text format, ok will be set to true
.
Definition at line 815 of file qgstextformat.cpp.
|
static |
Returns a text format matching the settings from an input font.
Unlike setFont(), this method also handles the size and size units from font.
Definition at line 766 of file qgstextformat.cpp.
bool QgsTextFormat::isValid | ( | ) | const |
Returns true
if the format is valid.
A default constructed QgsTextFormat is invalid, until at least one or more properties have been set on the format. An invalid state can be used as a representation of a "not set" text format, e.g. for indicating that a default text format should be used.
Definition at line 103 of file qgstextformat.cpp.
double QgsTextFormat::lineHeight | ( | ) | const |
Returns the line height for text.
If lineHeightUnit() is QgsUnitTypes::RenderPercentage (the default), then this is a number representing the leading between lines as a multiplier of line height (where 0 - 1.0 represents 0 to 100% of text line height). Otherwise the line height is an absolute measurement in lineHeightUnit().
Definition at line 342 of file qgstextformat.cpp.
QgsUnitTypes::RenderUnit QgsTextFormat::lineHeightUnit | ( | ) | const |
Returns the units for the line height for text.
Definition at line 353 of file qgstextformat.cpp.
QgsTextMaskSettings & QgsTextFormat::mask | ( | ) |
Returns a reference to the masking settings.
Definition at line 149 of file qgstextformat.cpp.
|
inline |
Returns a reference to the masking settings.
Masks may be defined in contexts where the text is rendered over some map layers, for labeling especially.
Definition at line 154 of file qgstextformat.h.
QString QgsTextFormat::namedStyle | ( | ) | const |
Returns the named style for the font used for rendering text (e.g., "bold").
Definition at line 214 of file qgstextformat.cpp.
double QgsTextFormat::opacity | ( | ) | const |
Returns the text's opacity.
The opacity is a double value between 0 (fully transparent) and 1 (totally opaque).
Definition at line 309 of file qgstextformat.cpp.
bool QgsTextFormat::operator!= | ( | const QgsTextFormat & | other | ) | const |
Definition at line 98 of file qgstextformat.cpp.
QgsTextFormat & QgsTextFormat::operator= | ( | const QgsTextFormat & | other | ) |
Definition at line 51 of file qgstextformat.cpp.
bool QgsTextFormat::operator== | ( | const QgsTextFormat & | other | ) | const |
Definition at line 68 of file qgstextformat.cpp.
Qgis::TextOrientation QgsTextFormat::orientation | ( | ) | const |
Returns the orientation of the text.
Definition at line 364 of file qgstextformat.cpp.
QColor QgsTextFormat::previewBackgroundColor | ( | ) | const |
Returns the background color for text previews.
Definition at line 405 of file qgstextformat.cpp.
void QgsTextFormat::readFromLayer | ( | QgsVectorLayer * | layer | ) |
Reads settings from a layer's custom properties (for QGIS 2.x projects).
layer | source vector layer |
Definition at line 416 of file qgstextformat.cpp.
void QgsTextFormat::readXml | ( | const QDomElement & | elem, |
const QgsReadWriteContext & | context | ||
) |
Read settings from a DOM element.
Definition at line 500 of file qgstextformat.cpp.
QSet< QString > QgsTextFormat::referencedFields | ( | const QgsRenderContext & | context | ) | const |
Returns all field names referenced by the configuration (e.g.
from data defined properties).
Definition at line 871 of file qgstextformat.cpp.
|
inline |
Returns the family for the resolved font, ie if the specified font was not found on the system this will return the name of the replacement font.
Definition at line 601 of file qgstextformat.h.
QFont QgsTextFormat::scaledFont | ( | const QgsRenderContext & | context, |
double | scaleFactor = 1.0 , |
||
bool * | isZeroSize = nullptr |
||
) | const |
Returns a font with the size scaled to match the format's size settings (including units and map unit scale) for a specified render context.
context | destination render context |
scaleFactor | optional font size scaling factor. It is recommended to set this to QgsTextRenderer::FONT_WORKAROUND_SCALE and then manually scale painter devices or calculations based on the resultant font metrics. Failure to do so will result in poor quality text rendering at small font sizes. |
isZeroSize | will be set to true if the font is scaled down to a near 0 size, and nothing should be rendered. Not available in Python bindings. |
Definition at line 166 of file qgstextformat.cpp.
void QgsTextFormat::setAllowHtmlFormatting | ( | bool | allow | ) |
Sets whether text should be treated as a HTML document and HTML tags should be used for formatting the rendered text.
Definition at line 399 of file qgstextformat.cpp.
void QgsTextFormat::setBackground | ( | const QgsTextBackgroundSettings & | backgroundSettings | ) |
Sets the text's background settings.q.
backgroundSettings | background settings |
Definition at line 131 of file qgstextformat.cpp.
void QgsTextFormat::setBlendMode | ( | QPainter::CompositionMode | mode | ) |
Sets the blending mode used for drawing the text.
mode | blending mode |
Definition at line 336 of file qgstextformat.cpp.
void QgsTextFormat::setBuffer | ( | const QgsTextBufferSettings & | bufferSettings | ) |
Sets the text's buffer settings.
bufferSettings | buffer settings |
Definition at line 119 of file qgstextformat.cpp.
void QgsTextFormat::setCapitalization | ( | Qgis::Capitalization | capitalization | ) |
Sets the text capitalization style.
Definition at line 383 of file qgstextformat.cpp.
void QgsTextFormat::setColor | ( | const QColor & | color | ) |
Sets the color that text will be rendered in.
color | text color |
Definition at line 303 of file qgstextformat.cpp.
void QgsTextFormat::setDataDefinedProperties | ( | const QgsPropertyCollection & | collection | ) |
Sets the format's property collection, used for data defined overrides.
collection | property collection. Existing properties will be replaced. |
Definition at line 881 of file qgstextformat.cpp.
void QgsTextFormat::setFamilies | ( | const QStringList & | families | ) |
Sets a list of font families to use for the text format, in order of precedence.
When restoring serialized versions of the text format then the first matching font family from this list will be used for the text format. This provides a way to specify a list of possible font families which are used as fallbacks if a family isn't available on a particular QGIS install (CSS style).
Definition at line 259 of file qgstextformat.cpp.
void QgsTextFormat::setFont | ( | const QFont & | font | ) |
Sets the font used for rendering text.
Note that the size of the font is not used, and setSize() should be called instead to explicitly set the size of rendered text.
font | desired font |
Definition at line 208 of file qgstextformat.cpp.
void QgsTextFormat::setForcedBold | ( | bool | forced | ) |
Sets whether the format is set to force a bold style.
Definition at line 235 of file qgstextformat.cpp.
void QgsTextFormat::setForcedItalic | ( | bool | forced | ) |
Sets whether the format is set to force an italic style.
Definition at line 247 of file qgstextformat.cpp.
void QgsTextFormat::setLineHeight | ( | double | height | ) |
Sets the line height for text.
If lineHeightUnit() is QgsUnitTypes::RenderPercentage (the default), then height is a number representing the leading between lines as a multiplier of line height (where 0 - 1.0 represents 0 to 100% of text line height). Otherwise height is an absolute measurement in lineHeightUnit().
Definition at line 347 of file qgstextformat.cpp.
void QgsTextFormat::setLineHeightUnit | ( | QgsUnitTypes::RenderUnit | unit | ) |
Sets the unit for the line height for text.
Definition at line 358 of file qgstextformat.cpp.
void QgsTextFormat::setMask | ( | const QgsTextMaskSettings & | maskSettings | ) |
Sets the text's masking settings.
Masks may be defined in contexts where the text is rendered over some map layers, for labeling especially.
maskSettings | mask settings |
Definition at line 155 of file qgstextformat.cpp.
void QgsTextFormat::setNamedStyle | ( | const QString & | style | ) |
Sets the named style for the font used for rendering text.
style | named style, e.g., "bold" |
Definition at line 223 of file qgstextformat.cpp.
void QgsTextFormat::setOpacity | ( | double | opacity | ) |
Sets the text's opacity.
opacity | opacity as a double value between 0 (fully transparent) and 1 (totally opaque) |
Definition at line 314 of file qgstextformat.cpp.
void QgsTextFormat::setOrientation | ( | Qgis::TextOrientation | orientation | ) |
Sets the orientation for the text.
Definition at line 369 of file qgstextformat.cpp.
void QgsTextFormat::setPreviewBackgroundColor | ( | const QColor & | color | ) |
Sets the background color that text will be rendered on for previews.
Definition at line 410 of file qgstextformat.cpp.
void QgsTextFormat::setShadow | ( | const QgsTextShadowSettings & | shadowSettings | ) |
Sets the text's drop shadow settings.
shadowSettings | shadow settings |
Definition at line 143 of file qgstextformat.cpp.
void QgsTextFormat::setSize | ( | double | size | ) |
Sets the size for rendered text.
size | size of rendered text. Units are set using setSizeUnit() |
Definition at line 292 of file qgstextformat.cpp.
void QgsTextFormat::setSizeMapUnitScale | ( | const QgsMapUnitScale & | scale | ) |
Sets the map unit scale object for the size.
This is only used if the sizeUnit() is set to QgsUnitTypes::RenderMapUnit.
Definition at line 281 of file qgstextformat.cpp.
void QgsTextFormat::setSizeUnit | ( | QgsUnitTypes::RenderUnit | unit | ) |
Sets the units for the size of rendered text.
unit | size units |
Definition at line 270 of file qgstextformat.cpp.
void QgsTextFormat::setStretchFactor | ( | int | factor | ) |
Sets the text's stretch factor.
The stretch factor matches a condensed or expanded version of the font or applies a stretch transform that changes the width of all characters in the font by factor percent.
For example, setting factor to 150 results in all characters in the font being 1.5 times (ie. 150%) wider. The minimum stretch factor is 1, and the maximum stretch factor is 4000.
Definition at line 325 of file qgstextformat.cpp.
void QgsTextFormat::setValid | ( | ) |
Sets the format to a valid state, without changing any of the default format settings.
Definition at line 108 of file qgstextformat.cpp.
QgsTextShadowSettings & QgsTextFormat::shadow | ( | ) |
Returns a reference to the text drop shadow settings.
Definition at line 137 of file qgstextformat.cpp.
|
inline |
Returns a reference to the text drop shadow settings.
Definition at line 133 of file qgstextformat.h.
double QgsTextFormat::size | ( | ) | const |
Returns the size for rendered text.
Units are retrieved using sizeUnit().
Definition at line 287 of file qgstextformat.cpp.
QgsMapUnitScale QgsTextFormat::sizeMapUnitScale | ( | ) | const |
Returns the map unit scale object for the size.
This is only used if the sizeUnit() is set to QgsUnitTypes::RenderMapUnit.
Definition at line 276 of file qgstextformat.cpp.
QgsUnitTypes::RenderUnit QgsTextFormat::sizeUnit | ( | ) | const |
Returns the units for the size of rendered text.
Definition at line 265 of file qgstextformat.cpp.
int QgsTextFormat::stretchFactor | ( | ) | const |
Returns the text's stretch factor.
The stretch factor matches a condensed or expanded version of the font or applies a stretch transform that changes the width of all characters in the font by factor percent.
For example, a factor of 150 results in all characters in the font being 1.5 times (ie. 150%) wider. The minimum stretch factor is 1, and the maximum stretch factor is 4000.
Definition at line 320 of file qgstextformat.cpp.
|
static |
Returns a pixmap preview for a text format.
format | text format |
size | target pixmap size |
previewText | text to render in preview, or empty for default text |
padding | space between icon edge and color ramp |
Definition at line 1095 of file qgstextformat.cpp.
QMimeData * QgsTextFormat::toMimeData | ( | ) | const |
Returns new mime data representing the text format settings.
Caller takes responsibility for deleting the returned object.
Definition at line 750 of file qgstextformat.cpp.
QFont QgsTextFormat::toQFont | ( | ) | const |
Returns a QFont matching the relevant settings from this text format.
Unlike font(), this method also handles the size and size units from the text format.
Definition at line 784 of file qgstextformat.cpp.
void QgsTextFormat::updateDataDefinedProperties | ( | QgsRenderContext & | context | ) |
Updates the format by evaluating current values of data defined properties.
Definition at line 887 of file qgstextformat.cpp.
QDomElement QgsTextFormat::writeXml | ( | QDomDocument & | doc, |
const QgsReadWriteContext & | context | ||
) | const |
Write settings into a DOM element.
Definition at line 695 of file qgstextformat.cpp.