QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgstextmetrics.h
Go to the documentation of this file.
1/***************************************************************************
2 qgstextmetrics.h
3 -----------------
4 begin : April 2021
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 QGSTEXTMETRICS_H
17#define QGSTEXTMETRICS_H
18
19#include "qgis_sip.h"
20#include "qgis_core.h"
22#include <QVector>
23#include <QStringList>
24
25#define SIP_NO_FILE
26
35{
36 public:
37
45 QgsPrecalculatedTextMetrics( const QStringList &graphemes,
46 const QVector< double > &characterWidths,
47 const QVector< double > &characterHeights,
48 const QVector< double > &characterDescents )
49 : mGraphemes( graphemes )
50 , mCharacterHeights( characterHeights )
51 , mCharacterWidths( characterWidths )
52 , mCharacterDescents( characterDescents )
53 {
54 Q_ASSERT( mCharacterHeights.size() == mCharacterWidths.size() );
55 Q_ASSERT( mCharacterDescents.size() == mCharacterWidths.size() );
56
57 if ( !mCharacterHeights.empty() )
58 {
59 mMaximumCharacterHeight = *std::max_element( mCharacterHeights.constBegin(), mCharacterHeights.constEnd() );
60 mMaximumCharacterDescent = *std::max_element( mCharacterDescents.constBegin(), mCharacterDescents.constEnd() );
61 }
62 }
63
67 int count() const { return static_cast< int >( mCharacterWidths.size() ); }
68
72 double characterWidth( int position ) const { return mCharacterWidths[position]; }
73
79 double characterHeight( int position ) const { return mCharacterHeights[position]; }
80
86 double characterDescent( int position ) const { return mCharacterDescents[position]; }
87
93 double maximumCharacterHeight() const { return mMaximumCharacterHeight; }
94
100 double maximumCharacterDescent() const { return mMaximumCharacterDescent; }
101
105 QStringList graphemes() const { return mGraphemes; }
106
110 QString grapheme( int index ) const { return mGraphemes.at( index ); }
111
115 void setGraphemeFormats( const QVector< QgsTextCharacterFormat > &formats ) { mGraphemeFormats = formats; }
116
120 int graphemeFormatCount() const { return mGraphemeFormats.count(); }
121
125 QgsTextCharacterFormat graphemeFormat( int index ) const { return mGraphemeFormats.value( index ); }
126
127 private:
128
129 QStringList mGraphemes;
130 QVector< QgsTextCharacterFormat > mGraphemeFormats;
131 QVector< double > mCharacterHeights;
132 QVector< double > mCharacterWidths;
133 QVector< double > mCharacterDescents;
134 double mMaximumCharacterHeight = 0;
135 double mMaximumCharacterDescent = 0;
136
137};
138
139
140#endif // QGSTEXTMETRICS_H
Contains precalculated properties regarding text metrics for text to be renderered at a later stage.
int graphemeFormatCount() const
Returns the number of grapheme formats available.
QgsTextCharacterFormat graphemeFormat(int index) const
Returns the character format for the grapheme at the specified index.
double maximumCharacterHeight() const
Returns the maximum height of any character found in the text.
QStringList graphemes() const
Returns the list of graphemes contained in the text.
QgsPrecalculatedTextMetrics(const QStringList &graphemes, const QVector< double > &characterWidths, const QVector< double > &characterHeights, const QVector< double > &characterDescents)
Constructor for QgsPrecalculatedTextMetrics.
double characterDescent(int position) const
Returns the descent of the character at the specified position.
int count() const
Returns the total number of characters.
double maximumCharacterDescent() const
Returns the maximum descent of any character found in the text.
double characterWidth(int position) const
Returns the width of the character at the specified position.
QString grapheme(int index) const
Returns the grapheme at the specified index.
double characterHeight(int position) const
Returns the character height of the character at the specified position (actually font metrics height...
void setGraphemeFormats(const QVector< QgsTextCharacterFormat > &formats)
Sets the character formats associated with the text graphemes().
Stores information relating to individual character formatting.