Skip to content

Commit

Permalink
Fix distorted line pattern fill when line offset is large compared
Browse files Browse the repository at this point in the history
with pattern distance

(cherry picked from commit e277b91)
  • Loading branch information
nyalldawson committed Oct 15, 2018
1 parent 34f2e95 commit 968948a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/core/symbology-ng/qgsfillsymbollayerv2.cpp
Expand Up @@ -2569,6 +2569,15 @@ void QgsLinePatternFillSymbolLayer::applyPattern( const QgsSymbolV2RenderContext
double outputPixelDist = distance * QgsSymbolLayerV2Utils::pixelSizeScaleFactor( ctx, mDistanceUnit, mDistanceMapUnitScale );
double outputPixelOffset = mOffset * QgsSymbolLayerV2Utils::pixelSizeScaleFactor( ctx, mOffsetUnit, mOffsetMapUnitScale );

// NOTE: this may need to be modified if we ever change from a forced rasterized/brush approach,
// because potentially we may want to allow vector based line pattern fills where the first line
// is offset by a large distance

// fix truncated pattern with larger offsets
outputPixelOffset = fmod( outputPixelOffset, outputPixelDist );
if ( outputPixelOffset > outputPixelDist / 2.0 )
outputPixelOffset -= outputPixelDist;

// To get all patterns into image, we have to consider symbols size (estimateMaxBleed()).
// For marker lines we have to get markers interval.
double outputPixelBleed = 0;
Expand Down
12 changes: 12 additions & 0 deletions tests/src/core/testqgslinefillsymbol.cpp
Expand Up @@ -61,6 +61,7 @@ class TestQgsLineFillSymbol : public QObject

void lineFillSymbol();
void lineFillSymbolOffset();
void lineFillLargeOffset();

void dataDefinedSubSymbol();

Expand Down Expand Up @@ -161,6 +162,17 @@ void TestQgsLineFillSymbol::lineFillSymbolOffset()
mLineFill->setOffset( 0 );
}

void TestQgsLineFillSymbol::lineFillLargeOffset()
{
// test line fill with large offset compared to line distance
mLineFill->setOffset( 8 );
QVERIFY( imageCheck( "symbol_linefill_large_posoffset" ) );

mLineFill->setOffset( -8 );
QVERIFY( imageCheck( "symbol_linefill_large_negoffset" ) );
mLineFill->setOffset( 0 );
}

void TestQgsLineFillSymbol::dataDefinedSubSymbol()
{
mReport += "<h2>Line fill symbol data defined sub symbol test</h2>\n";
Expand Down

0 comments on commit 968948a

Please sign in to comment.