QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgstextrenderer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgstextrenderer.h
3  -----------------
4  begin : September 2015
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 QGSTEXTRENDERER_H
17 #define QGSTEXTRENDERER_H
18 
19 #include "qgis_sip.h"
20 #include "qgis_core.h"
21 #include "qgstextblock.h"
22 #include "qgsrendercontext.h"
23 
24 #include <QPicture>
25 
26 class QgsTextFormat;
27 class QgsTextDocument;
28 
36 class CORE_EXPORT QgsTextRenderer
37 {
38  public:
39 
41  enum DrawMode
42  {
43  Rect = 0,
46  };
47 
49  enum TextPart
50  {
51  Text = 0,
55  };
56 
59  {
60  AlignLeft = 0,
63  };
64 
73  static int sizeToPixel( double size, const QgsRenderContext &c, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &mapUnitScale = QgsMapUnitScale() );
74 
75  // TODO QGIS 4.0 -- remove drawAsOutlines from below methods!
76 
90  static void drawText( const QRectF &rect, double rotation, HAlignment alignment, const QStringList &textLines,
91  QgsRenderContext &context, const QgsTextFormat &format,
92  bool drawAsOutlines = true );
93 
107  static void drawText( QPointF point, double rotation, HAlignment alignment, const QStringList &textLines,
108  QgsRenderContext &context, const QgsTextFormat &format,
109  bool drawAsOutlines = true );
110 
129  Q_DECL_DEPRECATED static void drawPart( const QRectF &rect, double rotation, HAlignment alignment, const QStringList &textLines,
130  QgsRenderContext &context, const QgsTextFormat &format,
131  TextPart part, bool drawAsOutlines = true ) SIP_DEPRECATED;
132 
151  Q_DECL_DEPRECATED static void drawPart( QPointF origin, double rotation, HAlignment alignment, const QStringList &textLines,
152  QgsRenderContext &context, const QgsTextFormat &format,
153  TextPart part, bool drawAsOutlines = true ) SIP_DEPRECATED;
154 
161  static QFontMetricsF fontMetrics( QgsRenderContext &context, const QgsTextFormat &format );
162 
170  static double textWidth( const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines,
171  QFontMetricsF *fontMetrics = nullptr );
172 
181  static double textHeight( const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, DrawMode mode = Point,
182  QFontMetricsF *fontMetrics = nullptr );
183 
184  private:
185 
186  struct Component
187  {
189  QgsTextBlock block;
191  QPointF origin;
193  bool useOrigin = false;
195  double rotation = 0.0;
197  double rotationOffset = 0.0;
199  QPointF center;
201  QSizeF size;
203  QPointF offset;
205  QPicture picture;
206 
211  double pictureBuffer = 0.0;
213  double dpiRatio = 1.0;
215  HAlignment hAlign = AlignLeft;
216  };
217 
218  static double textWidth( const QgsRenderContext &context, const QgsTextFormat &format, const QgsTextDocument &document );
219  static double textHeight( const QgsRenderContext &context, const QgsTextFormat &format, const QgsTextDocument &document, DrawMode mode = Point );
220 
235  static void drawPart( const QRectF &rect, double rotation, HAlignment alignment, const QgsTextDocument &document,
236  QgsRenderContext &context, const QgsTextFormat &format,
237  TextPart part );
238 
253  static void drawPart( QPointF origin, double rotation, HAlignment alignment, const QgsTextDocument &document,
254  QgsRenderContext &context, const QgsTextFormat &format,
255  TextPart part );
256 
257  static double drawBuffer( QgsRenderContext &context,
258  const Component &component,
259  const QgsTextFormat &format );
260 
261  static void drawBackground( QgsRenderContext &context,
262  Component component,
263  const QgsTextFormat &format,
264  const QgsTextDocument &document,
265  DrawMode mode = Rect );
266 
267  static void drawShadow( QgsRenderContext &context,
268  const Component &component,
269  const QgsTextFormat &format );
270 
271  static void drawMask( QgsRenderContext &context,
272  const Component &component,
273  const QgsTextFormat &format );
274 
275  static void drawText( QgsRenderContext &context,
276  const Component &component,
277  const QgsTextFormat &format );
278 
279  static void drawTextInternal( TextPart drawType,
280  QgsRenderContext &context,
281  const QgsTextFormat &format,
282  const Component &component,
283  const QgsTextDocument &document,
284  const QFontMetricsF *fontMetrics,
285  HAlignment alignment,
286  DrawMode mode = Rect );
287 
289  friend class QgsLabelPreview;
290 
291  static QgsTextFormat updateShadowPosition( const QgsTextFormat &format );
292 
293 
294 };
295 
296 
297 #endif // QGSTEXTRENDERER_H
QgsTextRenderer::TextPart
TextPart
Components of text.
Definition: qgstextrenderer.h:49
QgsUnitTypes::RenderUnit
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:166
QgsTextRenderer::Background
@ Background
Background shape.
Definition: qgstextrenderer.h:53
QgsTextRenderer::AlignCenter
@ AlignCenter
Center align.
Definition: qgstextrenderer.h:61
QgsTextRenderer::AlignRight
@ AlignRight
Right align.
Definition: qgstextrenderer.h:62
QgsRenderContext
Definition: qgsrendercontext.h:57
QgsTextRenderer::Shadow
@ Shadow
Drop shadow.
Definition: qgstextrenderer.h:54
QgsVectorLayerLabelProvider
The QgsVectorLayerLabelProvider class implements a label provider for vector layers....
Definition: qgsvectorlayerlabelprovider.h:40
QgsTextRenderer::DrawMode
DrawMode
Draw mode to calculate width and height.
Definition: qgstextrenderer.h:41
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QgsTextFormat
Definition: qgstextformat.h:38
QgsTextRenderer::Point
@ Point
Text at point of origin draw mode.
Definition: qgstextrenderer.h:44
qgis_sip.h
qgsrendercontext.h
QgsMapUnitScale
Struct for storing maximum and minimum scales for measurements in map units.
Definition: qgsmapunitscale.h:37
QgsTextBlock
Definition: qgstextblock.h:34
c
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
Definition: porting_processing.dox:1
QgsTextDocument
Definition: qgstextdocument.h:37
QgsTextRenderer::Label
@ Label
Label-specific draw mode.
Definition: qgstextrenderer.h:45
QgsTextRenderer
Definition: qgstextrenderer.h:36
QgsTextRenderer::Buffer
@ Buffer
Buffer component.
Definition: qgstextrenderer.h:52
qgstextblock.h
QgsTextRenderer::HAlignment
HAlignment
Horizontal alignment.
Definition: qgstextrenderer.h:58