31#include <QFontDatabase>
38 d =
new QgsTextSettingsPrivate();
42 : mBufferSettings( other.mBufferSettings )
43 , mBackgroundSettings( other.mBackgroundSettings )
44 , mShadowSettings( other.mShadowSettings )
45 , mMaskSettings( other.mMaskSettings )
46 , mTextFontFamily( other.mTextFontFamily )
47 , mTextFontFound( other.mTextFontFound )
56 mBufferSettings = other.mBufferSettings;
57 mBackgroundSettings = other.mBackgroundSettings;
58 mShadowSettings = other.mShadowSettings;
59 mMaskSettings = other.mMaskSettings;
60 mTextFontFamily = other.mTextFontFamily;
61 mTextFontFound = other.mTextFontFound;
72 if ( d->isValid != other.
isValid()
73 || d->textFont != other.
font()
75 || d->fontSizeUnits != other.
sizeUnit()
77 || d->fontSize != other.
size()
78 || d->textColor != other.
color()
79 || d->opacity != other.
opacity()
92 || mBufferSettings != other.mBufferSettings
93 || mBackgroundSettings != other.mBackgroundSettings
94 || mShadowSettings != other.mShadowSettings
95 || mMaskSettings != other.mMaskSettings
105 return !( *
this == other );
121 return mBufferSettings;
127 mBufferSettings = bufferSettings;
133 return mBackgroundSettings;
139 mBackgroundSettings = backgroundSettings;
145 return mShadowSettings;
151 mShadowSettings = shadowSettings;
157 return mMaskSettings;
163 mMaskSettings = maskSettings;
176 QFont
font = d->textFont;
177 if ( scaleFactor == 1 )
180 d->fontSizeMapUnitScale );
181 if ( fontPixelSize == 0 )
188 font.setPixelSize( fontPixelSize );
192 double fontPixelSize = context.
convertToPainterUnits( d->fontSize, d->fontSizeUnits, d->fontSizeMapUnitScale );
199 const int roundedPixelSize =
static_cast< int >( std::round( scaleFactor * fontPixelSize + 0.5 ) );
200 font.setPixelSize( roundedPixelSize );
203 font.setLetterSpacing( QFont::AbsoluteSpacing, context.
convertToPainterUnits( d->textFont.letterSpacing(), d->fontSizeUnits, d->fontSizeMapUnitScale ) * scaleFactor );
204 font.setWordSpacing( context.
convertToPainterUnits( d->textFont.wordSpacing(), d->fontSizeUnits, d->fontSizeMapUnitScale ) * scaleFactor * scaleFactor );
208 font.setCapitalization( QFont::SmallCaps );
221 if ( !d->textNamedStyle.isEmpty() )
222 return d->textNamedStyle;
225 return db.styleString( d->textFont );
232 d->textNamedStyle = style;
237 return d->forcedBold;
243 d->textFont.setBold( forced );
244 d->forcedBold =
true;
249 return d->forcedItalic;
255 d->textFont.setItalic( forced );
256 d->forcedItalic =
true;
272 return d->fontSizeUnits;
278 d->fontSizeUnits = unit;
283 return d->fontSizeMapUnitScale;
289 d->fontSizeMapUnitScale = scale;
311 d->textColor =
color;
323 d->opacity *= opacityFactor;
338 return d->textFont.stretch() > 0 ? d->textFont.stretch() : 100;
344 d->textFont.setStretch( factor );
360 return d->multilineHeight;
366 d->multilineHeight = height;
371 return d->multilineHeightUnits;
377 d->multilineHeightUnits = unit;
382 return d->tabStopDistance;
388 d->tabStopDistance = distance;
393 return d->tabStopDistanceUnits;
399 d->tabStopDistanceUnits = unit;
404 return d->tabStopDistanceMapUnitScale;
410 d->tabStopDistanceMapUnitScale = scale;
415 return d->orientation;
429 : d->capitalization ;
436#if defined(HAS_KDE_QT5_SMALL_CAPS_FIX) || QT_VERSION >= QT_VERSION_CHECK(6, 3, 0)
439 d->textFont.setCapitalization( QFont::MixedCase );
445 return d->allowHtmlFormatting;
451 d->allowHtmlFormatting = allow;
456 return d->previewBackgroundColor;
462 d->previewBackgroundColor =
color;
468 QFont appFont = QApplication::font();
470 QString fontFamily = mTextFontFamily;
474 mTextFontFound =
false;
480 fontFamily = appFont.family();
484 mTextFontFound =
true;
489 d->fontSize = appFont.pointSizeF();
493 d->fontSize = layer->
customProperty( QStringLiteral(
"labeling/fontSize" ) ).toDouble();
496 if ( layer->
customProperty( QStringLiteral(
"labeling/fontSizeUnit" ) ).toString().isEmpty() )
498 d->fontSizeUnits = layer->
customProperty( QStringLiteral(
"labeling/fontSizeInMapUnits" ), QVariant(
false ) ).toBool() ?
508 if ( layer->
customProperty( QStringLiteral(
"labeling/fontSizeMapUnitScale" ) ).toString().isEmpty() )
511 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/fontSizeMapUnitMinScale" ), 0.0 ).toDouble();
512 d->fontSizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
513 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/fontSizeMapUnitMaxScale" ), 0.0 ).toDouble();
514 d->fontSizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
520 int fontWeight = layer->
customProperty( QStringLiteral(
"labeling/fontWeight" ) ).toInt();
521 bool fontItalic = layer->
customProperty( QStringLiteral(
"labeling/fontItalic" ) ).toBool();
526 d->textFont.setUnderline( layer->
customProperty( QStringLiteral(
"labeling/fontUnderline" ) ).toBool() );
527 d->textFont.setStrikeOut( layer->
customProperty( QStringLiteral(
"labeling/fontStrikeout" ) ).toBool() );
528 d->textFont.setLetterSpacing( QFont::AbsoluteSpacing, layer->
customProperty( QStringLiteral(
"labeling/fontLetterSpacing" ), QVariant( 0.0 ) ).toDouble() );
529 d->textFont.setWordSpacing( layer->
customProperty( QStringLiteral(
"labeling/fontWordSpacing" ), QVariant( 0.0 ) ).toDouble() );
531 if ( layer->
customProperty( QStringLiteral(
"labeling/textOpacity" ) ).toString().isEmpty() )
533 d->opacity = ( 1 - layer->
customProperty( QStringLiteral(
"labeling/textTransp" ) ).toInt() / 100.0 );
537 d->opacity = ( layer->
customProperty( QStringLiteral(
"labeling/textOpacity" ) ).toDouble() );
541 d->multilineHeight = layer->
customProperty( QStringLiteral(
"labeling/multilineHeight" ), QVariant( 1.0 ) ).toDouble();
552 QDomElement textStyleElem;
553 if ( elem.nodeName() == QLatin1String(
"text-style" ) )
554 textStyleElem = elem;
556 textStyleElem = elem.firstChildElement( QStringLiteral(
"text-style" ) );
557 QFont appFont = QApplication::font();
559 QString fontFamily = mTextFontFamily;
561 const QDomElement familiesElem = textStyleElem.firstChildElement( QStringLiteral(
"families" ) );
562 const QDomNodeList familyNodes = familiesElem.childNodes();
564 families.reserve( familyNodes.size() );
565 for (
int i = 0; i < familyNodes.count(); ++i )
567 const QDomElement familyElem = familyNodes.at( i ).toElement();
568 families << familyElem.attribute( QStringLiteral(
"name" ) );
572 mTextFontFound =
false;
578 mTextFontFound =
true;
582 for (
const QString &family : std::as_const(
families ) )
588 mTextFontFound =
true;
589 fontFamily = processedFamily;
594 if ( !mTextFontFound )
597 fontFamily = appFont.family();
603 mTextFontFound =
true;
606 if ( !mTextFontFound )
608 context.
pushMessage( QObject::tr(
"Font “%1” not available on system" ).arg( mTextFontFamily ) );
611 if ( textStyleElem.hasAttribute( QStringLiteral(
"fontSize" ) ) )
613 d->fontSize = textStyleElem.attribute( QStringLiteral(
"fontSize" ) ).toDouble();
617 d->fontSize = appFont.pointSizeF();
620 if ( !textStyleElem.hasAttribute( QStringLiteral(
"fontSizeUnit" ) ) )
622 d->fontSizeUnits = textStyleElem.attribute( QStringLiteral(
"fontSizeInMapUnits" ) ).toUInt() == 0 ?
Qgis::RenderUnit::Points
630 if ( !textStyleElem.hasAttribute( QStringLiteral(
"fontSizeMapUnitScale" ) ) )
633 double oldMin = textStyleElem.attribute( QStringLiteral(
"fontSizeMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
634 d->fontSizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
635 double oldMax = textStyleElem.attribute( QStringLiteral(
"fontSizeMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
636 d->fontSizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
642 int fontWeight = textStyleElem.attribute( QStringLiteral(
"fontWeight" ) ).toInt();
643 bool fontItalic = textStyleElem.attribute( QStringLiteral(
"fontItalic" ) ).toInt();
645 d->textFont.setPointSizeF( d->fontSize );
648 d->forcedBold = textStyleElem.attribute( QStringLiteral(
"forcedBold" ) ).toInt();
649 d->forcedItalic = textStyleElem.attribute( QStringLiteral(
"forcedItalic" ) ).toInt();
650 d->textFont.setUnderline( textStyleElem.attribute( QStringLiteral(
"fontUnderline" ) ).toInt() );
651 d->textFont.setStrikeOut( textStyleElem.attribute( QStringLiteral(
"fontStrikeout" ) ).toInt() );
652 d->textFont.setKerning( textStyleElem.attribute( QStringLiteral(
"fontKerning" ), QStringLiteral(
"1" ) ).toInt() );
653 d->textFont.setLetterSpacing( QFont::AbsoluteSpacing, textStyleElem.attribute( QStringLiteral(
"fontLetterSpacing" ), QStringLiteral(
"0" ) ).toDouble() );
654 d->textFont.setWordSpacing( textStyleElem.attribute( QStringLiteral(
"fontWordSpacing" ), QStringLiteral(
"0" ) ).toDouble() );
656 if ( !textStyleElem.hasAttribute( QStringLiteral(
"textOpacity" ) ) )
658 d->opacity = ( 1 - textStyleElem.attribute( QStringLiteral(
"textTransp" ) ).toInt() / 100.0 );
662 d->opacity = ( textStyleElem.attribute( QStringLiteral(
"textOpacity" ) ).toDouble() );
664#ifdef HAS_KDE_QT5_FONT_STRETCH_FIX
665 d->textFont.setStretch( textStyleElem.attribute( QStringLiteral(
"stretchFactor" ), QStringLiteral(
"100" ) ).toInt() );
673 if ( !textStyleElem.hasAttribute( QStringLiteral(
"multilineHeight" ) ) )
675 QDomElement textFormatElem = elem.firstChildElement( QStringLiteral(
"text-format" ) );
676 d->multilineHeight = textFormatElem.attribute( QStringLiteral(
"multilineHeight" ), QStringLiteral(
"1" ) ).toDouble();
680 d->multilineHeight = textStyleElem.attribute( QStringLiteral(
"multilineHeight" ), QStringLiteral(
"1" ) ).toDouble();
683 d->multilineHeightUnits =
QgsUnitTypes::decodeRenderUnit( textStyleElem.attribute( QStringLiteral(
"multilineHeightUnit" ), QStringLiteral(
"percent" ) ), &ok );
685 d->tabStopDistance = textStyleElem.attribute( QStringLiteral(
"tabStopDistance" ), QStringLiteral(
"80" ) ).toDouble();
686 d->tabStopDistanceUnits =
QgsUnitTypes::decodeRenderUnit( textStyleElem.attribute( QStringLiteral(
"tabStopDistanceUnit" ), QStringLiteral(
"Point" ) ), &ok );
689 if ( textStyleElem.hasAttribute( QStringLiteral(
"capitalization" ) ) )
692 d->capitalization =
static_cast< Qgis::Capitalization >( textStyleElem.attribute( QStringLiteral(
"fontCapitals" ), QStringLiteral(
"0" ) ).toUInt() );
695 d->textFont.setCapitalization( QFont::SmallCaps );
697 d->allowHtmlFormatting = textStyleElem.attribute( QStringLiteral(
"allowHtml" ), QStringLiteral(
"0" ) ).toInt();
699 if ( textStyleElem.firstChildElement( QStringLiteral(
"text-buffer" ) ).isNull() )
701 mBufferSettings.
readXml( elem );
705 mBufferSettings.
readXml( textStyleElem );
707 if ( textStyleElem.firstChildElement( QStringLiteral(
"text-mask" ) ).isNull() )
713 mMaskSettings.
readXml( textStyleElem );
715 if ( textStyleElem.firstChildElement( QStringLiteral(
"shadow" ) ).isNull() )
717 mShadowSettings.
readXml( elem );
721 mShadowSettings.
readXml( textStyleElem );
723 if ( textStyleElem.firstChildElement( QStringLiteral(
"background" ) ).isNull() )
725 mBackgroundSettings.
readXml( elem, context );
729 mBackgroundSettings.
readXml( textStyleElem, context );
732 QDomElement ddElem = textStyleElem.firstChildElement( QStringLiteral(
"dd_properties" ) );
733 if ( ddElem.isNull() )
735 ddElem = elem.firstChildElement( QStringLiteral(
"dd_properties" ) );
737 if ( !ddElem.isNull() )
744 d->mDataDefinedProperties.clear();
751 QDomElement textStyleElem = doc.createElement( QStringLiteral(
"text-style" ) );
752 textStyleElem.setAttribute( QStringLiteral(
"fontFamily" ), d->textFont.family() );
754 QDomElement familiesElem = doc.createElement( QStringLiteral(
"families" ) );
755 for (
const QString &family : std::as_const( d->families ) )
757 QDomElement familyElem = doc.createElement( QStringLiteral(
"family" ) );
758 familyElem.setAttribute( QStringLiteral(
"name" ), family );
759 familiesElem.appendChild( familyElem );
761 textStyleElem.appendChild( familiesElem );
764 textStyleElem.setAttribute( QStringLiteral(
"fontSize" ), d->fontSize );
767 textStyleElem.setAttribute( QStringLiteral(
"fontWeight" ), d->textFont.weight() );
768 textStyleElem.setAttribute( QStringLiteral(
"fontItalic" ), d->textFont.italic() );
769 textStyleElem.setAttribute( QStringLiteral(
"fontStrikeout" ), d->textFont.strikeOut() );
770 textStyleElem.setAttribute( QStringLiteral(
"fontUnderline" ), d->textFont.underline() );
771 textStyleElem.setAttribute( QStringLiteral(
"forcedBold" ), d->forcedBold );
772 textStyleElem.setAttribute( QStringLiteral(
"forcedItalic" ), d->forcedItalic );
775 textStyleElem.setAttribute( QStringLiteral(
"fontLetterSpacing" ), d->textFont.letterSpacing() );
776 textStyleElem.setAttribute( QStringLiteral(
"fontWordSpacing" ), d->textFont.wordSpacing() );
777 textStyleElem.setAttribute( QStringLiteral(
"fontKerning" ), d->textFont.kerning() );
778 textStyleElem.setAttribute( QStringLiteral(
"textOpacity" ), d->opacity );
779#ifdef HAS_KDE_QT5_FONT_STRETCH_FIX
780 if ( d->textFont.stretch() > 0 )
781 textStyleElem.setAttribute( QStringLiteral(
"stretchFactor" ), d->textFont.stretch() );
785 textStyleElem.setAttribute( QStringLiteral(
"multilineHeight" ), d->multilineHeight );
786 textStyleElem.setAttribute( QStringLiteral(
"multilineHeightUnit" ),
QgsUnitTypes::encodeUnit( d->multilineHeightUnits ) );
788 textStyleElem.setAttribute( QStringLiteral(
"tabStopDistance" ), d->tabStopDistance );
789 textStyleElem.setAttribute( QStringLiteral(
"tabStopDistanceUnit" ),
QgsUnitTypes::encodeUnit( d->tabStopDistanceUnits ) );
792 textStyleElem.setAttribute( QStringLiteral(
"allowHtml" ), d->allowHtmlFormatting ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
793 textStyleElem.setAttribute( QStringLiteral(
"capitalization" ), QString::number(
static_cast< int >( d->capitalization ) ) );
795 QDomElement ddElem = doc.createElement( QStringLiteral(
"dd_properties" ) );
798 textStyleElem.appendChild( mBufferSettings.
writeXml( doc ) );
799 textStyleElem.appendChild( mMaskSettings.
writeXml( doc ) );
800 textStyleElem.appendChild( mBackgroundSettings.
writeXml( doc, context ) );
801 textStyleElem.appendChild( mShadowSettings.
writeXml( doc ) );
802 textStyleElem.appendChild( ddElem );
804 return textStyleElem;
811 QMimeData *mimeData =
new QMimeData;
812 mimeData->setColorData( QVariant(
color() ) );
815 QDomDocument textDoc;
816 QDomElement textElem =
writeXml( textDoc, rwContext );
817 textDoc.appendChild( textElem );
818 mimeData->setText( textDoc.toString() );
827 if (
font.pointSizeF() > 0 )
832 else if (
font.pixelSize() > 0 )
847 f.setPointSizeF(
size() );
851 f.setPointSizeF(
size() * 2.83464567 );
855 f.setPointSizeF(
size() * 72 );
859 f.setPixelSize(
static_cast< int >( std::round(
size() ) ) );
880 QString text = data->text();
881 if ( !text.isEmpty() )
887 if ( doc.setContent( text ) )
889 elem = doc.documentElement();
891 format.
readXml( elem, rwContext );
902 if ( d->blendMode != QPainter::CompositionMode_SourceOver )
905 if ( mBufferSettings.
enabled() && mBufferSettings.
blendMode() != QPainter::CompositionMode_SourceOver )
908 if ( mBackgroundSettings.
enabled() && mBackgroundSettings.
blendMode() != QPainter::CompositionMode_SourceOver )
911 if ( mShadowSettings.
enabled() && mShadowSettings.
blendMode() != QPainter::CompositionMode_SourceOver )
920 return d->mDataDefinedProperties;
925 return d->mDataDefinedProperties;
930 QSet< QString > fields = d->mDataDefinedProperties.referencedFields( context.
expressionContext(),
true );
941 d->mDataDefinedProperties = collection;
947 if ( !d->mDataDefinedProperties.hasActiveProperties() )
950 QString ddFontFamily;
955 QString family = exprVal.toString().trimmed();
957 if ( d->textFont.family() != family )
963 ddFontFamily = family;
974 QString fontstyle = exprVal.toString().trimmed();
975 ddFontStyle = fontstyle;
985 bool ddItalic =
false;
995 QFontDatabase fontDb;
996 QFont appFont = QApplication::font();
997 bool newFontBuilt =
false;
998 if ( ddBold || ddItalic )
1002 newFontBuilt =
true;
1003 newFont.setBold( ddBold );
1004 newFont.setItalic( ddItalic );
1006 else if ( !ddFontStyle.isEmpty()
1007 && ddFontStyle.compare( QLatin1String(
"Ignore" ), Qt::CaseInsensitive ) != 0 )
1009 if ( !ddFontFamily.isEmpty() )
1012 QFont styledfont = fontDb.font( ddFontFamily, ddFontStyle, appFont.pointSize() );
1013 if ( appFont != styledfont )
1015 newFont = styledfont;
1016 newFontBuilt =
true;
1023 else if ( !ddFontFamily.isEmpty() )
1025 if ( ddFontStyle.compare( QLatin1String(
"Ignore" ), Qt::CaseInsensitive ) != 0 )
1028 QFont styledfont = fontDb.font( ddFontFamily, d->textNamedStyle, appFont.pointSize() );
1029 if ( appFont != styledfont )
1031 newFont = styledfont;
1032 newFontBuilt =
true;
1038 newFontBuilt =
true;
1045 newFont.setUnderline( d->textFont.underline() );
1046 newFont.setStrikeOut( d->textFont.strikeOut() );
1047 newFont.setWordSpacing( d->textFont.wordSpacing() );
1048 newFont.setLetterSpacing( QFont::AbsoluteSpacing, d->textFont.letterSpacing() );
1049 d->textFont = newFont;
1079 QString units = exprVal.toString();
1080 if ( !units.isEmpty() )
1085 d->fontSizeUnits = res;
1095 d->opacity = val.toDouble() / 100.0;
1099#ifdef HAS_KDE_QT5_FONT_STRETCH_FIX
1106 d->textFont.setStretch( val.toInt() );
1124 d->textFont.setLetterSpacing( QFont::AbsoluteSpacing, val.toDouble() );
1134 d->textFont.setWordSpacing( val.toDouble() );
1144 d->tabStopDistance = val.toDouble();
1151 QString blendstr = exprVal.toString().trimmed();
1152 if ( !blendstr.isEmpty() )
1166 QPixmap pixmap(
size * devicePixelRatio );
1167 pixmap.fill( Qt::transparent );
1168 pixmap.setDevicePixelRatio( devicePixelRatio );
1171 painter.begin( &pixmap );
1173 painter.setRenderHint( QPainter::Antialiasing );
1175 const QRectF rect( 0, 0,
size.width(),
size.height() );
1178 painter.setPen( Qt::NoPen );
1180 if ( ( background1.lightnessF() < 0.7 ) )
1182 background1 = background1.darker( 125 );
1186 background1 = background1.lighter( 125 );
1189 QLinearGradient linearGrad( QPointF( 0, 0 ), QPointF( 0, rect.height() ) );
1190 linearGrad.setColorAt( 0, background1 );
1191 linearGrad.setColorAt( 1, background2 );
1192 painter.setBrush( QBrush( linearGrad ) );
1193 if (
size.width() > 30 )
1195 painter.drawRoundedRect( rect, 6, 6 );
1200 painter.drawRect( rect );
1202 painter.setBrush( Qt::NoBrush );
1203 painter.setPen( Qt::NoPen );
1217 QWidget *activeWindow = QApplication::activeWindow();
1218 if ( QScreen *screen = activeWindow ? activeWindow->screen() : nullptr )
1240 ? fontSize * tempFormat.
buffer().
size() / 100
1245 double ytrans = 0.0;
1248 ? fontSize * tempFormat.
buffer().
size() / 100
1253 const QStringList text = QStringList() << ( previewText.isEmpty() ? QObject::tr(
"Aa" ) : previewText );
1255 QRectF textRect = rect;
1256 textRect.setLeft( xtrans + padding );
1257 textRect.setWidth( rect.width() - xtrans - 2 * padding );
1259 if ( textRect.width() > 2000 )
1260 textRect.setWidth( 2000 - 2 * padding );
1262 const double bottom = textRect.height() / 2 + textHeight / 2;
1263 textRect.setTop( bottom - textHeight );
1264 textRect.setBottom( bottom );
1269 painter.setBrush( Qt::NoBrush );
1271 if (
size.width() > 30 )
1273 painter.drawRoundedRect( rect, 6, 6 );
1278 painter.drawRect( rect );
1291 css += QStringLiteral(
"line-height: %1%;" ).arg(
lineHeight() * 100 );
1294 css += QStringLiteral(
"line-height: %1px;" ).arg(
lineHeight() );
1298 css += QStringLiteral(
"line-height: %1px;" ).arg(
lineHeight() * pointToPixelMultiplier );
1302 css += QStringLiteral(
"line-height: %1px;" ).arg(
lineHeight() * 2.83464567 * pointToPixelMultiplier );
1310 css += QStringLiteral(
"color: rgba(%1,%2,%3,%4);" ).arg(
color().red() ).arg(
color().green() ).arg(
color().blue() ).arg( QString::number(
color().alphaF(),
'f', 4 ) );
1314 f.setPointSizeF(
size() / 0.352778 );
@ Rectangle
Text within rectangle layout mode.
BlendMode
Blending modes defining the available composition modes that can be used when painting.
Capitalization
String capitalization options.
@ AllSmallCaps
Force all characters to small caps (since QGIS 3.24)
@ MixedCase
Mixed case, ie no change.
@ SmallCaps
Mixed case small caps (since QGIS 3.24)
TextOrientation
Text orientations.
RenderUnit
Rendering size units.
@ Percentage
Percentage of another measurement (e.g., canvas size, feature size)
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes)
@ Unknown
Mixed or unknown units.
@ MetersInMapUnits
Meters value as Map units.
@ Antialiasing
Use antialiasing while drawing.
static QgsFontManager * fontManager()
Returns the application font manager, which manages available fonts and font installation for the QGI...
static QColor colorFromString(const QString &string)
Decodes a string into a color value.
static QString colorToString(const QColor &color)
Encodes a color into a string value.
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
QString processFontFamilyName(const QString &name) const
Processes a font family name, applying any matching fontFamilyReplacements() to the name.
static QString asCSS(const QFont &font, double pointToPixelMultiplier=1.0)
Returns a CSS string representing the specified font as closely as possible.
static QString translateNamedStyle(const QString &namedStyle)
Returns the localized named style of a font, if such a translation is available.
static QString untranslateNamedStyle(const QString &namedStyle)
Returns the english named style of a font, if possible.
static QFont createFont(const QString &family, int pointSize=-1, int weight=-1, bool italic=false)
Creates a font with the specified family.
static bool fontFamilyMatchOnSystem(const QString &family, QString *chosen=nullptr, bool *match=nullptr)
Check whether font family is on system.
static bool fontFamilyOnSystem(const QString &family)
Check whether font family is on system in a quick manner, which does not compare [foundry].
static bool updateFontViaStyle(QFont &f, const QString &fontstyle, bool fallback=false)
Updates font with named style and retain all font properties.
Q_INVOKABLE QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
Perform transforms between map coordinates and device coordinates.
void setParameters(double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation)
Sets parameters for use in transforming coordinates.
Struct for storing maximum and minimum scales for measurements in map units.
static Qgis::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a Qgis::BlendMode corresponding to a QPainter::CompositionMode.
static QPainter::CompositionMode getCompositionMode(Qgis::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a Qgis::BlendMode.
@ FontSizeUnit
Font size units.
@ FontStyle
Font style name.
@ Italic
Use italic style.
@ FontStretchFactor
Font stretch factor, since QGIS 3.24.
@ Strikeout
Use strikeout.
@ Underline
Use underline.
@ FontBlendMode
Text blend mode.
@ FontOpacity
Text opacity.
@ FontWordSpacing
Word spacing.
@ FontLetterSpacing
Letter spacing.
@ TabStopDistance
Tab stop distance, since QGIS 3.38.
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the labeling property definitions.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
The class is used as a container of context for various read/write operations on other objects.
void pushMessage(const QString &message, Qgis::MessageLevel level=Qgis::MessageLevel::Warning) const
Append a message to the context.
Contains information about the context of a rendering operation.
void setScaleFactor(double factor)
Sets the scaling factor for the render to convert painter units to physical sizes.
void setDevicePixelRatio(float ratio)
Sets the device pixel ratio.
void setUseAdvancedEffects(bool enabled)
Used to enable or disable advanced effects such as blend modes.
double convertToPainterUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
QgsExpressionContext & expressionContext()
Gets the expression context.
void setFlag(Qgis::RenderContextFlag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
void setMapToPixel(const QgsMapToPixel &mtp)
Sets the context's map to pixel transform, which transforms between map coordinates and device coordi...
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
Stores properties relating to a screen.
double devicePixelRatio() const
Returns the ratio between physical pixels and device-independent pixels for the screen.
bool isValid() const
Returns true if the properties are valid.
void updateRenderContextForScreen(QgsRenderContext &context) const
Updates the settings in a render context to match the screen settings.
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
static QPainter::CompositionMode decodeBlendMode(const QString &s)
static QString encodeColor(const QColor &color)
Container for settings relating to a text background object.
QSizeF size() const
Returns the size of the background shape.
QSet< QString > referencedFields(const QgsRenderContext &context) const
Returns all field names referenced by the configuration (e.g.
void upgradeDataDefinedProperties(QgsPropertyCollection &properties)
Upgrade data defined properties when reading a project file saved in QGIS prior to version 3....
void setOpacity(double opacity)
Sets the background shape's opacity.
QPainter::CompositionMode blendMode() const
Returns the blending mode used for drawing the background shape.
bool enabled() const
Returns whether the background is enabled.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
double opacity() const
Returns the background shape's opacity.
void updateDataDefinedProperties(QgsRenderContext &context, const QgsPropertyCollection &properties)
Updates the format by evaluating current values of data defined properties.
SizeType sizeType() const
Returns the method used to determine the size of the background shape (e.g., fixed size or buffer aro...
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
void readFromLayer(QgsVectorLayer *layer)
Reads settings from a layer's custom properties (for QGIS 2.x projects).
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the shape size.
Qgis::RenderUnit sizeUnit() const
Returns the units used for the shape's size.
Container for settings relating to a text buffer.
Qgis::RenderUnit sizeUnit() const
Returns the units for the buffer size.
void readFromLayer(QgsVectorLayer *layer)
Reads settings from a layer's custom properties (for QGIS 2.x projects).
QSet< QString > referencedFields(const QgsRenderContext &context) const
Returns all field names referenced by the configuration (e.g.
double size() const
Returns the size of the buffer.
void setOpacity(double opacity)
Sets the buffer opacity.
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the buffer size.
bool enabled() const
Returns whether the buffer is enabled.
double opacity() const
Returns the buffer opacity.
QDomElement writeXml(QDomDocument &doc) const
Write settings into a DOM element.
QPainter::CompositionMode blendMode() const
Returns the blending mode used for drawing the buffer.
void updateDataDefinedProperties(QgsRenderContext &context, const QgsPropertyCollection &properties)
Updates the format by evaluating current values of data defined properties.
void readXml(const QDomElement &elem)
Read settings from a DOM element.
Container for all settings relating to text rendering.
QgsTextFormat()
Default constructor for QgsTextFormat.
void setColor(const QColor &color)
Sets the color that text will be rendered in.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the text.
void setSize(double size)
Sets the size for rendered text.
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the size.
void setCapitalization(Qgis::Capitalization capitalization)
Sets the text capitalization style.
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the format's property collection, used for data defined overrides.
QStringList families() const
Returns the list of font families to use when restoring the text format, in order of precedence.
void setOrientation(Qgis::TextOrientation orientation)
Sets the orientation for the text.
void setFont(const QFont &font)
Sets the font used for rendering text.
QSet< QString > referencedFields(const QgsRenderContext &context) const
Returns all field names referenced by the configuration (e.g.
void setFamilies(const QStringList &families)
Sets a list of font families to use for the text format, in order of precedence.
void setForcedItalic(bool forced)
Sets whether the format is set to force an italic style.
static QgsTextFormat fromMimeData(const QMimeData *data, bool *ok=nullptr)
Attempts to parse the provided mime data as a QgsTextFormat.
double lineHeight() const
Returns the line height for text.
double tabStopDistance() const
Returns the distance for tab stops.
void setSizeUnit(Qgis::RenderUnit unit)
Sets the units for the size of rendered text.
int stretchFactor() const
Returns the text's stretch factor.
void updateDataDefinedProperties(QgsRenderContext &context)
Updates the format by evaluating current values of data defined properties.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the format's property collection, used for data defined overrides.
void setStretchFactor(int factor)
Sets the text's stretch factor.
void setShadow(const QgsTextShadowSettings &shadowSettings)
Sets the text's drop shadow settings.
void setMask(const QgsTextMaskSettings &maskSettings)
Sets the text's masking settings.
void setPreviewBackgroundColor(const QColor &color)
Sets the background color that text will be rendered on for previews.
QFont scaledFont(const QgsRenderContext &context, double scaleFactor=1.0, bool *isZeroSize=nullptr) const
Returns a font with the size scaled to match the format's size settings (including units and map unit...
void setTabStopDistanceUnit(Qgis::RenderUnit unit)
Sets the unit used for the tab stop distance.
void multiplyOpacity(double opacityFactor)
Multiply opacity by opacityFactor.
void setOpacity(double opacity)
Sets the text's opacity.
QPainter::CompositionMode blendMode() const
Returns the blending mode used for drawing the text.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
bool operator==(const QgsTextFormat &other) const
void setAllowHtmlFormatting(bool allow)
Sets whether text should be treated as a HTML document and HTML tags should be used for formatting th...
void setLineHeightUnit(Qgis::RenderUnit unit)
Sets the unit for the line height for text.
Qgis::RenderUnit lineHeightUnit() const
Returns the units for the line height for text.
Qgis::Capitalization capitalization() const
Returns the text capitalization style.
bool forcedItalic() const
Returns true if the format is set to force an italic style.
QgsTextMaskSettings & mask()
Returns a reference to the masking settings.
void setForcedBold(bool forced)
Sets whether the format is set to force a bold style.
bool isValid() const
Returns true if the format is valid.
void setTabStopDistanceMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the tab stop distance.
void setBuffer(const QgsTextBufferSettings &bufferSettings)
Sets the text's buffer settings.
QgsTextBackgroundSettings & background()
Returns a reference to the text background settings.
Qgis::RenderUnit sizeUnit() const
Returns the units for the size of rendered text.
static QgsTextFormat fromQFont(const QFont &font)
Returns a text format matching the settings from an input font.
void setValid()
Sets the format to a valid state, without changing any of the default format settings.
bool allowHtmlFormatting() const
Returns true if text should be treated as a HTML document and HTML tags should be used for formatting...
QFont toQFont() const
Returns a QFont matching the relevant settings from this text format.
bool operator!=(const QgsTextFormat &other) const
double opacity() const
Returns the text's opacity.
void setTabStopDistance(double distance)
Sets the distance for tab stops.
Qgis::TextOrientation orientation() const
Returns the orientation of the text.
QString namedStyle() const
Returns the named style for the font used for rendering text (e.g., "bold").
double size() const
Returns the size for rendered text.
QgsTextShadowSettings & shadow()
Returns a reference to the text drop shadow settings.
QgsTextFormat & operator=(const QgsTextFormat &other)
static QPixmap textFormatPreviewPixmap(const QgsTextFormat &format, QSize size, const QString &previewText=QString(), int padding=0, const QgsScreenProperties &screen=QgsScreenProperties())
Returns a pixmap preview for a text format.
Qgis::RenderUnit tabStopDistanceUnit() const
Returns the units for the tab stop distance.
bool forcedBold() const
Returns true if the format is set to force a bold style.
void setBackground(const QgsTextBackgroundSettings &backgroundSettings)
Sets the text's background settings.q.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
QString asCSS(double pointToPixelMultiplier=1.0) const
Returns a CSS string representing the specified text format as closely as possible.
QMimeData * toMimeData() const
Returns new mime data representing the text format settings.
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the size.
void setNamedStyle(const QString &style)
Sets the named style for the font used for rendering text.
QColor color() const
Returns the color that text will be rendered in.
QFont font() const
Returns the font used for rendering text.
void readFromLayer(QgsVectorLayer *layer)
Reads settings from a layer's custom properties (for QGIS 2.x projects).
QgsMapUnitScale tabStopDistanceMapUnitScale() const
Returns the map unit scale object for the tab stop distance.
QColor previewBackgroundColor() const
Returns the background color for text previews.
bool containsAdvancedEffects() const
Returns true if any component of the font format requires advanced effects such as blend modes,...
QgsTextBufferSettings & buffer()
Returns a reference to the text buffer settings.
void setLineHeight(double height)
Sets the line height for text.
Container for settings relating to a selective masking around a text.
QSet< QString > referencedFields(const QgsRenderContext &context) const
Returns all field names referenced by the configuration (e.g.
void updateDataDefinedProperties(QgsRenderContext &context, const QgsPropertyCollection &properties)
Updates the format by evaluating current values of data defined properties.
void readXml(const QDomElement &elem)
Read settings from a DOM element.
QDomElement writeXml(QDomDocument &doc) const
Write settings into a DOM element.
double opacity() const
Returns the mask's opacity.
void setOpacity(double opacity)
Sets the mask's opacity.
static Qgis::TextOrientation decodeTextOrientation(const QString &name, bool *ok=nullptr)
Attempts to decode a string representation of a text orientation.
static QColor readColor(QgsVectorLayer *layer, const QString &property, const QColor &defaultColor=Qt::black, bool withAlpha=true)
Converts an encoded color value from a layer property.
static QString encodeTextOrientation(Qgis::TextOrientation orientation)
Encodes a text orientation.
static int sizeToPixel(double size, const QgsRenderContext &c, Qgis::RenderUnit unit, const QgsMapUnitScale &mapUnitScale=QgsMapUnitScale())
Calculates pixel size (considering output size should be in pixel or map units, scale factors and opt...
static void drawText(const QRectF &rect, double rotation, Qgis::TextHorizontalAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, bool drawAsOutlines=true, Qgis::TextVerticalAlignment vAlignment=Qgis::TextVerticalAlignment::Top, Qgis::TextRendererFlags flags=Qgis::TextRendererFlags(), Qgis::TextLayoutMode mode=Qgis::TextLayoutMode::Rectangle)
Draws text within a rectangle using the specified settings.
static double textHeight(const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, Qgis::TextLayoutMode mode=Qgis::TextLayoutMode::Point, QFontMetricsF *fontMetrics=nullptr, Qgis::TextRendererFlags flags=Qgis::TextRendererFlags(), double maxLineWidth=0)
Returns the height of a text based on a given format.
Container for settings relating to a text shadow.
bool enabled() const
Returns whether the shadow is enabled.
double opacity() const
Returns the shadow's opacity.
void readXml(const QDomElement &elem)
Read settings from a DOM element.
QDomElement writeXml(QDomDocument &doc) const
Write settings into a DOM element.
void updateDataDefinedProperties(QgsRenderContext &context, const QgsPropertyCollection &properties)
Updates the format by evaluating current values of data defined properties.
QPainter::CompositionMode blendMode() const
Returns the blending mode used for drawing the drop shadow.
void setOpacity(double opacity)
Sets the shadow's opacity.
QSet< QString > referencedFields(const QgsRenderContext &context) const
Returns all field names referenced by the configuration (e.g.
void readFromLayer(QgsVectorLayer *layer)
Reads settings from a layer's custom properties (for QGIS 2.x projects).
static Q_INVOKABLE Qgis::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
static Q_INVOKABLE QString encodeUnit(Qgis::DistanceUnit unit)
Encodes a distance unit to a string.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
Represents a vector layer which manages a vector based data sets.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)