28 #include <QFontDatabase> 47 static void _fixQPictureDPI( QPainter *p )
53 p->scale( static_cast< double >(
qt_defaultDpiX() ) / p->device()->logicalDpiX(),
54 static_cast< double >(
qt_defaultDpiY() ) / p->device()->logicalDpiY() );
57 static QColor _readColor(
QgsVectorLayer *layer,
const QString &property,
const QColor &defaultColor = Qt::black,
bool withAlpha =
true )
59 int r = layer->
customProperty( property +
'R', QVariant( defaultColor.red() ) ).toInt();
60 int g = layer->
customProperty( property +
'G', QVariant( defaultColor.green() ) ).toInt();
61 int b = layer->
customProperty( property +
'B', QVariant( defaultColor.blue() ) ).toInt();
62 int a = withAlpha ? layer->
customProperty( property +
'A', QVariant( defaultColor.alpha() ) ).toInt() : 255;
63 return QColor( r, g, b, a );
68 d =
new QgsTextBufferSettingsPrivate();
119 return d->sizeMapUnitScale;
124 d->sizeMapUnitScale = scale;
139 return d->fillBufferInterior;
144 d->fillBufferInterior = fill;
164 d->joinStyle = style;
179 return d->paintEffect;
184 delete d->paintEffect;
185 d->paintEffect = effect;
191 double bufSize = layer->
customProperty( QStringLiteral(
"labeling/bufferSize" ), QVariant( 0.0 ) ).toDouble();
194 QVariant drawBuffer = layer->
customProperty( QStringLiteral(
"labeling/bufferDraw" ), QVariant() );
195 if ( drawBuffer.isValid() )
197 d->enabled = drawBuffer.toBool();
200 else if ( bufSize != 0.0 )
211 if ( layer->
customProperty( QStringLiteral(
"labeling/bufferSizeUnits" ) ).toString().isEmpty() )
213 bool bufferSizeInMapUnits = layer->
customProperty( QStringLiteral(
"labeling/bufferSizeInMapUnits" ) ).toBool();
221 if ( layer->
customProperty( QStringLiteral(
"labeling/bufferSizeMapUnitScale" ) ).toString().isEmpty() )
224 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/bufferSizeMapUnitMinScale" ), 0.0 ).toDouble();
225 d->sizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
226 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/bufferSizeMapUnitMaxScale" ), 0.0 ).toDouble();
227 d->sizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
233 d->color = _readColor( layer, QStringLiteral(
"labeling/bufferColor" ), Qt::white,
false );
234 if ( layer->
customProperty( QStringLiteral(
"labeling/bufferOpacity" ) ).toString().isEmpty() )
236 d->opacity = ( 1 - layer->
customProperty( QStringLiteral(
"labeling/bufferTransp" ) ).toInt() / 100.0 );
240 d->opacity = ( layer->
customProperty( QStringLiteral(
"labeling/bufferOpacity" ) ).toDouble() );
244 d->joinStyle =
static_cast< Qt::PenJoinStyle
>( layer->
customProperty( QStringLiteral(
"labeling/bufferJoinStyle" ), QVariant( Qt::RoundJoin ) ).toUInt() );
246 d->fillBufferInterior = !layer->
customProperty( QStringLiteral(
"labeling/bufferNoFill" ), QVariant(
false ) ).toBool();
248 if ( layer->
customProperty( QStringLiteral(
"labeling/bufferEffect" ) ).isValid() )
250 QDomDocument doc( QStringLiteral(
"effect" ) );
251 doc.setContent( layer->
customProperty( QStringLiteral(
"labeling/bufferEffect" ) ).toString() );
252 QDomElement effectElem = doc.firstChildElement( QStringLiteral(
"effect" ) ).firstChildElement( QStringLiteral(
"effect" ) );
261 QDomElement textBufferElem = elem.firstChildElement( QStringLiteral(
"text-buffer" ) );
262 double bufSize = textBufferElem.attribute( QStringLiteral(
"bufferSize" ), QStringLiteral(
"0" ) ).toDouble();
265 QVariant drawBuffer = textBufferElem.attribute( QStringLiteral(
"bufferDraw" ) );
266 if ( drawBuffer.isValid() )
268 d->enabled = drawBuffer.toBool();
271 else if ( bufSize != 0.0 )
282 if ( !textBufferElem.hasAttribute( QStringLiteral(
"bufferSizeUnits" ) ) )
284 bool bufferSizeInMapUnits = textBufferElem.attribute( QStringLiteral(
"bufferSizeInMapUnits" ) ).toInt();
292 if ( !textBufferElem.hasAttribute( QStringLiteral(
"bufferSizeMapUnitScale" ) ) )
295 double oldMin = textBufferElem.attribute( QStringLiteral(
"bufferSizeMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
296 d->sizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
297 double oldMax = textBufferElem.attribute( QStringLiteral(
"bufferSizeMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
298 d->sizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
306 if ( !textBufferElem.hasAttribute( QStringLiteral(
"bufferOpacity" ) ) )
308 d->opacity = ( 1 - textBufferElem.attribute( QStringLiteral(
"bufferTransp" ) ).toInt() / 100.0 );
312 d->opacity = ( textBufferElem.attribute( QStringLiteral(
"bufferOpacity" ) ).toDouble() );
316 static_cast< QgsPainting::BlendMode >( textBufferElem.attribute( QStringLiteral(
"bufferBlendMode" ), QString::number(
QgsPainting::BlendNormal ) ).toUInt() ) );
317 d->joinStyle =
static_cast< Qt::PenJoinStyle
>( textBufferElem.attribute( QStringLiteral(
"bufferJoinStyle" ), QString::number( Qt::RoundJoin ) ).toUInt() );
318 d->fillBufferInterior = !textBufferElem.attribute( QStringLiteral(
"bufferNoFill" ), QStringLiteral(
"0" ) ).toInt();
319 QDomElement effectElem = textBufferElem.firstChildElement( QStringLiteral(
"effect" ) );
320 if ( !effectElem.isNull() )
329 QDomElement textBufferElem = doc.createElement( QStringLiteral(
"text-buffer" ) );
330 textBufferElem.setAttribute( QStringLiteral(
"bufferDraw" ), d->enabled );
331 textBufferElem.setAttribute( QStringLiteral(
"bufferSize" ), d->size );
335 textBufferElem.setAttribute( QStringLiteral(
"bufferNoFill" ), !d->fillBufferInterior );
336 textBufferElem.setAttribute( QStringLiteral(
"bufferOpacity" ), d->opacity );
337 textBufferElem.setAttribute( QStringLiteral(
"bufferJoinStyle" ), static_cast< unsigned int >( d->joinStyle ) );
340 d->paintEffect->saveProperties( doc, textBufferElem );
341 return textBufferElem;
351 d =
new QgsTextBackgroundSettingsPrivate();
433 return d->sizeMapUnitScale;
438 d->sizeMapUnitScale = scale;
443 return d->rotationType;
448 d->rotationType =
type;
473 return d->offsetUnits;
478 d->offsetUnits = units;
483 return d->offsetMapUnitScale;
488 d->offsetMapUnitScale = scale;
503 return d->radiiUnits;
508 d->radiiUnits = units;
513 return d->radiiMapUnitScale;
518 d->radiiMapUnitScale = scale;
548 d->fillColor = color;
553 return d->strokeColor;
558 d->strokeColor = color;
563 return d->strokeWidth;
568 d->strokeWidth = width;
573 return d->strokeWidthUnits;
578 d->strokeWidthUnits = units;
583 return d->strokeWidthMapUnitScale;
588 d->strokeWidthMapUnitScale = scale;
598 d->joinStyle = style;
603 return d->paintEffect;
608 delete d->paintEffect;
609 d->paintEffect = effect;
614 d->enabled = layer->
customProperty( QStringLiteral(
"labeling/shapeDraw" ), QVariant(
false ) ).toBool();
616 d->svgFile = layer->
customProperty( QStringLiteral(
"labeling/shapeSVGFile" ), QVariant(
"" ) ).toString();
618 d->size = QSizeF( layer->
customProperty( QStringLiteral(
"labeling/shapeSizeX" ), QVariant( 0.0 ) ).toDouble(),
619 layer->
customProperty( QStringLiteral(
"labeling/shapeSizeY" ), QVariant( 0.0 ) ).toDouble() );
621 if ( layer->
customProperty( QStringLiteral(
"labeling/shapeSizeUnit" ) ).toString().isEmpty() )
630 if ( layer->
customProperty( QStringLiteral(
"labeling/shapeSizeMapUnitScale" ) ).toString().isEmpty() )
633 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/shapeSizeMapUnitMinScale" ), 0.0 ).toDouble();
634 d->sizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
635 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/shapeSizeMapUnitMaxScale" ), 0.0 ).toDouble();
636 d->sizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
643 d->rotation = layer->
customProperty( QStringLiteral(
"labeling/shapeRotation" ), QVariant( 0.0 ) ).toDouble();
644 d->offset = QPointF( layer->
customProperty( QStringLiteral(
"labeling/shapeOffsetX" ), QVariant( 0.0 ) ).toDouble(),
645 layer->
customProperty( QStringLiteral(
"labeling/shapeOffsetY" ), QVariant( 0.0 ) ).toDouble() );
647 if ( layer->
customProperty( QStringLiteral(
"labeling/shapeOffsetUnit" ) ).toString().isEmpty() )
656 if ( layer->
customProperty( QStringLiteral(
"labeling/shapeOffsetMapUnitScale" ) ).toString().isEmpty() )
659 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/shapeOffsetMapUnitMinScale" ), 0.0 ).toDouble();
660 d->offsetMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
661 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/shapeOffsetMapUnitMaxScale" ), 0.0 ).toDouble();
662 d->offsetMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
668 d->radii = QSizeF( layer->
customProperty( QStringLiteral(
"labeling/shapeRadiiX" ), QVariant( 0.0 ) ).toDouble(),
669 layer->
customProperty( QStringLiteral(
"labeling/shapeRadiiY" ), QVariant( 0.0 ) ).toDouble() );
672 if ( layer->
customProperty( QStringLiteral(
"labeling/shapeRadiiUnit" ) ).toString().isEmpty() )
681 if ( layer->
customProperty( QStringLiteral(
"labeling/shapeRadiiMapUnitScale" ) ).toString().isEmpty() )
684 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/shapeRadiiMapUnitMinScale" ), 0.0 ).toDouble();
685 d->radiiMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
686 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/shapeRadiiMapUnitMaxScale" ), 0.0 ).toDouble();
687 d->radiiMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
693 d->fillColor = _readColor( layer, QStringLiteral(
"labeling/shapeFillColor" ), Qt::white,
true );
694 d->strokeColor = _readColor( layer, QStringLiteral(
"labeling/shapeBorderColor" ), Qt::darkGray,
true );
695 d->strokeWidth = layer->
customProperty( QStringLiteral(
"labeling/shapeBorderWidth" ), QVariant( .0 ) ).toDouble();
696 if ( layer->
customProperty( QStringLiteral(
"labeling/shapeBorderWidthUnit" ) ).toString().isEmpty() )
704 if ( layer->
customProperty( QStringLiteral(
"labeling/shapeBorderWidthMapUnitScale" ) ).toString().isEmpty() )
707 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/shapeBorderWidthMapUnitMinScale" ), 0.0 ).toDouble();
708 d->strokeWidthMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
709 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/shapeBorderWidthMapUnitMaxScale" ), 0.0 ).toDouble();
710 d->strokeWidthMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
716 d->joinStyle =
static_cast< Qt::PenJoinStyle
>( layer->
customProperty( QStringLiteral(
"labeling/shapeJoinStyle" ), QVariant( Qt::BevelJoin ) ).toUInt() );
718 if ( layer->
customProperty( QStringLiteral(
"labeling/shapeOpacity" ) ).toString().isEmpty() )
720 d->opacity = ( 1 - layer->
customProperty( QStringLiteral(
"labeling/shapeTransparency" ) ).toInt() / 100.0 );
724 d->opacity = ( layer->
customProperty( QStringLiteral(
"labeling/shapeOpacity" ) ).toDouble() );
729 if ( layer->
customProperty( QStringLiteral(
"labeling/shapeEffect" ) ).isValid() )
731 QDomDocument doc( QStringLiteral(
"effect" ) );
732 doc.setContent( layer->
customProperty( QStringLiteral(
"labeling/shapeEffect" ) ).toString() );
733 QDomElement effectElem = doc.firstChildElement( QStringLiteral(
"effect" ) ).firstChildElement( QStringLiteral(
"effect" ) );
742 QDomElement backgroundElem = elem.firstChildElement( QStringLiteral(
"background" ) );
743 d->enabled = backgroundElem.attribute( QStringLiteral(
"shapeDraw" ), QStringLiteral(
"0" ) ).toInt();
744 d->type =
static_cast< ShapeType >( backgroundElem.attribute( QStringLiteral(
"shapeType" ), QString::number(
ShapeRectangle ) ).toUInt() );
746 d->sizeType =
static_cast< SizeType >( backgroundElem.attribute( QStringLiteral(
"shapeSizeType" ), QString::number(
SizeBuffer ) ).toUInt() );
747 d->size = QSizeF( backgroundElem.attribute( QStringLiteral(
"shapeSizeX" ), QStringLiteral(
"0" ) ).toDouble(),
748 backgroundElem.attribute( QStringLiteral(
"shapeSizeY" ), QStringLiteral(
"0" ) ).toDouble() );
750 if ( !backgroundElem.hasAttribute( QStringLiteral(
"shapeSizeUnit" ) ) )
752 d->sizeUnits =
convertFromOldLabelUnit( backgroundElem.attribute( QStringLiteral(
"shapeSizeUnits" ) ).toUInt() );
759 if ( !backgroundElem.hasAttribute( QStringLiteral(
"shapeSizeMapUnitScale" ) ) )
762 double oldMin = backgroundElem.attribute( QStringLiteral(
"shapeSizeMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
763 d->sizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
764 double oldMax = backgroundElem.attribute( QStringLiteral(
"shapeSizeMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
765 d->sizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
771 d->rotationType =
static_cast< RotationType >( backgroundElem.attribute( QStringLiteral(
"shapeRotationType" ), QString::number(
RotationSync ) ).toUInt() );
772 d->rotation = backgroundElem.attribute( QStringLiteral(
"shapeRotation" ), QStringLiteral(
"0" ) ).toDouble();
773 d->offset = QPointF( backgroundElem.attribute( QStringLiteral(
"shapeOffsetX" ), QStringLiteral(
"0" ) ).toDouble(),
774 backgroundElem.attribute( QStringLiteral(
"shapeOffsetY" ), QStringLiteral(
"0" ) ).toDouble() );
776 if ( !backgroundElem.hasAttribute( QStringLiteral(
"shapeOffsetUnit" ) ) )
778 d->offsetUnits =
convertFromOldLabelUnit( backgroundElem.attribute( QStringLiteral(
"shapeOffsetUnits" ) ).toUInt() );
785 if ( !backgroundElem.hasAttribute( QStringLiteral(
"shapeOffsetMapUnitScale" ) ) )
788 double oldMin = backgroundElem.attribute( QStringLiteral(
"shapeOffsetMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
789 d->offsetMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
790 double oldMax = backgroundElem.attribute( QStringLiteral(
"shapeOffsetMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
791 d->offsetMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
797 d->radii = QSizeF( backgroundElem.attribute( QStringLiteral(
"shapeRadiiX" ), QStringLiteral(
"0" ) ).toDouble(),
798 backgroundElem.attribute( QStringLiteral(
"shapeRadiiY" ), QStringLiteral(
"0" ) ).toDouble() );
800 if ( !backgroundElem.hasAttribute( QStringLiteral(
"shapeRadiiUnit" ) ) )
802 d->radiiUnits =
convertFromOldLabelUnit( backgroundElem.attribute( QStringLiteral(
"shapeRadiiUnits" ) ).toUInt() );
808 if ( !backgroundElem.hasAttribute( QStringLiteral(
"shapeRadiiMapUnitScale" ) ) )
811 double oldMin = backgroundElem.attribute( QStringLiteral(
"shapeRadiiMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
812 d->radiiMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
813 double oldMax = backgroundElem.attribute( QStringLiteral(
"shapeRadiiMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
814 d->radiiMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
822 d->strokeWidth = backgroundElem.attribute( QStringLiteral(
"shapeBorderWidth" ), QStringLiteral(
"0" ) ).toDouble();
824 if ( !backgroundElem.hasAttribute( QStringLiteral(
"shapeBorderWidthUnit" ) ) )
826 d->strokeWidthUnits =
convertFromOldLabelUnit( backgroundElem.attribute( QStringLiteral(
"shapeBorderWidthUnits" ) ).toUInt() );
832 if ( !backgroundElem.hasAttribute( QStringLiteral(
"shapeBorderWidthMapUnitScale" ) ) )
835 double oldMin = backgroundElem.attribute( QStringLiteral(
"shapeBorderWidthMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
836 d->strokeWidthMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
837 double oldMax = backgroundElem.attribute( QStringLiteral(
"shapeBorderWidthMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
838 d->strokeWidthMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
844 d->joinStyle =
static_cast< Qt::PenJoinStyle
>( backgroundElem.attribute( QStringLiteral(
"shapeJoinStyle" ), QString::number( Qt::BevelJoin ) ).toUInt() );
846 if ( !backgroundElem.hasAttribute( QStringLiteral(
"shapeOpacity" ) ) )
848 d->opacity = ( 1 - backgroundElem.attribute( QStringLiteral(
"shapeTransparency" ) ).toInt() / 100.0 );
852 d->opacity = ( backgroundElem.attribute( QStringLiteral(
"shapeOpacity" ) ).toDouble() );
856 static_cast< QgsPainting::BlendMode >( backgroundElem.attribute( QStringLiteral(
"shapeBlendMode" ), QString::number(
QgsPainting::BlendNormal ) ).toUInt() ) );
858 QDomElement effectElem = backgroundElem.firstChildElement( QStringLiteral(
"effect" ) );
859 if ( !effectElem.isNull() )
867 QDomElement backgroundElem = doc.createElement( QStringLiteral(
"background" ) );
868 backgroundElem.setAttribute( QStringLiteral(
"shapeDraw" ), d->enabled );
869 backgroundElem.setAttribute( QStringLiteral(
"shapeType" ), static_cast< unsigned int >( d->type ) );
871 backgroundElem.setAttribute( QStringLiteral(
"shapeSizeType" ), static_cast< unsigned int >( d->sizeType ) );
872 backgroundElem.setAttribute( QStringLiteral(
"shapeSizeX" ), d->size.width() );
873 backgroundElem.setAttribute( QStringLiteral(
"shapeSizeY" ), d->size.height() );
876 backgroundElem.setAttribute( QStringLiteral(
"shapeRotationType" ), static_cast< unsigned int >( d->rotationType ) );
877 backgroundElem.setAttribute( QStringLiteral(
"shapeRotation" ), d->rotation );
878 backgroundElem.setAttribute( QStringLiteral(
"shapeOffsetX" ), d->offset.x() );
879 backgroundElem.setAttribute( QStringLiteral(
"shapeOffsetY" ), d->offset.y() );
882 backgroundElem.setAttribute( QStringLiteral(
"shapeRadiiX" ), d->radii.width() );
883 backgroundElem.setAttribute( QStringLiteral(
"shapeRadiiY" ), d->radii.height() );
888 backgroundElem.setAttribute( QStringLiteral(
"shapeBorderWidth" ), d->strokeWidth );
889 backgroundElem.setAttribute( QStringLiteral(
"shapeBorderWidthUnit" ),
QgsUnitTypes::encodeUnit( d->strokeWidthUnits ) );
891 backgroundElem.setAttribute( QStringLiteral(
"shapeJoinStyle" ), static_cast< unsigned int >( d->joinStyle ) );
892 backgroundElem.setAttribute( QStringLiteral(
"shapeOpacity" ), d->opacity );
895 d->paintEffect->saveProperties( doc, backgroundElem );
896 return backgroundElem;
906 d =
new QgsTextShadowSettingsPrivate();
938 return d->shadowUnder;
943 d->shadowUnder = placement;
948 return d->offsetAngle;
953 d->offsetAngle =
angle;
958 return d->offsetDist;
963 d->offsetDist = distance;
968 return d->offsetUnits;
973 d->offsetUnits = units;
978 return d->offsetMapUnitScale;
983 d->offsetMapUnitScale =
scale;
988 return d->offsetGlobal;
993 d->offsetGlobal = global;
1008 return d->radiusUnits;
1013 d->radiusUnits = units;
1018 return d->radiusMapUnitScale;
1023 d->radiusMapUnitScale =
scale;
1028 return d->radiusAlphaOnly;
1033 d->radiusAlphaOnly = alphaOnly;
1068 return d->blendMode;
1073 d->blendMode = mode;
1078 d->enabled = layer->
customProperty( QStringLiteral(
"labeling/shadowDraw" ), QVariant(
false ) ).toBool();
1080 d->offsetAngle = layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetAngle" ), QVariant( 135 ) ).toInt();
1081 d->offsetDist = layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetDist" ), QVariant( 1.0 ) ).toDouble();
1083 if ( layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetUnit" ) ).toString().isEmpty() )
1091 if ( layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetMapUnitScale" ) ).toString().isEmpty() )
1094 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetMapUnitMinScale" ), 0.0 ).toDouble();
1095 d->offsetMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
1096 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetMapUnitMaxScale" ), 0.0 ).toDouble();
1097 d->offsetMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
1103 d->offsetGlobal = layer->
customProperty( QStringLiteral(
"labeling/shadowOffsetGlobal" ), QVariant(
true ) ).toBool();
1104 d->radius = layer->
customProperty( QStringLiteral(
"labeling/shadowRadius" ), QVariant( 1.5 ) ).toDouble();
1106 if ( layer->
customProperty( QStringLiteral(
"labeling/shadowRadiusUnit" ) ).toString().isEmpty() )
1114 if ( layer->
customProperty( QStringLiteral(
"labeling/shadowRadiusMapUnitScale" ) ).toString().isEmpty() )
1117 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/shadowRadiusMapUnitMinScale" ), 0.0 ).toDouble();
1118 d->radiusMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
1119 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/shadowRadiusMapUnitMaxScale" ), 0.0 ).toDouble();
1120 d->radiusMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
1126 d->radiusAlphaOnly = layer->
customProperty( QStringLiteral(
"labeling/shadowRadiusAlphaOnly" ), QVariant(
false ) ).toBool();
1128 if ( layer->
customProperty( QStringLiteral(
"labeling/shadowOpacity" ) ).toString().isEmpty() )
1130 d->opacity = ( 1 - layer->
customProperty( QStringLiteral(
"labeling/shadowTransparency" ) ).toInt() / 100.0 );
1134 d->opacity = ( layer->
customProperty( QStringLiteral(
"labeling/shadowOpacity" ) ).toDouble() );
1136 d->scale = layer->
customProperty( QStringLiteral(
"labeling/shadowScale" ), QVariant( 100 ) ).toInt();
1137 d->color = _readColor( layer, QStringLiteral(
"labeling/shadowColor" ), Qt::black,
false );
1144 QDomElement shadowElem = elem.firstChildElement( QStringLiteral(
"shadow" ) );
1145 d->enabled = shadowElem.attribute( QStringLiteral(
"shadowDraw" ), QStringLiteral(
"0" ) ).toInt();
1146 d->shadowUnder =
static_cast< ShadowPlacement >( shadowElem.attribute( QStringLiteral(
"shadowUnder" ), QString::number(
ShadowLowest ) ).toUInt() );
1147 d->offsetAngle = shadowElem.attribute( QStringLiteral(
"shadowOffsetAngle" ), QStringLiteral(
"135" ) ).toInt();
1148 d->offsetDist = shadowElem.attribute( QStringLiteral(
"shadowOffsetDist" ), QStringLiteral(
"1" ) ).toDouble();
1150 if ( !shadowElem.hasAttribute( QStringLiteral(
"shadowOffsetUnit" ) ) )
1152 d->offsetUnits =
convertFromOldLabelUnit( shadowElem.attribute( QStringLiteral(
"shadowOffsetUnits" ) ).toUInt() );
1159 if ( !shadowElem.hasAttribute( QStringLiteral(
"shadowOffsetMapUnitScale" ) ) )
1162 double oldMin = shadowElem.attribute( QStringLiteral(
"shadowOffsetMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
1163 d->offsetMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
1164 double oldMax = shadowElem.attribute( QStringLiteral(
"shadowOffsetMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
1165 d->offsetMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
1171 d->offsetGlobal = shadowElem.attribute( QStringLiteral(
"shadowOffsetGlobal" ), QStringLiteral(
"1" ) ).toInt();
1172 d->radius = shadowElem.attribute( QStringLiteral(
"shadowRadius" ), QStringLiteral(
"1.5" ) ).toDouble();
1174 if ( !shadowElem.hasAttribute( QStringLiteral(
"shadowRadiusUnit" ) ) )
1176 d->radiusUnits =
convertFromOldLabelUnit( shadowElem.attribute( QStringLiteral(
"shadowRadiusUnits" ) ).toUInt() );
1182 if ( !shadowElem.hasAttribute( QStringLiteral(
"shadowRadiusMapUnitScale" ) ) )
1185 double oldMin = shadowElem.attribute( QStringLiteral(
"shadowRadiusMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
1186 d->radiusMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
1187 double oldMax = shadowElem.attribute( QStringLiteral(
"shadowRadiusMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
1188 d->radiusMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
1194 d->radiusAlphaOnly = shadowElem.attribute( QStringLiteral(
"shadowRadiusAlphaOnly" ), QStringLiteral(
"0" ) ).toInt();
1196 if ( !shadowElem.hasAttribute( QStringLiteral(
"shadowOpacity" ) ) )
1198 d->opacity = ( 1 - shadowElem.attribute( QStringLiteral(
"shadowTransparency" ) ).toInt() / 100.0 );
1202 d->opacity = ( shadowElem.attribute( QStringLiteral(
"shadowOpacity" ) ).toDouble() );
1204 d->scale = shadowElem.attribute( QStringLiteral(
"shadowScale" ), QStringLiteral(
"100" ) ).toInt();
1207 static_cast< QgsPainting::BlendMode >( shadowElem.attribute( QStringLiteral(
"shadowBlendMode" ), QString::number(
QgsPainting::BlendMultiply ) ).toUInt() ) );
1212 QDomElement shadowElem = doc.createElement( QStringLiteral(
"shadow" ) );
1213 shadowElem.setAttribute( QStringLiteral(
"shadowDraw" ), d->enabled );
1214 shadowElem.setAttribute( QStringLiteral(
"shadowUnder" ), static_cast< unsigned int >( d->shadowUnder ) );
1215 shadowElem.setAttribute( QStringLiteral(
"shadowOffsetAngle" ), d->offsetAngle );
1216 shadowElem.setAttribute( QStringLiteral(
"shadowOffsetDist" ), d->offsetDist );
1219 shadowElem.setAttribute( QStringLiteral(
"shadowOffsetGlobal" ), d->offsetGlobal );
1220 shadowElem.setAttribute( QStringLiteral(
"shadowRadius" ), d->radius );
1223 shadowElem.setAttribute( QStringLiteral(
"shadowRadiusAlphaOnly" ), d->radiusAlphaOnly );
1224 shadowElem.setAttribute( QStringLiteral(
"shadowOpacity" ), d->opacity );
1225 shadowElem.setAttribute( QStringLiteral(
"shadowScale" ), d->scale );
1237 d =
new QgsTextSettingsPrivate();
1241 : mBufferSettings( other.mBufferSettings )
1242 , mBackgroundSettings( other.mBackgroundSettings )
1243 , mShadowSettings( other.mShadowSettings )
1244 , mTextFontFamily( other.mTextFontFamily )
1245 , mTextFontFound( other.mTextFontFound )
1254 mBufferSettings = other.mBufferSettings;
1255 mBackgroundSettings = other.mBackgroundSettings;
1256 mShadowSettings = other.mShadowSettings;
1257 mTextFontFamily = other.mTextFontFamily;
1258 mTextFontFound = other.mTextFontFound;
1274 QFont
font = d->textFont;
1276 d->fontSizeMapUnitScale );
1277 font.setPixelSize( fontPixelSize );
1288 if ( !d->textNamedStyle.isEmpty() )
1289 return d->textNamedStyle;
1292 return db.styleString( d->textFont );
1298 d->textNamedStyle = style;
1303 return d->fontSizeUnits;
1308 d->fontSizeUnits = unit;
1313 return d->fontSizeMapUnitScale;
1318 d->fontSizeMapUnitScale = scale;
1333 return d->textColor;
1338 d->textColor =
color;
1353 return d->blendMode;
1358 d->blendMode = mode;
1363 return d->multilineHeight;
1368 d->multilineHeight = height;
1373 QFont appFont = QApplication::font();
1374 mTextFontFamily = layer->
customProperty( QStringLiteral(
"labeling/fontFamily" ), QVariant( appFont.family() ) ).toString();
1375 QString fontFamily = mTextFontFamily;
1379 mTextFontFound =
false;
1385 fontFamily = appFont.family();
1389 mTextFontFound =
true;
1392 if ( !layer->
customProperty( QStringLiteral(
"labeling/fontSize" ) ).isValid() )
1394 d->fontSize = appFont.pointSizeF();
1398 d->fontSize = layer->
customProperty( QStringLiteral(
"labeling/fontSize" ) ).toDouble();
1401 if ( layer->
customProperty( QStringLiteral(
"labeling/fontSizeUnit" ) ).toString().isEmpty() )
1403 d->fontSizeUnits = layer->
customProperty( QStringLiteral(
"labeling/fontSizeInMapUnits" ), QVariant(
false ) ).toBool() ?
1413 if ( layer->
customProperty( QStringLiteral(
"labeling/fontSizeMapUnitScale" ) ).toString().isEmpty() )
1416 double oldMin = layer->
customProperty( QStringLiteral(
"labeling/fontSizeMapUnitMinScale" ), 0.0 ).toDouble();
1417 d->fontSizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
1418 double oldMax = layer->
customProperty( QStringLiteral(
"labeling/fontSizeMapUnitMaxScale" ), 0.0 ).toDouble();
1419 d->fontSizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
1425 int fontWeight = layer->
customProperty( QStringLiteral(
"labeling/fontWeight" ) ).toInt();
1426 bool fontItalic = layer->
customProperty( QStringLiteral(
"labeling/fontItalic" ) ).toBool();
1427 d->textFont = QFont( fontFamily, d->fontSize, fontWeight, fontItalic );
1430 d->textFont.setCapitalization( static_cast< QFont::Capitalization >( layer->
customProperty( QStringLiteral(
"labeling/fontCapitals" ), QVariant( 0 ) ).toUInt() ) );
1431 d->textFont.setUnderline( layer->
customProperty( QStringLiteral(
"labeling/fontUnderline" ) ).toBool() );
1432 d->textFont.setStrikeOut( layer->
customProperty( QStringLiteral(
"labeling/fontStrikeout" ) ).toBool() );
1433 d->textFont.setLetterSpacing( QFont::AbsoluteSpacing, layer->
customProperty( QStringLiteral(
"labeling/fontLetterSpacing" ), QVariant( 0.0 ) ).toDouble() );
1434 d->textFont.setWordSpacing( layer->
customProperty( QStringLiteral(
"labeling/fontWordSpacing" ), QVariant( 0.0 ) ).toDouble() );
1435 d->textColor = _readColor( layer, QStringLiteral(
"labeling/textColor" ), Qt::black,
false );
1436 if ( layer->
customProperty( QStringLiteral(
"labeling/textOpacity" ) ).toString().isEmpty() )
1438 d->opacity = ( 1 - layer->
customProperty( QStringLiteral(
"labeling/textTransp" ) ).toInt() / 100.0 );
1442 d->opacity = ( layer->
customProperty( QStringLiteral(
"labeling/textOpacity" ) ).toDouble() );
1446 d->multilineHeight = layer->
customProperty( QStringLiteral(
"labeling/multilineHeight" ), QVariant( 1.0 ) ).toDouble();
1455 QDomElement textStyleElem;
1456 if ( elem.nodeName() == QStringLiteral(
"text-style" ) )
1457 textStyleElem = elem;
1459 textStyleElem = elem.firstChildElement( QStringLiteral(
"text-style" ) );
1460 QFont appFont = QApplication::font();
1461 mTextFontFamily = textStyleElem.attribute( QStringLiteral(
"fontFamily" ), appFont.family() );
1462 QString fontFamily = mTextFontFamily;
1466 mTextFontFound =
false;
1472 fontFamily = appFont.family();
1476 mTextFontFound =
true;
1479 if ( textStyleElem.hasAttribute( QStringLiteral(
"fontSize" ) ) )
1481 d->fontSize = textStyleElem.attribute( QStringLiteral(
"fontSize" ) ).toDouble();
1485 d->fontSize = appFont.pointSizeF();
1488 if ( !textStyleElem.hasAttribute( QStringLiteral(
"fontSizeUnit" ) ) )
1490 d->fontSizeUnits = textStyleElem.attribute( QStringLiteral(
"fontSizeInMapUnits" ) ).toUInt() == 0 ?
QgsUnitTypes::RenderPoints 1498 if ( !textStyleElem.hasAttribute( QStringLiteral(
"fontSizeMapUnitScale" ) ) )
1501 double oldMin = textStyleElem.attribute( QStringLiteral(
"fontSizeMapUnitMinScale" ), QStringLiteral(
"0" ) ).toDouble();
1502 d->fontSizeMapUnitScale.minScale = oldMin != 0 ? 1.0 / oldMin : 0;
1503 double oldMax = textStyleElem.attribute( QStringLiteral(
"fontSizeMapUnitMaxScale" ), QStringLiteral(
"0" ) ).toDouble();
1504 d->fontSizeMapUnitScale.maxScale = oldMax != 0 ? 1.0 / oldMax : 0;
1510 int fontWeight = textStyleElem.attribute( QStringLiteral(
"fontWeight" ) ).toInt();
1511 bool fontItalic = textStyleElem.attribute( QStringLiteral(
"fontItalic" ) ).toInt();
1512 d->textFont = QFont( fontFamily, d->fontSize, fontWeight, fontItalic );
1513 d->textFont.setPointSizeF( d->fontSize );
1516 d->textFont.setCapitalization( static_cast< QFont::Capitalization >( textStyleElem.attribute( QStringLiteral(
"fontCapitals" ), QStringLiteral(
"0" ) ).toUInt() ) );
1517 d->textFont.setUnderline( textStyleElem.attribute( QStringLiteral(
"fontUnderline" ) ).toInt() );
1518 d->textFont.setStrikeOut( textStyleElem.attribute( QStringLiteral(
"fontStrikeout" ) ).toInt() );
1519 d->textFont.setLetterSpacing( QFont::AbsoluteSpacing, textStyleElem.attribute( QStringLiteral(
"fontLetterSpacing" ), QStringLiteral(
"0" ) ).toDouble() );
1520 d->textFont.setWordSpacing( textStyleElem.attribute( QStringLiteral(
"fontWordSpacing" ), QStringLiteral(
"0" ) ).toDouble() );
1522 if ( !textStyleElem.hasAttribute( QStringLiteral(
"textOpacity" ) ) )
1524 d->opacity = ( 1 - textStyleElem.attribute( QStringLiteral(
"textTransp" ) ).toInt() / 100.0 );
1528 d->opacity = ( textStyleElem.attribute( QStringLiteral(
"textOpacity" ) ).toDouble() );
1531 static_cast< QgsPainting::BlendMode >( textStyleElem.attribute( QStringLiteral(
"blendMode" ), QString::number(
QgsPainting::BlendNormal ) ).toUInt() ) );
1533 if ( !textStyleElem.hasAttribute( QStringLiteral(
"multilineHeight" ) ) )
1535 QDomElement textFormatElem = elem.firstChildElement( QStringLiteral(
"text-format" ) );
1536 d->multilineHeight = textFormatElem.attribute( QStringLiteral(
"multilineHeight" ), QStringLiteral(
"1" ) ).toDouble();
1540 d->multilineHeight = textStyleElem.attribute( QStringLiteral(
"multilineHeight" ), QStringLiteral(
"1" ) ).toDouble();
1543 if ( textStyleElem.firstChildElement( QStringLiteral(
"text-buffer" ) ).isNull() )
1545 mBufferSettings.
readXml( elem );
1549 mBufferSettings.
readXml( textStyleElem );
1551 if ( textStyleElem.firstChildElement( QStringLiteral(
"shadow" ) ).isNull() )
1553 mShadowSettings.
readXml( elem );
1557 mShadowSettings.
readXml( textStyleElem );
1559 if ( textStyleElem.firstChildElement( QStringLiteral(
"background" ) ).isNull() )
1561 mBackgroundSettings.
readXml( elem, context );
1565 mBackgroundSettings.
readXml( textStyleElem, context );
1572 QDomElement textStyleElem = doc.createElement( QStringLiteral(
"text-style" ) );
1573 textStyleElem.setAttribute( QStringLiteral(
"fontFamily" ), d->textFont.family() );
1575 textStyleElem.setAttribute( QStringLiteral(
"fontSize" ), d->fontSize );
1578 textStyleElem.setAttribute( QStringLiteral(
"fontWeight" ), d->textFont.weight() );
1579 textStyleElem.setAttribute( QStringLiteral(
"fontItalic" ), d->textFont.italic() );
1580 textStyleElem.setAttribute( QStringLiteral(
"fontStrikeout" ), d->textFont.strikeOut() );
1581 textStyleElem.setAttribute( QStringLiteral(
"fontUnderline" ), d->textFont.underline() );
1583 textStyleElem.setAttribute( QStringLiteral(
"fontCapitals" ), static_cast< unsigned int >( d->textFont.capitalization() ) );
1584 textStyleElem.setAttribute( QStringLiteral(
"fontLetterSpacing" ), d->textFont.letterSpacing() );
1585 textStyleElem.setAttribute( QStringLiteral(
"fontWordSpacing" ), d->textFont.wordSpacing() );
1586 textStyleElem.setAttribute( QStringLiteral(
"textOpacity" ), d->opacity );
1588 textStyleElem.setAttribute( QStringLiteral(
"multilineHeight" ), d->multilineHeight );
1590 textStyleElem.appendChild( mBufferSettings.
writeXml( doc ) );
1591 textStyleElem.appendChild( mBackgroundSettings.
writeXml( doc, context ) );
1592 textStyleElem.appendChild( mShadowSettings.
writeXml( doc ) );
1593 return textStyleElem;
1599 QMimeData *mimeData =
new QMimeData;
1600 mimeData->setColorData( QVariant(
color() ) );
1603 QDomDocument textDoc;
1604 QDomElement textElem =
writeXml( textDoc, rwContext );
1605 textDoc.appendChild( textElem );
1606 mimeData->setText( textDoc.toString() );
1615 if ( font.pointSizeF() > 0 )
1617 format.
setSize( font.pointSizeF() );
1620 else if ( font.pixelSize() > 0 )
1622 format.
setSize( font.pixelSize() );
1635 f.setPointSizeF(
size() );
1639 f.setPointSizeF(
size() * 2.83464567 );
1643 f.setPointSizeF(
size() * 72 );
1647 f.setPixelSize( static_cast< int >( std::round(
size() ) ) );
1668 QString text = data->text();
1669 if ( !text.isEmpty() )
1675 if ( doc.setContent( text ) )
1677 elem = doc.documentElement();
1679 format.
readXml( elem, rwContext );
1690 if ( d->blendMode != QPainter::CompositionMode_SourceOver )
1693 if ( mBufferSettings.
enabled() && mBufferSettings.
blendMode() != QPainter::CompositionMode_SourceOver )
1696 if ( mBackgroundSettings.
enabled() && mBackgroundSettings.
blendMode() != QPainter::CompositionMode_SourceOver )
1699 if ( mShadowSettings.
enabled() && mShadowSettings.
blendMode() != QPainter::CompositionMode_SourceOver )
1717 drawPart( rect, rotation, alignment, textLines, context, tmpFormat, Background );
1722 drawPart( rect, rotation, alignment, textLines, context, tmpFormat, Buffer );
1725 drawPart( rect, rotation, alignment, textLines, context, tmpFormat, Text );
1734 drawPart( point, rotation, alignment, textLines, context, tmpFormat, Background );
1739 drawPart( point, rotation, alignment, textLines, context, tmpFormat, Buffer );
1742 drawPart( point, rotation, alignment, textLines, context, tmpFormat, Text );
1774 Component component;
1775 component.dpiRatio = 1.0;
1776 component.origin = rect.topLeft();
1777 component.rotation = rotation;
1778 component.size = rect.size();
1779 component.hAlign = alignment;
1792 double xc = rect.width() / 2.0;
1793 double yc = rect.height() / 2.0;
1795 double angle = -rotation;
1796 double xd = xc * std::cos( angle ) - yc * std::sin( angle );
1797 double yd = xc * std::sin( angle ) + yc * std::cos( angle );
1799 component.center = QPointF( component.origin.x() + xd, component.origin.y() + yd );
1803 component.center = rect.center();
1806 QgsTextRenderer::drawBackground( context, component, format, textLines, Rect );
1820 QFontMetricsF fm( format.
scaledFont( context ) );
1821 drawTextInternal( part, context, format, component,
1837 Component component;
1838 component.dpiRatio = 1.0;
1839 component.origin = origin;
1840 component.rotation = rotation;
1841 component.hAlign = alignment;
1850 QgsTextRenderer::drawBackground( context, component, format, textLines, Point );
1863 QFontMetricsF fm( format.
scaledFont( context ) );
1864 drawTextInternal( part, context, format, component,
1881 QPainter *p = context.
painter();
1888 path.setFillRule( Qt::WindingFill );
1889 path.addText( 0, 0, format.
scaledFont( context ), component.text );
1890 QColor bufferColor = buffer.
color();
1891 bufferColor.setAlphaF( buffer.
opacity() );
1892 QPen pen( bufferColor );
1893 pen.setWidthF( penSize );
1895 QColor tmpColor( bufferColor );
1899 tmpColor.setAlpha( 0 );
1905 buffp.begin( &buffPict );
1912 context.
painter()->setPen( pen );
1913 context.
painter()->setBrush( tmpColor );
1914 context.
painter()->drawPath( path );
1921 buffp.setPen( pen );
1922 buffp.setBrush( tmpColor );
1923 buffp.drawPath( path );
1929 QgsTextRenderer::Component bufferComponent = component;
1930 bufferComponent.origin = QPointF( 0.0, 0.0 );
1931 bufferComponent.picture = buffPict;
1932 bufferComponent.pictureBuffer = penSize / 2.0;
1933 drawShadow( context, bufferComponent, format );
1938 p->setCompositionMode( buffer.
blendMode() );
1942 p->setRenderHint( QPainter::Antialiasing );
1946 p->scale( component.dpiRatio, component.dpiRatio );
1947 _fixQPictureDPI( p );
1948 p->drawPicture( 0, 0, buffPict );
1955 std::unique_ptr< QFontMetricsF > newFm;
1958 newFm.reset(
new QFontMetricsF( format.
scaledFont( context ) ) );
1959 fontMetrics = newFm.get();
1962 double maxWidth = 0;
1963 const auto constTextLines = textLines;
1964 for (
const QString &line : constTextLines )
1966 maxWidth = std::max( maxWidth, fontMetrics->width( line ) );
1974 std::unique_ptr< QFontMetricsF > newFm;
1977 newFm.reset(
new QFontMetricsF( format.
scaledFont( context ) ) );
1978 fontMetrics = newFm.get();
1981 double labelHeight = fontMetrics->ascent() + fontMetrics->descent();
1989 return labelHeight + ( textLines.size() - 1 ) * labelHeight * format.
lineHeight();
1994 return labelHeight + ( textLines.size() - 1 ) * fontMetrics->lineSpacing() * format.
lineHeight();
2001 const QStringList &textLines,
DrawMode mode )
2005 QPainter *prevP = context.
painter();
2006 QPainter *p = context.
painter();
2020 component.rotation = -( component.rotation * 180 / M_PI );
2021 component.rotationOffset =
2026 component.rotation = 0.0;
2027 component.rotationOffset = background.
rotation();
2030 if ( mode != Label )
2033 QFontMetricsF fm( format.
scaledFont( context ) );
2034 double width = textWidth( context, format, textLines, &fm );
2035 double height = textHeight( context, format, textLines, mode, &fm );
2040 switch ( component.hAlign )
2043 component.center = QPointF( component.origin.x() + width / 2.0,
2044 component.origin.y() + height / 2.0 );
2048 component.center = QPointF( component.origin.x() + component.size.width() / 2.0,
2049 component.origin.y() + height / 2.0 );
2053 component.center = QPointF( component.origin.x() + component.size.width() - width / 2.0,
2054 component.origin.y() + height / 2.0 );
2061 double originAdjust = fm.ascent() / 2.0 - fm.leading() / 2.0;
2062 switch ( component.hAlign )
2065 component.center = QPointF( component.origin.x() + width / 2.0,
2066 component.origin.y() - height / 2.0 + originAdjust );
2070 component.center = QPointF( component.origin.x(),
2071 component.origin.y() - height / 2.0 + originAdjust );
2075 component.center = QPointF( component.origin.x() - width / 2.0,
2076 component.origin.y() - height / 2.0 + originAdjust );
2087 component.size = QSizeF( width, height );
2096 if ( background.
svgFile().isEmpty() )
2099 double sizeOut = 0.0;
2107 sizeOut = std::max( component.size.width(), component.size.height() );
2111 sizeOut += bufferSize * 2;
2116 if ( sizeOut < 1.0 )
2120 map[QStringLiteral(
"name" )] = background.
svgFile().trimmed();
2121 map[QStringLiteral(
"size" )] = QString::number( sizeOut );
2123 map[QStringLiteral(
"angle" )] = QString::number( 0.0 );
2131 map[QStringLiteral(
"fill" )] = background.
fillColor().name();
2132 map[QStringLiteral(
"outline" )] = background.
strokeColor().name();
2133 map[QStringLiteral(
"outline-width" )] = QString::number( background.
strokeWidth() );
2141 shdwmap[QStringLiteral(
"fill" )] = shadow.
color().name();
2142 shdwmap[QStringLiteral(
"outline" )] = shadow.
color().name();
2143 shdwmap[QStringLiteral(
"size" )] = QString::number( sizeOut );
2148 svgp.begin( &svgPict );
2165 svgShdwM->
renderPoint( QPointF( sizeOut / 2, -sizeOut / 2 ), svgShdwContext );
2168 component.picture = svgPict;
2170 component.pictureBuffer = 0.0;
2172 component.size = QSizeF( sizeOut, sizeOut );
2173 component.offset = QPointF( 0.0, 0.0 );
2177 p->translate( component.center.x(), component.center.y() );
2178 p->rotate( component.rotation );
2181 p->translate( QPointF( xoff, yoff ) );
2182 p->rotate( component.rotationOffset );
2183 p->translate( -sizeOut / 2, sizeOut / 2 );
2186 p->setRenderHint( QPainter::Antialiasing );
2189 drawShadow( context, component, format );
2204 p->setCompositionMode( background.
blendMode() );
2208 p->setRenderHint( QPainter::Antialiasing );
2210 p->translate( component.center.x(), component.center.y() );
2211 p->rotate( component.rotation );
2214 p->translate( QPointF( xoff, yoff ) );
2215 p->rotate( component.rotationOffset );
2217 p->setCompositionMode( QPainter::CompositionMode_SourceOver );
2226 double w = component.
size.width();
2227 double h = component.size.height();
2248 h = std::sqrt( std::pow( w, 2 ) + std::pow( h, 2 ) );
2254 h = h * M_SQRT1_2 * 2;
2255 w = w * M_SQRT1_2 * 2;
2263 w += bufferWidth * 2;
2264 h += bufferHeight * 2;
2268 QRectF rect( -w / 2.0, - h / 2.0, w, h );
2270 if ( rect.isNull() )
2276 p->setRenderHint( QPainter::Antialiasing );
2278 p->translate( QPointF( component.center.x(), component.center.y() ) );
2279 p->rotate( component.rotation );
2282 p->translate( QPointF( xoff, yoff ) );
2283 p->rotate( component.rotationOffset );
2291 pen.setWidthF( penSize );
2293 pen.setJoinStyle( background.
joinStyle() );
2303 shapep.begin( &shapePict );
2304 shapep.setPen( pen );
2305 shapep.setBrush( background.
fillColor() );
2312 shapep.drawRoundedRect( rect, background.
radii().width(), background.
radii().height(), Qt::RelativeSize );
2318 shapep.drawRoundedRect( rect, xRadius, yRadius );
2324 shapep.drawEllipse( rect );
2330 component.picture = shapePict;
2331 component.pictureBuffer = penSize / 2.0;
2333 component.size = rect.size();
2334 component.offset = QPointF( rect.width() / 2, -rect.height() / 2 );
2335 drawShadow( context, component, format );
2338 p->setOpacity( background.
opacity() );
2341 p->setCompositionMode( background.
blendMode() );
2345 p->scale( component.dpiRatio, component.dpiRatio );
2346 _fixQPictureDPI( p );
2347 p->drawPicture( 0, 0, shapePict );
2365 QPainter *p = context.
painter();
2366 double componentWidth = component.size.width(), componentHeight = component.size.height();
2367 double xOffset = component.offset.x(), yOffset = component.offset.y();
2368 double pictbuffer = component.pictureBuffer;
2373 radius /= ( mapUnits ? context.
scaleFactor() / component.dpiRatio : 1 );
2374 radius =
static_cast< int >( radius + 0.5 );
2378 double blurBufferClippingScale = 3.75;
2379 int blurbuffer = ( radius > 17 ? 16 : radius ) * blurBufferClippingScale;
2381 QImage blurImg( componentWidth + ( pictbuffer * 2.0 ) + ( blurbuffer * 2.0 ),
2382 componentHeight + ( pictbuffer * 2.0 ) + ( blurbuffer * 2.0 ),
2383 QImage::Format_ARGB32_Premultiplied );
2387 int minBlurImgSize = 1;
2391 int maxBlurImgSize = 40000;
2392 if ( blurImg.isNull()
2393 || ( blurImg.width() < minBlurImgSize || blurImg.height() < minBlurImgSize )
2394 || ( blurImg.width() > maxBlurImgSize || blurImg.height() > maxBlurImgSize ) )
2397 blurImg.fill( QColor( Qt::transparent ).rgba() );
2399 if ( !pictp.begin( &blurImg ) )
2401 pictp.setRenderHints( QPainter::Antialiasing | QPainter::SmoothPixmapTransform );
2402 QPointF imgOffset( blurbuffer + pictbuffer + xOffset,
2403 blurbuffer + pictbuffer + componentHeight + yOffset );
2405 pictp.drawPicture( imgOffset,
2406 component.picture );
2409 pictp.setCompositionMode( QPainter::CompositionMode_SourceIn );
2410 pictp.fillRect( blurImg.rect(), shadow.
color() );
2414 if ( shadow.
blurRadius() > 0.0 && radius > 0 )
2422 picti.begin( &blurImg );
2423 picti.setBrush( Qt::Dense7Pattern );
2424 QPen imgPen( QColor( 0, 0, 255, 255 ) );
2425 imgPen.setWidth( 1 );
2426 picti.setPen( imgPen );
2427 picti.setOpacity( 0.1 );
2428 picti.drawRect( 0, 0, blurImg.width(), blurImg.height() );
2433 double angleRad = shadow.
offsetAngle() * M_PI / 180;
2441 angleRad -= ( component.rotation * M_PI / 180 + component.rotationOffset * M_PI / 180 );
2444 QPointF transPt( -offsetDist * std::cos( angleRad + M_PI_2 ),
2445 -offsetDist * std::sin( angleRad + M_PI_2 ) );
2448 p->setRenderHint( QPainter::SmoothPixmapTransform );
2451 p->setRenderHint( QPainter::Antialiasing );
2455 p->setCompositionMode( shadow.
blendMode() );
2457 p->setOpacity( shadow.
opacity() );
2459 double scale = shadow.
scale() / 100.0;
2461 p->scale( scale, scale );
2462 if ( component.useOrigin )
2464 p->translate( component.origin.x(), component.origin.y() );
2466 p->translate( transPt );
2467 p->translate( -imgOffset.x(),
2469 p->drawImage( 0, 0, blurImg );
2476 p->setBrush( Qt::NoBrush );
2477 QPen imgPen( QColor( 255, 0, 0, 10 ) );
2478 imgPen.setWidth( 2 );
2479 imgPen.setStyle( Qt::DashLine );
2480 p->setPen( imgPen );
2481 p->scale( scale, scale );
2482 if ( component.useOrigin() )
2484 p->translate( component.origin().x(), component.origin().y() );
2486 p->translate( transPt );
2487 p->translate( -imgOffset.x(),
2489 p->drawRect( 0, 0, blurImg.width(), blurImg.height() );
2494 p->setBrush( Qt::NoBrush );
2495 QPen componentRectPen( QColor( 0, 255, 0, 70 ) );
2496 componentRectPen.setWidth( 1 );
2497 if ( component.useOrigin() )
2499 p->translate( component.origin().x(), component.origin().y() );
2501 p->setPen( componentRectPen );
2502 p->drawRect( QRect( -xOffset, -componentHeight - yOffset, componentWidth, componentHeight ) );
2507 void QgsTextRenderer::drawTextInternal(
TextPart drawType,
2510 const Component &component,
2511 const QStringList &textLines,
2512 const QFontMetricsF *fontMetrics,
2520 double labelWidest = 0.0;
2525 for (
const QString &line : textLines )
2527 double labelWidth = fontMetrics->width( line );
2528 if ( labelWidth > labelWidest )
2530 labelWidest = labelWidth;
2536 labelWidest = component.size.width();
2540 double labelHeight = fontMetrics->ascent() + fontMetrics->descent();
2544 double ascentOffset = 0.25 * fontMetrics->ascent();
2548 bool adjustForAlignment = alignment != AlignLeft && ( mode != Label || textLines.size() > 1 );
2550 const auto constTextLines = textLines;
2551 for (
const QString &line : constTextLines )
2556 context.
painter()->setRenderHint( QPainter::Antialiasing );
2558 context.
painter()->translate( component.origin );
2560 context.
painter()->rotate( -component.rotation * 180 / M_PI );
2563 double xMultiLineOffset = 0.0;
2564 double labelWidth = fontMetrics->width( line );
2565 if ( adjustForAlignment )
2567 double labelWidthDiff = labelWidest - labelWidth;
2568 if ( alignment == AlignCenter )
2570 labelWidthDiff /= 2;
2576 xMultiLineOffset = labelWidthDiff;
2580 if ( alignment == AlignRight )
2581 xMultiLineOffset = labelWidthDiff - labelWidest;
2582 else if ( alignment == AlignCenter )
2583 xMultiLineOffset = labelWidthDiff - labelWidest / 2.0;
2590 double yMultiLineOffset = 0.0;
2597 yMultiLineOffset = - ascentOffset - ( textLines.size() - 1 - i ) * labelHeight * format.
lineHeight();
2602 yMultiLineOffset = - ascentOffset + labelHeight - 1 + format.
lineHeight() * fontMetrics->lineSpacing() * i;
2607 yMultiLineOffset = 0 - ( textLines.size() - 1 - i ) * fontMetrics->lineSpacing() * format.
lineHeight();
2612 context.
painter()->translate( QPointF( xMultiLineOffset, yMultiLineOffset ) );
2614 Component subComponent;
2615 subComponent.text = line;
2616 subComponent.size = QSizeF( labelWidth, labelHeight );
2617 subComponent.offset = QPointF( 0.0, -ascentOffset );
2618 subComponent.rotation = -component.rotation * 180 / M_PI;
2619 subComponent.rotationOffset = 0.0;
2623 QgsTextRenderer::drawBuffer( context, subComponent, format );
2629 path.setFillRule( Qt::WindingFill );
2630 path.addText( 0, 0, format.
scaledFont( context ), subComponent.text );
2635 textp.begin( &textPict );
2636 textp.setPen( Qt::NoPen );
2637 QColor textColor = format.
color();
2638 textColor.setAlphaF( format.
opacity() );
2639 textp.setBrush( textColor );
2640 textp.drawPath( path );
2650 subComponent.picture = textPict;
2651 subComponent.pictureBuffer = 0.0;
2652 subComponent.origin = QPointF( 0.0, 0.0 );
2654 QgsTextRenderer::drawShadow( context, subComponent, format );
2664 context.
painter()->scale( subComponent.dpiRatio, subComponent.dpiRatio );
2671 _fixQPictureDPI( context.
painter() );
2672 context.
painter()->drawPicture( 0, 0, textPict );
2679 QColor textColor = format.
color();
2680 textColor.setAlphaF( format.
opacity() );
2681 context.
painter()->setPen( textColor );
2682 context.
painter()->setRenderHint( QPainter::TextAntialiasing );
2683 context.
painter()->drawText( 0, 0, subComponent.text );
QPainter::CompositionMode blendMode() const
Returns the blending mode used for drawing the buffer.
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.
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.
void setOffsetMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale object for the shadow offset distance.
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.
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.
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.
QFont toQFont() const
Returns a QFont matching the relevant settings from this text format.
QgsTextShadowSettings & operator=(const QgsTextShadowSettings &other)
void readXml(const QDomElement &elem)
Read settings from a DOM element.
Use antialiasing while drawing.
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.
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.
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.
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)
void readXml(const QDomElement &elem)
Read settings from a DOM element.
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.
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
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.
Shape rotation is a fixed angle.
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.
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.
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.
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.
double size() const
Returns the symbol size.
Always render text using path objects (AKA outlines/curves).
void setBlendMode(QPainter::CompositionMode mode)
Sets the blending mode used for drawing the drop shadow.
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.
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.
bool enabled() const
Returns whether the effect is enabled.
Q_GUI_EXPORT int qt_defaultDpiY()
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...
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.
QgsUnitTypes::RenderUnit offsetUnit() const
Returns the units used for the shape's offset.
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.
TextPart
Components of text.
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.
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...
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.
void setShadowPlacement(QgsTextShadowSettings::ShadowPlacement placement)
Sets the placement for the drop shadow.
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.
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.
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.
void setOpacity(double opacity)
Sets the background shape's opacity.
RenderUnit
Rendering size units.
static QColor decodeColor(const QString &str)
void setPaintEffect(QgsPaintEffect *effect)
Sets the current paint effect for the background shape.
void setOffsetAngle(int angle)
Sets the angle for offsetting the position of the shadow from the text.
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.