QGIS API Documentation 4.1.0-Master (60fea48833c)
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:
45 QgsPrecalculatedTextMetrics( const QStringList &graphemes, const QVector< double > &characterWidths, const QVector< double > &characterHeights, const QVector< double > &characterDescents )
46 : mGraphemes( graphemes )
47 , mCharacterHeights( characterHeights )
48 , mCharacterWidths( characterWidths )
49 , mCharacterDescents( characterDescents )
50 {
51 Q_ASSERT( mCharacterHeights.size() == mCharacterWidths.size() );
52 Q_ASSERT( mCharacterDescents.size() == mCharacterWidths.size() );
53
54 if ( !mCharacterHeights.empty() )
55 {
56 mMaximumCharacterHeight = *std::max_element( mCharacterHeights.constBegin(), mCharacterHeights.constEnd() );
57 mMaximumCharacterDescent = *std::max_element( mCharacterDescents.constBegin(), mCharacterDescents.constEnd() );
58 }
59 }
60
64 int count() const { return static_cast< int >( mCharacterWidths.size() ); }
65
69 double characterWidth( int position ) const
70 {
71 // caller's responsibility to check!
72 // cppcheck-suppress negativeContainerIndex
73 return mCharacterWidths[position];
74 }
75
81 double characterHeight( int position ) const
82 {
83 // caller's responsibility to check!
84 // cppcheck-suppress negativeContainerIndex
85 return mCharacterHeights[position];
86 }
87
93 double characterDescent( int position ) const
94 {
95 // caller's responsibility to check!
96 // cppcheck-suppress negativeContainerIndex
97 return mCharacterDescents[position];
98 }
99
105 double maximumCharacterHeight() const { return mMaximumCharacterHeight; }
106
112 double maximumCharacterDescent() const { return mMaximumCharacterDescent; }
113
117 QStringList graphemes() const { return mGraphemes; }
118
122 QString grapheme( int index ) const { return mGraphemes.at( index ); }
123
127 void setGraphemeFormats( const QVector< QgsTextCharacterFormat > &formats ) { mGraphemeFormats = formats; }
128
132 int graphemeFormatCount() const { return mGraphemeFormats.count(); }
133
137 QgsTextCharacterFormat graphemeFormat( int index ) const { return mGraphemeFormats.value( index ); }
138
139 private:
140 QStringList mGraphemes;
141 QVector< QgsTextCharacterFormat > mGraphemeFormats;
142 QVector< double > mCharacterHeights;
143 QVector< double > mCharacterWidths;
144 QVector< double > mCharacterDescents;
145 double mMaximumCharacterHeight = 0;
146 double mMaximumCharacterDescent = 0;
147};
148
149
150#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.