QGIS API Documentation  3.0.2-Girona (307d082)
Classes | Public Types | Static Public Member Functions | Friends | List of all members
QgsTextRenderer Class Reference

Handles rendering text using rich formatting options, including drop shadows, buffers and background shapes. More...

#include <qgstextrenderer.h>

Public Types

enum  HAlignment { AlignLeft = 0, AlignCenter, AlignRight }
 Horizontal alignment. More...
 
enum  TextPart { Text = 0, Buffer, Background, Shadow }
 Components of text. More...
 

Static Public Member Functions

static 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 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)
 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 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...
 

Friends

class QgsLabelPreview
 
class QgsVectorLayerLabelProvider
 

Detailed Description

Handles rendering text using rich formatting options, including drop shadows, buffers and background shapes.

Since
QGIS 3.0

Definition at line 1276 of file qgstextrenderer.h.

Member Enumeration Documentation

◆ HAlignment

Horizontal alignment.

Enumerator
AlignLeft 

Left align.

AlignCenter 

Center align.

AlignRight 

Right align.

Definition at line 1290 of file qgstextrenderer.h.

◆ TextPart

Components of text.

Enumerator
Text 

Text component.

Buffer 

Buffer component.

Background 

Background shape.

Shadow 

Drop shadow.

Definition at line 1281 of file qgstextrenderer.h.

Member Function Documentation

◆ drawPart() [1/2]

void QgsTextRenderer::drawPart ( const QRectF &  rect,
double  rotation,
HAlignment  alignment,
const QStringList &  textLines,
QgsRenderContext context,
const QgsTextFormat format,
QgsTextRenderer::TextPart  part,
bool  drawAsOutlines = true 
)
static

Draws a single component of rendered text using the specified settings.

Parameters
rectdestination rectangle for text
rotationtext rotation
alignmenthorizontal alignment
textLineslist of lines of text to draw
contextrender context
formattext format
partcomponent 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)
drawAsOutlinesset 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.

Definition at line 1717 of file qgstextrenderer.cpp.

◆ drawPart() [2/2]

void QgsTextRenderer::drawPart ( QPointF  origin,
double  rotation,
QgsTextRenderer::HAlignment  alignment,
const QStringList &  textLines,
QgsRenderContext context,
const QgsTextFormat format,
QgsTextRenderer::TextPart  part,
bool  drawAsOutlines = true 
)
static

Draws a single component of rendered text using the specified settings.

Parameters
originorigin for start of text. Y coordinate will be used as baseline.
rotationtext rotation
alignmenthorizontal alignment
textLineslist of lines of text to draw
contextrender context
formattext format
partcomponent 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)
drawAsOutlinesset 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.

Definition at line 1782 of file qgstextrenderer.cpp.

◆ drawText() [1/2]

void QgsTextRenderer::drawText ( const QRectF &  rect,
double  rotation,
QgsTextRenderer::HAlignment  alignment,
const QStringList &  textLines,
QgsRenderContext context,
const QgsTextFormat format,
bool  drawAsOutlines = true 
)
static

Draws text within a rectangle using the specified settings.

Parameters
rectdestination rectangle for text
rotationtext rotation
alignmenthorizontal alignment
textLineslist of lines of text to draw
contextrender context
formattext format
drawAsOutlinesset 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.

Definition at line 1662 of file qgstextrenderer.cpp.

◆ drawText() [2/2]

void QgsTextRenderer::drawText ( QPointF  point,
double  rotation,
QgsTextRenderer::HAlignment  alignment,
const QStringList &  textLines,
QgsRenderContext context,
const QgsTextFormat format,
bool  drawAsOutlines = true 
)
static

Draws text at a point origin using the specified settings.

Parameters
pointorigin of text
rotationtext rotation
alignmenthorizontal alignment
textLineslist of lines of text to draw
contextrender context
formattext format
drawAsOutlinesset 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.

Definition at line 1679 of file qgstextrenderer.cpp.

◆ sizeToPixel()

int QgsTextRenderer::sizeToPixel ( double  size,
const QgsRenderContext c,
QgsUnitTypes::RenderUnit  unit,
const QgsMapUnitScale mapUnitScale = QgsMapUnitScale() 
)
static

Calculates pixel size (considering output size should be in pixel or map units, scale factors and optionally oversampling)

Parameters
sizesize to convert
crendercontext
unitsize units
mapUnitScalea mapUnitScale clamper
Returns
font pixel size

Definition at line 1657 of file qgstextrenderer.cpp.

Friends And Related Function Documentation

◆ QgsLabelPreview

friend class QgsLabelPreview
friend

Definition at line 1447 of file qgstextrenderer.h.

◆ QgsVectorLayerLabelProvider

friend class QgsVectorLayerLabelProvider
friend

Definition at line 1446 of file qgstextrenderer.h.


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