QGIS API Documentation 4.1.0-Master (60fea48833c)
Loading...
Searching...
No Matches
qgstextrendererutils.h
Go to the documentation of this file.
1/***************************************************************************
2 qgstextrendererutils.h
3 -----------------
4 begin : May 2020
5 copyright : (C) Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSTEXTRENDERERUTILS_H
17#define QGSTEXTRENDERERUTILS_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
22#include "qgstextmetrics.h"
24
31class CORE_EXPORT QgsTextRendererUtils
32{
33 public:
37 static QgsTextBackgroundSettings::ShapeType decodeShapeType( const QString &string );
38
43
48
53
59 static QString encodeTextOrientation( Qgis::TextOrientation orientation );
60
68 static Qgis::TextOrientation decodeTextOrientation( const QString &name, bool *ok = nullptr );
69
77
84 static QColor readColor( QgsVectorLayer *layer, const QString &property, const QColor &defaultColor = Qt::black, bool withAlpha = true ) SIP_SKIP;
85
86#ifndef SIP_RUN
87
96 {
97 public:
99 double x = 0;
101 double y = 0;
103 double width = 0;
105 double height = 0;
107 double angle = 0;
111 bool isWhitespace = false;
112 };
113
122 {
123 public:
125 QVector< QgsTextRendererUtils::CurvedGraphemePlacement > graphemePlacement;
132 };
133
142
157 static std::unique_ptr< CurvePlacementProperties > generateCurvedTextPlacement(
158 const QgsPrecalculatedTextMetrics &metrics,
159 const QPolygonF &line,
160 double offsetAlongLine,
161 LabelLineDirection direction = RespectPainterOrientation,
162 double maxConcaveAngle = -1,
163 double maxConvexAngle = -1,
165 ) SIP_SKIP;
166
186 static std::unique_ptr< CurvePlacementProperties > generateCurvedTextPlacement(
187 const QgsPrecalculatedTextMetrics &metrics,
188 const double *x,
189 const double *y,
190 int numPoints,
191 const std::vector< double> &pathDistances,
192 double offsetAlongLine,
193 LabelLineDirection direction = RespectPainterOrientation,
194 double maxConcaveAngle = -1,
195 double maxConvexAngle = -1,
196 Qgis::CurvedTextFlags flags = Qgis::CurvedTextFlags(),
197 double additionalCharacterSpacing = 0.0,
198 double additionalWordSpacing = 0.0
199 ) SIP_SKIP;
200#endif
201
202 private:
203 static std::unique_ptr< CurvePlacementProperties > generateCurvedTextPlacementPrivate(
204 const QgsPrecalculatedTextMetrics &metrics,
205 const double *x,
206 const double *y,
207 int numPoints,
208 const std::vector< double> &pathDistances,
209 double offsetAlongLine,
210 LabelLineDirection direction,
212 double maxConcaveAngle = -1,
213 double maxConvexAngle = -1,
214 bool isSecondAttempt = false,
215 double additionalCharacterSpacing = 0,
216 double additionalWordSpacing = 0
217 ) SIP_SKIP;
218
220 static bool nextCharPosition(
221 double charWidth,
222 const std::vector< double > &pathDistances,
223 const double *x,
224 const double *y,
225 int numPoints,
226 int &index,
227 double &currentDistanceAlongSegment,
228 double &characterStartX,
229 double &characterStartY,
230 double &characterEndX,
231 double &characterEndY,
232 Qgis::CurvedTextFlags flags,
233 double additionalSpacing
234 );
235
236 static void findLineCircleIntersection( double cx, double cy, double radius, double x1, double y1, double x2, double y2, double &xRes, double &yRes );
237};
238
239
240#endif // QGSTEXTRENDERERUTILS_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
TextOrientation
Text orientations.
Definition qgis.h:2987
RenderUnit
Rendering size units.
Definition qgis.h:5340
QFlags< CurvedTextFlag > CurvedTextFlags
Flags controlling behavior of curved text generation.
Definition qgis.h:3104
Contains precalculated properties regarding text metrics for text to be rendered at a later stage.
SizeType
Methods for determining the background shape size.
RotationType
Methods for determining the rotation of the background shape.
Contains placement information for a curved text layout.
bool flippedCharacterPlacementToGetUprightLabels
true if the character placement had to be reversed in order to obtain upright labels on the segment
int upsideDownCharCount
Total count of upside down characters.
QVector< QgsTextRendererUtils::CurvedGraphemePlacement > graphemePlacement
Placement information for all graphemes in text.
bool labeledLineSegmentIsRightToLeft
true if labeled section of line is calculated to be of right-to-left orientation
Contains placement information for a single grapheme in a curved text layout.
int graphemeIndex
Index of corresponding grapheme.
double angle
Angle for grapheme, in radians.
double x
X coordinate of start of grapheme.
double y
Y coordinate of start of grapheme.
bool isWhitespace
true if grapheme is considered whitespace (eg a tab or space character)
Utility functions for text rendering.
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.
LabelLineDirection
Controls behavior of curved text with respect to line directions.
@ FollowLineDirection
Curved text placement will respect the line direction and ignore painter orientation.
@ RespectPainterOrientation
Curved text will be placed respecting the painter orientation, and the actual line direction will be ...
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.
static QgsTextShadowSettings::ShadowPlacement decodeShadowPlacementType(const QString &string)
Decodes a string representation of a shadow placement type to a type.
static QgsTextBackgroundSettings::RotationType decodeBackgroundRotationType(const QString &string)
Decodes a string representation of a background rotation type to a type.
static QString encodeTextOrientation(Qgis::TextOrientation orientation)
Encodes a text orientation.
static QgsTextBackgroundSettings::SizeType decodeBackgroundSizeType(const QString &string)
Decodes a string representation of a background size type to a type.
static Qgis::RenderUnit convertFromOldLabelUnit(int val)
Converts a unit from an old (pre 3.0) label unit.
ShadowPlacement
Placement positions for text shadow.
Represents a vector layer which manages a vector based dataset.
#define SIP_SKIP
Definition qgis_sip.h:133