QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
textrenderer
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
"
21
#include "
qgstextcharacterformat.h
"
22
23
#include <QStringList>
24
#include <QVector>
25
26
#define SIP_NO_FILE
27
35
class
CORE_EXPORT
QgsPrecalculatedTextMetrics
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
QgsPrecalculatedTextMetrics::graphemeFormatCount
int graphemeFormatCount() const
Returns the number of grapheme formats available.
Definition
qgstextmetrics.h:132
QgsPrecalculatedTextMetrics::graphemeFormat
QgsTextCharacterFormat graphemeFormat(int index) const
Returns the character format for the grapheme at the specified index.
Definition
qgstextmetrics.h:137
QgsPrecalculatedTextMetrics::maximumCharacterHeight
double maximumCharacterHeight() const
Returns the maximum height of any character found in the text.
Definition
qgstextmetrics.h:105
QgsPrecalculatedTextMetrics::graphemes
QStringList graphemes() const
Returns the list of graphemes contained in the text.
Definition
qgstextmetrics.h:117
QgsPrecalculatedTextMetrics::QgsPrecalculatedTextMetrics
QgsPrecalculatedTextMetrics(const QStringList &graphemes, const QVector< double > &characterWidths, const QVector< double > &characterHeights, const QVector< double > &characterDescents)
Constructor for QgsPrecalculatedTextMetrics.
Definition
qgstextmetrics.h:45
QgsPrecalculatedTextMetrics::characterDescent
double characterDescent(int position) const
Returns the descent of the character at the specified position.
Definition
qgstextmetrics.h:93
QgsPrecalculatedTextMetrics::count
int count() const
Returns the total number of characters.
Definition
qgstextmetrics.h:64
QgsPrecalculatedTextMetrics::maximumCharacterDescent
double maximumCharacterDescent() const
Returns the maximum descent of any character found in the text.
Definition
qgstextmetrics.h:112
QgsPrecalculatedTextMetrics::characterWidth
double characterWidth(int position) const
Returns the width of the character at the specified position.
Definition
qgstextmetrics.h:69
QgsPrecalculatedTextMetrics::grapheme
QString grapheme(int index) const
Returns the grapheme at the specified index.
Definition
qgstextmetrics.h:122
QgsPrecalculatedTextMetrics::characterHeight
double characterHeight(int position) const
Returns the character height of the character at the specified position (actually font metrics height...
Definition
qgstextmetrics.h:81
QgsPrecalculatedTextMetrics::setGraphemeFormats
void setGraphemeFormats(const QVector< QgsTextCharacterFormat > &formats)
Sets the character formats associated with the text graphemes().
Definition
qgstextmetrics.h:127
QgsTextCharacterFormat
Stores information relating to individual character formatting.
Definition
qgstextcharacterformat.h:44
qgis_sip.h
qgstextcharacterformat.h
Generated on
for QGIS API Documentation by
1.17.0