QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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_core.h"
20#include "qgis_sip.h"
22
23#include <QStringList>
24#include <QVector>
25
26#define SIP_NO_FILE
27
36{
37 public:
38
47 const QVector< double > &characterWidths,
48 const QVector< double > &characterHeights,
49 const QVector< double > &characterDescents )
50 : mGraphemes( graphemes )
51 , mCharacterHeights( characterHeights )
52 , mCharacterWidths( characterWidths )
53 , mCharacterDescents( characterDescents )
54 {
55 Q_ASSERT( mCharacterHeights.size() == mCharacterWidths.size() );
56 Q_ASSERT( mCharacterDescents.size() == mCharacterWidths.size() );
57
58 if ( !mCharacterHeights.empty() )
59 {
60 mMaximumCharacterHeight = *std::max_element( mCharacterHeights.constBegin(), mCharacterHeights.constEnd() );
61 mMaximumCharacterDescent = *std::max_element( mCharacterDescents.constBegin(), mCharacterDescents.constEnd() );
62 }
63 }
64
68 int count() const { return static_cast< int >( mCharacterWidths.size() ); }
69
73 double characterWidth( int position ) const { return mCharacterWidths[position]; }
74
80 double characterHeight( int position ) const { return mCharacterHeights[position]; }
81
87 double characterDescent( int position ) const { return mCharacterDescents[position]; }
88
94 double maximumCharacterHeight() const { return mMaximumCharacterHeight; }
95
101 double maximumCharacterDescent() const { return mMaximumCharacterDescent; }
102
106 QStringList graphemes() const { return mGraphemes; }
107
111 QString grapheme( int index ) const { return mGraphemes.at( index ); }
112
116 void setGraphemeFormats( const QVector< QgsTextCharacterFormat > &formats ) { mGraphemeFormats = formats; }
117
121 int graphemeFormatCount() const { return mGraphemeFormats.count(); }
122
126 QgsTextCharacterFormat graphemeFormat( int index ) const { return mGraphemeFormats.value( index ); }
127
128 private:
129
130 QStringList mGraphemes;
131 QVector< QgsTextCharacterFormat > mGraphemeFormats;
132 QVector< double > mCharacterHeights;
133 QVector< double > mCharacterWidths;
134 QVector< double > mCharacterDescents;
135 double mMaximumCharacterHeight = 0;
136 double mMaximumCharacterDescent = 0;
137
138};
139
140
141#endif // QGSTEXTMETRICS_H
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.