Skip to content

Commit

Permalink
[cpt] Fix invalid interpretation of SVG stops with no stop-color tag
Browse files Browse the repository at this point in the history
This resulted in CPT ramps having a green color present when there
should have been black!
  • Loading branch information
nyalldawson committed Jul 20, 2022
1 parent 43ec089 commit 51abf19
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/core/symbology/qgscptcityarchive.cpp
Expand Up @@ -387,9 +387,18 @@ QMap< double, QPair<QColor, QColor> >QgsCptCityArchive::gradientColorMap( const
else
offset = offsetStr.toDouble();

// QColor color( 255, 0, 0 ); // red color as a warning :)
QColor color = QgsSymbolLayerUtils::parseColor( colorStr );
if ( color != QColor() )
QColor color;
if ( colorStr.isEmpty() )
{
// SVG spec says that stops without color default to black!
color = QColor( 0, 0, 0 );
}
else
{
color = QgsSymbolLayerUtils::parseColor( colorStr );
}

if ( color.isValid() )
{
const int alpha = opacityStr.toDouble() * 255; // test
color.setAlpha( alpha );
Expand All @@ -400,7 +409,7 @@ QMap< double, QPair<QColor, QColor> >QgsCptCityArchive::gradientColorMap( const
}
else
{
QgsDebugMsg( QStringLiteral( "at offset=%1 invalid color" ).arg( offset ) );
QgsDebugMsg( QStringLiteral( "at offset=%1 invalid color \"%2\"" ).arg( offset ).arg( colorStr ) );
}
}
else
Expand Down

0 comments on commit 51abf19

Please sign in to comment.