QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
Classes | Public Types | Static Public Member Functions | List of all members
QgsTextRendererUtils Class Reference

Utility functions for text rendering. More...

#include <qgstextrendererutils.h>

Classes

class  CurvedGraphemePlacement
 Contains placement information for a single grapheme in a curved text layout. More...
 
class  CurvePlacementProperties
 Contains placement information for a curved text layout. More...
 

Public Types

enum class  CurvedTextFlag : int { TruncateStringWhenLineIsTooShort = 1 << 0 , UseBaselinePlacement = 1 << 1 , UprightCharactersOnly = 1 << 2 }
 Flags controlling behavior of curved text generation. More...
 
typedef QFlags< CurvedTextFlagCurvedTextFlags
 Flags controlling behavior of curved text generation.
 
enum  LabelLineDirection { RespectPainterOrientation , FollowLineDirection }
 Controls behavior of curved text with respect to line directions. More...
 

Static Public Member Functions

static Qgis::RenderUnit convertFromOldLabelUnit (int val)
 Converts a unit from an old (pre 3.0) label unit.
 
static QgsTextBackgroundSettings::RotationType decodeBackgroundRotationType (const QString &string)
 Decodes a string representation of a background rotation type to a type.
 
static QgsTextBackgroundSettings::SizeType decodeBackgroundSizeType (const QString &string)
 Decodes a string representation of a background size type to a type.
 
static QgsTextShadowSettings::ShadowPlacement decodeShadowPlacementType (const QString &string)
 Decodes a string representation of a shadow placement type to a type.
 
static QgsTextBackgroundSettings::ShapeType decodeShapeType (const QString &string)
 Decodes a string representation of a background shape type to a type.
 
static Qgis::TextOrientation decodeTextOrientation (const QString &name, bool *ok=nullptr)
 Attempts to decode a string representation of a text orientation.
 
static QString encodeTextOrientation (Qgis::TextOrientation orientation)
 Encodes a text orientation.
 
static std::unique_ptr< CurvePlacementPropertiesgenerateCurvedTextPlacement (const QgsPrecalculatedTextMetrics &metrics, const double *x, const double *y, int numPoints, const std::vector< double > &pathDistances, double offsetAlongLine, LabelLineDirection direction=RespectPainterOrientation, double maxConcaveAngle=-1, double maxConvexAngle=-1, CurvedTextFlags flags=CurvedTextFlags())
 Calculates curved text placement properties.
 
static std::unique_ptr< CurvePlacementPropertiesgenerateCurvedTextPlacement (const QgsPrecalculatedTextMetrics &metrics, const QPolygonF &line, double offsetAlongLine, LabelLineDirection direction=RespectPainterOrientation, double maxConcaveAngle=-1, double maxConvexAngle=-1, CurvedTextFlags flags=CurvedTextFlags())
 Calculates curved text placement properties.
 
static QColor readColor (QgsVectorLayer *layer, const QString &property, const QColor &defaultColor=Qt::black, bool withAlpha=true)
 Converts an encoded color value from a layer property.
 

Detailed Description

Utility functions for text rendering.

Since
QGIS 3.10

Definition at line 31 of file qgstextrendererutils.h.

Member Typedef Documentation

◆ CurvedTextFlags

Flags controlling behavior of curved text generation.

Since
QGIS 3.2

Definition at line 161 of file qgstextrendererutils.h.

Member Enumeration Documentation

◆ CurvedTextFlag

enum class QgsTextRendererUtils::CurvedTextFlag : int
strong

Flags controlling behavior of curved text generation.

Since
QGIS 3.2
Enumerator
TruncateStringWhenLineIsTooShort 

When a string is too long for the line, truncate characters instead of aborting the placement.

UseBaselinePlacement 

Generate placement based on the character baselines instead of centers.

UprightCharactersOnly 

Permit upright characters only. If not present then upside down text placement is permitted.

Definition at line 149 of file qgstextrendererutils.h.

◆ LabelLineDirection

Controls behavior of curved text with respect to line directions.

Enumerator
RespectPainterOrientation 

Curved text will be placed respecting the painter orientation, and the actual line direction will be ignored.

FollowLineDirection 

Curved text placement will respect the line direction and ignore painter orientation.

Definition at line 138 of file qgstextrendererutils.h.

Member Function Documentation

◆ convertFromOldLabelUnit()

Qgis::RenderUnit QgsTextRendererUtils::convertFromOldLabelUnit ( int  val)
static

Converts a unit from an old (pre 3.0) label unit.

Note
Not available in Python bindings.
Since
QGIS 3.14

Definition at line 132 of file qgstextrendererutils.cpp.

◆ decodeBackgroundRotationType()

QgsTextBackgroundSettings::RotationType QgsTextRendererUtils::decodeBackgroundRotationType ( const QString &  string)
static

Decodes a string representation of a background rotation type to a type.

Definition at line 61 of file qgstextrendererutils.cpp.

◆ decodeBackgroundSizeType()

QgsTextBackgroundSettings::SizeType QgsTextRendererUtils::decodeBackgroundSizeType ( const QString &  string)
static

Decodes a string representation of a background size type to a type.

Definition at line 48 of file qgstextrendererutils.cpp.

◆ decodeShadowPlacementType()

QgsTextShadowSettings::ShadowPlacement QgsTextRendererUtils::decodeShadowPlacementType ( const QString &  string)
static

Decodes a string representation of a shadow placement type to a type.

Definition at line 78 of file qgstextrendererutils.cpp.

◆ decodeShapeType()

QgsTextBackgroundSettings::ShapeType QgsTextRendererUtils::decodeShapeType ( const QString &  string)
static

Decodes a string representation of a background shape type to a type.

Definition at line 20 of file qgstextrendererutils.cpp.

◆ decodeTextOrientation()

Qgis::TextOrientation QgsTextRendererUtils::decodeTextOrientation ( const QString &  name,
bool *  ok = nullptr 
)
static

Attempts to decode a string representation of a text orientation.

Parameters
nameencoded text orientation name
okif specified, will be set to true if the name was successfully decoded
Returns
decoded text orientation
See also
encodeTextOrientation()

Definition at line 113 of file qgstextrendererutils.cpp.

◆ encodeTextOrientation()

QString QgsTextRendererUtils::encodeTextOrientation ( Qgis::TextOrientation  orientation)
static

Encodes a text orientation.

Returns
encoded string
See also
decodeTextOrientation()

Definition at line 99 of file qgstextrendererutils.cpp.

◆ generateCurvedTextPlacement() [1/2]

std::unique_ptr< QgsTextRendererUtils::CurvePlacementProperties > QgsTextRendererUtils::generateCurvedTextPlacement ( const QgsPrecalculatedTextMetrics metrics,
const double *  x,
const double *  y,
int  numPoints,
const std::vector< double > &  pathDistances,
double  offsetAlongLine,
LabelLineDirection  direction = RespectPainterOrientation,
double  maxConcaveAngle = -1,
double  maxConvexAngle = -1,
CurvedTextFlags  flags = CurvedTextFlags() 
)
static

Calculates curved text placement properties.

Parameters
metricsprecalculated text metrics for text to render
xarray of linestring x coordinates
yarray of linestring y coordinates
numPointsnumber of points in x, y arrays
pathDistancesvector of precalculated distances between vertices in x, y arrays
offsetAlongLineoffset along line at which to start the curved text placement
directioncontrols placement of text with respect to painter orientation or line direction
maxConcaveAnglemaximum angle between characters for concave text, or -1 if not set
maxConvexAnglemaximum angle between characters for convex text, or -1 if not set
flagsflags controlling behavior of curved text generation
Returns
calculated placement properties, or nullptr if placement could not be calculated. Caller takes ownership of the returned placement.
Since
QGIS 3.20

Definition at line 189 of file qgstextrendererutils.cpp.

◆ generateCurvedTextPlacement() [2/2]

std::unique_ptr< QgsTextRendererUtils::CurvePlacementProperties > QgsTextRendererUtils::generateCurvedTextPlacement ( const QgsPrecalculatedTextMetrics metrics,
const QPolygonF &  line,
double  offsetAlongLine,
LabelLineDirection  direction = RespectPainterOrientation,
double  maxConcaveAngle = -1,
double  maxConvexAngle = -1,
CurvedTextFlags  flags = CurvedTextFlags() 
)
static

Calculates curved text placement properties.

Parameters
metricsprecalculated text metrics for text to render
lineline to render text along
offsetAlongLineoffset along line at which to start the curved text placement
directioncontrols placement of text with respect to painter orientation or line direction
maxConcaveAnglemaximum angle between characters for concave text, or -1 if not set
maxConvexAnglemaximum angle between characters for convex text, or -1 if not set
flagsflags controlling behavior of curved text generation
Returns
calculated placement properties, or nullptr if placement could not be calculated. Caller takes ownership of the returned placement.
Since
QGIS 3.20

Definition at line 155 of file qgstextrendererutils.cpp.

◆ readColor()

QColor QgsTextRendererUtils::readColor ( QgsVectorLayer layer,
const QString &  property,
const QColor &  defaultColor = Qt::black,
bool  withAlpha = true 
)
static

Converts an encoded color value from a layer property.

Note
Not available in Python bindings.
Since
QGIS 3.14

Definition at line 146 of file qgstextrendererutils.cpp.


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