29 #include <QFontDatabase> 30 #include <QDesktopWidget> 49 static void _fixQPictureDPI( QPainter *p )
55 p->scale( static_cast< double >(
qt_defaultDpiX() ) / p->device()->logicalDpiX(),
56 static_cast< double >(
qt_defaultDpiY() ) / p->device()->logicalDpiY() );
59 static QColor _readColor(
QgsVectorLayer *layer,
const QString &property,
const QColor &defaultColor = Qt::black,
bool withAlpha =
true )
61 int r = layer->
customProperty( property +
'R', QVariant( defaultColor.red() ) ).toInt();
62 int g = layer->
customProperty( property +
'G', QVariant( defaultColor.green() ) ).toInt();
63 int b = layer->
customProperty( property +
'B', QVariant( defaultColor.blue() ) ).toInt();
64 int a = withAlpha ? layer->
customProperty( property +
'A', QVariant( defaultColor.alpha() ) ).toInt() : 255;
65 return QColor( r, g, b, a );
70 d =
new QgsTextBufferSettingsPrivate();
121 return d->sizeMapUnitScale;
126 d->sizeMapUnitScale = scale;
141 return d->fillBufferInterior;
146 d->fillBufferInterior = fill;
166 d->joinStyle = style;
181 return d->paintEffect.get();
186 d->paintEffect.reset( effect );
204 if ( exprVal.isValid() )
206 QString units = exprVal.toString();
207 if ( !units.isEmpty() )
231 QString blendstr = exprVal.toString().trimmed();
232 if ( !blendstr.isEmpty() )
239 QString joinstr = exprVal.toString().trimmed();
240 if ( !joinstr.isEmpty() )
250 double bufSize = layer->
customProperty( QStringLiteral(
"labeling/bufferSize" ), QVariant( 0.0 ) ).toDouble();
253 QVariant drawBuffer = layer->
customProperty( QStringLiteral(
"labeling/bufferDraw" ), QVariant() );
254 if ( drawBuffer.isValid() )
256 d->enabled = drawBuffer.toBool();
259 else if ( bufSize != 0.0 )
270 if ( layer->
customProperty( QStringLiteral(
"labeling/bufferSizeUnits" ) ).toString().isEmpty() )
272 bool bufferSizeInMapUnits = layer->
customProperty( QStringLiteral(
"labeling/bufferSizeInMapUnits" ) ).toBool();
280 if ( layer->
customProperty( QStringLiteral(
"labeling/bufferSizeMapUnitScale" ) ).toString().isEmpty() )
283 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/bufferSizeMapUnitMinScale" ), 0.0 ).toDouble();
284 d->sizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
285 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/bufferSizeMapUnitMaxScale" ), 0.0 ).toDouble();
286 d->sizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
292 d->color = _readColor( layer, QStringLiteral(
"labeling/bufferColor" ), Qt::white,
false );
293 if ( layer->
customProperty( QStringLiteral(
"labeling/bufferOpacity" ) ).toString().isEmpty() )
295 d->opacity = ( 1 - layer->
customProperty( QStringLiteral(
"labeling/bufferTransp" ) ).toInt() / 100.0 );
299 d->opacity = ( layer->
customProperty( QStringLiteral(
"labeling/bufferOpacity" ) ).toDouble() );
303 d->joinStyle =
static_cast< Qt::PenJoinStyle
>( layer->
customProperty( QStringLiteral(
"labeling/bufferJoinStyle" ), QVariant( Qt::RoundJoin ) ).toUInt() );
305 d->fillBufferInterior = !layer->
customProperty( QStringLiteral(
"labeling/bufferNoFill" ), QVariant(
false ) ).toBool();
307 if ( layer->
customProperty( QStringLiteral(
"labeling/bufferEffect" ) ).isValid() )
309 QDomDocument doc( QStringLiteral(
"effect" ) );
310 doc.setContent( layer->
customProperty( QStringLiteral(
"labeling/bufferEffect" ) ).toString() );
311 QDomElement effectElem = doc.firstChildElement( QStringLiteral(
"effect" ) ).firstChildElement( QStringLiteral(
"effect" ) );
320 QDomElement textBufferElem = elem.firstChildElement( QStringLiteral(
"text-buffer" ) );
321 double bufSize = textBufferElem.attribute( QStringLiteral(
"bufferSize" ), QStringLiteral(
"0" ) ).toDouble();
324 QVariant drawBuffer = textBufferElem.attribute( QStringLiteral(
"bufferDraw" ) );
325 if ( drawBuffer.isValid() )
327 d->enabled = drawBuffer.toBool();
330 else if ( bufSize != 0.0 )
341 if ( !textBufferElem.hasAttribute( QStringLiteral(
"bufferSizeUnits" ) ) )
343 bool bufferSizeInMapUnits = textBufferElem.attribute( QStringLiteral(
"bufferSizeInMapUnits" ) ).toInt();
351 if ( !textBufferElem.hasAttribute( QStringLiteral(
"bufferSizeMapUnitScale" ) ) )
354 double oldMin = textBufferElem.attribute( QStringLiteral(
"bufferSizeMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
355 d->sizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
356 double oldMax = textBufferElem.attribute( QStringLiteral(
"bufferSizeMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
357 d->sizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
365 if ( !textBufferElem.hasAttribute( QStringLiteral(
"bufferOpacity" ) ) )
367 d->opacity = ( 1 - textBufferElem.attribute( QStringLiteral(
"bufferTransp" ) ).toInt() / 100.0 );
371 d->opacity = ( textBufferElem.attribute( QStringLiteral(
"bufferOpacity" ) ).toDouble() );
375 static_cast< QgsPainting::BlendMode >( textBufferElem.attribute( QStringLiteral(
"bufferBlendMode" ), QString::number(
QgsPainting::BlendNormal ) ).toUInt() ) );
376 d->joinStyle =
static_cast< Qt::PenJoinStyle
>( textBufferElem.attribute( QStringLiteral(
"bufferJoinStyle" ), QString::number( Qt::RoundJoin ) ).toUInt() );
377 d->fillBufferInterior = !textBufferElem.attribute( QStringLiteral(
"bufferNoFill" ), QStringLiteral(
"0" ) ).toInt();
378 QDomElement effectElem = textBufferElem.firstChildElement( QStringLiteral(
"effect" ) );
379 if ( !effectElem.isNull() )
388 QDomElement textBufferElem = doc.createElement( QStringLiteral(
"text-buffer" ) );
389 textBufferElem.setAttribute( QStringLiteral(
"bufferDraw" ), d->enabled );
390 textBufferElem.setAttribute( QStringLiteral(
"bufferSize" ), d->size );
394 textBufferElem.setAttribute( QStringLiteral(
"bufferNoFill" ), !d->fillBufferInterior );
395 textBufferElem.setAttribute( QStringLiteral(
"bufferOpacity" ), d->opacity );
396 textBufferElem.setAttribute( QStringLiteral(
"bufferJoinStyle" ), static_cast< unsigned int >( d->joinStyle ) );
399 d->paintEffect->saveProperties( doc, textBufferElem );
400 return textBufferElem;
410 d =
new QgsTextBackgroundSettingsPrivate();
462 return d->markerSymbol.get();
467 d->markerSymbol.reset( symbol );
502 return d->sizeMapUnitScale;
507 d->sizeMapUnitScale = scale;
512 return d->rotationType;
517 d->rotationType =
type;
542 return d->offsetUnits;
547 d->offsetUnits = units;
552 return d->offsetMapUnitScale;
557 d->offsetMapUnitScale = scale;
572 return d->radiiUnits;
577 d->radiiUnits = units;
582 return d->radiiMapUnitScale;
587 d->radiiMapUnitScale = scale;
617 d->fillColor = color;
622 return d->strokeColor;
627 d->strokeColor = color;
632 return d->strokeWidth;
637 d->strokeWidth = width;
642 return d->strokeWidthUnits;
647 d->strokeWidthUnits = units;
652 return d->strokeWidthMapUnitScale;
657 d->strokeWidthMapUnitScale = scale;
667 d->joinStyle = style;
672 return d->paintEffect.get();
677 d->paintEffect.reset( effect );
682 d->enabled = layer->
customProperty( QStringLiteral(
"labeling/shapeDraw" ), QVariant(
false ) ).toBool();
684 d->svgFile = layer->
customProperty( QStringLiteral(
"labeling/shapeSVGFile" ), QVariant(
"" ) ).toString();
686 d->size = QSizeF( layer->
customProperty( QStringLiteral(
"labeling/shapeSizeX" ), QVariant( 0.0 ) ).toDouble(),
687 layer->
customProperty( QStringLiteral(
"labeling/shapeSizeY" ), QVariant( 0.0 ) ).toDouble() );
689 if ( layer->
customProperty( QStringLiteral(
"labeling/shapeSizeUnit" ) ).toString().isEmpty() )
698 if ( layer->
customProperty( QStringLiteral(
"labeling/shapeSizeMapUnitScale" ) ).toString().isEmpty() )
701 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/shapeSizeMapUnitMinScale" ), 0.0 ).toDouble();
702 d->sizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
703 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/shapeSizeMapUnitMaxScale" ), 0.0 ).toDouble();
704 d->sizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
711 d->rotation = layer->
customProperty( QStringLiteral(
"labeling/shapeRotation" ), QVariant( 0.0 ) ).toDouble();
712 d->offset = QPointF( layer->
customProperty( QStringLiteral(
"labeling/shapeOffsetX" ), QVariant( 0.0 ) ).toDouble(),
713 layer->
customProperty( QStringLiteral(
"labeling/shapeOffsetY" ), QVariant( 0.0 ) ).toDouble() );
715 if ( layer->
customProperty( QStringLiteral(
"labeling/shapeOffsetUnit" ) ).toString().isEmpty() )
724 if ( layer->
customProperty( QStringLiteral(
"labeling/shapeOffsetMapUnitScale" ) ).toString().isEmpty() )
727 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/shapeOffsetMapUnitMinScale" ), 0.0 ).toDouble();
728 d->offsetMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
729 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/shapeOffsetMapUnitMaxScale" ), 0.0 ).toDouble();
730 d->offsetMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
736 d->radii = QSizeF( layer->
customProperty( QStringLiteral(
"labeling/shapeRadiiX" ), QVariant( 0.0 ) ).toDouble(),
737 layer->
customProperty( QStringLiteral(
"labeling/shapeRadiiY" ), QVariant( 0.0 ) ).toDouble() );
740 if ( layer->
customProperty( QStringLiteral(
"labeling/shapeRadiiUnit" ) ).toString().isEmpty() )
749 if ( layer->
customProperty( QStringLiteral(
"labeling/shapeRadiiMapUnitScale" ) ).toString().isEmpty() )
752 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/shapeRadiiMapUnitMinScale" ), 0.0 ).toDouble();
753 d->radiiMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
754 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/shapeRadiiMapUnitMaxScale" ), 0.0 ).toDouble();
755 d->radiiMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
761 d->fillColor = _readColor( layer, QStringLiteral(
"labeling/shapeFillColor" ), Qt::white,
true );
762 d->strokeColor = _readColor( layer, QStringLiteral(
"labeling/shapeBorderColor" ), Qt::darkGray,
true );
763 d->strokeWidth = layer->
customProperty( QStringLiteral(
"labeling/shapeBorderWidth" ), QVariant( .0 ) ).toDouble();
764 if ( layer->
customProperty( QStringLiteral(
"labeling/shapeBorderWidthUnit" ) ).toString().isEmpty() )
772 if ( layer->
customProperty( QStringLiteral(
"labeling/shapeBorderWidthMapUnitScale" ) ).toString().isEmpty() )
775 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/shapeBorderWidthMapUnitMinScale" ), 0.0 ).toDouble();
776 d->strokeWidthMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
777 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/shapeBorderWidthMapUnitMaxScale" ), 0.0 ).toDouble();
778 d->strokeWidthMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
784 d->joinStyle =
static_cast< Qt::PenJoinStyle
>( layer->
customProperty( QStringLiteral(
"labeling/shapeJoinStyle" ), QVariant( Qt::BevelJoin ) ).toUInt() );
786 if ( layer->
customProperty( QStringLiteral(
"labeling/shapeOpacity" ) ).toString().isEmpty() )
788 d->opacity = ( 1 - layer->
customProperty( QStringLiteral(
"labeling/shapeTransparency" ) ).toInt() / 100.0 );
792 d->opacity = ( layer->
customProperty( QStringLiteral(
"labeling/shapeOpacity" ) ).toDouble() );
797 if ( layer->
customProperty( QStringLiteral(
"labeling/shapeEffect" ) ).isValid() )
799 QDomDocument doc( QStringLiteral(
"effect" ) );
800 doc.setContent( layer->
customProperty( QStringLiteral(
"labeling/shapeEffect" ) ).toString() );
801 QDomElement effectElem = doc.firstChildElement( QStringLiteral(
"effect" ) ).firstChildElement( QStringLiteral(
"effect" ) );
810 QDomElement backgroundElem = elem.firstChildElement( QStringLiteral(
"background" ) );
811 d->enabled = backgroundElem.attribute( QStringLiteral(
"shapeDraw" ), QStringLiteral(
"0" ) ).toInt();
812 d->type =
static_cast< ShapeType >( backgroundElem.attribute( QStringLiteral(
"shapeType" ), QString::number(
ShapeRectangle ) ).toUInt() );
814 d->sizeType =
static_cast< SizeType >( backgroundElem.attribute( QStringLiteral(
"shapeSizeType" ), QString::number(
SizeBuffer ) ).toUInt() );
815 d->size = QSizeF( backgroundElem.attribute( QStringLiteral(
"shapeSizeX" ), QStringLiteral(
"0" ) ).toDouble(),
816 backgroundElem.attribute( QStringLiteral(
"shapeSizeY" ), QStringLiteral(
"0" ) ).toDouble() );
818 if ( !backgroundElem.hasAttribute( QStringLiteral(
"shapeSizeUnit" ) ) )
820 d->sizeUnits =
convertFromOldLabelUnit( backgroundElem.attribute( QStringLiteral(
"shapeSizeUnits" ) ).toUInt() );
827 if ( !backgroundElem.hasAttribute( QStringLiteral(
"shapeSizeMapUnitScale" ) ) )
830 double oldMin = backgroundElem.attribute( QStringLiteral(
"shapeSizeMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
831 d->sizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
832 double oldMax = backgroundElem.attribute( QStringLiteral(
"shapeSizeMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
833 d->sizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
839 d->rotationType =
static_cast< RotationType >( backgroundElem.attribute( QStringLiteral(
"shapeRotationType" ), QString::number(
RotationSync ) ).toUInt() );
840 d->rotation = backgroundElem.attribute( QStringLiteral(
"shapeRotation" ), QStringLiteral(
"0" ) ).toDouble();
841 d->offset = QPointF( backgroundElem.attribute( QStringLiteral(
"shapeOffsetX" ), QStringLiteral(
"0" ) ).toDouble(),
842 backgroundElem.attribute( QStringLiteral(
"shapeOffsetY" ), QStringLiteral(
"0" ) ).toDouble() );
844 if ( !backgroundElem.hasAttribute( QStringLiteral(
"shapeOffsetUnit" ) ) )
846 d->offsetUnits =
convertFromOldLabelUnit( backgroundElem.attribute( QStringLiteral(
"shapeOffsetUnits" ) ).toUInt() );
853 if ( !backgroundElem.hasAttribute( QStringLiteral(
"shapeOffsetMapUnitScale" ) ) )
856 double oldMin = backgroundElem.attribute( QStringLiteral(
"shapeOffsetMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
857 d->offsetMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
858 double oldMax = backgroundElem.attribute( QStringLiteral(
"shapeOffsetMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
859 d->offsetMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
865 d->radii = QSizeF( backgroundElem.attribute( QStringLiteral(
"shapeRadiiX" ), QStringLiteral(
"0" ) ).toDouble(),
866 backgroundElem.attribute( QStringLiteral(
"shapeRadiiY" ), QStringLiteral(
"0" ) ).toDouble() );
868 if ( !backgroundElem.hasAttribute( QStringLiteral(
"shapeRadiiUnit" ) ) )
870 d->radiiUnits =
convertFromOldLabelUnit( backgroundElem.attribute( QStringLiteral(
"shapeRadiiUnits" ) ).toUInt() );
876 if ( !backgroundElem.hasAttribute( QStringLiteral(
"shapeRadiiMapUnitScale" ) ) )
879 double oldMin = backgroundElem.attribute( QStringLiteral(
"shapeRadiiMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
880 d->radiiMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
881 double oldMax = backgroundElem.attribute( QStringLiteral(
"shapeRadiiMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
882 d->radiiMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
890 d->strokeWidth = backgroundElem.attribute( QStringLiteral(
"shapeBorderWidth" ), QStringLiteral(
"0" ) ).toDouble();
892 if ( !backgroundElem.hasAttribute( QStringLiteral(
"shapeBorderWidthUnit" ) ) )
894 d->strokeWidthUnits =
convertFromOldLabelUnit( backgroundElem.attribute( QStringLiteral(
"shapeBorderWidthUnits" ) ).toUInt() );
900 if ( !backgroundElem.hasAttribute( QStringLiteral(
"shapeBorderWidthMapUnitScale" ) ) )
903 double oldMin = backgroundElem.attribute( QStringLiteral(
"shapeBorderWidthMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
904 d->strokeWidthMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
905 double oldMax = backgroundElem.attribute( QStringLiteral(
"shapeBorderWidthMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
906 d->strokeWidthMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
912 d->joinStyle =
static_cast< Qt::PenJoinStyle
>( backgroundElem.attribute( QStringLiteral(
"shapeJoinStyle" ), QString::number( Qt::BevelJoin ) ).toUInt() );
914 if ( !backgroundElem.hasAttribute( QStringLiteral(
"shapeOpacity" ) ) )
916 d->opacity = ( 1 - backgroundElem.attribute( QStringLiteral(
"shapeTransparency" ) ).toInt() / 100.0 );
920 d->opacity = ( backgroundElem.attribute( QStringLiteral(
"shapeOpacity" ) ).toDouble() );
924 static_cast< QgsPainting::BlendMode >( backgroundElem.attribute( QStringLiteral(
"shapeBlendMode" ), QString::number(
QgsPainting::BlendNormal ) ).toUInt() ) );
926 QDomElement effectElem = backgroundElem.firstChildElement( QStringLiteral(
"effect" ) );
927 if ( !effectElem.isNull() )
932 const QDomElement symbolElem = backgroundElem.firstChildElement( QStringLiteral(
"symbol" ) );
933 if ( !symbolElem.isNull() )
934 setMarkerSymbol( QgsSymbolLayerUtils::loadSymbol< QgsMarkerSymbol >( symbolElem, context ) );
941 QDomElement backgroundElem = doc.createElement( QStringLiteral(
"background" ) );
942 backgroundElem.setAttribute( QStringLiteral(
"shapeDraw" ), d->enabled );
943 backgroundElem.setAttribute( QStringLiteral(
"shapeType" ), static_cast< unsigned int >( d->type ) );
945 backgroundElem.setAttribute( QStringLiteral(
"shapeSizeType" ), static_cast< unsigned int >( d->sizeType ) );
946 backgroundElem.setAttribute( QStringLiteral(
"shapeSizeX" ), d->size.width() );
947 backgroundElem.setAttribute( QStringLiteral(
"shapeSizeY" ), d->size.height() );
950 backgroundElem.setAttribute( QStringLiteral(
"shapeRotationType" ), static_cast< unsigned int >( d->rotationType ) );
951 backgroundElem.setAttribute( QStringLiteral(
"shapeRotation" ), d->rotation );
952 backgroundElem.setAttribute( QStringLiteral(
"shapeOffsetX" ), d->offset.x() );
953 backgroundElem.setAttribute( QStringLiteral(
"shapeOffsetY" ), d->offset.y() );
956 backgroundElem.setAttribute( QStringLiteral(
"shapeRadiiX" ), d->radii.width() );
957 backgroundElem.setAttribute( QStringLiteral(
"shapeRadiiY" ), d->radii.height() );
962 backgroundElem.setAttribute( QStringLiteral(
"shapeBorderWidth" ), d->strokeWidth );
963 backgroundElem.setAttribute( QStringLiteral(
"shapeBorderWidthUnit" ),
QgsUnitTypes::encodeUnit( d->strokeWidthUnits ) );
965 backgroundElem.setAttribute( QStringLiteral(
"shapeJoinStyle" ), static_cast< unsigned int >( d->joinStyle ) );
966 backgroundElem.setAttribute( QStringLiteral(
"shapeOpacity" ), d->opacity );
969 d->paintEffect->saveProperties( doc, backgroundElem );
971 if ( d->markerSymbol )
974 return backgroundElem;
997 if ( exprVal.isValid() )
999 QString units = exprVal.toString();
1000 if ( !units.isEmpty() )
1010 if ( exprVal.isValid() )
1012 const QString skind = exprVal.toString().trimmed();
1013 if ( !skind.isEmpty() )
1020 if ( exprVal.isValid() )
1022 QString stype = exprVal.toString().trimmed();
1023 if ( !stype.isEmpty() )
1032 if ( exprVal.isValid() )
1034 QString svgfile = exprVal.toString().trimmed();
1044 if ( exprVal.isValid() )
1046 QString rotstr = exprVal.toString().trimmed();
1047 if ( !rotstr.isEmpty() )
1054 if ( exprVal.isValid() )
1064 if ( exprVal.isValid() )
1066 QString units = exprVal.toString();
1067 if ( !units.isEmpty() )
1072 d->offsetUnits = res;
1077 if ( exprVal.isValid() )
1088 if ( exprVal.isValid() )
1090 QString units = exprVal.toString();
1091 if ( !units.isEmpty() )
1096 d->radiiUnits = res;
1123 if ( exprVal.isValid() )
1125 QString units = exprVal.toString();
1126 if ( !units.isEmpty() )
1131 d->strokeWidthUnits = res;
1138 QString blendstr = exprVal.toString().trimmed();
1139 if ( !blendstr.isEmpty() )
1146 QString joinstr = exprVal.toString().trimmed();
1147 if ( !joinstr.isEmpty() )
1161 d =
new QgsTextShadowSettingsPrivate();
1193 return d->shadowUnder;
1198 d->shadowUnder = placement;
1203 return d->offsetAngle;
1208 d->offsetAngle =
angle;
1213 return d->offsetDist;
1218 d->offsetDist = distance;
1223 return d->offsetUnits;
1228 d->offsetUnits = units;
1233 return d->offsetMapUnitScale;
1238 d->offsetMapUnitScale =
scale;
1243 return d->offsetGlobal;
1248 d->offsetGlobal = global;
1263 return d->radiusUnits;
1268 d->radiusUnits = units;
1273 return d->radiusMapUnitScale;
1278 d->radiusMapUnitScale =
scale;
1283 return d->radiusAlphaOnly;
1288 d->radiusAlphaOnly = alphaOnly;
1323 return d->blendMode;
1328 d->blendMode = mode;
1333 d->enabled = layer->
customProperty( QStringLiteral(
"labeling/shadowDraw" ), QVariant(
false ) ).toBool();
1335 d->offsetAngle = layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetAngle" ), QVariant( 135 ) ).toInt();
1336 d->offsetDist = layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetDist" ), QVariant( 1.0 ) ).toDouble();
1338 if ( layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetUnit" ) ).toString().isEmpty() )
1346 if ( layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetMapUnitScale" ) ).toString().isEmpty() )
1349 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetMapUnitMinScale" ), 0.0 ).toDouble();
1350 d->offsetMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
1351 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetMapUnitMaxScale" ), 0.0 ).toDouble();
1352 d->offsetMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
1358 d->offsetGlobal = layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetGlobal" ), QVariant(
true ) ).toBool();
1359 d->radius = layer->
customProperty( QStringLiteral(
"labeling/shadowRadius" ), QVariant( 1.5 ) ).toDouble();
1361 if ( layer->
customProperty( QStringLiteral(
"labeling/shadowRadiusUnit" ) ).toString().isEmpty() )
1369 if ( layer->
customProperty( QStringLiteral(
"labeling/shadowRadiusMapUnitScale" ) ).toString().isEmpty() )
1372 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/shadowRadiusMapUnitMinScale" ), 0.0 ).toDouble();
1373 d->radiusMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
1374 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/shadowRadiusMapUnitMaxScale" ), 0.0 ).toDouble();
1375 d->radiusMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
1381 d->radiusAlphaOnly = layer->
customProperty( QStringLiteral(
"labeling/shadowRadiusAlphaOnly" ), QVariant(
false ) ).toBool();
1383 if ( layer->
customProperty( QStringLiteral(
"labeling/shadowOpacity" ) ).toString().isEmpty() )
1385 d->opacity = ( 1 - layer->
customProperty( QStringLiteral(
"labeling/shadowTransparency" ) ).toInt() / 100.0 );
1389 d->opacity = ( layer->
customProperty( QStringLiteral(
"labeling/shadowOpacity" ) ).toDouble() );
1391 d->scale = layer->
customProperty( QStringLiteral(
"labeling/shadowScale" ), QVariant( 100 ) ).toInt();
1392 d->color = _readColor( layer, QStringLiteral(
"labeling/shadowColor" ), Qt::black,
false );
1399 QDomElement shadowElem = elem.firstChildElement( QStringLiteral(
"shadow" ) );
1400 d->enabled = shadowElem.attribute( QStringLiteral(
"shadowDraw" ), QStringLiteral(
"0" ) ).toInt();
1401 d->shadowUnder =
static_cast< ShadowPlacement >( shadowElem.attribute( QStringLiteral(
"shadowUnder" ), QString::number(
ShadowLowest ) ).toUInt() );
1402 d->offsetAngle = shadowElem.attribute( QStringLiteral(
"shadowOffsetAngle" ), QStringLiteral(
"135" ) ).toInt();
1403 d->offsetDist = shadowElem.attribute( QStringLiteral(
"shadowOffsetDist" ), QStringLiteral(
"1" ) ).toDouble();
1405 if ( !shadowElem.hasAttribute( QStringLiteral(
"shadowOffsetUnit" ) ) )
1407 d->offsetUnits =
convertFromOldLabelUnit( shadowElem.attribute( QStringLiteral(
"shadowOffsetUnits" ) ).toUInt() );
1414 if ( !shadowElem.hasAttribute( QStringLiteral(
"shadowOffsetMapUnitScale" ) ) )
1417 double oldMin = shadowElem.attribute( QStringLiteral(
"shadowOffsetMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
1418 d->offsetMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
1419 double oldMax = shadowElem.attribute( QStringLiteral(
"shadowOffsetMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
1420 d->offsetMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
1426 d->offsetGlobal = shadowElem.attribute( QStringLiteral(
"shadowOffsetGlobal" ), QStringLiteral(
"1" ) ).toInt();
1427 d->radius = shadowElem.attribute( QStringLiteral(
"shadowRadius" ), QStringLiteral(
"1.5" ) ).toDouble();
1429 if ( !shadowElem.hasAttribute( QStringLiteral(
"shadowRadiusUnit" ) ) )
1431 d->radiusUnits =
convertFromOldLabelUnit( shadowElem.attribute( QStringLiteral(
"shadowRadiusUnits" ) ).toUInt() );
1437 if ( !shadowElem.hasAttribute( QStringLiteral(
"shadowRadiusMapUnitScale" ) ) )
1440 double oldMin = shadowElem.attribute( QStringLiteral(
"shadowRadiusMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
1441 d->radiusMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
1442 double oldMax = shadowElem.attribute( QStringLiteral(
"shadowRadiusMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
1443 d->radiusMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
1449 d->radiusAlphaOnly = shadowElem.attribute( QStringLiteral(
"shadowRadiusAlphaOnly" ), QStringLiteral(
"0" ) ).toInt();
1451 if ( !shadowElem.hasAttribute( QStringLiteral(
"shadowOpacity" ) ) )
1453 d->opacity = ( 1 - shadowElem.attribute( QStringLiteral(
"shadowTransparency" ) ).toInt() / 100.0 );
1457 d->opacity = ( shadowElem.attribute( QStringLiteral(
"shadowOpacity" ) ).toDouble() );
1459 d->scale = shadowElem.attribute( QStringLiteral(
"shadowScale" ), QStringLiteral(
"100" ) ).toInt();
1462 static_cast< QgsPainting::BlendMode >( shadowElem.attribute( QStringLiteral(
"shadowBlendMode" ), QString::number(
QgsPainting::BlendMultiply ) ).toUInt() ) );
1467 QDomElement shadowElem = doc.createElement( QStringLiteral(
"shadow" ) );
1468 shadowElem.setAttribute( QStringLiteral(
"shadowDraw" ), d->enabled );
1469 shadowElem.setAttribute( QStringLiteral(
"shadowUnder" ), static_cast< unsigned int >( d->shadowUnder ) );
1470 shadowElem.setAttribute( QStringLiteral(
"shadowOffsetAngle" ), d->offsetAngle );
1471 shadowElem.setAttribute( QStringLiteral(
"shadowOffsetDist" ), d->offsetDist );
1474 shadowElem.setAttribute( QStringLiteral(
"shadowOffsetGlobal" ), d->offsetGlobal );
1475 shadowElem.setAttribute( QStringLiteral(
"shadowRadius" ), d->radius );
1478 shadowElem.setAttribute( QStringLiteral(
"shadowRadiusAlphaOnly" ), d->radiusAlphaOnly );
1479 shadowElem.setAttribute( QStringLiteral(
"shadowOpacity" ), d->opacity );
1480 shadowElem.setAttribute( QStringLiteral(
"shadowScale" ), d->scale );
1496 if ( exprVal.isValid() )
1498 QString str = exprVal.toString().trimmed();
1499 if ( !str.isEmpty() )
1517 if ( exprVal.isValid() )
1519 QString units = exprVal.toString();
1520 if ( !units.isEmpty() )
1525 d->offsetUnits = res;
1536 if ( exprVal.isValid() )
1538 QString units = exprVal.toString();
1539 if ( !units.isEmpty() )
1544 d->radiusUnits = res;
1569 QString blendstr = exprVal.toString().trimmed();
1570 if ( !blendstr.isEmpty() )
1581 d =
new QgsTextSettingsPrivate();
1585 : mBufferSettings( other.mBufferSettings )
1586 , mBackgroundSettings( other.mBackgroundSettings )
1587 , mShadowSettings( other.mShadowSettings )
1588 , mTextFontFamily( other.mTextFontFamily )
1589 , mTextFontFound( other.mTextFontFound )
1598 mBufferSettings = other.mBufferSettings;
1599 mBackgroundSettings = other.mBackgroundSettings;
1600 mShadowSettings = other.mShadowSettings;
1601 mTextFontFamily = other.mTextFontFamily;
1602 mTextFontFound = other.mTextFontFound;
1618 QFont
font = d->textFont;
1620 d->fontSizeMapUnitScale );
1621 font.setPixelSize( fontPixelSize );
1632 if ( !d->textNamedStyle.isEmpty() )
1633 return d->textNamedStyle;
1636 return db.styleString( d->textFont );
1642 d->textNamedStyle = style;
1647 return d->fontSizeUnits;
1652 d->fontSizeUnits = unit;
1657 return d->fontSizeMapUnitScale;
1662 d->fontSizeMapUnitScale = scale;
1677 return d->textColor;
1682 d->textColor =
color;
1697 return d->blendMode;
1702 d->blendMode = mode;
1707 return d->multilineHeight;
1712 d->multilineHeight = height;
1717 return d->orientation;
1727 return d->previewBackgroundColor;
1732 d->previewBackgroundColor =
color;
1737 QFont appFont = QApplication::font();
1738 mTextFontFamily = layer->
customProperty( QStringLiteral(
"labeling/fontFamily" ), QVariant( appFont.family() ) ).toString();
1739 QString fontFamily = mTextFontFamily;
1743 mTextFontFound =
false;
1749 fontFamily = appFont.family();
1753 mTextFontFound =
true;
1756 if ( !layer->
customProperty( QStringLiteral(
"labeling/fontSize" ) ).isValid() )
1758 d->fontSize = appFont.pointSizeF();
1762 d->fontSize = layer->
customProperty( QStringLiteral(
"labeling/fontSize" ) ).toDouble();
1765 if ( layer->
customProperty( QStringLiteral(
"labeling/fontSizeUnit" ) ).toString().isEmpty() )
1767 d->fontSizeUnits = layer->
customProperty( QStringLiteral(
"labeling/fontSizeInMapUnits" ), QVariant(
false ) ).toBool() ?
1777 if ( layer->
customProperty( QStringLiteral(
"labeling/fontSizeMapUnitScale" ) ).toString().isEmpty() )
1780 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/fontSizeMapUnitMinScale" ), 0.0 ).toDouble();
1781 d->fontSizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
1782 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/fontSizeMapUnitMaxScale" ), 0.0 ).toDouble();
1783 d->fontSizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
1789 int fontWeight = layer->
customProperty( QStringLiteral(
"labeling/fontWeight" ) ).toInt();
1790 bool fontItalic = layer->
customProperty( QStringLiteral(
"labeling/fontItalic" ) ).toBool();
1791 d->textFont = QFont( fontFamily, d->fontSize, fontWeight, fontItalic );
1794 d->textFont.setCapitalization( static_cast< QFont::Capitalization >( layer->
customProperty( QStringLiteral(
"labeling/fontCapitals" ), QVariant( 0 ) ).toUInt() ) );
1795 d->textFont.setUnderline( layer->
customProperty( QStringLiteral(
"labeling/fontUnderline" ) ).toBool() );
1796 d->textFont.setStrikeOut( layer->
customProperty( QStringLiteral(
"labeling/fontStrikeout" ) ).toBool() );
1797 d->textFont.setLetterSpacing( QFont::AbsoluteSpacing, layer->
customProperty( QStringLiteral(
"labeling/fontLetterSpacing" ), QVariant( 0.0 ) ).toDouble() );
1798 d->textFont.setWordSpacing( layer->
customProperty( QStringLiteral(
"labeling/fontWordSpacing" ), QVariant( 0.0 ) ).toDouble() );
1799 d->textColor = _readColor( layer, QStringLiteral(
"labeling/textColor" ), Qt::black,
false );
1800 if ( layer->
customProperty( QStringLiteral(
"labeling/textOpacity" ) ).toString().isEmpty() )
1802 d->opacity = ( 1 - layer->
customProperty( QStringLiteral(
"labeling/textTransp" ) ).toInt() / 100.0 );
1806 d->opacity = ( layer->
customProperty( QStringLiteral(
"labeling/textOpacity" ) ).toDouble() );
1810 d->multilineHeight = layer->
customProperty( QStringLiteral(
"labeling/multilineHeight" ), QVariant( 1.0 ) ).toDouble();
1811 d->previewBackgroundColor = _readColor( layer, QStringLiteral(
"labeling/previewBkgrdColor" ),
"#ffffff",
false );
1820 QDomElement textStyleElem;
1821 if ( elem.nodeName() == QStringLiteral(
"text-style" ) )
1822 textStyleElem = elem;
1824 textStyleElem = elem.firstChildElement( QStringLiteral(
"text-style" ) );
1825 QFont appFont = QApplication::font();
1826 mTextFontFamily = textStyleElem.attribute( QStringLiteral(
"fontFamily" ), appFont.family() );
1827 QString fontFamily = mTextFontFamily;
1831 mTextFontFound =
false;
1837 fontFamily = appFont.family();
1841 mTextFontFound =
true;
1844 if ( textStyleElem.hasAttribute( QStringLiteral(
"fontSize" ) ) )
1846 d->fontSize = textStyleElem.attribute( QStringLiteral(
"fontSize" ) ).toDouble();
1850 d->fontSize = appFont.pointSizeF();
1853 if ( !textStyleElem.hasAttribute( QStringLiteral(
"fontSizeUnit" ) ) )
1855 d->fontSizeUnits = textStyleElem.attribute( QStringLiteral(
"fontSizeInMapUnits" ) ).toUInt() == 0 ?
QgsUnitTypes::RenderPoints 1863 if ( !textStyleElem.hasAttribute( QStringLiteral(
"fontSizeMapUnitScale" ) ) )
1866 double oldMin = textStyleElem.attribute( QStringLiteral(
"fontSizeMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
1867 d->fontSizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
1868 double oldMax = textStyleElem.attribute( QStringLiteral(
"fontSizeMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
1869 d->fontSizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
1875 int fontWeight = textStyleElem.attribute( QStringLiteral(
"fontWeight" ) ).toInt();
1876 bool fontItalic = textStyleElem.attribute( QStringLiteral(
"fontItalic" ) ).toInt();
1877 d->textFont = QFont( fontFamily, d->fontSize, fontWeight, fontItalic );
1878 d->textFont.setPointSizeF( d->fontSize );
1881 d->textFont.setCapitalization( static_cast< QFont::Capitalization >( textStyleElem.attribute( QStringLiteral(
"fontCapitals" ), QStringLiteral(
"0" ) ).toUInt() ) );
1882 d->textFont.setUnderline( textStyleElem.attribute( QStringLiteral(
"fontUnderline" ) ).toInt() );
1883 d->textFont.setStrikeOut( textStyleElem.attribute( QStringLiteral(
"fontStrikeout" ) ).toInt() );
1884 d->textFont.setKerning( textStyleElem.attribute( QStringLiteral(
"fontKerning" ), QStringLiteral(
"1" ) ).toInt() );
1885 d->textFont.setLetterSpacing( QFont::AbsoluteSpacing, textStyleElem.attribute( QStringLiteral(
"fontLetterSpacing" ), QStringLiteral(
"0" ) ).toDouble() );
1886 d->textFont.setWordSpacing( textStyleElem.attribute( QStringLiteral(
"fontWordSpacing" ), QStringLiteral(
"0" ) ).toDouble() );
1888 if ( !textStyleElem.hasAttribute( QStringLiteral(
"textOpacity" ) ) )
1890 d->opacity = ( 1 - textStyleElem.attribute( QStringLiteral(
"textTransp" ) ).toInt() / 100.0 );
1894 d->opacity = ( textStyleElem.attribute( QStringLiteral(
"textOpacity" ) ).toDouble() );
1900 static_cast< QgsPainting::BlendMode >( textStyleElem.attribute( QStringLiteral(
"blendMode" ), QString::number(
QgsPainting::BlendNormal ) ).toUInt() ) );
1902 if ( !textStyleElem.hasAttribute( QStringLiteral(
"multilineHeight" ) ) )
1904 QDomElement textFormatElem = elem.firstChildElement( QStringLiteral(
"text-format" ) );
1905 d->multilineHeight = textFormatElem.attribute( QStringLiteral(
"multilineHeight" ), QStringLiteral(
"1" ) ).toDouble();
1909 d->multilineHeight = textStyleElem.attribute( QStringLiteral(
"multilineHeight" ), QStringLiteral(
"1" ) ).toDouble();
1912 if ( textStyleElem.firstChildElement( QStringLiteral(
"text-buffer" ) ).isNull() )
1914 mBufferSettings.
readXml( elem );
1918 mBufferSettings.
readXml( textStyleElem );
1920 if ( textStyleElem.firstChildElement( QStringLiteral(
"shadow" ) ).isNull() )
1922 mShadowSettings.
readXml( elem );
1926 mShadowSettings.
readXml( textStyleElem );
1928 if ( textStyleElem.firstChildElement( QStringLiteral(
"background" ) ).isNull() )
1930 mBackgroundSettings.
readXml( elem, context );
1934 mBackgroundSettings.
readXml( textStyleElem, context );
1937 QDomElement ddElem = textStyleElem.firstChildElement( QStringLiteral(
"dd_properties" ) );
1938 if ( ddElem.isNull() )
1940 ddElem = elem.firstChildElement( QStringLiteral(
"dd_properties" ) );
1942 if ( !ddElem.isNull() )
1948 d->mDataDefinedProperties.clear();
1955 QDomElement textStyleElem = doc.createElement( QStringLiteral(
"text-style" ) );
1956 textStyleElem.setAttribute( QStringLiteral(
"fontFamily" ), d->textFont.family() );
1958 textStyleElem.setAttribute( QStringLiteral(
"fontSize" ), d->fontSize );
1961 textStyleElem.setAttribute( QStringLiteral(
"fontWeight" ), d->textFont.weight() );
1962 textStyleElem.setAttribute( QStringLiteral(
"fontItalic" ), d->textFont.italic() );
1963 textStyleElem.setAttribute( QStringLiteral(
"fontStrikeout" ), d->textFont.strikeOut() );
1964 textStyleElem.setAttribute( QStringLiteral(
"fontUnderline" ), d->textFont.underline() );
1967 textStyleElem.setAttribute( QStringLiteral(
"fontCapitals" ), static_cast< unsigned int >( d->textFont.capitalization() ) );
1968 textStyleElem.setAttribute( QStringLiteral(
"fontLetterSpacing" ), d->textFont.letterSpacing() );
1969 textStyleElem.setAttribute( QStringLiteral(
"fontWordSpacing" ), d->textFont.wordSpacing() );
1970 textStyleElem.setAttribute( QStringLiteral(
"fontKerning" ), d->textFont.kerning() );
1971 textStyleElem.setAttribute( QStringLiteral(
"textOpacity" ), d->opacity );
1974 textStyleElem.setAttribute( QStringLiteral(
"multilineHeight" ), d->multilineHeight );
1976 QDomElement ddElem = doc.createElement( QStringLiteral(
"dd_properties" ) );
1979 textStyleElem.appendChild( mBufferSettings.
writeXml( doc ) );
1980 textStyleElem.appendChild( mBackgroundSettings.
writeXml( doc, context ) );
1981 textStyleElem.appendChild( mShadowSettings.
writeXml( doc ) );
1982 textStyleElem.appendChild( ddElem );
1984 return textStyleElem;
1990 QMimeData *mimeData =
new QMimeData;
1991 mimeData->setColorData( QVariant(
color() ) );
1994 QDomDocument textDoc;
1995 QDomElement textElem =
writeXml( textDoc, rwContext );
1996 textDoc.appendChild( textElem );
1997 mimeData->setText( textDoc.toString() );
2006 if ( font.pointSizeF() > 0 )
2008 format.
setSize( font.pointSizeF() );
2011 else if ( font.pixelSize() > 0 )
2013 format.
setSize( font.pixelSize() );
2026 f.setPointSizeF(
size() );
2030 f.setPointSizeF(
size() * 2.83464567 );
2034 f.setPointSizeF(
size() * 72 );
2038 f.setPixelSize( static_cast< int >( std::round(
size() ) ) );
2059 QString text = data->text();
2060 if ( !text.isEmpty() )
2066 if ( doc.setContent( text ) )
2068 elem = doc.documentElement();
2070 format.
readXml( elem, rwContext );
2081 if ( d->blendMode != QPainter::CompositionMode_SourceOver )
2084 if ( mBufferSettings.
enabled() && mBufferSettings.
blendMode() != QPainter::CompositionMode_SourceOver )
2087 if ( mBackgroundSettings.
enabled() && mBackgroundSettings.
blendMode() != QPainter::CompositionMode_SourceOver )
2090 if ( mShadowSettings.
enabled() && mShadowSettings.
blendMode() != QPainter::CompositionMode_SourceOver )
2098 return d->mDataDefinedProperties;
2103 return d->mDataDefinedProperties;
2108 d->mDataDefinedProperties = collection;
2113 if ( !d->mDataDefinedProperties.hasActiveProperties() )
2116 QString ddFontFamily;
2119 if ( exprVal.isValid() )
2121 QString family = exprVal.toString().trimmed();
2122 if ( d->textFont.family() != family )
2128 ddFontFamily = family;
2134 QString ddFontStyle;
2137 if ( exprVal.isValid() )
2139 QString fontstyle = exprVal.toString().trimmed();
2140 ddFontStyle = fontstyle;
2143 bool ddBold =
false;
2150 bool ddItalic =
false;
2160 QFontDatabase fontDb;
2161 QFont appFont = QApplication::font();
2162 bool newFontBuilt =
false;
2163 if ( ddBold || ddItalic )
2166 newFont = QFont( !ddFontFamily.isEmpty() ? ddFontFamily : d->textFont.family() );
2167 newFontBuilt =
true;
2168 newFont.setBold( ddBold );
2169 newFont.setItalic( ddItalic );
2171 else if ( !ddFontStyle.isEmpty()
2172 && ddFontStyle.compare( QLatin1String(
"Ignore" ), Qt::CaseInsensitive ) != 0 )
2174 if ( !ddFontFamily.isEmpty() )
2177 QFont styledfont = fontDb.font( ddFontFamily, ddFontStyle, appFont.pointSize() );
2178 if ( appFont != styledfont )
2180 newFont = styledfont;
2181 newFontBuilt =
true;
2188 else if ( !ddFontFamily.isEmpty() )
2190 if ( ddFontStyle.compare( QLatin1String(
"Ignore" ), Qt::CaseInsensitive ) != 0 )
2193 QFont styledfont = fontDb.font( ddFontFamily, d->textNamedStyle, appFont.pointSize() );
2194 if ( appFont != styledfont )
2196 newFont = styledfont;
2197 newFontBuilt =
true;
2202 newFont = QFont( ddFontFamily );
2203 newFontBuilt =
true;
2210 newFont.setUnderline( d->textFont.underline() );
2211 newFont.setStrikeOut( d->textFont.strikeOut() );
2212 newFont.setWordSpacing( d->textFont.wordSpacing() );
2213 newFont.setLetterSpacing( QFont::AbsoluteSpacing, d->textFont.letterSpacing() );
2214 d->textFont = newFont;
2242 if ( exprVal.isValid() )
2244 QString units = exprVal.toString();
2245 if ( !units.isEmpty() )
2250 d->fontSizeUnits = res;
2282 QString blendstr = exprVal.toString().trimmed();
2283 if ( !blendstr.isEmpty() )
2295 QPixmap pixmap( size );
2296 pixmap.fill( Qt::transparent );
2298 painter.begin( &pixmap );
2300 painter.setRenderHint( QPainter::Antialiasing );
2302 QRect rect( 0, 0, size.width(), size.height() );
2305 painter.setPen( Qt::NoPen );
2307 if ( ( background1.lightnessF() < 0.7 ) )
2309 background1 = background1.darker( 125 );
2313 background1 = background1.lighter( 125 );
2316 QLinearGradient linearGrad( QPointF( 0, 0 ), QPointF( 0, rect.height() ) );
2317 linearGrad.setColorAt( 0, background1 );
2318 linearGrad.setColorAt( 1, background2 );
2319 painter.setBrush( QBrush( linearGrad ) );
2320 if ( size.width() > 30 )
2322 painter.drawRoundedRect( rect, 6, 6 );
2327 painter.drawRect( rect );
2329 painter.setBrush( Qt::NoBrush );
2330 painter.setPen( Qt::NoPen );
2338 context.
setScaleFactor( QgsApplication::desktop()->logicalDpiX() / 25.4 );
2349 double ytrans = 0.0;
2355 const QStringList text = QStringList() << ( previewText.isEmpty() ? QObject::tr(
"Aa" ) : previewText );
2357 QRectF textRect = rect;
2358 textRect.setLeft( xtrans + padding );
2359 textRect.setWidth( rect.width() - xtrans - 2 * padding );
2361 if ( textRect.width() > 2000 )
2362 textRect.setWidth( 2000 - 2 * padding );
2364 const double bottom = textRect.height() / 2 + textHeight / 2;
2365 textRect.setTop( bottom - textHeight );
2366 textRect.setBottom( bottom );
2371 painter.setBrush( Qt::NoBrush );
2373 if ( size.width() > 30 )
2375 painter.drawRoundedRect( rect, 6, 6 );
2380 painter.drawRect( rect );
2397 tmpFormat = updateShadowPosition( tmpFormat );
2401 drawPart( rect, rotation, alignment, textLines, context, tmpFormat, Background );
2406 drawPart( rect, rotation, alignment, textLines, context, tmpFormat, Buffer );
2409 drawPart( rect, rotation, alignment, textLines, context, tmpFormat, Text );
2417 tmpFormat = updateShadowPosition( tmpFormat );
2421 drawPart( point, rotation, alignment, textLines, context, tmpFormat, Background );
2426 drawPart( point, rotation, alignment, textLines, context, tmpFormat, Buffer );
2429 drawPart( point, rotation, alignment, textLines, context, tmpFormat, Text );
2461 Component component;
2462 component.dpiRatio = 1.0;
2463 component.origin = rect.topLeft();
2464 component.rotation = rotation;
2465 component.size = rect.size();
2466 component.hAlign = alignment;
2479 double xc = rect.width() / 2.0;
2480 double yc = rect.height() / 2.0;
2482 double angle = -rotation;
2483 double xd = xc * std::cos( angle ) - yc * std::sin( angle );
2484 double yd = xc * std::sin( angle ) + yc * std::cos( angle );
2486 component.center = QPointF( component.origin.x() + xd, component.origin.y() + yd );
2490 component.center = rect.center();
2493 QgsTextRenderer::drawBackground( context, component, format, textLines, Rect );
2507 QFontMetricsF fm( format.
scaledFont( context ) );
2508 drawTextInternal( part, context, format, component,
2524 Component component;
2525 component.dpiRatio = 1.0;
2526 component.origin = origin;
2527 component.rotation = rotation;
2528 component.hAlign = alignment;
2537 QgsTextRenderer::drawBackground( context, component, format, textLines, Point );
2550 QFontMetricsF fm( format.
scaledFont( context ) );
2551 drawTextInternal( part, context, format, component,
2566 void QgsTextRenderer::drawBuffer(
QgsRenderContext &context,
const QgsTextRenderer::Component &component,
const QgsTextFormat &format,
const QFontMetricsF *fontMetrics )
2568 QPainter *p = context.
painter();
2573 if ( component.rotation >= -315 && component.rotation < -90 )
2577 else if ( component.rotation >= -90 && component.rotation < -45 )
2592 path.setFillRule( Qt::WindingFill );
2593 switch ( orientation )
2596 path.addText( 0, 0, format.
scaledFont( context ), component.text );
2600 double letterSpacing = format.
scaledFont( context ).letterSpacing();
2601 double labelWidth = fontMetrics->maxWidth();
2603 double partYOffset = 0.0;
2604 for (
const auto &part : parts )
2606 double partXOffset = ( labelWidth - ( fontMetrics->width( part ) - letterSpacing ) ) / 2;
2607 path.addText( partXOffset, partYOffset, format.
scaledFont( context ), part );
2608 partYOffset += fontMetrics->ascent() + letterSpacing;
2612 QColor bufferColor = buffer.
color();
2613 bufferColor.setAlphaF( buffer.
opacity() );
2614 QPen pen( bufferColor );
2615 pen.setWidthF( penSize );
2617 QColor tmpColor( bufferColor );
2621 tmpColor.setAlpha( 0 );
2627 buffp.begin( &buffPict );
2634 context.
painter()->setPen( pen );
2635 context.
painter()->setBrush( tmpColor );
2636 context.
painter()->drawPath( path );
2643 buffp.setPen( pen );
2644 buffp.setBrush( tmpColor );
2645 buffp.drawPath( path );
2651 QgsTextRenderer::Component bufferComponent = component;
2652 bufferComponent.origin = QPointF( 0.0, 0.0 );
2653 bufferComponent.picture = buffPict;
2654 bufferComponent.pictureBuffer = penSize / 2.0;
2655 drawShadow( context, bufferComponent, format );
2660 p->setCompositionMode( buffer.
blendMode() );
2664 p->setRenderHint( QPainter::Antialiasing );
2668 p->scale( component.dpiRatio, component.dpiRatio );
2669 _fixQPictureDPI( p );
2670 p->drawPicture( 0, 0, buffPict );
2677 std::unique_ptr< QFontMetricsF > newFm;
2680 newFm.reset(
new QFontMetricsF( format.
scaledFont( context ) ) );
2681 fontMetrics = newFm.get();
2689 double maxLineWidth = 0;
2690 const auto constTextLines = textLines;
2691 for (
const QString &line : constTextLines )
2693 maxLineWidth = std::max( maxLineWidth, fontMetrics->width( line ) );
2695 width = maxLineWidth;
2701 double labelWidth = fontMetrics->maxWidth();
2702 width = labelWidth + ( textLines.size() - 1 ) * labelWidth * format.
lineHeight();
2719 std::unique_ptr< QFontMetricsF > newFm;
2722 newFm.reset(
new QFontMetricsF( format.
scaledFont( context ) ) );
2723 fontMetrics = newFm.get();
2730 double labelHeight = fontMetrics->ascent() + fontMetrics->descent();
2737 return labelHeight + ( textLines.size() - 1 ) * labelHeight * format.
lineHeight();
2742 return labelHeight + ( textLines.size() - 1 ) * fontMetrics->lineSpacing() * format.
lineHeight();
2749 double labelHeight = fontMetrics->ascent();
2750 double letterSpacing = format.
scaledFont( context ).letterSpacing();
2751 int maxLineLength = 0;
2752 for (
const auto &line : textLines )
2754 if ( line.length() > maxLineLength )
2755 maxLineLength = line.length();
2757 return labelHeight * maxLineLength + ( maxLineLength - 1 ) * letterSpacing;
2772 const QStringList &textLines,
DrawMode mode )
2776 QPainter *prevP = context.
painter();
2777 QPainter *p = context.
painter();
2791 component.rotation = -( component.rotation * 180 / M_PI );
2792 component.rotationOffset =
2797 component.rotation = 0.0;
2798 component.rotationOffset = background.
rotation();
2801 if ( mode != Label )
2804 QFontMetricsF fm( format.
scaledFont( context ) );
2805 double width = textWidth( context, format, textLines, &fm );
2806 double height = textHeight( context, format, textLines, mode, &fm );
2811 switch ( component.hAlign )
2814 component.center = QPointF( component.origin.x() + width / 2.0,
2815 component.origin.y() + height / 2.0 );
2819 component.center = QPointF( component.origin.x() + component.size.width() / 2.0,
2820 component.origin.y() + height / 2.0 );
2824 component.center = QPointF( component.origin.x() + component.size.width() - width / 2.0,
2825 component.origin.y() + height / 2.0 );
2832 double originAdjust = fm.ascent() / 2.0 - fm.leading() / 2.0;
2833 switch ( component.hAlign )
2836 component.center = QPointF( component.origin.x() + width / 2.0,
2837 component.origin.y() - height / 2.0 + originAdjust );
2841 component.center = QPointF( component.origin.x(),
2842 component.origin.y() - height / 2.0 + originAdjust );
2846 component.center = QPointF( component.origin.x() - width / 2.0,
2847 component.origin.y() - height / 2.0 + originAdjust );
2858 component.size = QSizeF( width, height );
2863 switch ( background.
type() )
2876 double sizeOut = 0.0;
2884 sizeOut = std::max( component.size.width(), component.size.height() );
2888 sizeOut += bufferSize * 2;
2893 if ( sizeOut < 1.0 )
2896 std::unique_ptr< QgsMarkerSymbol > renderedSymbol;
2900 map[QStringLiteral(
"name" )] = background.
svgFile().trimmed();
2901 map[QStringLiteral(
"size" )] = QString::number( sizeOut );
2903 map[QStringLiteral(
"angle" )] = QString::number( 0.0 );
2911 map[QStringLiteral(
"fill" )] = background.
fillColor().name();
2912 map[QStringLiteral(
"outline" )] = background.
strokeColor().name();
2913 map[QStringLiteral(
"outline-width" )] = QString::number( background.
strokeWidth() );
2921 shdwmap[QStringLiteral(
"fill" )] = shadow.
color().name();
2922 shdwmap[QStringLiteral(
"outline" )] = shadow.
color().name();
2923 shdwmap[QStringLiteral(
"size" )] = QString::number( sizeOut );
2928 svgp.begin( &svgPict );
2945 svgShdwM->
renderPoint( QPointF( sizeOut / 2, -sizeOut / 2 ), svgShdwContext );
2948 component.picture = svgPict;
2950 component.pictureBuffer = 0.0;
2952 component.size = QSizeF( sizeOut, sizeOut );
2953 component.offset = QPointF( 0.0, 0.0 );
2957 p->translate( component.center.x(), component.center.y() );
2958 p->rotate( component.rotation );
2961 p->translate( QPointF( xoff, yoff ) );
2962 p->rotate( component.rotationOffset );
2963 p->translate( -sizeOut / 2, sizeOut / 2 );
2966 p->setRenderHint( QPainter::Antialiasing );
2969 drawShadow( context, component, format );
2975 renderedSymbol.reset( );
2983 renderedSymbol->setSize( sizeOut );
2987 renderedSymbol->setOpacity( background.
opacity() );
2993 p->setCompositionMode( background.
blendMode() );
2997 p->setRenderHint( QPainter::Antialiasing );
2999 p->translate( component.center.x(), component.center.y() );
3000 p->rotate( component.rotation );
3003 p->translate( QPointF( xoff, yoff ) );
3004 p->rotate( component.rotationOffset );
3008 renderedSymbol->renderPoint( QPointF( 0, 0 ), &f, context );
3009 renderedSymbol->stopRender( context );
3010 p->setCompositionMode( QPainter::CompositionMode_SourceOver );
3021 double w = component.size.width();
3022 double h = component.size.height();
3043 h = std::sqrt( std::pow( w, 2 ) + std::pow( h, 2 ) );
3049 h = h * M_SQRT1_2 * 2;
3050 w = w * M_SQRT1_2 * 2;
3058 w += bufferWidth * 2;
3059 h += bufferHeight * 2;
3063 QRectF rect( -w / 2.0, - h / 2.0, w, h );
3065 if ( rect.isNull() )
3071 p->setRenderHint( QPainter::Antialiasing );
3073 p->translate( QPointF( component.center.x(), component.center.y() ) );
3074 p->rotate( component.rotation );
3077 p->translate( QPointF( xoff, yoff ) );
3078 p->rotate( component.rotationOffset );
3086 pen.setWidthF( penSize );
3088 pen.setJoinStyle( background.
joinStyle() );
3098 shapep.begin( &shapePict );
3099 shapep.setPen( pen );
3100 shapep.setBrush( background.
fillColor() );
3107 shapep.drawRoundedRect( rect, background.
radii().width(), background.
radii().height(), Qt::RelativeSize );
3113 shapep.drawRoundedRect( rect, xRadius, yRadius );
3119 shapep.drawEllipse( rect );
3125 component.picture = shapePict;
3126 component.pictureBuffer = penSize / 2.0;
3128 component.size = rect.size();
3129 component.offset = QPointF( rect.width() / 2, -rect.height() / 2 );
3130 drawShadow( context, component, format );
3133 p->setOpacity( background.
opacity() );
3136 p->setCompositionMode( background.
blendMode() );
3140 p->scale( component.dpiRatio, component.dpiRatio );
3141 _fixQPictureDPI( p );
3142 p->drawPicture( 0, 0, shapePict );
3163 QPainter *p = context.
painter();
3164 double componentWidth = component.size.width(), componentHeight = component.size.height();
3165 double xOffset = component.offset.x(), yOffset = component.offset.y();
3166 double pictbuffer = component.pictureBuffer;
3171 radius /= ( mapUnits ? context.
scaleFactor() / component.dpiRatio : 1 );
3172 radius =
static_cast< int >( radius + 0.5 );
3176 double blurBufferClippingScale = 3.75;
3177 int blurbuffer = ( radius > 17 ? 16 : radius ) * blurBufferClippingScale;
3179 QImage blurImg( componentWidth + ( pictbuffer * 2.0 ) + ( blurbuffer * 2.0 ),
3180 componentHeight + ( pictbuffer * 2.0 ) + ( blurbuffer * 2.0 ),
3181 QImage::Format_ARGB32_Premultiplied );
3185 int minBlurImgSize = 1;
3189 int maxBlurImgSize = 40000;
3190 if ( blurImg.isNull()
3191 || ( blurImg.width() < minBlurImgSize || blurImg.height() < minBlurImgSize )
3192 || ( blurImg.width() > maxBlurImgSize || blurImg.height() > maxBlurImgSize ) )
3195 blurImg.fill( QColor( Qt::transparent ).rgba() );
3197 if ( !pictp.begin( &blurImg ) )
3199 pictp.setRenderHints( QPainter::Antialiasing | QPainter::SmoothPixmapTransform );
3200 QPointF imgOffset( blurbuffer + pictbuffer + xOffset,
3201 blurbuffer + pictbuffer + componentHeight + yOffset );
3203 pictp.drawPicture( imgOffset,
3204 component.picture );
3207 pictp.setCompositionMode( QPainter::CompositionMode_SourceIn );
3208 pictp.fillRect( blurImg.rect(), shadow.
color() );
3212 if ( shadow.
blurRadius() > 0.0 && radius > 0 )
3220 picti.begin( &blurImg );
3221 picti.setBrush( Qt::Dense7Pattern );
3222 QPen imgPen( QColor( 0, 0, 255, 255 ) );
3223 imgPen.setWidth( 1 );
3224 picti.setPen( imgPen );
3225 picti.setOpacity( 0.1 );
3226 picti.drawRect( 0, 0, blurImg.width(), blurImg.height() );
3231 double angleRad = shadow.
offsetAngle() * M_PI / 180;
3239 angleRad -= ( component.rotation * M_PI / 180 + component.rotationOffset * M_PI / 180 );
3242 QPointF transPt( -offsetDist * std::cos( angleRad + M_PI_2 ),
3243 -offsetDist * std::sin( angleRad + M_PI_2 ) );
3246 p->setRenderHint( QPainter::SmoothPixmapTransform );
3249 p->setRenderHint( QPainter::Antialiasing );
3253 p->setCompositionMode( shadow.
blendMode() );
3255 p->setOpacity( shadow.
opacity() );
3257 double scale = shadow.
scale() / 100.0;
3259 p->scale( scale, scale );
3260 if ( component.useOrigin )
3262 p->translate( component.origin.x(), component.origin.y() );
3264 p->translate( transPt );
3265 p->translate( -imgOffset.x(),
3267 p->drawImage( 0, 0, blurImg );
3274 p->setBrush( Qt::NoBrush );
3275 QPen imgPen( QColor( 255, 0, 0, 10 ) );
3276 imgPen.setWidth( 2 );
3277 imgPen.setStyle( Qt::DashLine );
3278 p->setPen( imgPen );
3279 p->scale( scale, scale );
3280 if ( component.useOrigin() )
3282 p->translate( component.origin().x(), component.origin().y() );
3284 p->translate( transPt );
3285 p->translate( -imgOffset.x(),
3287 p->drawRect( 0, 0, blurImg.width(), blurImg.height() );
3292 p->setBrush( Qt::NoBrush );
3293 QPen componentRectPen( QColor( 0, 255, 0, 70 ) );
3294 componentRectPen.setWidth( 1 );
3295 if ( component.useOrigin() )
3297 p->translate( component.origin().x(), component.origin().y() );
3299 p->setPen( componentRectPen );
3300 p->drawRect( QRect( -xOffset, -componentHeight - yOffset, componentWidth, componentHeight ) );
3305 void QgsTextRenderer::drawTextInternal(
TextPart drawType,
3308 const Component &component,
3309 const QStringList &textLines,
3310 const QFontMetricsF *fontMetrics,
3319 double rotation = -component.rotation * 180 / M_PI;
3323 if ( rotation >= -315 && rotation < -90 )
3328 else if ( rotation >= -90 && rotation < -45 )
3339 switch ( orientation )
3343 double labelWidest = 0.0;
3348 for (
const QString &line : textLines )
3350 double labelWidth = fontMetrics->width( line );
3351 if ( labelWidth > labelWidest )
3353 labelWidest = labelWidth;
3359 labelWidest = component.size.width();
3363 double labelHeight = fontMetrics->ascent() + fontMetrics->descent();
3367 double ascentOffset = 0.25 * fontMetrics->ascent();
3371 bool adjustForAlignment = alignment != AlignLeft && ( mode != Label || textLines.size() > 1 );
3373 const auto constTextLines = textLines;
3374 for (
const QString &line : constTextLines )
3379 context.
painter()->setRenderHint( QPainter::Antialiasing );
3381 context.
painter()->translate( component.origin );
3383 context.
painter()->rotate( rotation );
3386 double xMultiLineOffset = 0.0;
3387 double labelWidth = fontMetrics->width( line );
3388 if ( adjustForAlignment )
3390 double labelWidthDiff = labelWidest - labelWidth;
3391 if ( alignment == AlignCenter )
3393 labelWidthDiff /= 2;
3399 xMultiLineOffset = labelWidthDiff;
3403 if ( alignment == AlignRight )
3404 xMultiLineOffset = labelWidthDiff - labelWidest;
3405 else if ( alignment == AlignCenter )
3406 xMultiLineOffset = labelWidthDiff - labelWidest / 2.0;
3413 double yMultiLineOffset = ascentOffset;
3420 yMultiLineOffset = - ascentOffset - ( textLines.size() - 1 - i ) * labelHeight * format.
lineHeight();
3425 yMultiLineOffset = - ascentOffset + labelHeight - 1 + format.
lineHeight() * fontMetrics->lineSpacing() * i;
3430 yMultiLineOffset = 0 - ( textLines.size() - 1 - i ) * fontMetrics->lineSpacing() * format.
lineHeight();
3435 context.
painter()->translate( QPointF( xMultiLineOffset, yMultiLineOffset ) );
3437 Component subComponent;
3438 subComponent.text = line;
3439 subComponent.size = QSizeF( labelWidth, labelHeight );
3440 subComponent.offset = QPointF( 0.0, -ascentOffset );
3441 subComponent.rotation = -component.rotation * 180 / M_PI;
3442 subComponent.rotationOffset = 0.0;
3446 QgsTextRenderer::drawBuffer( context, subComponent, format, fontMetrics );
3452 path.setFillRule( Qt::WindingFill );
3453 path.addText( 0, 0, format.
scaledFont( context ), subComponent.text );
3458 textp.begin( &textPict );
3459 textp.setPen( Qt::NoPen );
3460 QColor textColor = format.
color();
3461 textColor.setAlphaF( format.
opacity() );
3462 textp.setBrush( textColor );
3463 textp.drawPath( path );
3473 subComponent.picture = textPict;
3474 subComponent.pictureBuffer = 0.0;
3475 subComponent.origin = QPointF( 0.0, 0.0 );
3477 QgsTextRenderer::drawShadow( context, subComponent, format );
3487 context.
painter()->scale( subComponent.dpiRatio, subComponent.dpiRatio );
3494 _fixQPictureDPI( context.
painter() );
3495 context.
painter()->drawPicture( 0, 0, textPict );
3502 QColor textColor = format.
color();
3503 textColor.setAlphaF( format.
opacity() );
3504 context.
painter()->setPen( textColor );
3505 context.
painter()->setRenderHint( QPainter::TextAntialiasing );
3506 context.
painter()->drawText( 0, 0, subComponent.text );
3519 double letterSpacing = format.
scaledFont( context ).letterSpacing();
3521 double labelWidth = fontMetrics->maxWidth();
3522 double actualLabelWidest = labelWidth + ( textLines.size() - 1 ) * labelWidth * format.
lineHeight();
3523 double labelWidest = 0.0;
3528 labelWidest = actualLabelWidest;
3532 labelWidest = component.size.width();
3536 int maxLineLength = 0;
3537 for (
auto const &line : textLines )
3539 maxLineLength = std::max( maxLineLength, line.length() );
3541 double actualLabelHeight = fontMetrics->ascent() + ( fontMetrics->ascent() + letterSpacing ) * ( maxLineLength - 1 );
3542 double ascentOffset = fontMetrics->ascent();
3546 bool adjustForAlignment = alignment != AlignLeft && ( mode != Label || textLines.size() > 1 );
3549 QString lines = textLines.join(
'\n' );
3551 for ( QString line : constTextLines )
3556 context.
painter()->setRenderHint( QPainter::Antialiasing );
3558 context.
painter()->translate( component.origin );
3560 context.
painter()->rotate( rotation );
3563 double xOffset = actualLabelWidest - labelWidth - ( i * labelWidth * format.
lineHeight() );
3564 if ( adjustForAlignment )
3566 double labelWidthDiff = labelWidest - actualLabelWidest;
3567 if ( alignment == AlignCenter )
3569 labelWidthDiff /= 2;
3575 xOffset += labelWidthDiff;
3583 double yOffset = 0.0;
3589 if ( rotation >= -405 && rotation < -180 )
3591 yOffset = ascentOffset;
3593 else if ( rotation >= 0 && rotation < 45 )
3595 xOffset -= actualLabelWidest;
3596 yOffset = -actualLabelHeight + ascentOffset + fontMetrics->descent();
3601 yOffset = -actualLabelHeight + ascentOffset;
3606 yOffset = -actualLabelHeight + ascentOffset;
3610 yOffset = ascentOffset;
3614 context.
painter()->translate( QPointF( xOffset, yOffset ) );
3616 double labelHeight = fontMetrics->ascent() + ( fontMetrics->ascent() + letterSpacing ) * ( line.length() - 1 );
3618 Component subComponent;
3619 subComponent.text = line;
3620 subComponent.size = QSizeF( labelWidth, labelHeight );
3621 subComponent.offset = QPointF( 0.0, 0.0 );
3622 subComponent.rotation = -component.rotation * 180 / M_PI;
3623 subComponent.rotationOffset = 0.0;
3627 QgsTextRenderer::drawBuffer( context, subComponent, format, fontMetrics );
3633 path.setFillRule( Qt::WindingFill );
3635 double partYOffset = 0.0;
3636 for (
const auto &part : parts )
3638 double partXOffset = ( labelWidth - ( fontMetrics->width( part ) - letterSpacing ) ) / 2;
3639 path.addText( partXOffset, partYOffset, format.
scaledFont( context ), part );
3640 partYOffset += fontMetrics->ascent() + letterSpacing;
3646 textp.begin( &textPict );
3647 textp.setPen( Qt::NoPen );
3648 QColor textColor = format.
color();
3649 textColor.setAlphaF( format.
opacity() );
3650 textp.setBrush( textColor );
3651 textp.drawPath( path );
3661 subComponent.picture = textPict;
3662 subComponent.pictureBuffer = 0.0;
3663 subComponent.origin = QPointF( 0.0, 0.0 );
3665 QgsTextRenderer::drawShadow( context, subComponent, format );
3675 context.
painter()->scale( subComponent.dpiRatio, subComponent.dpiRatio );
3682 _fixQPictureDPI( context.
painter() );
3683 context.
painter()->drawPicture( 0, 0, textPict );
3690 QColor textColor = format.
color();
3691 textColor.setAlphaF( format.
opacity() );
3692 context.
painter()->setPen( textColor );
3693 context.
painter()->setRenderHint( QPainter::TextAntialiasing );
3694 context.
painter()->drawText( 0, 0, subComponent.text );
3714 const QString skind =
string.trimmed();
3716 if ( skind.compare( QLatin1String(
"Square" ), Qt::CaseInsensitive ) == 0 )
3720 else if ( skind.compare( QLatin1String(
"Ellipse" ), Qt::CaseInsensitive ) == 0 )
3724 else if ( skind.compare( QLatin1String(
"Circle" ), Qt::CaseInsensitive ) == 0 )
3728 else if ( skind.compare( QLatin1String(
"SVG" ), Qt::CaseInsensitive ) == 0 )
3732 else if ( skind.compare( QLatin1String(
"marker" ), Qt::CaseInsensitive ) == 0 )
3741 const QString stype =
string.trimmed();
3745 if ( stype.compare( QLatin1String(
"Fixed" ), Qt::CaseInsensitive ) == 0 )
3754 const QString rotstr =
string.trimmed();
3758 if ( rotstr.compare( QLatin1String(
"Offset" ), Qt::CaseInsensitive ) == 0 )
3762 else if ( rotstr.compare( QLatin1String(
"Fixed" ), Qt::CaseInsensitive ) == 0 )
3771 const QString str =
string.trimmed();
3775 if ( str.compare( QLatin1String(
"Text" ), Qt::CaseInsensitive ) == 0 )
3779 else if ( str.compare( QLatin1String(
"Buffer" ), Qt::CaseInsensitive ) == 0 )
3783 else if ( str.compare( QLatin1String(
"Background" ), Qt::CaseInsensitive ) == 0 )
3792 switch ( orientation )
3795 return QStringLiteral(
"horizontal" );
3797 return QStringLiteral(
"vertical" );
3799 return QStringLiteral(
"rotation-based" );
3809 QString cleaned = name.toLower().trimmed();
3811 if ( cleaned == QLatin1String(
"horizontal" ) )
3813 else if ( cleaned == QLatin1String(
"vertical" ) )
3815 else if ( cleaned == QLatin1String(
"rotation-based" ) )
TextOrientation
Text orientation.
QPainter::CompositionMode blendMode() const
Returns the blending mode used for drawing the buffer.
static const QgsPropertiesDefinition & propertyDefinitions()
Returns the labeling property definitions.
The class is used as a container of context for various read/write operations on other objects...
QColor strokeColor() const
Returns the color used for outlining the background shape.
QColor valueAsColor(int key, const QgsExpressionContext &context, const QColor &defaultColor=QColor(), bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a color...
Meters value as Map units.
void setScale(int scale)
Sets the scaling used for the drop shadow (in percentage of original size).
Shape size is determined by adding a buffer margin around text.
void setLineHeight(double height)
Sets the line height for text.
void setRadiiUnit(QgsUnitTypes::RenderUnit units)
Sets the units used for the shape's radii.
void setStrokeWidth(double width)
Sets the width of the shape's stroke (stroke).
RotationType
Methods for determining the rotation of the background shape.
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the shadow offset distance.
Horizontally or vertically oriented text based on rotation (only available for map labeling) ...
void setOpacity(double opacity)
Sets the text's opacity.
void setStrokeWidthMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the shape stroke width.
void setOffsetUnit(QgsUnitTypes::RenderUnit units)
Sets the units used for the shadow's offset.
static QPointF toPoint(const QVariant &value, bool *ok=nullptr)
Converts a value to a point.
QgsTextShadowSettings::ShadowPlacement shadowPlacement() const
Returns the placement for the drop shadow.
QSizeF radii() const
Returns the radii used for rounding the corners of shapes.
QSizeF size() const
Returns the size of the background shape.
double opacity() const
Returns the text's opacity.
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units used for the shape's size.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
void setOrientation(TextOrientation orientation)
Sets the orientation for the text.
QPainter::CompositionMode blendMode() const
Returns the blending mode used for drawing the drop shadow.
QPointF offset() const
Returns the offset used for drawing the background shape.
QColor fillColor() const
Returns the color used for filing the background shape.
QgsMapUnitScale strokeWidthMapUnitScale() const
Returns the map unit scale object for the shape stroke width.
static QgsTextBackgroundSettings::RotationType decodeBackgroundRotationType(const QString &string)
Decodes a string representation of a background rotation type to a type.
double valueAsDouble(int key, const QgsExpressionContext &context, double defaultValue=0.0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a double...
QFont toQFont() const
Returns a QFont matching the relevant settings from this text format.
QgsTextShadowSettings & operator=(const QgsTextShadowSettings &other)
static QString substituteVerticalCharacters(QString string)
Returns a string with characters having vertical representation form substituted. ...
void readXml(const QDomElement &elem)
Read settings from a DOM element.
Use antialiasing while drawing.
void setPreviewBackgroundColor(const QColor &color)
Sets the background color that text will be rendered on for previews.
Draw shadow under buffer.
ShadowPlacement
Placement positions for text shadow.
Always render text as text objects.
QgsTextShadowSettings & shadow()
Returns a reference to the text drop shadow settings.
double blurRadius() const
Returns the blur radius for the shadow.
QgsUnitTypes::RenderUnit convertFromOldLabelUnit(int val)
double opacity() const
Returns the background shape's opacity.
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the size.
void setStrokeColor(const QColor &color)
Sets the color used for outlining the background shape.
void setSize(double size)
Sets the size of the buffer.
double strokeWidth() const
Returns the width of the shape's stroke (stroke).
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units used for the buffer size.
HAlignment
Horizontal alignment.
double offsetDistance() const
Returns the distance for offsetting the position of the shadow from the text.
void setFont(const QFont &font)
Sets the font used for rendering text.
void setJoinStyle(Qt::PenJoinStyle style)
Sets the join style used for drawing the buffer.
static bool isDefaultStack(QgsPaintEffect *effect)
Tests whether a paint effect matches the default effects stack.
static QgsPainting::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
Base class for visual effects which can be applied to QPicture drawings.
void setOffsetUnit(QgsUnitTypes::RenderUnit units)
Sets the units used for the shape's offset.
static QgsTextBackgroundSettings::SizeType decodeBackgroundSizeType(const QString &string)
Decodes a string representation of a background size type to a type.
QColor color() const
Returns the color that text will be rendered in.
static void drawPart(const QRectF &rect, double rotation, HAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, TextPart part, bool drawAsOutlines=true)
Draws a single component of rendered text using the specified settings.
void setFillBufferInterior(bool fill)
Sets whether the interior of the buffer will be filled in.
void setBlurRadius(double blurRadius)
Sets the blur radius for the shadow.
void setPaintEffect(QgsPaintEffect *effect)
Sets the current paint effect for the buffer.
void setOpacity(double opacity)
Sets the shadow's opacity.
QgsTextBufferSettings & operator=(const QgsTextBufferSettings &other)
Copy constructor.
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the shape size.
static QString encodeMapUnitScale(const QgsMapUnitScale &mapUnitScale)
static QPainter::CompositionMode getCompositionMode(QgsPainting::BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
Flags flags() const
Returns combination of flags used for rendering.
static QDomElement saveSymbol(const QString &symbolName, const QgsSymbol *symbol, QDomDocument &doc, const QgsReadWriteContext &context)
Writes a symbol definition to XML.
QgsFields fields() const
Convenience function for retrieving the fields for the context, if set.
void setJoinStyle(Qt::PenJoinStyle style)
Sets the join style used for drawing the background shape.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context)
Read settings from a DOM element.
TextRenderFormat textRenderFormat() const
Returns the text render format, which dictates how text is rendered (e.g.
static QgsTextFormat fromQFont(const QFont &font)
Returns a text format matching the settings from an input font.
void setMarkerSymbol(QgsMarkerSymbol *symbol)
Sets the current marker symbol for the background shape.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Container for settings relating to a text background object.
Percentage of another measurement (e.g., canvas size, feature size)
static int sizeToPixel(double size, const QgsRenderContext &c, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &mapUnitScale=QgsMapUnitScale())
Calculates pixel size (considering output size should be in pixel or map units, scale factors and opt...
QgsMapUnitScale offsetMapUnitScale() const
Returns the map unit scale object for the shape offset.
void setRadiiMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the shape radii.
void setBlurRadiusUnit(QgsUnitTypes::RenderUnit units)
Sets the units used for the shadow's blur radius.
static QString translateNamedStyle(const QString &namedStyle)
Returns the localized named style of a font, if such a translation is available.
QMap< QString, QString > QgsStringMap
void setBlurRadiusMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the shadow blur radius.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
A marker symbol type, for rendering Point and MultiPoint geometries.
void readXml(const QDomElement &elem)
Read settings from a DOM element.
static Qt::PenJoinStyle decodePenJoinStyle(const QString &str)
static QgsPaintEffectRegistry * paintEffectRegistry()
Returns the application's paint effect registry, used for managing paint effects. ...
ShapeType type() const
Returns the type of background shape (e.g., square, ellipse, SVG).
void setOffset(QPointF offset)
Sets the offset used for drawing the background shape.
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
QDomElement writeXml(QDomDocument &doc) const
Write settings into a DOM element.
bool isActive(int key) const override
Returns true if the collection contains an active property with the specified key.
Qt::PenJoinStyle joinStyle() const
Returns the buffer join style.
static QString encodeColor(const QColor &color)
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the buffer size.
static QgsTextFormat fromMimeData(const QMimeData *data, bool *ok=nullptr)
Attempts to parse the provided mime data as a QgsTextFormat.
void readFromLayer(QgsVectorLayer *layer)
Reads settings from a layer's custom properties (for QGIS 2.x projects).
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
static QSizeF toSize(const QVariant &value, bool *ok=nullptr)
Converts a value to a size.
QVariant value(int key, const QgsExpressionContext &context, const QVariant &defaultValue=QVariant()) const override
Returns the calculated value of the property with the specified key from within the collection...
Perform transforms between map coordinates and device coordinates.
void readFromLayer(QgsVectorLayer *layer)
Reads settings from a layer's custom properties (for QGIS 2.x projects).
static QString svgSymbolPathToName(const QString &path, const QgsPathResolver &pathResolver)
Determines an SVG symbol's name from its path.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the background shape.
void updateDataDefinedProperties(QgsRenderContext &context, const QgsPropertyCollection &properties)
Updates the format by evaluating current values of data defined properties.
Shape rotation is a fixed angle.
static QString encodeTextOrientation(QgsTextFormat::TextOrientation orientation)
Encodes a text orientation.
QgsMapUnitScale offsetMapUnitScale() const
Returns the map unit scale object for the shadow offset distance.
QPainter::CompositionMode blendMode() const
Returns the blending mode used for drawing the text.
void setUseAdvancedEffects(bool enabled)
Used to enable or disable advanced effects such as blend modes.
QColor color() const
Returns the color of the drop shadow.
void setSize(double size)
Sets the size for rendered text.
void setOffsetDistance(double distance)
Sets the distance for offsetting the position of the shadow from the text.
void setScaleFactor(double factor)
Sets the scaling factor for the render to convert painter units to physical sizes.
static QgsTextFormat::TextOrientation decodeTextOrientation(const QString &name, bool *ok=nullptr)
Attempts to decode a string representation of a text orientation.
Text within rectangle draw mode.
QColor previewBackgroundColor() const
Returns the background color for text previews.
QgsMapUnitScale blurRadiusMapUnitScale() const
Returns the map unit scale object for the shadow blur radius.
bool fillBufferInterior() const
Returns whether the interior of the buffer will be filled in.
TextOrientation orientation() const
Returns the orientation of the text.
static bool fontFamilyOnSystem(const QString &family)
Check whether font family is on system in a quick manner, which does not compare [foundry].
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the shape offset.
~QgsTextBackgroundSettings()
QDomElement writeXml(QDomDocument &doc, const QgsReadWriteContext &context) const
Write settings into a DOM element.
void setBlurAlphaOnly(bool alphaOnly)
Sets whether only the alpha channel for the shadow should be blurred.
RotationType rotationType() const
Returns the method used for rotating the background shape.
void setSizeMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the buffer size.
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the background shape.
Always render text using path objects (AKA outlines/curves).
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the drop shadow.
Vertically oriented text.
static QPixmap textFormatPreviewPixmap(const QgsTextFormat &format, QSize size, const QString &previewText=QString(), int padding=0)
Returns a pixmap preview for a text format.
void setColor(const QColor &color)
Sets the color for the drop shadow.
static QgsSymbolLayer * create(const QgsStringMap &properties=QgsStringMap())
void setEnabled(bool enabled)
Sets whether the text shadow will be drawn.
void setEnabled(bool enabled)
Sets whether the text buffer will be drawn.
void setColor(const QColor &color)
Sets the color that text will be rendered in.
QgsMapUnitScale radiiMapUnitScale() const
Returns the map unit scale object for the shape radii.
QString svgFile() const
Returns the absolute path to the background SVG file, if set.
Qt::PenJoinStyle joinStyle() const
Returns the join style used for drawing the background shape.
void setNamedStyle(const QString &style)
Sets the named style for the font used for rendering text.
QList< QgsSymbolLayer * > QgsSymbolLayerList
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
QgsTextBackgroundSettings & background()
Returns a reference to the text background settings.
QDomElement writeXml(QDomDocument &doc) const
Write settings into a DOM element.
QgsTextBufferSettings & buffer()
Returns a reference to the text buffer settings.
void setSizeUnit(QgsUnitTypes::RenderUnit unit)
Sets the units for the size of rendered text.
SizeType
Methods for determining the background shape size.
QgsTextBackgroundSettings()
double opacity() const
Returns the buffer opacity.
static QPainter::CompositionMode decodeBlendMode(const QString &s)
void updateDataDefinedProperties(QgsRenderContext &context)
Updates the format by evaluating current values of data defined properties.
bool enabled() const
Returns whether the effect is enabled.
Q_GUI_EXPORT int qt_defaultDpiY()
static QgsTextShadowSettings::ShadowPlacement decodeShadowPlacementType(const QString &string)
Decodes a string representation of a shadow placement type to a type.
void setSize(QSizeF size)
Sets the size of the background shape.
static Q_INVOKABLE QgsUnitTypes::RenderUnit decodeRenderUnit(const QString &string, bool *ok=nullptr)
Decodes a render unit from a string.
QMimeData * toMimeData() const
Returns new mime data representing the text format settings.
void setRadii(QSizeF radii)
Sets the radii used for rounding the corners of shapes.
static QFontMetricsF fontMetrics(QgsRenderContext &context, const QgsTextFormat &format)
Returns the font metrics for the given text format, when rendered in the specified render context...
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the format's property collection, used for data defined overrides.
QgsUnitTypes::RenderUnit strokeWidthUnit() const
Returns the units used for the shape's stroke width.
void setSizeType(SizeType type)
Sets the method used to determine the size of the background shape (e.g., fixed size or buffer around...
void renderPoint(QPointF point, QgsSymbolRenderContext &context) override
Renders a marker at the specified point.
void setType(ShapeType type)
Sets the type of background shape to draw (e.g., square, ellipse, SVG).
Draw shadow below all text components.
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
QPainter::CompositionMode blendMode() const
Returns the blending mode used for drawing the background shape.
static void drawText(const QRectF &rect, double rotation, HAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, bool drawAsOutlines=true)
Draws text within a rectangle using the specified settings.
QgsExpressionContext & expressionContext()
Gets the expression context.
QgsUnitTypes::RenderUnit offsetUnit() const
Returns the units used for the shape's offset.
void setParameters(double mapUnitsPerPixel, double centerX, double centerY, int widthPixels, int heightPixels, double rotation)
Set parameters for use in transforming coordinates.
double rotation() const
Returns the rotation for the background shape, in degrees clockwise.
double lineHeight() const
Returns the line height for text.
void setEnabled(bool enabled)
Sets whether the text background will be drawn.
int offsetAngle() const
Returns the angle for offsetting the position of the shadow from the text.
ShapeType
Background shape types.
bool valueAsBool(int key, const QgsExpressionContext &context, bool defaultValue=false, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as an boolean...
TextPart
Components of text.
void updateDataDefinedProperties(QgsRenderContext &context, const QgsPropertyCollection &properties)
Updates the format by evaluating current values of data defined properties.
static QString untranslateNamedStyle(const QString &namedStyle)
Returns the english named style of a font, if possible.
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
QFont scaledFont(const QgsRenderContext &context) const
Returns a font with the size scaled to match the format's size settings (including units and map unit...
Contains information about the context of a rendering operation.
Shape rotation is offset from text rotation.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
static bool fontFamilyMatchOnSystem(const QString &family, QString *chosen=nullptr, bool *match=nullptr)
Check whether font family is on system.
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the size.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units for the buffer size.
QPainter * painter()
Returns the destination QPainter for the render operation.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
static void blurImageInPlace(QImage &image, QRect rect, int radius, bool alphaOnly)
Blurs an image in place, e.g. creating Qt-independent drop shadows.
Points (e.g., for font sizes)
QgsUnitTypes::RenderUnit offsetUnit() const
Returns the units used for the shadow's offset.
bool enabled() const
Returns whether the shadow is enabled.
void updateDataDefinedProperties(QgsRenderContext &context, const QgsPropertyCollection &properties)
Updates the format by evaluating current values of data defined properties.
QgsTextBackgroundSettings & operator=(const QgsTextBackgroundSettings &other)
Struct for storing maximum and minimum scales for measurements in map units.
QgsTextFormat & operator=(const QgsTextFormat &other)
Container for settings relating to a text shadow.
bool offsetGlobal() const
Returns true if the global shadow offset will be used.
QColor color() const
Returns the color of the buffer.
double size() const
Returns the size of the buffer.
QgsUnitTypes::RenderUnit radiiUnit() const
Returns the units used for the shape's radii.
Container for settings relating to a text buffer.
void setFillColor(const QColor &color)
Sets the color used for filing the background shape.
static bool updateFontViaStyle(QFont &f, const QString &fontstyle, bool fallback=false)
Updates font with named style and retain all font properties.
bool useAdvancedEffects() const
Returns true if advanced effects such as blend modes such be used.
double size() const
Returns the size for rendered text.
void setStrokeWidthUnit(QgsUnitTypes::RenderUnit units)
Sets the units used for the shape's stroke width.
bool enabled() const
Returns whether the background is enabled.
void setMapToPixel(const QgsMapToPixel &mtp)
Sets the context's map to pixel transform, which transforms between map coordinates and device coordi...
static QStringList splitToGraphemes(const QString &text)
Splits a text string to a list of graphemes, which are the smallest allowable character divisions in ...
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the format's property collection, used for data defined overrides.
SizeType sizeType() const
Returns the method used to determine the size of the background shape (e.g., fixed size or buffer aro...
QgsUnitTypes::RenderUnit blurRadiusUnit() const
Returns the units used for the shadow's blur radius.
bool enabled() const
Returns whether the buffer is enabled.
int scale() const
Returns the scaling used for the drop shadow (in percentage of original size).
Shape rotation is synced with text rotation.
QgsFeature feature() const
Convenience function for retrieving the feature for the context, if set.
void setShadowPlacement(QgsTextShadowSettings::ShadowPlacement placement)
Sets the placement for the drop shadow.
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the text.
Q_GUI_EXPORT int qt_defaultDpiX()
static QgsMapUnitScale decodeMapUnitScale(const QString &str)
Draw shadow under background shape.
bool hasActiveProperties() const override
Returns true if the collection has any active properties, or false if all properties within the colle...
QgsPaintEffect * paintEffect() const
Returns the current paint effect for the buffer.
QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
QgsMapUnitScale sizeMapUnitScale() const
Returns the map unit scale object for the shape size.
static QString svgSymbolNameToPath(const QString &name, const QgsPathResolver &pathResolver)
Determines an SVG symbol's path from its name.
Container for all settings relating to text rendering.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units for the size of rendered text.
QgsPaintEffect * createEffect(const QString &name, const QgsStringMap &properties=QgsStringMap()) const
Creates a new paint effect given the effect name and properties map.
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the buffer.
void setSvgFile(const QString &file)
Sets the path to the background SVG file.
static double textWidth(const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, QFontMetricsF *fontMetrics=nullptr)
Returns the width of a text based on a given format.
bool blurAlphaOnly() const
Returns whether only the alpha channel for the shadow will be blurred.
void setOffsetGlobal(bool global)
Sets whether the global shadow offset should be used.
DrawMode
Draw mode to calculate width and height.
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
Represents a vector layer which manages a vector based data sets.
void setOpacity(double opacity)
Sets the buffer opacity.
Square - buffered sizes only.
int valueAsInt(int key, const QgsExpressionContext &context, int defaultValue=0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as an integer...
void setOriginalValueVariable(const QVariant &value)
Sets the original value variable value for the context.
void readFromLayer(QgsVectorLayer *layer)
Reads settings from a layer's custom properties (for QGIS 2.x projects).
virtual void end(QgsRenderContext &context)
Ends interception of paint operations to a render context, and draws the result to the render context...
bool containsAdvancedEffects() const
Returns true if any component of the font format requires advanced effects such as blend modes...
QString namedStyle() const
Returns the named style for the font used for rendering text (e.g., "bold").
QFont font() const
Returns the font used for rendering text.
void setRotationType(RotationType type)
Sets the method used for rotating the background shape.
void setColor(const QColor &color)
Sets the color for the buffer.
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the units used for the shape's size.
virtual void begin(QgsRenderContext &context)
Begins intercepting paint operations to a render context.
double opacity() const
Returns the shadow's opacity.
QgsMarkerSymbol * clone() const override
Returns a deep copy of this symbol.
void setOpacity(double opacity)
Sets the background shape's opacity.
RenderUnit
Rendering size units.
static QColor decodeColor(const QString &str)
QgsMarkerSymbol * markerSymbol() const
Returns the marker symbol to be rendered in the background.
void setPaintEffect(QgsPaintEffect *effect)
Sets the current paint effect for the background shape.
Horizontally oriented text.
void setOffsetAngle(int angle)
Sets the angle for offsetting the position of the shadow from the text.
static QgsTextBackgroundSettings::ShapeType decodeShapeType(const QString &string)
Decodes a string representation of a background shape type to a type.
static double textHeight(const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, DrawMode mode, QFontMetricsF *fontMetrics=nullptr)
Returns the height of a text based on a given format.
void readFromLayer(QgsVectorLayer *layer)
Reads settings from a layer's custom properties (for QGIS 2.x projects).
void setRotation(double rotation)
Sets the rotation for the background shape, in degrees clockwise.