QGIS API Documentation 3.39.0-Master (bca3cdb6021)
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
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
121 double fragmentFixedHeight( int blockIndex, int fragmentIndex, Qgis::TextLayoutMode mode ) const;
122
126 double verticalOrientationXOffset( int blockIndex ) const;
127
131 double blockMaximumCharacterWidth( int blockIndex ) const;
132
136 double blockMaximumDescent( int blockIndex ) const;
137
141 QFont fragmentFont( int blockIndex, int fragmentIndex ) const;
142
146 double ascentOffset() const { return mFirstLineAscentOffset; }
147
148 private:
149
150 bool mIsNullSize = false;
151
152 QSizeF mDocumentSizeLabelMode;
153 QSizeF mDocumentSizePointRectMode;
154 QSizeF mDocumentSizeVerticalOrientation;
155 QSizeF mDocumentSizeCapHeightMode;
156 QSizeF mDocumentSizeAscentMode;
157
158 QRectF mOuterBoundsLabelMode;
159
160 QList < QList< QFont > > mFragmentFonts;
161 QList< double > mBlockWidths;
162 QList< double > mBlockHeights;
163 QList< double > mBaselineOffsetsLabelMode;
164 QList< double > mBaselineOffsetsPointMode;
165 QList< double > mBaselineOffsetsRectMode;
166 QList< double > mBaselineOffsetsCapHeightMode;
167 QList< double > mBaselineOffsetsAscentBased;
168
169 QList< QList< double > > mFragmentHorizontalAdvance;
170 QList< QList< double > > mFragmentFixedHeights;
171
172 QList< QList< double > > mFragmentVerticalOffsetsLabelMode;
173 QList< QList< double > > mFragmentVerticalOffsetsPointMode;
174 QList< QList< double > > mFragmentVerticalOffsetsRectMode;
175
176 QList< double > mVerticalOrientationXOffsets;
177 QList< double > mBlockMaxDescent;
178 QList< double > mBlockMaxCharacterWidth;
179 double mFirstLineAscentOffset = 0;
180 double mLastLineAscentOffset = 0;
181 double mFirstLineCapHeight = 0;
182
183};
184
185#endif // QGSTEXTDOCUMENTMETRICS_H
TextLayoutMode
Text layout modes.
Definition qgis.h:2698
TextOrientation
Text orientations.
Definition qgis.h:2683
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.