QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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"
21 #include "qgstextcharacterformat.h"
22 #include <QVector>
23 #include <QStringList>
24 
25 #define SIP_NO_FILE
26 
34 class CORE_EXPORT QgsPrecalculatedTextMetrics
35 {
36  public:
37 
44  QgsPrecalculatedTextMetrics( const QStringList &graphemes, double characterHeight, const QVector< double > &characterWidths )
45  : mGraphemes( graphemes )
46  , mCharacterHeight( characterHeight )
47  , mCharacterWidths( characterWidths )
48  {
49  }
50 
54  double characterHeight() const { return mCharacterHeight; }
55 
59  int count() const { return static_cast< int >( mCharacterWidths.size() ); }
60 
64  double characterWidth( int position ) const { return mCharacterWidths[position]; }
65 
69  QStringList graphemes() const { return mGraphemes; }
70 
74  QString grapheme( int index ) const { return mGraphemes.at( index ); }
75 
79  void setGraphemeFormats( const QVector< QgsTextCharacterFormat > &formats ) { mGraphemeFormats = formats; }
80 
84  int graphemeFormatCount() const { return mGraphemeFormats.count(); }
85 
89  QgsTextCharacterFormat graphemeFormat( int index ) const { return mGraphemeFormats.value( index ); }
90 
91  private:
92 
93  QStringList mGraphemes;
94  QVector< QgsTextCharacterFormat > mGraphemeFormats;
95  double mCharacterHeight = 0;
96  QVector< double > mCharacterWidths;
97 
98 };
99 
100 
101 #endif // QGSTEXTMETRICS_H
Contains precalculated properties regarding text metrics for text to be renderered at a later stage.
double characterHeight() const
Character height (actually font metrics height, not individual character height).
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.
QgsPrecalculatedTextMetrics(const QStringList &graphemes, double characterHeight, const QVector< double > &characterWidths)
Constructor for QgsPrecalculatedTextMetrics.
QStringList graphemes() const
Returns the list of graphemes contained in the text.
int count() const
Returns the total number of characters.
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.
void setGraphemeFormats(const QVector< QgsTextCharacterFormat > &formats)
Sets the character formats associated with the text graphemes().
Stores information relating to individual character formatting.