QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
3d
qgsfonttextureatlasgenerator.h
Go to the documentation of this file.
1
/***************************************************************************
2
qgsfonttextureatlasgenerator.h
3
--------------------------------------
4
Date : September 2025
5
Copyright : (C) 2025 by 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 QGSFONTTEXTUREATLASGENERATOR_H
17
#define QGSFONTTEXTUREATLASGENERATOR_H
18
19
#include <vector>
20
21
#include "qgis_3d.h"
22
#include "
qgstextformat.h
"
23
24
#include <QImage>
25
#include <QRect>
26
#include <QString>
27
28
using namespace
Qt::StringLiterals;
29
31
class
QgsCharTextureRect;
33
34
46
class
_3D_EXPORT
QgsFontTextureAtlas
47
{
48
public
:
49
QgsFontTextureAtlas
();
50
~QgsFontTextureAtlas
();
51
52
QgsFontTextureAtlas
(
const
QgsFontTextureAtlas
&other );
53
QgsFontTextureAtlas
&
operator=
(
const
QgsFontTextureAtlas
&other );
54
58
bool
isValid
()
const
{
return
mAtlasSize.isValid(); }
59
64
QSize
atlasSize
()
const
{
return
mAtlasSize; }
65
66
#ifndef SIP_RUN
70
QRect rect(
const
QString &grapheme )
const
;
71
#else
72
78
QRect rect(
const
QString &grapheme )
const
;
79
//%MethodCode
80
const
QRect res = sipCpp->rect( *a0 );
81
if
( res.isNull() )
82
{
83
PyErr_SetString( PyExc_KeyError, u
"No rectangle for character %1 exists."
_s.arg( *a0 ).toUtf8().constData() );
84
sipIsErr = 1;
85
}
86
else
87
{
88
return
sipConvertFromNewType(
new
QRect( res ), sipType_QRect, Py_None );
89
}
90
//%End
91
#endif
92
99
int
graphemeCount(
const
QString &
string
)
const
;
100
107
int
totalWidth(
const
QString &
string
)
const
;
108
115
QPoint pixelOffsetForGrapheme(
const
QString &
string
,
int
graphemeIndex )
const
;
116
123
QRect textureRectForGrapheme(
const
QString &
string
,
int
graphemeIndex )
const
;
124
128
QImage renderAtlasTexture()
const
;
129
136
QImage renderDebugTexture()
const
;
137
141
int
count()
const
;
142
143
#ifdef SIP_RUN
144
// clang-format off
145
int
__len__()
const
;
146
% Docstring
147
Returns the number of textures in the atlas.
148
% End
149
//%MethodCode
150
sipRes = sipCpp->count();
151
//% End
152
// clang-format on
153
#endif
154
155
private
:
156
struct
GraphemeMetric
157
{
158
GraphemeMetric(
int
horizontalAdvance = 0,
const
QString &grapheme = QString() )
159
: horizontalAdvance( horizontalAdvance )
160
, grapheme( grapheme )
161
{}
162
163
int
horizontalAdvance = 0;
164
QString grapheme;
165
};
166
167
struct
StringMetrics
168
{
169
int
totalWidth = 0;
170
QVector< GraphemeMetric > graphemeMetrics;
171
};
172
173
QgsTextFormat mFormat;
174
std::vector< QgsCharTextureRect > mRects;
175
QSize mAtlasSize;
176
QHash< QString, int > mGraphemeIndices;
177
QMap< QString, StringMetrics > mStringMetrics;
178
int
mTexturePaddingPixels = 0;
179
180
friend
class
QgsFontTextureAtlasGenerator
;
181
};
182
189
class
_3D_EXPORT
QgsFontTextureAtlasGenerator
190
{
191
public
:
195
static
QgsFontTextureAtlas
create
(
const
QgsTextFormat
&format,
const
QStringList &strings );
196
};
197
198
#endif
// QGSFONTTEXTUREATLASGENERATOR_H
QgsFontTextureAtlasGenerator
Generates texture atlases for a font by efficiently packing the characters required for a set of stri...
Definition
qgsfonttextureatlasgenerator.h:190
QgsFontTextureAtlasGenerator::create
static QgsFontTextureAtlas create(const QgsTextFormat &format, const QStringList &strings)
Creates the texture atlas for a set of strings, using the specified text format.
Definition
qgsfonttextureatlasgenerator.cpp:186
QgsFontTextureAtlas
Encapsulates a font texture atlas.
Definition
qgsfonttextureatlasgenerator.h:47
QgsFontTextureAtlas::atlasSize
QSize atlasSize() const
Returns the total size required for the atlas, i.e.
Definition
qgsfonttextureatlasgenerator.h:64
QgsFontTextureAtlas::QgsFontTextureAtlasGenerator
friend class QgsFontTextureAtlasGenerator
Definition
qgsfonttextureatlasgenerator.h:180
QgsFontTextureAtlas::QgsFontTextureAtlas
QgsFontTextureAtlas()
QgsFontTextureAtlas::~QgsFontTextureAtlas
~QgsFontTextureAtlas()
QgsFontTextureAtlas::isValid
bool isValid() const
Returns true if the atlas is valid.
Definition
qgsfonttextureatlasgenerator.h:58
QgsFontTextureAtlas::QgsFontTextureAtlas
QgsFontTextureAtlas(const QgsFontTextureAtlas &other)
QgsFontTextureAtlas::operator=
QgsFontTextureAtlas & operator=(const QgsFontTextureAtlas &other)
QgsTextFormat
Container for all settings relating to text rendering.
Definition
qgstextformat.h:44
qgstextformat.h
Generated on
for QGIS API Documentation by
1.17.0