Skip to content

Commit 968948a

Browse files
committed
Fix distorted line pattern fill when line offset is large compared
with pattern distance (cherry picked from commit e277b91)
1 parent 34f2e95 commit 968948a

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/core/symbology-ng/qgsfillsymbollayerv2.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2569,6 +2569,15 @@ void QgsLinePatternFillSymbolLayer::applyPattern( const QgsSymbolV2RenderContext
25692569
double outputPixelDist = distance * QgsSymbolLayerV2Utils::pixelSizeScaleFactor( ctx, mDistanceUnit, mDistanceMapUnitScale );
25702570
double outputPixelOffset = mOffset * QgsSymbolLayerV2Utils::pixelSizeScaleFactor( ctx, mOffsetUnit, mOffsetMapUnitScale );
25712571

2572+
// NOTE: this may need to be modified if we ever change from a forced rasterized/brush approach,
2573+
// because potentially we may want to allow vector based line pattern fills where the first line
2574+
// is offset by a large distance
2575+
2576+
// fix truncated pattern with larger offsets
2577+
outputPixelOffset = fmod( outputPixelOffset, outputPixelDist );
2578+
if ( outputPixelOffset > outputPixelDist / 2.0 )
2579+
outputPixelOffset -= outputPixelDist;
2580+
25722581
// To get all patterns into image, we have to consider symbols size (estimateMaxBleed()).
25732582
// For marker lines we have to get markers interval.
25742583
double outputPixelBleed = 0;

tests/src/core/testqgslinefillsymbol.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class TestQgsLineFillSymbol : public QObject
6161

6262
void lineFillSymbol();
6363
void lineFillSymbolOffset();
64+
void lineFillLargeOffset();
6465

6566
void dataDefinedSubSymbol();
6667

@@ -161,6 +162,17 @@ void TestQgsLineFillSymbol::lineFillSymbolOffset()
161162
mLineFill->setOffset( 0 );
162163
}
163164

165+
void TestQgsLineFillSymbol::lineFillLargeOffset()
166+
{
167+
// test line fill with large offset compared to line distance
168+
mLineFill->setOffset( 8 );
169+
QVERIFY( imageCheck( "symbol_linefill_large_posoffset" ) );
170+
171+
mLineFill->setOffset( -8 );
172+
QVERIFY( imageCheck( "symbol_linefill_large_negoffset" ) );
173+
mLineFill->setOffset( 0 );
174+
}
175+
164176
void TestQgsLineFillSymbol::dataDefinedSubSymbol()
165177
{
166178
mReport += "<h2>Line fill symbol data defined sub symbol test</h2>\n";

0 commit comments

Comments
 (0)