Skip to content

Commit 874d4b3

Browse files
committed
Clip borders correctly to avoid zero-width lines. Fix cmps. Minor refactoring
DEVSIX-1311 Autoported commit. Original commit hash: [a0c7e7f]
1 parent 154640b commit 874d4b3

File tree

7 files changed

+51
-45
lines changed

7 files changed

+51
-45
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

itext/itext.layout/itext/layout/renderer/AbstractRenderer.cs

Lines changed: 50 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -536,40 +536,46 @@ protected internal virtual bool ClipBorderArea(DrawContext drawContext, Rectangl
536536
float right = outerBorderBox.GetRight();
537537
float bottom = outerBorderBox.GetBottom();
538538
float left = outerBorderBox.GetLeft();
539+
float verticalRadius = Math.Min(outerBorderBox.GetHeight() / 2, radius);
540+
float horizontalRadius = Math.Min(outerBorderBox.GetWidth() / 2, radius);
539541
// radius border bbox
540-
float x1 = right - radius;
541-
float y1 = top - radius;
542-
float x2 = right - radius;
543-
float y2 = bottom + radius;
544-
float x3 = left + radius;
545-
float y3 = bottom + radius;
546-
float x4 = left + radius;
547-
float y4 = top - radius;
542+
float x1 = right - horizontalRadius;
543+
float y1 = top - verticalRadius;
544+
float x2 = right - horizontalRadius;
545+
float y2 = bottom + verticalRadius;
546+
float x3 = left + horizontalRadius;
547+
float y3 = bottom + verticalRadius;
548+
float x4 = left + horizontalRadius;
549+
float y4 = top - verticalRadius;
548550
PdfCanvas canvas = drawContext.GetCanvas();
549551
canvas.SaveState();
550-
canvas.MoveTo(left, top).LineTo(x1, top).CurveTo(x1 + radius * curv, top, right, y1 + radius * curv, right
551-
, y1).LineTo(right, bottom).LineTo(left, bottom).LineTo(left, top);
552+
// right top corner
553+
canvas.MoveTo(left, top).LineTo(x1, top).CurveTo(x1 + horizontalRadius * curv, top, right, y1 + verticalRadius
554+
* curv, right, y1).LineTo(right, bottom).LineTo(left, bottom).LineTo(left, top);
552555
canvas.Clip().NewPath();
553-
canvas.MoveTo(right, top).LineTo(right, y2).CurveTo(right, y2 - radius * curv, x2 + radius * curv, bottom,
554-
x2, bottom).LineTo(left, bottom).LineTo(left, top).LineTo(right, top);
556+
// right bottom corner
557+
canvas.MoveTo(right, top).LineTo(right, y2).CurveTo(right, y2 - verticalRadius * curv, x2 + horizontalRadius
558+
* curv, bottom, x2, bottom).LineTo(left, bottom).LineTo(left, top).LineTo(right, top);
555559
canvas.Clip().NewPath();
556-
canvas.MoveTo(right, bottom).LineTo(x3, bottom).CurveTo(x3 - radius * curv, bottom, left, y3 - radius * curv
557-
, left, y3).LineTo(left, top).LineTo(right, top).LineTo(right, bottom);
560+
// left bottom corner
561+
canvas.MoveTo(right, bottom).LineTo(x3, bottom).CurveTo(x3 - horizontalRadius * curv, bottom, left, y3 - verticalRadius
562+
* curv, left, y3).LineTo(left, top).LineTo(right, top).LineTo(right, bottom);
558563
canvas.Clip().NewPath();
559-
canvas.MoveTo(left, bottom).LineTo(left, y4).CurveTo(left, y4 + radius * curv, x4 - radius * curv, top, x4
560-
, top).LineTo(right, top).LineTo(right, bottom).LineTo(left, bottom);
564+
// left top corner
565+
canvas.MoveTo(left, bottom).LineTo(left, y4).CurveTo(left, y4 + verticalRadius * curv, x4 - horizontalRadius
566+
* curv, top, x4, top).LineTo(right, top).LineTo(right, bottom).LineTo(left, bottom);
561567
canvas.Clip().NewPath();
562568
Border[] borders = GetBorders();
563-
float radiusTop = radius;
564-
float radiusRight = radius;
565-
float radiusBottom = radius;
566-
float radiusLeft = radius;
567-
float deltaTop = 0;
568-
float deltaRight = 0;
569-
float deltaBottom = 0;
570-
float deltaLeft = 0;
569+
float radiusTop = verticalRadius;
570+
float radiusRight = horizontalRadius;
571+
float radiusBottom = verticalRadius;
572+
float radiusLeft = horizontalRadius;
573+
float topBorderWidth = 0;
574+
float rightBorderWidth = 0;
575+
float bottomBorderWidth = 0;
576+
float leftBorderWidth = 0;
571577
if (borders[0] != null) {
572-
deltaTop = borders[0].GetWidth();
578+
topBorderWidth = borders[0].GetWidth();
573579
top = top - borders[0].GetWidth();
574580
if (y1 > top) {
575581
y1 = top;
@@ -578,7 +584,7 @@ protected internal virtual bool ClipBorderArea(DrawContext drawContext, Rectangl
578584
radiusTop = Math.Max(0, radiusTop - borders[0].GetWidth());
579585
}
580586
if (borders[1] != null) {
581-
deltaRight = borders[1].GetWidth();
587+
rightBorderWidth = borders[1].GetWidth();
582588
right = right - borders[1].GetWidth();
583589
if (x1 > right) {
584590
x1 = right;
@@ -587,7 +593,7 @@ protected internal virtual bool ClipBorderArea(DrawContext drawContext, Rectangl
587593
radiusRight = Math.Max(0, radiusRight - borders[1].GetWidth());
588594
}
589595
if (borders[2] != null) {
590-
deltaBottom = borders[2].GetWidth();
596+
bottomBorderWidth = borders[2].GetWidth();
591597
bottom = bottom + borders[2].GetWidth();
592598
if (x3 < left) {
593599
x3 = left;
@@ -596,33 +602,33 @@ protected internal virtual bool ClipBorderArea(DrawContext drawContext, Rectangl
596602
radiusBottom = Math.Max(0, radiusBottom - borders[2].GetWidth());
597603
}
598604
if (borders[3] != null) {
599-
deltaLeft = borders[3].GetWidth();
605+
leftBorderWidth = borders[3].GetWidth();
600606
left = left + borders[3].GetWidth();
601607
radiusLeft = Math.Max(0, radiusLeft - borders[3].GetWidth());
602608
}
603609
canvas.MoveTo(x1, top).CurveTo(x1 + Math.Min(radiusTop, radiusRight) * curv, top, right, y1 + Math.Min(radiusTop
604-
, radiusRight) * curv, right, y1).LineTo(x4, y1).LineTo(x4, top).LineTo(x1, top).LineTo(x1, top + deltaTop
605-
).LineTo(left - deltaLeft, top + deltaTop).LineTo(left - deltaLeft, bottom - deltaBottom).LineTo(right
606-
+ deltaRight, bottom - deltaBottom).LineTo(right + deltaRight, top + deltaTop).LineTo(x1, top + deltaTop
607-
);
610+
, radiusRight) * curv, right, y1).LineTo(right, y2).LineTo(x3, y2).LineTo(x3, top).LineTo(x1, top).LineTo
611+
(x1, top + topBorderWidth).LineTo(left - leftBorderWidth, top + topBorderWidth).LineTo(left - leftBorderWidth
612+
, bottom - bottomBorderWidth).LineTo(right + rightBorderWidth, bottom - bottomBorderWidth).LineTo(right
613+
+ rightBorderWidth, top + topBorderWidth).LineTo(x1, top + topBorderWidth);
608614
canvas.Clip().NewPath();
609615
canvas.MoveTo(right, y2).CurveTo(right, y2 - Math.Min(radiusRight, radiusBottom) * curv, x2 + Math.Min(radiusRight
610-
, radiusBottom) * curv, bottom, x2, bottom).LineTo(x2, y1).LineTo(right, y1).LineTo(right, y2).LineTo(
611-
right + deltaRight, y2).LineTo(right + deltaRight, top + deltaTop).LineTo(left - deltaLeft, top + deltaTop
612-
).LineTo(left - deltaLeft, bottom - deltaBottom).LineTo(right + deltaRight, bottom - deltaBottom).LineTo
613-
(right + deltaRight, y2);
616+
, radiusBottom) * curv, bottom, x2, bottom).LineTo(x3, bottom).LineTo(x3, y4).LineTo(right, y4).LineTo
617+
(right, y2).LineTo(right + rightBorderWidth, y2).LineTo(right + rightBorderWidth, top + topBorderWidth
618+
).LineTo(left - leftBorderWidth, top + topBorderWidth).LineTo(left - leftBorderWidth, bottom - bottomBorderWidth
619+
).LineTo(right + rightBorderWidth, bottom - bottomBorderWidth).LineTo(right + rightBorderWidth, y2);
614620
canvas.Clip().NewPath();
615621
canvas.MoveTo(x3, bottom).CurveTo(x3 - Math.Min(radiusBottom, radiusLeft) * curv, bottom, left, y3 - Math.
616-
Min(radiusBottom, radiusLeft) * curv, left, y3).LineTo(x2, y3).LineTo(x2, bottom).LineTo(x3, bottom).LineTo
617-
(x3, bottom - deltaBottom).LineTo(right + deltaRight, bottom - deltaBottom).LineTo(right + deltaRight,
618-
top + deltaTop).LineTo(left - deltaLeft, top + deltaTop).LineTo(left - deltaLeft, bottom - deltaBottom
619-
).LineTo(x3, bottom - deltaBottom);
622+
Min(radiusBottom, radiusLeft) * curv, left, y3).LineTo(left, y4).LineTo(x1, y4).LineTo(x1, bottom).LineTo
623+
(x3, bottom).LineTo(x3, bottom - bottomBorderWidth).LineTo(right + rightBorderWidth, bottom - bottomBorderWidth
624+
).LineTo(right + rightBorderWidth, top + topBorderWidth).LineTo(left - leftBorderWidth, top + topBorderWidth
625+
).LineTo(left - leftBorderWidth, bottom - bottomBorderWidth).LineTo(x3, bottom - bottomBorderWidth);
620626
canvas.Clip().NewPath();
621627
canvas.MoveTo(left, y4).CurveTo(left, y4 + Math.Min(radiusLeft, radiusTop) * curv, x4 - Math.Min(radiusLeft
622-
, radiusTop) * curv, top, x4, top).LineTo(x4, y3).LineTo(left, y3).LineTo(left, y4).LineTo(left - deltaLeft
623-
, y4).LineTo(left - deltaLeft, bottom - deltaBottom).LineTo(right + deltaRight, bottom - deltaBottom).
624-
LineTo(right + deltaRight, top + deltaTop).LineTo(left - deltaLeft, top + deltaTop).LineTo(left - deltaLeft
625-
, y4);
628+
, radiusTop) * curv, top, x4, top).LineTo(x1, top).LineTo(x1, y2).LineTo(left, y2).LineTo(left, y4).LineTo
629+
(left - leftBorderWidth, y4).LineTo(left - leftBorderWidth, bottom - bottomBorderWidth).LineTo(right +
630+
rightBorderWidth, bottom - bottomBorderWidth).LineTo(right + rightBorderWidth, top + topBorderWidth).
631+
LineTo(left - leftBorderWidth, top + topBorderWidth).LineTo(left - leftBorderWidth, y4);
626632
canvas.Clip().NewPath();
627633
}
628634
return 0 != radius;

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9761a2eddde528939734a5c10db48712a65c4867
1+
a0c7e7fe25d17d5eaa6c1f31c3c8dd2eb656193b

0 commit comments

Comments
 (0)