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() );
1619 QString text = data->text();
1620 if ( !text.isEmpty() )
1626 if ( doc.setContent( text ) )
1628 elem = doc.documentElement();
1630 format.
readXml( elem, rwContext );
1641 if ( d->blendMode != QPainter::CompositionMode_SourceOver )
1644 if ( mBufferSettings.
enabled() && mBufferSettings.
blendMode() != QPainter::CompositionMode_SourceOver )
1647 if ( mBackgroundSettings.
enabled() && mBackgroundSettings.
blendMode() != QPainter::CompositionMode_SourceOver )
1650 if ( mShadowSettings.
enabled() && mShadowSettings.
blendMode() != QPainter::CompositionMode_SourceOver )
1668 drawPart( rect, rotation, alignment, textLines, context, tmpFormat, Background, drawAsOutlines );
1673 drawPart( rect, rotation, alignment, textLines, context, tmpFormat, Buffer, drawAsOutlines );
1676 drawPart( rect, rotation, alignment, textLines, context, tmpFormat, Text, drawAsOutlines );
1685 drawPart( point, rotation, alignment, textLines, context, tmpFormat, Background, drawAsOutlines );
1690 drawPart( point, rotation, alignment, textLines, context, tmpFormat, Buffer, drawAsOutlines );
1693 drawPart( point, rotation, alignment, textLines, context, tmpFormat, Text, drawAsOutlines );
1725 Component component;
1726 component.dpiRatio = 1.0;
1727 component.origin = rect.topLeft();
1728 component.rotation = rotation;
1729 component.size = rect.size();
1730 component.hAlign = alignment;
1743 double xc = rect.width() / 2.0;
1744 double yc = rect.height() / 2.0;
1746 double angle = -rotation;
1747 double xd = xc * std::cos( angle ) - yc * std::sin( angle );
1748 double yd = xc * std::sin( angle ) + yc * std::cos( angle );
1750 component.center = QPointF( component.origin.x() + xd, component.origin.y() + yd );
1754 component.center = rect.center();
1757 QgsTextRenderer::drawBackground( context, component, format, textLines, Rect );
1771 QFontMetricsF fm( format.
scaledFont( context ) );
1772 drawTextInternal( part, context, format, component,
1789 Component component;
1790 component.dpiRatio = 1.0;
1791 component.origin = origin;
1792 component.rotation = rotation;
1793 component.hAlign = alignment;
1802 QgsTextRenderer::drawBackground( context, component, format, textLines, Point );
1815 QFontMetricsF fm( format.
scaledFont( context ) );
1816 drawTextInternal( part, context, format, component,
1829 QPainter *p = context.
painter();
1836 path.setFillRule( Qt::WindingFill );
1837 path.addText( 0, 0, format.
scaledFont( context ), component.text );
1838 QColor bufferColor = buffer.
color();
1839 bufferColor.setAlphaF( buffer.
opacity() );
1840 QPen pen( bufferColor );
1841 pen.setWidthF( penSize );
1843 QColor tmpColor( bufferColor );
1847 tmpColor.setAlpha( 0 );
1853 buffp.begin( &buffPict );
1860 context.
painter()->setPen( pen );
1861 context.
painter()->setBrush( tmpColor );
1862 context.
painter()->drawPath( path );
1869 buffp.setPen( pen );
1870 buffp.setBrush( tmpColor );
1871 buffp.drawPath( path );
1877 QgsTextRenderer::Component bufferComponent = component;
1878 bufferComponent.origin = QPointF( 0.0, 0.0 );
1879 bufferComponent.picture = buffPict;
1880 bufferComponent.pictureBuffer = penSize / 2.0;
1881 drawShadow( context, bufferComponent, format );
1886 p->setCompositionMode( buffer.
blendMode() );
1890 p->setRenderHint( QPainter::Antialiasing );
1894 p->scale( component.dpiRatio, component.dpiRatio );
1895 _fixQPictureDPI( p );
1896 p->drawPicture( 0, 0, buffPict );
1900 double QgsTextRenderer::textWidth(
const QgsRenderContext &context,
const QgsTextFormat &format,
const QStringList &textLines, QFontMetricsF *fm )
1903 std::unique_ptr< QFontMetricsF > newFm;
1906 newFm.reset(
new QFontMetricsF( format.
scaledFont( context ) ) );
1910 double maxWidth = 0;
1911 Q_FOREACH (
const QString &line, textLines )
1913 maxWidth = std::max( maxWidth, fm->width( line ) );
1918 double QgsTextRenderer::textHeight(
const QgsRenderContext &context,
const QgsTextFormat &format,
const QStringList &textLines, DrawMode mode, QFontMetricsF *fm )
1921 std::unique_ptr< QFontMetricsF > newFm;
1924 newFm.reset(
new QFontMetricsF( format.
scaledFont( context ) ) );
1928 double labelHeight = fm->ascent() + fm->descent();
1936 return labelHeight + ( textLines.size() - 1 ) * labelHeight * format.
lineHeight();
1941 return labelHeight + ( textLines.size() - 1 ) * fm->lineSpacing() * format.
lineHeight();
1948 const QStringList &textLines, DrawMode mode )
1952 QPainter *prevP = context.
painter();
1953 QPainter *p = context.
painter();
1967 component.rotation = -( component.rotation * 180 / M_PI );
1968 component.rotationOffset =
1973 component.rotation = 0.0;
1974 component.rotationOffset = background.
rotation();
1977 if ( mode != Label )
1980 QFontMetricsF fm( format.
scaledFont( context ) );
1981 double width = textWidth( context, format, textLines, &fm );
1982 double height = textHeight( context, format, textLines, mode, &fm );
1987 switch ( component.hAlign )
1990 component.center = QPointF( component.origin.x() + width / 2.0,
1991 component.origin.y() + height / 2.0 );
1995 component.center = QPointF( component.origin.x() + component.size.width() / 2.0,
1996 component.origin.y() + height / 2.0 );
2000 component.center = QPointF( component.origin.x() + component.size.width() - width / 2.0,
2001 component.origin.y() + height / 2.0 );
2008 double originAdjust = fm.ascent() / 2.0 - fm.leading() / 2.0;
2009 switch ( component.hAlign )
2012 component.center = QPointF( component.origin.x() + width / 2.0,
2013 component.origin.y() - height / 2.0 + originAdjust );
2017 component.center = QPointF( component.origin.x(),
2018 component.origin.y() - height / 2.0 + originAdjust );
2022 component.center = QPointF( component.origin.x() - width / 2.0,
2023 component.origin.y() - height / 2.0 + originAdjust );
2033 component.size = QSizeF( width, height );
2042 if ( background.
svgFile().isEmpty() )
2045 double sizeOut = 0.0;
2053 sizeOut = std::max( component.size.width(), component.size.height() );
2057 sizeOut += bufferSize * 2;
2062 if ( sizeOut < 1.0 )
2066 map[QStringLiteral(
"name" )] = background.
svgFile().trimmed();
2067 map[QStringLiteral(
"size" )] = QString::number( sizeOut );
2069 map[QStringLiteral(
"angle" )] = QString::number( 0.0 );
2077 map[QStringLiteral(
"fill" )] = background.
fillColor().name();
2078 map[QStringLiteral(
"outline" )] = background.
strokeColor().name();
2079 map[QStringLiteral(
"outline-width" )] = QString::number( background.
strokeWidth() );
2087 shdwmap[QStringLiteral(
"fill" )] = shadow.
color().name();
2088 shdwmap[QStringLiteral(
"outline" )] = shadow.
color().name();
2089 shdwmap[QStringLiteral(
"size" )] = QString::number( sizeOut );
2094 svgp.begin( &svgPict );
2111 svgShdwM->
renderPoint( QPointF( sizeOut / 2, -sizeOut / 2 ), svgShdwContext );
2114 component.picture = svgPict;
2116 component.pictureBuffer = 0.0;
2118 component.size = QSizeF( sizeOut, sizeOut );
2119 component.offset = QPointF( 0.0, 0.0 );
2123 p->translate( component.center.x(), component.center.y() );
2124 p->rotate( component.rotation );
2127 p->translate( QPointF( xoff, yoff ) );
2128 p->rotate( component.rotationOffset );
2129 p->translate( -sizeOut / 2, sizeOut / 2 );
2132 p->setRenderHint( QPainter::Antialiasing );
2135 drawShadow( context, component, format );
2150 p->setCompositionMode( background.
blendMode() );
2154 p->setRenderHint( QPainter::Antialiasing );
2156 p->translate( component.center.x(), component.center.y() );
2157 p->rotate( component.rotation );
2160 p->translate( QPointF( xoff, yoff ) );
2161 p->rotate( component.rotationOffset );
2163 p->setCompositionMode( QPainter::CompositionMode_SourceOver );
2172 double w = component.
size.width();
2173 double h = component.size.height();
2194 h = std::sqrt( std::pow( w, 2 ) + std::pow( h, 2 ) );
2200 h = h * M_SQRT1_2 * 2;
2201 w = w * M_SQRT1_2 * 2;
2209 w += bufferWidth * 2;
2210 h += bufferHeight * 2;
2214 QRectF rect( -w / 2.0, - h / 2.0, w, h );
2216 if ( rect.isNull() )
2222 p->setRenderHint( QPainter::Antialiasing );
2224 p->translate( QPointF( component.center.x(), component.center.y() ) );
2225 p->rotate( component.rotation );
2228 p->translate( QPointF( xoff, yoff ) );
2229 p->rotate( component.rotationOffset );
2237 pen.setWidthF( penSize );
2239 pen.setJoinStyle( background.
joinStyle() );
2249 shapep.begin( &shapePict );
2250 shapep.setPen( pen );
2251 shapep.setBrush( background.
fillColor() );
2258 shapep.drawRoundedRect( rect, background.
radii().width(), background.
radii().height(), Qt::RelativeSize );
2264 shapep.drawRoundedRect( rect, xRadius, yRadius );
2270 shapep.drawEllipse( rect );
2276 component.picture = shapePict;
2277 component.pictureBuffer = penSize / 2.0;
2279 component.size = rect.size();
2280 component.offset = QPointF( rect.width() / 2, -rect.height() / 2 );
2281 drawShadow( context, component, format );
2284 p->setOpacity( background.
opacity() );
2287 p->setCompositionMode( background.
blendMode() );
2291 p->scale( component.dpiRatio, component.dpiRatio );
2292 _fixQPictureDPI( p );
2293 p->drawPicture( 0, 0, shapePict );
2311 QPainter *p = context.
painter();
2312 double componentWidth = component.size.width(), componentHeight = component.size.height();
2313 double xOffset = component.offset.x(), yOffset = component.offset.y();
2314 double pictbuffer = component.pictureBuffer;
2319 radius /= ( mapUnits ? context.
scaleFactor() / component.dpiRatio : 1 );
2320 radius =
static_cast< int >( radius + 0.5 );
2324 double blurBufferClippingScale = 3.75;
2325 int blurbuffer = ( radius > 17 ? 16 : radius ) * blurBufferClippingScale;
2327 QImage blurImg( componentWidth + ( pictbuffer * 2.0 ) + ( blurbuffer * 2.0 ),
2328 componentHeight + ( pictbuffer * 2.0 ) + ( blurbuffer * 2.0 ),
2329 QImage::Format_ARGB32_Premultiplied );
2333 int minBlurImgSize = 1;
2337 int maxBlurImgSize = 40000;
2338 if ( blurImg.isNull()
2339 || ( blurImg.width() < minBlurImgSize || blurImg.height() < minBlurImgSize )
2340 || ( blurImg.width() > maxBlurImgSize || blurImg.height() > maxBlurImgSize ) )
2343 blurImg.fill( QColor( Qt::transparent ).rgba() );
2345 if ( !pictp.begin( &blurImg ) )
2347 pictp.setRenderHints( QPainter::Antialiasing | QPainter::SmoothPixmapTransform );
2348 QPointF imgOffset( blurbuffer + pictbuffer + xOffset,
2349 blurbuffer + pictbuffer + componentHeight + yOffset );
2351 pictp.drawPicture( imgOffset,
2352 component.picture );
2355 pictp.setCompositionMode( QPainter::CompositionMode_SourceIn );
2356 pictp.fillRect( blurImg.rect(), shadow.
color() );
2360 if ( shadow.
blurRadius() > 0.0 && radius > 0 )
2368 picti.begin( &blurImg );
2369 picti.setBrush( Qt::Dense7Pattern );
2370 QPen imgPen( QColor( 0, 0, 255, 255 ) );
2371 imgPen.setWidth( 1 );
2372 picti.setPen( imgPen );
2373 picti.setOpacity( 0.1 );
2374 picti.drawRect( 0, 0, blurImg.width(), blurImg.height() );
2379 double angleRad = shadow.
offsetAngle() * M_PI / 180;
2387 angleRad -= ( component.rotation * M_PI / 180 + component.rotationOffset * M_PI / 180 );
2390 QPointF transPt( -offsetDist * std::cos( angleRad + M_PI_2 ),
2391 -offsetDist * std::sin( angleRad + M_PI_2 ) );
2394 p->setRenderHint( QPainter::SmoothPixmapTransform );
2397 p->setRenderHint( QPainter::Antialiasing );
2401 p->setCompositionMode( shadow.
blendMode() );
2403 p->setOpacity( shadow.
opacity() );
2405 double scale = shadow.
scale() / 100.0;
2407 p->scale( scale, scale );
2408 if ( component.useOrigin )
2410 p->translate( component.origin.x(), component.origin.y() );
2412 p->translate( transPt );
2413 p->translate( -imgOffset.x(),
2415 p->drawImage( 0, 0, blurImg );
2422 p->setBrush( Qt::NoBrush );
2423 QPen imgPen( QColor( 255, 0, 0, 10 ) );
2424 imgPen.setWidth( 2 );
2425 imgPen.setStyle( Qt::DashLine );
2426 p->setPen( imgPen );
2427 p->scale( scale, scale );
2428 if ( component.useOrigin() )
2430 p->translate( component.origin().x(), component.origin().y() );
2432 p->translate( transPt );
2433 p->translate( -imgOffset.x(),
2435 p->drawRect( 0, 0, blurImg.width(), blurImg.height() );
2440 p->setBrush( Qt::NoBrush );
2441 QPen componentRectPen( QColor( 0, 255, 0, 70 ) );
2442 componentRectPen.setWidth( 1 );
2443 if ( component.useOrigin() )
2445 p->translate( component.origin().x(), component.origin().y() );
2447 p->setPen( componentRectPen );
2448 p->drawRect( QRect( -xOffset, -componentHeight - yOffset, componentWidth, componentHeight ) );
2453 void QgsTextRenderer::drawTextInternal(
TextPart drawType,
2456 const Component &component,
2457 const QStringList &textLines,
2458 const QFontMetricsF *fontMetrics,
2468 double labelWidest = 0.0;
2473 Q_FOREACH (
const QString &line, textLines )
2475 double labelWidth = fontMetrics->width( line );
2476 if ( labelWidth > labelWidest )
2478 labelWidest = labelWidth;
2484 labelWidest = component.size.width();
2488 double labelHeight = fontMetrics->ascent() + fontMetrics->descent();
2492 double ascentOffset = 0.25 * fontMetrics->ascent();
2496 bool adjustForAlignment = alignment != AlignLeft && ( mode != Label || textLines.size() > 1 );
2498 Q_FOREACH (
const QString &line, textLines )
2503 context.
painter()->setRenderHint( QPainter::Antialiasing );
2505 context.
painter()->translate( component.origin );
2507 context.
painter()->rotate( -component.rotation * 180 / M_PI );
2510 double xMultiLineOffset = 0.0;
2511 double labelWidth = fontMetrics->width( line );
2512 if ( adjustForAlignment )
2514 double labelWidthDiff = labelWidest - labelWidth;
2515 if ( alignment == AlignCenter )
2517 labelWidthDiff /= 2;
2523 xMultiLineOffset = labelWidthDiff;
2527 if ( alignment == AlignRight )
2528 xMultiLineOffset = labelWidthDiff - labelWidest;
2529 else if ( alignment == AlignCenter )
2530 xMultiLineOffset = labelWidthDiff - labelWidest / 2.0;
2537 double yMultiLineOffset = 0.0;
2544 yMultiLineOffset = - ascentOffset - ( textLines.size() - 1 - i ) * labelHeight * format.
lineHeight();
2549 yMultiLineOffset = - ascentOffset + labelHeight - 1 + format.
lineHeight() * fontMetrics->lineSpacing() * i;
2554 yMultiLineOffset = 0 - ( textLines.size() - 1 - i ) * fontMetrics->lineSpacing() * format.
lineHeight();
2559 context.
painter()->translate( QPointF( xMultiLineOffset, yMultiLineOffset ) );
2561 Component subComponent;
2562 subComponent.text = line;
2563 subComponent.size = QSizeF( labelWidth, labelHeight );
2564 subComponent.offset = QPointF( 0.0, -ascentOffset );
2565 subComponent.rotation = -component.rotation * 180 / M_PI;
2566 subComponent.rotationOffset = 0.0;
2570 QgsTextRenderer::drawBuffer( context, subComponent, format );
2576 path.setFillRule( Qt::WindingFill );
2577 path.addText( 0, 0, format.
scaledFont( context ), subComponent.text );
2582 textp.begin( &textPict );
2583 textp.setPen( Qt::NoPen );
2584 QColor textColor = format.
color();
2585 textColor.setAlphaF( format.
opacity() );
2586 textp.setBrush( textColor );
2587 textp.drawPath( path );
2597 subComponent.picture = textPict;
2598 subComponent.pictureBuffer = 0.0;
2599 subComponent.origin = QPointF( 0.0, 0.0 );
2601 QgsTextRenderer::drawShadow( context, subComponent, format );
2611 context.
painter()->scale( subComponent.dpiRatio, subComponent.dpiRatio );
2613 if ( drawAsOutlines )
2616 _fixQPictureDPI( context.
painter() );
2617 context.
painter()->drawPicture( 0, 0, textPict );
2623 QColor textColor = format.
color();
2624 textColor.setAlphaF( format.
opacity() );
2625 context.
painter()->setPen( textColor );
2626 context.
painter()->setRenderHint( QPainter::TextAntialiasing );
2627 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.
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.
static QString svgSymbolPathToName(QString path, const QgsPathResolver &pathResolver)
Get SVG symbols's name from its path.
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.
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.
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).
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
Return 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.
static QString svgSymbolNameToPath(QString name, const QgsPathResolver &pathResolver)
Get SVG symbol's path from its name.
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.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
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).
void readFromLayer(QgsVectorLayer *layer)
Reads settings from a layer's custom properties (for QGIS 2.x projects).
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.
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
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.
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.
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.
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
static void blurImageInPlace(QImage &image, QRect rect, int radius, bool alphaOnly)
Blurs an image in place, e.g. creating Qt-independent drop shadows.
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)
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.
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.
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.
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.
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.