QGIS API Documentation 3.99.0-Master (a8882ad4560)
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
74 {
75 // caller's responsibility to check!
76 // cppcheck-suppress negativeContainerIndex
77 return mCharacterWidths[position];
78 }
79
85 double characterHeight( int position ) const
86 {
87 // caller's responsibility to check!
88 // cppcheck-suppress negativeContainerIndex
89 return mCharacterHeights[position];
90 }
91
97 double characterDescent( int position ) const
98 {
99 // caller's responsibility to check!
100 // cppcheck-suppress negativeContainerIndex
101 return mCharacterDescents[position];
102 }
103
109 double maximumCharacterHeight() const { return mMaximumCharacterHeight; }
110
116 double maximumCharacterDescent() const { return mMaximumCharacterDescent; }
117
121 QStringList graphemes() const { return mGraphemes; }
122
126 QString grapheme( int index ) const { return mGraphemes.at( index ); }
127
131 void setGraphemeFormats( const QVector< QgsTextCharacterFormat > &formats ) { mGraphemeFormats = formats; }
132
136 int graphemeFormatCount() const { return mGraphemeFormats.count(); }
137
141 QgsTextCharacterFormat graphemeFormat( int index ) const { return mGraphemeFormats.value( index ); }
142
143 private:
144
145 QStringList mGraphemes;
146 QVector< QgsTextCharacterFormat > mGraphemeFormats;
147 QVector< double > mCharacterHeights;
148 QVector< double > mCharacterWidths;
149 QVector< double > mCharacterDescents;
150 double mMaximumCharacterHeight = 0;
151 double mMaximumCharacterDescent = 0;
152
153};
154
155
156#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.