QGIS API Documentation
3.22.4-Białowieża (ce8e65e95e)
|
Handles rendering text using rich formatting options, including drop shadows, buffers and background shapes. More...
#include <qgstextrenderer.h>
Public Types | |
enum | DrawMode { Rect = 0 , Point , Label } |
Draw mode to calculate width and height. More... | |
enum | HAlignment { AlignLeft = 0 , AlignCenter , AlignRight , AlignJustify } |
Horizontal alignment. More... | |
enum | TextPart { Text = 0 , Buffer , Background , Shadow } |
Components of text. More... | |
enum | VAlignment { AlignTop = 0 , AlignVCenter , AlignBottom } |
Vertical alignment. More... | |
Static Public Member Functions | |
static HAlignment | convertQtHAlignment (Qt::Alignment alignment) |
Converts a Qt horizontal alignment flag to a QgsTextRenderer::HAlignment value. More... | |
static VAlignment | convertQtVAlignment (Qt::Alignment alignment) |
Converts a Qt vertical alignment flag to a QgsTextRenderer::VAlignment value. More... | |
static Q_DECL_DEPRECATED void | drawPart (const QRectF &rect, double rotation, HAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, TextPart part, bool drawAsOutlines=true) |
Draws a single component of rendered text using the specified settings. More... | |
static Q_DECL_DEPRECATED void | drawPart (QPointF origin, double rotation, HAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, TextPart part, bool drawAsOutlines=true) |
Draws a single component of rendered text using the specified settings. More... | |
static void | drawText (const QRectF &rect, double rotation, HAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, bool drawAsOutlines=true, VAlignment vAlignment=AlignTop) |
Draws text within a rectangle using the specified settings. More... | |
static void | drawText (QPointF point, double rotation, HAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, bool drawAsOutlines=true) |
Draws text at a point origin using the specified settings. More... | |
static QFontMetricsF | fontMetrics (QgsRenderContext &context, const QgsTextFormat &format, double scaleFactor=1.0) |
Returns the font metrics for the given text format, when rendered in the specified render context. More... | |
static int | sizeToPixel (double size, const QgsRenderContext &c, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &mapUnitScale=QgsMapUnitScale()) |
Calculates pixel size (considering output size should be in pixel or map units, scale factors and optionally oversampling) More... | |
static double | textHeight (const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, DrawMode mode=Point, QFontMetricsF *fontMetrics=nullptr) |
Returns the height of a text based on a given format. More... | |
static double | textHeight (const QgsRenderContext &context, const QgsTextFormat &format, QChar character, bool includeEffects=false) |
Returns the height of a character when rendered with the specified text format. More... | |
static double | textWidth (const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, QFontMetricsF *fontMetrics=nullptr) |
Returns the width of a text based on a given format. More... | |
Static Public Attributes | |
static constexpr double | FONT_WORKAROUND_SCALE = 10 |
Scale factor for upscaling font sizes and downscaling destination painter devices. More... | |
Friends | |
class | QgsLabelPreview |
class | QgsVectorLayerLabelProvider |
Handles rendering text using rich formatting options, including drop shadows, buffers and background shapes.
Definition at line 36 of file qgstextrenderer.h.
Draw mode to calculate width and height.
Enumerator | |
---|---|
Rect | Text within rectangle draw mode. |
Point | Text at point of origin draw mode. |
Label | Label-specific draw mode. |
Definition at line 41 of file qgstextrenderer.h.
Horizontal alignment.
Enumerator | |
---|---|
AlignLeft | Left align. |
AlignCenter | Center align. |
AlignRight | Right align. |
AlignJustify | Justify align. |
Definition at line 58 of file qgstextrenderer.h.
Components of text.
Enumerator | |
---|---|
Text | Text component. |
Buffer | Buffer component. |
Background | Background shape. |
Shadow | Drop shadow. |
Definition at line 49 of file qgstextrenderer.h.
Vertical alignment.
Enumerator | |
---|---|
AlignTop | Align to top. |
AlignVCenter | Center align. |
AlignBottom | Align to bottom. |
Definition at line 78 of file qgstextrenderer.h.
|
static |
Converts a Qt horizontal alignment flag to a QgsTextRenderer::HAlignment value.
Definition at line 45 of file qgstextrenderer.cpp.
|
static |
Converts a Qt vertical alignment flag to a QgsTextRenderer::VAlignment value.
Definition at line 60 of file qgstextrenderer.cpp.
|
static |
Draws a single component of rendered text using the specified settings.
rect | destination rectangle for text |
rotation | text rotation |
alignment | horizontal alignment |
textLines | list of lines of text to draw |
context | render context |
format | text format |
part | component of text to draw. Note that Shadow parts cannot be drawn individually and instead are drawn with their associated part (e.g., drawn together with the text or background parts) |
drawAsOutlines | set to false to render text as text. This allows outputs to formats like SVG to maintain text as text objects, but at the cost of degraded rendering and may result in side effects like misaligned text buffers. This setting is deprecated and has no effect as of QGIS 3.4.3 and the text format should be set using QgsRenderContext::setTextRenderFormat() instead. |
Definition at line 147 of file qgstextrenderer.cpp.
|
static |
Draws a single component of rendered text using the specified settings.
origin | origin for start of text. Y coordinate will be used as baseline. |
rotation | text rotation |
alignment | horizontal alignment |
textLines | list of lines of text to draw |
context | render context |
format | text format |
part | component of text to draw. Note that Shadow parts cannot be drawn individually and instead are drawn with their associated part (e.g., drawn together with the text or background parts) |
drawAsOutlines | set to false to render text as text. This allows outputs to formats like SVG to maintain text as text objects, but at the cost of degraded rendering and may result in side effects like misaligned text buffers. This setting is deprecated and has no effect as of QGIS 3.4.3 and the text format should be set using QgsRenderContext::setTextRenderFormat() instead. |
Definition at line 217 of file qgstextrenderer.cpp.
|
static |
Draws text within a rectangle using the specified settings.
rect | destination rectangle for text |
rotation | text rotation |
alignment | horizontal alignment |
textLines | list of lines of text to draw |
context | render context |
format | text format |
drawAsOutlines | set to false to render text as text. This allows outputs to formats like SVG to maintain text as text objects, but at the cost of degraded rendering and may result in side effects like misaligned text buffers. This setting is deprecated and has no effect as of QGIS 3.4.3 and the text format should be set using QgsRenderContext::setTextRenderFormat() instead. |
vAlignment | vertical alignment (since QGIS 3.16) |
Definition at line 80 of file qgstextrenderer.cpp.
|
static |
Draws text at a point origin using the specified settings.
point | origin of text |
rotation | text rotation |
alignment | horizontal alignment |
textLines | list of lines of text to draw |
context | render context |
format | text format |
drawAsOutlines | set to false to render text as text. This allows outputs to formats like SVG to maintain text as text objects, but at the cost of degraded rendering and may result in side effects like misaligned text buffers. This setting is deprecated and has no effect as of QGIS 3.4.3 and the text format should be set using QgsRenderContext::setTextRenderFormat() instead. |
Definition at line 103 of file qgstextrenderer.cpp.
|
static |
Returns the font metrics for the given text format, when rendered in the specified render context.
The font metrics will take into account all scaling required by the render context.
The optional scaleFactor argument can specify a 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.
Definition at line 266 of file qgstextrenderer.cpp.
|
static |
Calculates pixel size (considering output size should be in pixel or map units, scale factors and optionally oversampling)
size | size to convert |
c | rendercontext |
unit | size units |
mapUnitScale | a mapUnitScale clamper |
Definition at line 75 of file qgstextrenderer.cpp.
|
static |
Returns the height of a text based on a given format.
context | render context |
format | text format |
textLines | list of lines of text to calculate width from |
mode | draw mode |
fontMetrics | font metrics |
Definition at line 602 of file qgstextrenderer.cpp.
|
static |
Returns the height of a character when rendered with the specified text format.
context | render context |
format | text format |
character | character to determine height of. If character is invalid, then the maximum character height will be returned. |
includeEffects | if true , then the size of formatting effects such as buffers and shadows will be considered in the returned height. If false , then the returned size considers the character only. |
Definition at line 614 of file qgstextrenderer.cpp.
|
static |
Returns the width of a text based on a given format.
context | render context |
format | text format |
textLines | list of lines of text to calculate width from |
fontMetrics | font metrics |
Definition at line 527 of file qgstextrenderer.cpp.
|
friend |
Definition at line 387 of file qgstextrenderer.h.
|
friend |
Definition at line 386 of file qgstextrenderer.h.
|
staticconstexpr |
Scale factor for upscaling font sizes and downscaling destination painter devices.
Using this scale factor and manually adjusting any font metric based calculations results in more stable font metrics and sizes for small font sizes.
Definition at line 240 of file qgstextrenderer.h.