QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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_sip.h"
20 #include "qgis_core.h"
22 #include "qgstextshadowsettings.h"
23 #include "qgstextformat.h"
24 #include "qgstextmetrics.h"
25 
32 class CORE_EXPORT QgsTextRendererUtils
33 {
34  public:
35 
39  static QgsTextBackgroundSettings::ShapeType decodeShapeType( const QString &string );
40 
44  static QgsTextBackgroundSettings::SizeType decodeBackgroundSizeType( const QString &string );
45 
49  static QgsTextBackgroundSettings::RotationType decodeBackgroundRotationType( const QString &string );
50 
54  static QgsTextShadowSettings::ShadowPlacement decodeShadowPlacementType( const QString &string );
55 
61  static QString encodeTextOrientation( QgsTextFormat::TextOrientation orientation );
62 
70  static QgsTextFormat::TextOrientation decodeTextOrientation( const QString &name, bool *ok = nullptr );
71 
78  static QgsUnitTypes::RenderUnit convertFromOldLabelUnit( int val ) SIP_SKIP;
79 
86  static QColor readColor( QgsVectorLayer *layer, const QString &property, const QColor &defaultColor = Qt::black, bool withAlpha = true ) SIP_SKIP;
87 
88 #ifndef SIP_RUN
89 
98  {
99  public:
100 
102  double x = 0;
104  double y = 0;
106  double width = 0;
108  double height = 0;
110  double angle = 0;
112  int graphemeIndex = 0;
113  };
114 
123  {
124  public:
125 
127  QVector< QgsTextRendererUtils::CurvedGraphemePlacement > graphemePlacement;
129  int upsideDownCharCount = 0;
131  bool labeledLineSegmentIsRightToLeft = false;
133  bool flippedCharacterPlacementToGetUprightLabels = false;
134  };
135 
140  {
142  FollowLineDirection
143  };
144 
145 #if 0
146  // TODO - refine API when used. We probably want to use QPolygonF here instead of QgsLineString!
147  static CurvePlacementProperties *generateCurvedTextPlacement( const QgsPrecalculatedTextMetrics &metrics, const QgsLineString *line, double offsetAlongLine, LabelLineDirection direction = RespectPainterOrientation, double maxConcaveAngle = -1, double maxConvexAngle = -1, bool uprightOnly = true ) SIP_FACTORY;
148 #endif
149 
167  static CurvePlacementProperties *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, bool uprightOnly = true ) SIP_SKIP;
168 #endif
169 
170  private:
171 
172  static CurvePlacementProperties *generateCurvedTextPlacementPrivate( const QgsPrecalculatedTextMetrics &metrics, const double *x, const double *y, int numPoints, const std::vector< double> &pathDistances, double offsetAlongLine, LabelLineDirection direction, double maxConcaveAngle = -1, double maxConvexAngle = -1, bool uprightOnly = true, bool isSecondAttempt = false ) SIP_SKIP;
173 
175  static bool nextCharPosition( double charWidth, double segmentLength, const double *x, const double *y, int numPoints, int &index, double &currentDistanceAlongSegment,
176  double &characterStartX, double &characterStartY, double &characterEndX, double &characterEndY );
177 
178  static void findLineCircleIntersection( double cx, double cy, double radius,
179  double x1, double y1, double x2, double y2,
180  double &xRes, double &yRes );
181 };
182 
183 
184 #endif // QGSTEXTRENDERERUTILS_H
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:44
Contains precalculated properties regarding text metrics for text to be renderered at a later stage.
SizeType
Methods for determining the background shape size.
ShapeType
Background shape types.
RotationType
Methods for determining the rotation of the background shape.
TextOrientation
Text orientation.
Definition: qgstextformat.h:46
Contains placement information for a curved text layout.
QVector< QgsTextRendererUtils::CurvedGraphemePlacement > graphemePlacement
Placement information for all graphemes in text.
Contains placement information for a single grapheme in a curved text layout.
Utility functions for text rendering.
LabelLineDirection
Controls behavior of curved text with respect to line directions.
@ RespectPainterOrientation
Curved text will be placed respecting the painter orientation, and the actual line direction will be ...
ShadowPlacement
Placement positions for text shadow.
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:168
Represents a vector layer which manages a vector based data sets.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
Definition: MathUtils.cpp:786
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_FACTORY
Definition: qgis_sip.h:76