Skip to content

Commit 2ea552f

Browse files
BezrukovMiText-CI
authored andcommitted
Fix problem with desc coordinates domain for gradient
DEVSIX-2086
1 parent 769c3e2 commit 2ea552f

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

kernel/src/main/java/com/itextpdf/kernel/colors/gradients/AbstractLinearGradientBuilder.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,15 +281,18 @@ private static PdfShading.Axial createAxialShading(Point[] baseCoordinatesVector
281281
// to ensure that stops list covers the full domain. For repeat and reflect cases
282282
// this is done by adjusting the initial stops to cover the evaluated domain
283283
coordinatesDomain[0] = Math.max(coordinatesDomain[0], stopsToConstruct.get(0).getOffset());
284-
coordinatesDomain[1] = Math
285-
.min(coordinatesDomain[1], stopsToConstruct.get(stopsToConstruct.size() - 1).getOffset());
284+
coordinatesDomain[1] = Math.min(coordinatesDomain[1],
285+
stopsToConstruct.get(stopsToConstruct.size() - 1).getOffset());
286+
coordinatesDomain[1] = Math.max(coordinatesDomain[0], coordinatesDomain[1]);
286287
}
287288

288289
// workaround for PAD case
289290
if (spreadMethod == GradientSpreadMethod.PAD) {
290291
coordinatesDomain = modifyNormalizedStopsForPad(stopsToConstruct, coordinatesDomain);
291292
}
292293

294+
assert coordinatesDomain[0] <= coordinatesDomain[1];
295+
293296
Point[] actualCoordinates = createCoordinatesForNewDomain(coordinatesDomain, baseCoordinatesVector);
294297

295298
PdfShading.Axial axial = new PdfShading.Axial(

kernel/src/test/java/com/itextpdf/kernel/colors/gradients/LinearGradientBuilderTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,32 @@ public void buildWithTwoStopsInTheMiddleTest() throws IOException, InterruptedEx
124124
generateAndComparePdfs("buildWithTwoStopsInTheMiddleTest.pdf", targetBoundingBox, null, gradientBuilder);
125125
}
126126

127+
@Test
128+
public void buildWithTwoStopsBeforeTheBeginningTest() throws IOException, InterruptedException {
129+
Rectangle targetBoundingBox = new Rectangle(50f, 450f, 300f, 300f);
130+
AbstractLinearGradientBuilder gradientBuilder = new LinearGradientBuilder()
131+
.setGradientVector(targetBoundingBox.getLeft() + 100f, targetBoundingBox.getBottom() + 100f,
132+
targetBoundingBox.getRight() - 100f, targetBoundingBox.getTop() - 100f)
133+
.setSpreadMethod(GradientSpreadMethod.PAD)
134+
.addColorStop(new GradientColorStop(ColorConstants.RED.getColorValue(), -0.1d, OffsetType.RELATIVE))
135+
.addColorStop(new GradientColorStop(ColorConstants.BLUE.getColorValue(), -0.2d, OffsetType.RELATIVE));
136+
137+
generateAndComparePdfs("buildWithTwoStopsBeforeTheBeginningTest.pdf", targetBoundingBox, null, gradientBuilder);
138+
}
139+
140+
@Test
141+
public void buildWithTwoStopsAfterTheEndTest() throws IOException, InterruptedException {
142+
Rectangle targetBoundingBox = new Rectangle(50f, 450f, 300f, 300f);
143+
AbstractLinearGradientBuilder gradientBuilder = new LinearGradientBuilder()
144+
.setGradientVector(targetBoundingBox.getLeft() + 100f, targetBoundingBox.getBottom() + 100f,
145+
targetBoundingBox.getRight() - 100f, targetBoundingBox.getTop() - 100f)
146+
.setSpreadMethod(GradientSpreadMethod.PAD)
147+
.addColorStop(new GradientColorStop(ColorConstants.RED.getColorValue(), 1.2d, OffsetType.RELATIVE))
148+
.addColorStop(new GradientColorStop(ColorConstants.BLUE.getColorValue(), 0d, OffsetType.RELATIVE));
149+
150+
generateAndComparePdfs("buildWithTwoStopsAfterTheEndTest.pdf", targetBoundingBox, null, gradientBuilder);
151+
}
152+
127153
@Test
128154
public void padCaseWithVeryCloseCornerStopsTest() throws IOException, InterruptedException {
129155
Rectangle targetBoundingBox = new Rectangle(50f, 450f, 300f, 300f);

0 commit comments

Comments
 (0)