QGIS API Documentation 3.41.0-Master (45a0abf3bec)
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
228 double blockVerticalMargin( int blockIndex ) const;
229
238 double blockLeftMargin( int blockIndex ) const;
239
248 double blockRightMargin( int blockIndex ) const;
249
250 private:
251
252 QgsTextDocument mDocument;
253
254 bool mIsNullSize = false;
255
256 QSizeF mDocumentSizeLabelMode;
257 QSizeF mDocumentSizePointRectMode;
258 QSizeF mDocumentSizeVerticalOrientation;
259 QSizeF mDocumentSizeCapHeightMode;
260 QSizeF mDocumentSizeAscentMode;
261
262 QRectF mOuterBoundsLabelMode;
263
264 QList < QList< QFont > > mFragmentFonts;
265 QList< double > mBlockWidths;
266 QList< double > mBlockHeights;
267 QList< double > mBaselineOffsetsLabelMode;
268 QList< double > mBaselineOffsetsPointMode;
269 QList< double > mBaselineOffsetsRectMode;
270 QList< double > mBaselineOffsetsCapHeightMode;
271 QList< double > mBaselineOffsetsAscentBased;
272
273 QList< QList< double > > mFragmentHorizontalAdvance;
274 QList< QList< double > > mFragmentFixedHeights;
275
276 QList< QList< double > > mFragmentVerticalOffsetsLabelMode;
277 QList< QList< double > > mFragmentVerticalOffsetsPointMode;
278 QList< QList< double > > mFragmentVerticalOffsetsRectMode;
279
280 QList< double > mVerticalOrientationXOffsets;
281 QList< double > mBlockMaxDescent;
282 QList< double > mBlockMaxCharacterWidth;
283 double mFirstLineAscentOffset = 0;
284 double mLastLineAscentOffset = 0;
285 double mFirstLineCapHeight = 0;
286
287 QVector< double > mVerticalMarginsBetweenBlocks;
288 QVector< double > mLeftBlockMargins;
289 QVector< double > mRightBlockMargins;
290
291 static void finalizeBlock( QgsTextDocumentMetrics &res, const QgsTextFormat &format, DocumentMetrics &documentMetrics, QgsTextBlock &outputBlock, BlockMetrics &metrics );
292 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 );
293};
294
295#endif // QGSTEXTDOCUMENTMETRICS_H
TextLayoutMode
Text layout modes.
Definition qgis.h:2699
QFlags< TextRendererFlag > TextRendererFlags
Definition qgis.h:3162
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.