QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
Loading...
Searching...
No Matches
qgstextdocumentmetrics.h
Go to the documentation of this file.
1/***************************************************************************
2 qgstextdocumentmetrics.h
3 -----------------
4 begin : September 2022
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 QGSTEXTDOCUMENTMETRICS_H
17#define QGSTEXTDOCUMENTMETRICS_H
18
19#include "qgis_sip.h"
20#include "qgis_core.h"
21#include "qgis.h"
22#include "qgstextdocument.h"
23
24#include <QVector>
25#include <QSizeF>
26#include <QRectF>
27
29class QgsTextFormat;
30struct DocumentMetrics;
31struct BlockMetrics;
32
44{
45 public:
46
52 Qgis::TextRendererFlags flags() const { return mFlags; }
53
59 void setFlags( Qgis::TextRendererFlags flags ) { mFlags = flags; }
60
68 double maximumWidth() const { return mMaximumWidth; }
69
77 void setMaximumWidth( double width ) { mMaximumWidth = width; }
78
79 private:
80
82 double mMaximumWidth = 0;
83
84};
85
96class CORE_EXPORT QgsTextDocumentMetrics
97{
98 public:
99
112 static QgsTextDocumentMetrics calculateMetrics( const QgsTextDocument &document, const QgsTextFormat &format, const QgsRenderContext &context, double scaleFactor = 1.0,
114
120 bool isNullFontSize() const { return mIsNullSize; }
121
130 const QgsTextDocument &document() const { return mDocument; }
131
135 QSizeF documentSize( Qgis::TextLayoutMode mode, Qgis::TextOrientation orientation ) const;
136
146 QRectF outerBounds( Qgis::TextLayoutMode mode, Qgis::TextOrientation orientation ) const;
147
151 double blockWidth( int blockIndex ) const;
152
156 double blockHeight( int blockIndex ) const;
157
163 double firstLineCapHeight() const;
164
168 double baselineOffset( int blockIndex, Qgis::TextLayoutMode mode ) const;
169
175 double fragmentHorizontalAdvance( int blockIndex, int fragmentIndex, Qgis::TextLayoutMode mode ) const;
176
183 double fragmentVerticalOffset( int blockIndex, int fragmentIndex, Qgis::TextLayoutMode mode ) const;
184
190 double fragmentFixedHeight( int blockIndex, int fragmentIndex, Qgis::TextLayoutMode mode ) const;
191
195 double verticalOrientationXOffset( int blockIndex ) const;
196
200 double blockMaximumCharacterWidth( int blockIndex ) const;
201
205 double blockMaximumDescent( int blockIndex ) const;
206
210 QFont fragmentFont( int blockIndex, int fragmentIndex ) const;
211
215 double ascentOffset() const { return mFirstLineAscentOffset; }
216
217 private:
218
219 QgsTextDocument mDocument;
220
221 bool mIsNullSize = false;
222
223 QSizeF mDocumentSizeLabelMode;
224 QSizeF mDocumentSizePointRectMode;
225 QSizeF mDocumentSizeVerticalOrientation;
226 QSizeF mDocumentSizeCapHeightMode;
227 QSizeF mDocumentSizeAscentMode;
228
229 QRectF mOuterBoundsLabelMode;
230
231 QList < QList< QFont > > mFragmentFonts;
232 QList< double > mBlockWidths;
233 QList< double > mBlockHeights;
234 QList< double > mBaselineOffsetsLabelMode;
235 QList< double > mBaselineOffsetsPointMode;
236 QList< double > mBaselineOffsetsRectMode;
237 QList< double > mBaselineOffsetsCapHeightMode;
238 QList< double > mBaselineOffsetsAscentBased;
239
240 QList< QList< double > > mFragmentHorizontalAdvance;
241 QList< QList< double > > mFragmentFixedHeights;
242
243 QList< QList< double > > mFragmentVerticalOffsetsLabelMode;
244 QList< QList< double > > mFragmentVerticalOffsetsPointMode;
245 QList< QList< double > > mFragmentVerticalOffsetsRectMode;
246
247 QList< double > mVerticalOrientationXOffsets;
248 QList< double > mBlockMaxDescent;
249 QList< double > mBlockMaxCharacterWidth;
250 double mFirstLineAscentOffset = 0;
251 double mLastLineAscentOffset = 0;
252 double mFirstLineCapHeight = 0;
253
254 static void finalizeBlock( QgsTextDocumentMetrics &res, const QgsTextFormat &format, DocumentMetrics &documentMetrics, QgsTextBlock &outputBlock, BlockMetrics &metrics );
255 static void processFragment( QgsTextDocumentMetrics &res, const QgsTextFormat &format, const QgsRenderContext &context, const QgsTextDocumentRenderContext &documentContext, double scaleFactor, DocumentMetrics &documentMetrics, BlockMetrics &thisBlockMetrics, const QFont &font, const QgsTextFragment &fragment, QgsTextBlock &currentOutputBlock );
256};
257
258#endif // QGSTEXTDOCUMENTMETRICS_H
TextLayoutMode
Text layout modes.
Definition qgis.h:2699
QFlags< TextRendererFlag > TextRendererFlags
Definition qgis.h:3154
TextOrientation
Text orientations.
Definition qgis.h:2684
Contains information about the context of a rendering operation.
Represents a block of text consisting of one or more QgsTextFragment objects.
Contains pre-calculated metrics of a QgsTextDocument.
bool isNullFontSize() const
Returns true if the metrics could not be calculated because the text format has a null font size.
const QgsTextDocument & document() const
Returns the document associated with the calculated metrics.
double ascentOffset() const
Returns the ascent offset of the first block in the document.
Encapsulates the context in which a text document is to be rendered.
void setFlags(Qgis::TextRendererFlags flags)
Sets associated text renderer flags.
Qgis::TextRendererFlags flags() const
Returns associated text renderer flags.
void setMaximumWidth(double width)
Sets the maximum width (in painter units) for rendered text.
double maximumWidth() const
Returns the maximum width (in painter units) for rendered text.
Represents a document consisting of one or more QgsTextBlock objects.
Container for all settings relating to text rendering.
Stores a fragment of document along with formatting overrides to be used when rendering the fragment.