@@ -1983,6 +1983,10 @@ QgsFontMarkerSymbolLayerV2::QgsFontMarkerSymbolLayerV2( const QString& fontFamil
1983
1983
mSizeUnit = QgsSymbolV2::MM;
1984
1984
mOffset = QPointF ( 0 , 0 );
1985
1985
mOffsetUnit = QgsSymbolV2::MM;
1986
+ mOutlineColor = DEFAULT_FONTMARKER_BORDERCOLOR;
1987
+ mOutlineWidth = 0.0 ;
1988
+ mOutlineWidthUnit = QgsSymbolV2::MM;
1989
+ mPenJoinStyle = DEFAULT_FONTMARKER_JOINSTYLE;
1986
1990
}
1987
1991
1988
1992
QgsFontMarkerSymbolLayerV2::~QgsFontMarkerSymbolLayerV2 ()
@@ -2010,6 +2014,11 @@ QgsSymbolLayerV2* QgsFontMarkerSymbolLayerV2::create( const QgsStringMap& props
2010
2014
angle = props[" angle" ].toDouble ();
2011
2015
2012
2016
QgsFontMarkerSymbolLayerV2* m = new QgsFontMarkerSymbolLayerV2 ( fontFamily, chr, pointSize, color, angle );
2017
+
2018
+ if ( props.contains ( " outline_color" ) )
2019
+ m->setOutlineColor ( QgsSymbolLayerV2Utils::decodeColor ( props[" outline_color" ] ) );
2020
+ if ( props.contains ( " outline_width" ) )
2021
+ m->setOutlineWidth ( props[" outline_width" ].toDouble () );
2013
2022
if ( props.contains ( " offset" ) )
2014
2023
m->setOffset ( QgsSymbolLayerV2Utils::decodePoint ( props[" offset" ] ) );
2015
2024
if ( props.contains ( " offset_unit" ) )
@@ -2020,14 +2029,16 @@ QgsSymbolLayerV2* QgsFontMarkerSymbolLayerV2::create( const QgsStringMap& props
2020
2029
m->setSizeUnit ( QgsSymbolLayerV2Utils::decodeOutputUnit ( props[" size_unit" ] ) );
2021
2030
if ( props.contains ( " size_map_unit_scale" ) )
2022
2031
m->setSizeMapUnitScale ( QgsSymbolLayerV2Utils::decodeMapUnitScale ( props[" size_map_unit_scale" ] ) );
2032
+ if ( props.contains ( " outline_width_unit" ) )
2033
+ m->setOutlineWidthUnit ( QgsSymbolLayerV2Utils::decodeOutputUnit ( props[" outline_width_unit" ] ) );
2034
+ if ( props.contains ( " outline_width_map_unit_scale" ) )
2035
+ m->setOutlineWidthMapUnitScale ( QgsSymbolLayerV2Utils::decodeMapUnitScale ( props[" outline_width_map_unit_scale" ] ) );
2036
+ if ( props.contains ( " joinstyle" ) )
2037
+ m->setPenJoinStyle ( QgsSymbolLayerV2Utils::decodePenJoinStyle ( props[" joinstyle" ] ) );
2023
2038
if ( props.contains ( " horizontal_anchor_point" ) )
2024
- {
2025
2039
m->setHorizontalAnchorPoint ( QgsMarkerSymbolLayerV2::HorizontalAnchorPoint ( props[ " horizontal_anchor_point" ].toInt () ) );
2026
- }
2027
2040
if ( props.contains ( " vertical_anchor_point" ) )
2028
- {
2029
2041
m->setVerticalAnchorPoint ( QgsMarkerSymbolLayerV2::VerticalAnchorPoint ( props[ " vertical_anchor_point" ].toInt () ) );
2030
- }
2031
2042
2032
2043
m->restoreDataDefinedProperties ( props );
2033
2044
@@ -2041,6 +2052,17 @@ QString QgsFontMarkerSymbolLayerV2::layerType() const
2041
2052
2042
2053
void QgsFontMarkerSymbolLayerV2::startRender ( QgsSymbolV2RenderContext& context )
2043
2054
{
2055
+ QColor brushColor = mColor ;
2056
+ QColor penColor = mOutlineColor ;
2057
+
2058
+ brushColor.setAlphaF ( mColor .alphaF () * context.alpha () );
2059
+ penColor.setAlphaF ( mOutlineColor .alphaF () * context.alpha () );
2060
+
2061
+ mBrush = QBrush ( brushColor );
2062
+ mPen = QPen ( penColor );
2063
+ mPen .setJoinStyle ( mPenJoinStyle );
2064
+ mPen .setWidthF ( QgsSymbolLayerV2Utils::convertToPainterUnits ( context.renderContext (), mOutlineWidth , mOutlineWidthUnit , mOutlineWidthMapUnitScale ) );
2065
+
2044
2066
mFont = QFont ( mFontFamily );
2045
2067
mFont .setPixelSize ( QgsSymbolLayerV2Utils::convertToPainterUnits ( context.renderContext (), mSize , mSizeUnit , mSizeMapUnitScale ) );
2046
2068
delete mFontMetrics ;
@@ -2152,20 +2174,63 @@ void QgsFontMarkerSymbolLayerV2::renderPoint( QPointF point, QgsSymbolV2RenderCo
2152
2174
if ( !p )
2153
2175
return ;
2154
2176
2155
- QColor penColor = mColor ;
2177
+ QTransform transform;
2178
+
2156
2179
bool ok;
2180
+ QColor brushColor = mColor ;
2157
2181
if ( hasDataDefinedProperty ( QgsSymbolLayerV2::EXPR_COLOR ) )
2158
2182
{
2159
2183
context.setOriginalValueVariable ( QgsSymbolLayerV2Utils::encodeColor ( mColor ) );
2160
2184
QString colorString = evaluateDataDefinedProperty ( QgsSymbolLayerV2::EXPR_COLOR, context, QVariant (), &ok ).toString ();
2185
+ if ( ok )
2186
+ brushColor = QgsSymbolLayerV2Utils::decodeColor ( colorString );
2187
+ }
2188
+ brushColor = context.selected () ? context.renderContext ().selectionColor () : brushColor;
2189
+ brushColor.setAlphaF ( brushColor.alphaF () * context.alpha () );
2190
+ mBrush .setColor ( brushColor );
2191
+
2192
+ QColor penColor = mOutlineColor ;
2193
+ if ( hasDataDefinedProperty ( QgsSymbolLayerV2::EXPR_COLOR_BORDER ) )
2194
+ {
2195
+ context.setOriginalValueVariable ( QgsSymbolLayerV2Utils::encodeColor ( mOutlineColor ) );
2196
+ QString colorString = evaluateDataDefinedProperty ( QgsSymbolLayerV2::EXPR_COLOR_BORDER, context, QVariant (), &ok ).toString ();
2161
2197
if ( ok )
2162
2198
penColor = QgsSymbolLayerV2Utils::decodeColor ( colorString );
2163
2199
}
2164
- penColor = context.selected () ? context.renderContext ().selectionColor () : penColor;
2165
2200
penColor.setAlphaF ( penColor.alphaF () * context.alpha () );
2166
2201
2167
- p->setPen ( penColor );
2168
- p->setFont ( mFont );
2202
+ double penWidth = QgsSymbolLayerV2Utils::convertToPainterUnits ( context.renderContext (), mOutlineWidth , mOutlineWidthUnit , mOutlineWidthMapUnitScale );
2203
+ if ( hasDataDefinedProperty ( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH ) )
2204
+ {
2205
+ context.setOriginalValueVariable ( mOutlineWidth );
2206
+ double outlineWidth = evaluateDataDefinedProperty ( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH, context, QVariant (), &ok ).toDouble ();
2207
+ if ( ok )
2208
+ {
2209
+ penWidth = QgsSymbolLayerV2Utils::convertToPainterUnits ( context.renderContext (), outlineWidth, mOutlineWidthUnit , mOutlineWidthMapUnitScale );
2210
+ }
2211
+ }
2212
+
2213
+ if ( hasDataDefinedProperty ( QgsSymbolLayerV2::EXPR_JOIN_STYLE ) )
2214
+ {
2215
+ context.setOriginalValueVariable ( QgsSymbolLayerV2Utils::encodePenJoinStyle ( mPenJoinStyle ) );
2216
+ QString style = evaluateDataDefinedProperty ( QgsSymbolLayerV2::EXPR_JOIN_STYLE, context, QVariant (), &ok ).toString ();
2217
+ if ( ok )
2218
+ {
2219
+ mPen .setJoinStyle ( QgsSymbolLayerV2Utils::decodePenJoinStyle ( style ) );
2220
+ }
2221
+ }
2222
+
2223
+ p->setBrush ( mBrush );
2224
+ if ( !qgsDoubleNear ( penWidth, 0.0 ) )
2225
+ {
2226
+ mPen .setColor ( penColor );
2227
+ mPen .setWidthF ( penWidth );
2228
+ p->setPen ( mPen );
2229
+ }
2230
+ else
2231
+ {
2232
+ p->setPen ( Qt::NoPen );
2233
+ }
2169
2234
p->save ();
2170
2235
2171
2236
QPointF chrOffset = mChrOffset ;
@@ -2179,18 +2244,20 @@ void QgsFontMarkerSymbolLayerV2::renderPoint( QPointF point, QgsSymbolV2RenderCo
2179
2244
double angle = 0 ;
2180
2245
calculateOffsetAndRotation ( context, sizeToRender, hasDataDefinedRotation, offset, angle );
2181
2246
2182
- p->translate ( point + offset );
2247
+ transform.translate ( point.x () + offset.x (), point.y () + offset.y () );
2248
+
2249
+ if ( !qgsDoubleNear ( angle, 0.0 ) )
2250
+ transform.rotate ( angle );
2183
2251
2184
2252
if ( !qgsDoubleNear ( sizeToRender, mOrigSize ) )
2185
2253
{
2186
2254
double s = sizeToRender / mOrigSize ;
2187
- p-> scale ( s, s );
2255
+ transform. scale ( s, s );
2188
2256
}
2189
2257
2190
- if ( !qgsDoubleNear ( angle, 0 ) )
2191
- p->rotate ( angle );
2192
-
2193
- p->drawText ( -chrOffset, charToRender );
2258
+ QPainterPath path;
2259
+ path.addText ( -chrOffset.x (), -chrOffset.y (), mFont , charToRender );
2260
+ p->drawPath ( transform.map ( path ) );
2194
2261
p->restore ();
2195
2262
}
2196
2263
@@ -2203,6 +2270,10 @@ QgsStringMap QgsFontMarkerSymbolLayerV2::properties() const
2203
2270
props[" size_unit" ] = QgsSymbolLayerV2Utils::encodeOutputUnit ( mSizeUnit );
2204
2271
props[" size_map_unit_scale" ] = QgsSymbolLayerV2Utils::encodeMapUnitScale ( mSizeMapUnitScale );
2205
2272
props[" color" ] = QgsSymbolLayerV2Utils::encodeColor ( mColor );
2273
+ props[" outline_color" ] = QgsSymbolLayerV2Utils::encodeColor ( mOutlineColor );
2274
+ props[" outline_width" ] = QString::number ( mOutlineWidth );
2275
+ props[" outline_width_unit" ] = QgsSymbolLayerV2Utils::encodeOutputUnit ( mOutlineWidthUnit );
2276
+ props[" outline_width_map_unit_scale" ] = QgsSymbolLayerV2Utils::encodeMapUnitScale ( mOutlineWidthMapUnitScale );
2206
2277
props[" angle" ] = QString::number ( mAngle );
2207
2278
props[" offset" ] = QgsSymbolLayerV2Utils::encodePoint ( mOffset );
2208
2279
props[" offset_unit" ] = QgsSymbolLayerV2Utils::encodeOutputUnit ( mOffsetUnit );
@@ -2219,6 +2290,11 @@ QgsStringMap QgsFontMarkerSymbolLayerV2::properties() const
2219
2290
QgsFontMarkerSymbolLayerV2* QgsFontMarkerSymbolLayerV2::clone () const
2220
2291
{
2221
2292
QgsFontMarkerSymbolLayerV2* m = new QgsFontMarkerSymbolLayerV2 ( mFontFamily , mChr , mSize , mColor , mAngle );
2293
+ m->setOutlineColor ( mOutlineColor );
2294
+ m->setOutlineWidth ( mOutlineWidth );
2295
+ m->setOutlineWidthUnit ( mOutlineWidthUnit );
2296
+ m->setOutlineWidthMapUnitScale ( mOutlineWidthMapUnitScale );
2297
+ m->setPenJoinStyle ( mPenJoinStyle );
2222
2298
m->setOffset ( mOffset );
2223
2299
m->setOffsetUnit ( mOffsetUnit );
2224
2300
m->setOffsetMapUnitScale ( mOffsetMapUnitScale );
0 commit comments