Skip to content

Commit

Permalink
Convert halo blur
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 6, 2020
1 parent 6bbca2b commit f2f1f4a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
42 changes: 32 additions & 10 deletions src/core/vectortile/qgsmapboxglstyleconverter.cpp
Expand Up @@ -28,7 +28,9 @@
#include "qgslinesymbollayer.h"
#include "qgsfontutils.h"
#include "qgsjsonutils.h"

#include "qgspainteffect.h"
#include "qgseffectstack.h"
#include "qgsblureffect.h"


constexpr double PIXEL_RATIO = 1;
Expand Down Expand Up @@ -704,17 +706,24 @@ void QgsMapBoxGlStyleConverter::parseSymbolLayer( const QVariantMap &jsonLayer,
}
}

// TODO implement halo blur
#if 0
if ( 'text-halo-blur' in json_paint )
double haloBlurSize = 0;
if ( jsonPaint.contains( QStringLiteral( "text-halo-blur" ) ) )
{
json_text_halo_blur = json_paint['text-halo-blur'];
if ( isinstance( json_text_halo_blur, ( float, int ) ) )
buffer_size = buffer_size - json_text_halo_blur;
else
print( "skipping non-float text-halo-blur", json_text_halo_blur );
const QVariant jsonTextHaloBlur = jsonPaint.value( QStringLiteral( "text-halo-blur" ) );
switch ( jsonTextHaloBlur.type() )
{
case QVariant::Int:
case QVariant::Double:
{
haloBlurSize = jsonTextHaloBlur.toDouble();
break;
}

default:
context.pushWarning( QObject::tr( "Skipping non-implemented text-halo-width expression" ) );
break;
}
}
#endif

QgsTextFormat format;
format.setSizeUnit( QgsUnitTypes::RenderPixels );
Expand All @@ -731,6 +740,19 @@ void QgsMapBoxGlStyleConverter::parseSymbolLayer( const QVariantMap &jsonLayer,
format.buffer().setSize( bufferSize * PIXEL_RATIO );
format.buffer().setSizeUnit( QgsUnitTypes::RenderPixels );
format.buffer().setColor( bufferColor );

if ( haloBlurSize > 0 )
{
QgsEffectStack *stack = new QgsEffectStack();
QgsBlurEffect *blur = new QgsBlurEffect() ;
blur->setEnabled( true );
blur->setBlurUnit( QgsUnitTypes::RenderPixels );
blur->setBlurLevel( haloBlurSize );
blur->setBlurMethod( QgsBlurEffect::StackBlur );
stack->appendEffect( blur );
stack->setEnabled( true );
format.buffer().setPaintEffect( stack );
}
}

QgsPalLayerSettings labelSettings;
Expand Down
6 changes: 3 additions & 3 deletions tests/src/python/test_qgsmapboxglconverter.py
Expand Up @@ -14,7 +14,8 @@

from qgis.PyQt.QtGui import (QColor)
from qgis.core import (QgsMapBoxGlStyleConverter,
QgsMapBoxGlStyleConversionContext
QgsMapBoxGlStyleConversionContext,
QgsEffectStack
)

from qgis.testing import start_app, unittest
Expand Down Expand Up @@ -234,8 +235,7 @@ def testConvertLabels(self):
"paint": {
"text-color": "#666",
"text-halo-width": 1.5,
"text-halo-color": "rgba(255,255,255,0.95)",
"text-halo-blur": 1
"text-halo-color": "rgba(255,255,255,0.95)"
},
"source-layer": "poi_label"
}
Expand Down

0 comments on commit f2f1f4a

Please sign in to comment.