QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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
QgsPrecalculatedTextMetrics::setGraphemeFormats
void setGraphemeFormats(const QVector< QgsTextCharacterFormat > &formats)
Sets the character formats associated with the text graphemes().
Definition: qgstextmetrics.h:79
QgsPrecalculatedTextMetrics::characterHeight
double characterHeight() const
Character height (actually font metrics height, not individual character height).
Definition: qgstextmetrics.h:54
QgsTextCharacterFormat
Stores information relating to individual character formatting.
Definition: qgstextcharacterformat.h:39
QgsPrecalculatedTextMetrics::graphemeFormat
QgsTextCharacterFormat graphemeFormat(int index) const
Returns the character format for the grapheme at the specified index.
Definition: qgstextmetrics.h:89
QgsPrecalculatedTextMetrics::characterWidth
double characterWidth(int position) const
Returns the width of the character at the specified position.
Definition: qgstextmetrics.h:64
QgsPrecalculatedTextMetrics::grapheme
QString grapheme(int index) const
Returns the grapheme at the specified index.
Definition: qgstextmetrics.h:74
QgsPrecalculatedTextMetrics::count
int count() const
Returns the total number of characters.
Definition: qgstextmetrics.h:59
qgstextcharacterformat.h
qgis_sip.h
QgsPrecalculatedTextMetrics
Contains precalculated properties regarding text metrics for text to be renderered at a later stage.
Definition: qgstextmetrics.h:34
QgsPrecalculatedTextMetrics::graphemeFormatCount
int graphemeFormatCount() const
Returns the number of grapheme formats available.
Definition: qgstextmetrics.h:84
QgsPrecalculatedTextMetrics::QgsPrecalculatedTextMetrics
QgsPrecalculatedTextMetrics(const QStringList &graphemes, double characterHeight, const QVector< double > &characterWidths)
Constructor for QgsPrecalculatedTextMetrics.
Definition: qgstextmetrics.h:44
QgsPrecalculatedTextMetrics::graphemes
QStringList graphemes() const
Returns the list of graphemes contained in the text.
Definition: qgstextmetrics.h:69