QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
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
28class QgsCharTextureRect;
30
31
43class _3D_EXPORT QgsFontTextureAtlas
44{
45 public:
48
51
55 bool isValid() const { return mAtlasSize.isValid(); }
56
61 QSize atlasSize() const { return mAtlasSize; }
62
63#ifndef SIP_RUN
67 QRect rect( const QString &grapheme ) const;
68#else
69
75 QRect rect( const QString &grapheme ) const;
76 //%MethodCode
77 const QRect res = sipCpp->rect( *a0 );
78 if ( res.isNull() )
79 {
80 PyErr_SetString( PyExc_KeyError, QStringLiteral( "No rectangle for character %1 exists." ).arg( *a0 ).toUtf8().constData() );
81 sipIsErr = 1;
82 }
83 else
84 {
85 return sipConvertFromNewType( new QRect( res ), sipType_QRect, Py_None );
86 }
87 //%End
88#endif
89
96 int graphemeCount( const QString &string ) const;
97
104 int totalWidth( const QString &string ) const;
105
112 QPoint pixelOffsetForGrapheme( const QString &string, int graphemeIndex ) const;
113
120 QRect textureRectForGrapheme( const QString &string, int graphemeIndex ) const;
121
125 QImage renderAtlasTexture() const;
126
133 QImage renderDebugTexture() const;
134
138 int count() const;
139
140#ifdef SIP_RUN
141 int __len__() const;
142 % Docstring
143 Returns the number of textures in the atlas.
144 % End
145 //%MethodCode
146 sipRes
147 = sipCpp->count();
148 //% End
149#endif
150
151 private:
152 struct GraphemeMetric
153 {
154 GraphemeMetric( int horizontalAdvance = 0, const QString &grapheme = QString() )
155 : horizontalAdvance( horizontalAdvance )
156 , grapheme( grapheme )
157 {}
158
159 int horizontalAdvance = 0;
160 QString grapheme;
161 };
162
163 struct StringMetrics
164 {
165 int totalWidth = 0;
166 QVector< GraphemeMetric > graphemeMetrics;
167 };
168
169 QgsTextFormat mFormat;
170 std::vector< QgsCharTextureRect > mRects;
171 QSize mAtlasSize;
172 QHash< QString, int > mGraphemeIndices;
173 QMap< QString, StringMetrics > mStringMetrics;
174 int mTexturePaddingPixels = 0;
175
177};
178
186{
187 public:
188
192 static QgsFontTextureAtlas create( const QgsTextFormat &format, const QStringList &strings );
193};
194
195#endif // QGSFONTTEXTUREATLASGENERATOR_H
Generates texture atlases for a font by efficiently packing the characters required for a set of stri...
static QgsFontTextureAtlas create(const QgsTextFormat &format, const QStringList &strings)
Creates the texture atlas for a set of strings, using the specified text format.
Encapsulates a font texture atlas.
QSize atlasSize() const
Returns the total size required for the atlas, i.e.
bool isValid() const
Returns true if the atlas is valid.
QgsFontTextureAtlas(const QgsFontTextureAtlas &other)
QgsFontTextureAtlas & operator=(const QgsFontTextureAtlas &other)
Container for all settings relating to text rendering.