Skip to content

Commit d4b44b7

Browse files
committed
Calculate border radii correctly. Fix dashed and dotted borders drawing algo. Update cmps.
DEVSIX-1911
1 parent a3bed9f commit d4b44b7

File tree

8 files changed

+10
-7
lines changed

8 files changed

+10
-7
lines changed

layout/src/main/java/com/itextpdf/layout/borders/DashedBorder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float
257257
y0 += borderWidthBefore / 2;
258258

259259
x3 -= innerRadiusSecond;
260-
y3 -= borderWidthAfter;
260+
y3 -= borderWidthAfter / 2;
261261

262262
clipPoint1 = getIntersectionPoint(new Point(x1 + width, y1 + borderWidthBefore), new Point(x1, y1), new Point(x0, y0), new Point(x0, y0 - 10));
263263
clipPoint2 = getIntersectionPoint(new Point(x2 + width, y2 -borderWidthAfter), new Point(x2, y2), new Point(x3, y3), new Point(x3, y3 - 10));
@@ -325,7 +325,7 @@ public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float
325325
y0 -= borderWidthBefore / 2;
326326

327327
x3 += innerRadiusSecond;
328-
y3 += borderWidthAfter;
328+
y3 += borderWidthAfter / 2;
329329

330330
clipPoint1 = getIntersectionPoint(new Point(x1 - width, y1 - borderWidthBefore), new Point(x1, y1), new Point(x0, y0), new Point(x0, y0 + 10));
331331
clipPoint2 = getIntersectionPoint(new Point(x2 - width, y2 + borderWidthAfter), new Point(x2, y2), new Point(x3, y3), new Point(x3, y3 + 10));

layout/src/main/java/com/itextpdf/layout/borders/DottedBorder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float
224224
y0 += borderWidthBefore / 2;
225225

226226
x3 -= innerRadiusSecond;
227-
y3 -= borderWidthAfter;
227+
y3 -= borderWidthAfter / 2;
228228

229229
clipPoint1 = getIntersectionPoint(new Point(x1 + width, y1 + borderWidthBefore), new Point(x1, y1), new Point(x0, y0), new Point(x0, y0 - 10));
230230
clipPoint2 = getIntersectionPoint(new Point(x2 + width, y2 - borderWidthAfter), new Point(x2, y2), new Point(x3, y3), new Point(x3, y3 - 10));
@@ -290,7 +290,7 @@ public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float
290290
y0 -= borderWidthBefore / 2;
291291

292292
x3 += innerRadiusSecond;
293-
y3 += borderWidthAfter;
293+
y3 += borderWidthAfter / 2;
294294

295295
clipPoint1 = getIntersectionPoint(new Point(x1 - width, y1 - borderWidthBefore), new Point(x1, y1), new Point(x0, y0), new Point(x0, y0 + 10));
296296
clipPoint2 = getIntersectionPoint(new Point(x2 - width, y2 + borderWidthAfter), new Point(x2, y2), new Point(x3, y3), new Point(x3, y3 + 10));

layout/src/main/java/com/itextpdf/layout/borders/RoundDotsBorder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float
247247
y0 += borderWidthBefore / 2;
248248

249249
x3 -= innerRadiusSecond;
250-
y3 -= borderWidthAfter;
250+
y3 -= borderWidthAfter / 2;
251251

252252
clipPoint1 = getIntersectionPoint(new Point(x1 + width, y1 + borderWidthBefore), new Point(x1, y1), new Point(x0, y0), new Point(x0, y0 - 10));
253253
clipPoint2 = getIntersectionPoint(new Point(x2 + width, y2 - borderWidthAfter), new Point(x2, y2), new Point(x3, y3), new Point(x3, y3 - 10));
@@ -313,7 +313,7 @@ public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float
313313
y0 -= borderWidthBefore / 2;
314314

315315
x3 += innerRadiusSecond;
316-
y3 += borderWidthAfter;
316+
y3 += borderWidthAfter / 2;
317317

318318
clipPoint1 = getIntersectionPoint(new Point(x1 - width, y1 - borderWidthBefore), new Point(x1, y1), new Point(x0, y0), new Point(x0, y0 + 10));
319319
clipPoint2 = getIntersectionPoint(new Point(x2 - width, y2 + borderWidthAfter), new Point(x2, y2), new Point(x3, y3), new Point(x3, y3 + 10));

layout/src/main/java/com/itextpdf/layout/renderer/AbstractRenderer.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,10 @@ public void drawBorder(DrawContext drawContext) {
907907
BorderRadius[] borderRadii = getBorderRadii();
908908
float[] verticalRadii = calculateRadii(borderRadii, borderRect, false);
909909
float[] horizontalRadii = calculateRadii(borderRadii, borderRect, true);
910-
910+
for (int i = 0; i < 4; i++) {
911+
verticalRadii[i] = Math.min(verticalRadii[i], borderRect.getHeight() / 2);
912+
horizontalRadii[i] = Math.min(horizontalRadii[i], borderRect.getWidth() / 2);
913+
}
911914
if (borders[0] != null) {
912915
if (0 != horizontalRadii[0] || 0 != verticalRadii[0] || 0 != horizontalRadii[1] || 0 != verticalRadii[1]) {
913916
borders[0].draw(canvas, x1, y2, x2, y2, horizontalRadii[0], verticalRadii[0], horizontalRadii[1], verticalRadii[1], Border.Side.TOP, leftWidth, rightWidth);
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)