QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
QgsTextDocumentMetrics Class Reference

Contains pre-calculated metrics of a QgsTextDocument. More...

#include <qgstextdocumentmetrics.h>

Public Member Functions

double ascentOffset () const
 Returns the ascent offset of the first block in the document.
 
double baselineOffset (int blockIndex, Qgis::TextLayoutMode mode) const
 Returns the offset from the top of the document to the text baseline for the given block index.
 
double blockHeight (int blockIndex) const
 Returns the height of the block at the specified index.
 
double blockLeftMargin (int blockIndex) const
 Returns the margin for the left side of the specified block index.
 
double blockMaximumAscent (int blockIndex) const
 Returns the maximum ascent encountered in the specified block.
 
double blockMaximumCharacterWidth (int blockIndex) const
 Returns the maximum character width for the specified block.
 
double blockMaximumDescent (int blockIndex) const
 Returns the maximum descent encountered in the specified block.
 
double blockRightMargin (int blockIndex) const
 Returns the margin for the right side of the specified block index.
 
double blockVerticalMargin (int blockIndex) const
 Returns the vertical margin for the specified block index.
 
double blockWidth (int blockIndex) const
 Returns the width of the block at the specified index.
 
const QgsTextDocumentdocument () const
 Returns the document associated with the calculated metrics.
 
QSizeF documentSize (Qgis::TextLayoutMode mode, Qgis::TextOrientation orientation) const
 Returns the overall size of the document.
 
double firstLineCapHeight () const
 Returns the cap height for the first line of text.
 
double fragmentAscent (int blockIndex, int fragmentIndex, Qgis::TextLayoutMode mode) const
 Returns the ascent of the fragment at the specified block and fragment index.
 
double fragmentDescent (int blockIndex, int fragmentIndex, Qgis::TextLayoutMode mode) const
 Returns the descent of the fragment at the specified block and fragment index.
 
double fragmentFixedHeight (int blockIndex, int fragmentIndex, Qgis::TextLayoutMode mode) const
 Returns the fixed height of the fragment at the specified block and fragment index, or -1 if the fragment does not have a fixed height.
 
QFont fragmentFont (int blockIndex, int fragmentIndex) const
 Returns the calculated font for the fragment at the specified block and fragment indices.
 
double fragmentHorizontalAdvance (int blockIndex, int fragmentIndex, Qgis::TextLayoutMode mode) const
 Returns the horizontal advance of the fragment at the specified block and fragment index.
 
double fragmentVerticalOffset (int blockIndex, int fragmentIndex, Qgis::TextLayoutMode mode) const
 Returns the vertical offset from a text block's baseline which should be applied to the fragment at the specified index within that block.
 
bool isNullFontSize () const
 Returns true if the metrics could not be calculated because the text format has a null font size.
 
QRectF outerBounds (Qgis::TextLayoutMode mode, Qgis::TextOrientation orientation) const
 Returns the outer bounds of the document, which is the documentSize() adjusted to account for any text elements which fall outside of the usual document margins (such as super or sub script elements)
 
double verticalOrientationXOffset (int blockIndex) const
 Returns the vertical orientation x offset for the specified block.
 

Static Public Member Functions

static QgsTextDocumentMetrics calculateMetrics (const QgsTextDocument &document, const QgsTextFormat &format, const QgsRenderContext &context, double scaleFactor=1.0, const QgsTextDocumentRenderContext &documentContext=QgsTextDocumentRenderContext())
 Returns precalculated text metrics for a text document, when rendered using the given base format and render context.
 

Detailed Description

Contains pre-calculated metrics of a QgsTextDocument.

Warning
This API is not considered stable and may change in future QGIS versions.
Since
QGIS 3.28

Definition at line 96 of file qgstextdocumentmetrics.h.

Member Function Documentation

◆ ascentOffset()

double QgsTextDocumentMetrics::ascentOffset ( ) const
inline

Returns the ascent offset of the first block in the document.

Definition at line 243 of file qgstextdocumentmetrics.h.

◆ baselineOffset()

double QgsTextDocumentMetrics::baselineOffset ( int  blockIndex,
Qgis::TextLayoutMode  mode 
) const

Returns the offset from the top of the document to the text baseline for the given block index.

Definition at line 810 of file qgstextdocumentmetrics.cpp.

◆ blockHeight()

double QgsTextDocumentMetrics::blockHeight ( int  blockIndex) const

Returns the height of the block at the specified index.

Definition at line 800 of file qgstextdocumentmetrics.cpp.

◆ blockLeftMargin()

double QgsTextDocumentMetrics::blockLeftMargin ( int  blockIndex) const

Returns the margin for the left side of the specified block index.

See also
blockVerticalMargin()
blockRightMargin()
Since
QGIS 3.42

Definition at line 904 of file qgstextdocumentmetrics.cpp.

◆ blockMaximumAscent()

double QgsTextDocumentMetrics::blockMaximumAscent ( int  blockIndex) const

Returns the maximum ascent encountered in the specified block.

See also
blockMaximumDescent()
Since
QGIS 3.42

Definition at line 886 of file qgstextdocumentmetrics.cpp.

◆ blockMaximumCharacterWidth()

double QgsTextDocumentMetrics::blockMaximumCharacterWidth ( int  blockIndex) const

Returns the maximum character width for the specified block.

Definition at line 876 of file qgstextdocumentmetrics.cpp.

◆ blockMaximumDescent()

double QgsTextDocumentMetrics::blockMaximumDescent ( int  blockIndex) const

Returns the maximum descent encountered in the specified block.

See also
blockMaximumAscent()

Definition at line 881 of file qgstextdocumentmetrics.cpp.

◆ blockRightMargin()

double QgsTextDocumentMetrics::blockRightMargin ( int  blockIndex) const

Returns the margin for the right side of the specified block index.

See also
blockVerticalMargin()
blockLeftMargin()
Since
QGIS 3.42

Definition at line 909 of file qgstextdocumentmetrics.cpp.

◆ blockVerticalMargin()

double QgsTextDocumentMetrics::blockVerticalMargin ( int  blockIndex) const

Returns the vertical margin for the specified block index.

If blockIndex >= 0 then the returned value will be the margin to place after the block. If blockIndex < 0 then the returned value will be the margin to place before the first block.

See also
blockLeftMargin()
blockRightMargin()
Since
QGIS 3.42

Definition at line 896 of file qgstextdocumentmetrics.cpp.

◆ blockWidth()

double QgsTextDocumentMetrics::blockWidth ( int  blockIndex) const

Returns the width of the block at the specified index.

Definition at line 795 of file qgstextdocumentmetrics.cpp.

◆ calculateMetrics()

QgsTextDocumentMetrics QgsTextDocumentMetrics::calculateMetrics ( const QgsTextDocument document,
const QgsTextFormat format,
const QgsRenderContext context,
double  scaleFactor = 1.0,
const QgsTextDocumentRenderContext documentContext = QgsTextDocumentRenderContext() 
)
static

Returns precalculated text metrics for a text document, when rendered using the given base format and render context.

The optional scaleFactor parameter can specify a font size scaling factor. It is recommended to set this to QgsTextRenderer::calculateScaleFactorForFormat() and then manually calculations based on the resultant font metrics. Failure to do so will result in poor quality text rendering at small font sizes.

Since QGIS 3.40 the optional documentContext argument can be used to pass text renderer context to change the logistics of the calculated metrics.

Definition at line 598 of file qgstextdocumentmetrics.cpp.

◆ document()

const QgsTextDocument & QgsTextDocumentMetrics::document ( ) const
inline

Returns the document associated with the calculated metrics.

Note that this may not exactly match the original document which was used in the call to calculateMetrics(), as certain settings (such as text wrapping) require restructuring the document.

Since
QGIS 3.40

Definition at line 130 of file qgstextdocumentmetrics.h.

◆ documentSize()

QSizeF QgsTextDocumentMetrics::documentSize ( Qgis::TextLayoutMode  mode,
Qgis::TextOrientation  orientation 
) const

Returns the overall size of the document.

Definition at line 738 of file qgstextdocumentmetrics.cpp.

◆ firstLineCapHeight()

double QgsTextDocumentMetrics::firstLineCapHeight ( ) const

Returns the cap height for the first line of text.

Since
QGIS 3.30

Definition at line 805 of file qgstextdocumentmetrics.cpp.

◆ fragmentAscent()

double QgsTextDocumentMetrics::fragmentAscent ( int  blockIndex,
int  fragmentIndex,
Qgis::TextLayoutMode  mode 
) const

Returns the ascent of the fragment at the specified block and fragment index.

See also
fragmentDescent()
Since
QGIS 3.42

Definition at line 861 of file qgstextdocumentmetrics.cpp.

◆ fragmentDescent()

double QgsTextDocumentMetrics::fragmentDescent ( int  blockIndex,
int  fragmentIndex,
Qgis::TextLayoutMode  mode 
) const

Returns the descent of the fragment at the specified block and fragment index.

See also
fragmentAscent()
Since
QGIS 3.42

Definition at line 866 of file qgstextdocumentmetrics.cpp.

◆ fragmentFixedHeight()

double QgsTextDocumentMetrics::fragmentFixedHeight ( int  blockIndex,
int  fragmentIndex,
Qgis::TextLayoutMode  mode 
) const

Returns the fixed height of the fragment at the specified block and fragment index, or -1 if the fragment does not have a fixed height.

Since
QGIS 3.40

Definition at line 856 of file qgstextdocumentmetrics.cpp.

◆ fragmentFont()

QFont QgsTextDocumentMetrics::fragmentFont ( int  blockIndex,
int  fragmentIndex 
) const

Returns the calculated font for the fragment at the specified block and fragment indices.

Definition at line 891 of file qgstextdocumentmetrics.cpp.

◆ fragmentHorizontalAdvance()

double QgsTextDocumentMetrics::fragmentHorizontalAdvance ( int  blockIndex,
int  fragmentIndex,
Qgis::TextLayoutMode  mode 
) const

Returns the horizontal advance of the fragment at the specified block and fragment index.

Since
QGIS 3.30

Definition at line 835 of file qgstextdocumentmetrics.cpp.

◆ fragmentVerticalOffset()

double QgsTextDocumentMetrics::fragmentVerticalOffset ( int  blockIndex,
int  fragmentIndex,
Qgis::TextLayoutMode  mode 
) const

Returns the vertical offset from a text block's baseline which should be applied to the fragment at the specified index within that block.

Since
QGIS 3.30

Definition at line 840 of file qgstextdocumentmetrics.cpp.

◆ isNullFontSize()

bool QgsTextDocumentMetrics::isNullFontSize ( ) const
inline

Returns true if the metrics could not be calculated because the text format has a null font size.

Since
QGIS 3.30

Definition at line 120 of file qgstextdocumentmetrics.h.

◆ outerBounds()

QRectF QgsTextDocumentMetrics::outerBounds ( Qgis::TextLayoutMode  mode,
Qgis::TextOrientation  orientation 
) const

Returns the outer bounds of the document, which is the documentSize() adjusted to account for any text elements which fall outside of the usual document margins (such as super or sub script elements)

Warning
Currently this is only supported for the Qgis::TextLayoutMode::Labeling mode.
Since
QGIS 3.30

Definition at line 769 of file qgstextdocumentmetrics.cpp.

◆ verticalOrientationXOffset()

double QgsTextDocumentMetrics::verticalOrientationXOffset ( int  blockIndex) const

Returns the vertical orientation x offset for the specified block.

Definition at line 871 of file qgstextdocumentmetrics.cpp.


The documentation for this class was generated from the following files: