QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
61 const double characterHeight = mapScale * fontMetrics.height();
62 QStringList graphemes;
63 QVector< QgsTextCharacterFormat > graphemeFormats;
72 for (
const QString &grapheme : fragmentGraphemes )
74 graphemes.append( grapheme );
75 graphemeFormats.append( fragment.characterFormat() );
86 QVector< double > characterWidths( graphemes.count() );
87 for (
int i = 0; i < graphemes.count(); i++ )
92 qreal wordSpaceFix = qreal( 0.0 );
93 if ( graphemes[i] == QLatin1String(
" " ) )
97 wordSpaceFix = ( nxt < graphemes.count() && graphemes[nxt] != QLatin1String(
" " ) ) ? wordSpacing : qreal( 0.0 );
101 if ( graphemes[i].length() == 1 &&
102 !
qgsDoubleNear( fontMetrics.horizontalAdvance( QString( graphemes[i].at( 0 ) ) ), fontMetrics.horizontalAdvance( graphemes[i].at( 0 ) ) + letterSpacing ) )
105 wordSpaceFix -= wordSpacing;
108 const double charWidth = fontMetrics.horizontalAdvance( QString( graphemes[i] ) ) + wordSpaceFix;
109 characterWidths[i] = mapScale * charWidth;
void setDocument(const QgsTextDocument &document)
Sets the document for the label.
QString text(int partId) const
Returns the text component corresponding to a specified label part.
void setGraphemeFormats(const QVector< QgsTextCharacterFormat > &formats)
Sets the character formats associated with the text graphemes().
double mapUnitsPerPixel() const
Returns the current map units per pixel.
~QgsTextLabelFeature() override
Clean up.
bool hasCharacterFormat(int partId) const
Returns true if the feature contains specific character formatting for the part with matching ID.
static QgsPrecalculatedTextMetrics calculateTextMetrics(const QgsMapToPixel *xform, const QFontMetricsF &fontMetrics, double letterSpacing, double wordSpacing, const QString &text=QString(), QgsTextDocument *document=nullptr)
Calculate text metrics for later retrieval via textMetrics().
QgsTextCharacterFormat characterFormat(int partId) const
Returns the character format corresponding to the specified label part.
QFont mDefinedFont
Font for rendering.
Stores information relating to individual character formatting.
std::optional< QFontMetricsF > mFontMetrics
Metrics of the font for rendering.
QgsTextLabelFeature(QgsFeatureId id, geos::unique_ptr geometry, QSizeF size)
Construct text label feature.
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Stores a fragment of text along with formatting overrides to be used when rendering the fragment.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QString mLabelText
text of the label
QgsTextDocument mDocument
void setFontMetrics(const QFontMetricsF &metrics)
Sets the font metrics.
Represents a block of text consisting of one or more QgsTextFragment objects.
Perform transforms between map coordinates and device coordinates.
Represents a document consisting of one or more QgsTextBlock objects.
QgsTextDocument document() const
Returns the document for the label.
std::optional< QgsPrecalculatedTextMetrics > mTextMetrics
Contains precalculated properties regarding text metrics for text to be renderered at a later stage.
The QgsLabelFeature class describes a feature that should be used within the labeling engine....
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
static QStringList splitToGraphemes(const QString &text)
Splits a text string to a list of graphemes, which are the smallest allowable character divisions in ...