QGIS API Documentation 3.41.0-Master (cea29feecf2)
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
199 double fragmentAscent( int blockIndex, int fragmentIndex, Qgis::TextLayoutMode mode ) const;
200
208 double fragmentDescent( int blockIndex, int fragmentIndex, Qgis::TextLayoutMode mode ) const;
209
213 double verticalOrientationXOffset( int blockIndex ) const;
214
218 double blockMaximumCharacterWidth( int blockIndex ) const;
219
225 double blockMaximumDescent( int blockIndex ) const;
226
233 double blockMaximumAscent( int blockIndex ) const;
234
238 QFont fragmentFont( int blockIndex, int fragmentIndex ) const;
239
243 double ascentOffset() const { return mFirstLineAscentOffset; }
244
256 double blockVerticalMargin( int blockIndex ) const;
257
266 double blockLeftMargin( int blockIndex ) const;
267
276 double blockRightMargin( int blockIndex ) const;
277
278 private:
279
280 QgsTextDocument mDocument;
281
282 bool mIsNullSize = false;
283
284 QSizeF mDocumentSizeLabelMode;
285 QSizeF mDocumentSizePointRectMode;
286 QSizeF mDocumentSizeVerticalOrientation;
287 QSizeF mDocumentSizeCapHeightMode;
288 QSizeF mDocumentSizeAscentMode;
289
290 QRectF mOuterBoundsLabelMode;
291
292 QList < QList< QFont > > mFragmentFonts;
293 QList< double > mBlockWidths;
294 QList< double > mBlockHeights;
295 QList< double > mBaselineOffsetsLabelMode;
296 QList< double > mBaselineOffsetsPointMode;
297 QList< double > mBaselineOffsetsRectMode;
298 QList< double > mBaselineOffsetsCapHeightMode;
299 QList< double > mBaselineOffsetsAscentBased;
300
301 QList< QList< double > > mFragmentHorizontalAdvance;
302 QList< QList< double > > mFragmentFixedHeights;
303
304 QList< QList< double > > mFragmentVerticalOffsetsLabelMode;
305 QList< QList< double > > mFragmentVerticalOffsetsPointMode;
306 QList< QList< double > > mFragmentVerticalOffsetsRectMode;
307
308 QList< QList< double > > mFragmentAscent;
309 QList< QList< double > > mFragmentDescent;
310
311 QList< double > mVerticalOrientationXOffsets;
312 QList< double > mBlockMaxDescent;
313 QList< double > mBlockMaxAscent;
314 QList< double > mBlockMaxCharacterWidth;
315 double mFirstLineAscentOffset = 0;
316 double mLastLineAscentOffset = 0;
317 double mFirstLineCapHeight = 0;
318
319 QVector< double > mVerticalMarginsBetweenBlocks;
320 QVector< double > mLeftBlockMargins;
321 QVector< double > mRightBlockMargins;
322
323 static void finalizeBlock( QgsTextDocumentMetrics &res, const QgsTextFormat &format, DocumentMetrics &documentMetrics, QgsTextBlock &outputBlock, BlockMetrics &metrics );
324 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 );
325};
326
327#endif // QGSTEXTDOCUMENTMETRICS_H
TextLayoutMode
Text layout modes.
Definition qgis.h:2744
QFlags< TextRendererFlag > TextRendererFlags
Definition qgis.h:3207
TextOrientation
Text orientations.
Definition qgis.h:2729
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.