Skip to content
Permalink
Browse files

Fix conversion of text alignment

  • Loading branch information
nyalldawson committed Sep 14, 2020
1 parent 0685c5e commit c11608071b376bb434f65682039c3476aef954ce
Showing with 48 additions and 0 deletions.
  1. +48 −0 src/core/vectortile/qgsmapboxglstyleconverter.cpp
@@ -1142,6 +1142,54 @@ void QgsMapBoxGlStyleConverter::parseSymbolLayer( const QVariantMap &jsonLayer,
}
}

if ( jsonLayout.contains( QStringLiteral( "text-justify" ) ) )
{
const QVariant jsonTextJustify = jsonLayout.value( QStringLiteral( "text-justify" ) );

// default is center
QString textAlign = QStringLiteral( "center" );

const QVariantMap conversionMap
{
{ QStringLiteral( "left" ), QStringLiteral( "left" ) },
{ QStringLiteral( "center" ), QStringLiteral( "center" ) },
{ QStringLiteral( "right" ), QStringLiteral( "right" ) },
{ QStringLiteral( "auto" ), QStringLiteral( "follow" ) }
};

switch ( jsonTextJustify.type() )
{
case QVariant::String:
textAlign = jsonTextJustify.toString();
break;

case QVariant::List:
ddLabelProperties.setProperty( QgsPalLayerSettings::OffsetQuad, QgsProperty::fromExpression( parseStringStops( jsonTextJustify.toList(), context, conversionMap, &textAlign ) ) );
break;

case QVariant::Map:
ddLabelProperties.setProperty( QgsPalLayerSettings::OffsetQuad, parseInterpolateStringByZoom( jsonTextJustify.toMap(), context, conversionMap, &textAlign ) );
break;

default:
context.pushWarning( QObject::tr( "Skipping non-implemented text-anchor expression" ) );
break;
}

if ( textAlign == QLatin1String( "left" ) )
labelSettings.multilineAlign = QgsPalLayerSettings::MultiLeft;
else if ( textAlign == QLatin1String( "right" ) )
labelSettings.multilineAlign = QgsPalLayerSettings::MultiRight;
else if ( textAlign == QLatin1String( "center" ) )
labelSettings.multilineAlign = QgsPalLayerSettings::MultiCenter;
else if ( textAlign == QLatin1String( "follow" ) )
labelSettings.multilineAlign = QgsPalLayerSettings::MultiFollowPlacement;
}
else
{
labelSettings.multilineAlign = QgsPalLayerSettings::MultiCenter;
}

if ( labelSettings.placement == QgsPalLayerSettings::OverPoint )
{
if ( jsonLayout.contains( QStringLiteral( "text-anchor" ) ) )

0 comments on commit c116080

Please sign in to comment.
You can’t perform that action at this time.