QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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
23#include <QVector>
24#include <QSizeF>
25#include <QRectF>
26
27class QgsTextDocument;
29class QgsTextFormat;
30
41class CORE_EXPORT QgsTextDocumentMetrics
42{
43 public:
44
54 static QgsTextDocumentMetrics calculateMetrics( const QgsTextDocument &document, const QgsTextFormat &format, const QgsRenderContext &context, double scaleFactor = 1.0 );
55
61 bool isNullFontSize() const { return mIsNullSize; }
62
66 QSizeF documentSize( Qgis::TextLayoutMode mode, Qgis::TextOrientation orientation ) const;
67
77 QRectF outerBounds( Qgis::TextLayoutMode mode, Qgis::TextOrientation orientation ) const;
78
82 double blockWidth( int blockIndex ) const;
83
87 double blockHeight( int blockIndex ) const;
88
94 double firstLineCapHeight() const;
95
99 double baselineOffset( int blockIndex, Qgis::TextLayoutMode mode ) const;
100
106 double fragmentHorizontalAdvance( int blockIndex, int fragmentIndex, Qgis::TextLayoutMode mode ) const;
107
114 double fragmentVerticalOffset( int blockIndex, int fragmentIndex, Qgis::TextLayoutMode mode ) const;
115
119 double verticalOrientationXOffset( int blockIndex ) const;
120
124 double blockMaximumCharacterWidth( int blockIndex ) const;
125
129 double blockMaximumDescent( int blockIndex ) const;
130
134 QFont fragmentFont( int blockIndex, int fragmentIndex ) const;
135
139 double ascentOffset() const { return mFirstLineAscentOffset; }
140
141 private:
142
143 bool mIsNullSize = false;
144
145 QSizeF mDocumentSizeLabelMode;
146 QSizeF mDocumentSizePointRectMode;
147 QSizeF mDocumentSizeVerticalOrientation;
148 QSizeF mDocumentSizeCapHeightMode;
149 QSizeF mDocumentSizeAscentMode;
150
151 QRectF mOuterBoundsLabelMode;
152
153 QList < QList< QFont > > mFragmentFonts;
154 QList< double > mBlockWidths;
155 QList< double > mBlockHeights;
156 QList< double > mBaselineOffsetsLabelMode;
157 QList< double > mBaselineOffsetsPointMode;
158 QList< double > mBaselineOffsetsRectMode;
159 QList< double > mBaselineOffsetsCapHeightMode;
160 QList< double > mBaselineOffsetsAscentBased;
161
162 QList< QList< double > > mFragmentHorizontalAdvance;
163
164 QList< QList< double > > mFragmentVerticalOffsetsLabelMode;
165 QList< QList< double > > mFragmentVerticalOffsetsPointMode;
166 QList< QList< double > > mFragmentVerticalOffsetsRectMode;
167
168 QList< double > mVerticalOrientationXOffsets;
169 QList< double > mBlockMaxDescent;
170 QList< double > mBlockMaxCharacterWidth;
171 double mFirstLineAscentOffset = 0;
172 double mLastLineAscentOffset = 0;
173 double mFirstLineCapHeight = 0;
174
175};
176
177#endif // QGSTEXTDOCUMENTMETRICS_H
TextLayoutMode
Text layout modes.
Definition: qgis.h:2383
TextOrientation
Text orientations.
Definition: qgis.h:2368
Contains information about the context of a rendering operation.
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.
double ascentOffset() const
Returns the ascent offset of the first block in the document.
Represents a document consisting of one or more QgsTextBlock objects.
Container for all settings relating to text rendering.
Definition: qgstextformat.h:41