Skip to content

Commit 81c4b42

Browse files
committed
Refactor draw method. Fix bug in border clipping. Minor fixes.
DEVSIX-1311 Autoported commit. Original commit hash: [79e118a]
1 parent 874d4b3 commit 81c4b42

File tree

9 files changed

+31
-62
lines changed

9 files changed

+31
-62
lines changed

itext/itext.layout/itext/layout/borders/Border.cs

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public abstract class Border {
108108
/// <summary>The hash value for the border.</summary>
109109
private int hash;
110110

111+
[Obsolete]
111112
private Border.Side tmpSide = Border.Side.NONE;
112113

113114
/// <summary>
@@ -265,47 +266,8 @@ public virtual void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y
265266
/// </param>
266267
/// <param name="borderWidthBefore">defines width of the border that is before the current one</param>
267268
/// <param name="borderWidthAfter">defines width of the border that is after the current one</param>
268-
public virtual void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float borderRadius, Border.Side
269-
side, float borderWidthBefore, float borderWidthAfter) {
270-
tmpSide = side;
271-
Draw(canvas, x1, y1, x2, y2, borderRadius, borderWidthBefore, borderWidthAfter);
272-
tmpSide = Border.Side.NONE;
273-
}
274-
275-
/// <summary>
276-
/// <p>
277-
/// All borders are supposed to be drawn in such way, that inner content of the element is on the right from the
278-
/// drawing direction.
279-
/// </summary>
280-
/// <remarks>
281-
/// <p>
282-
/// All borders are supposed to be drawn in such way, that inner content of the element is on the right from the
283-
/// drawing direction. Borders are drawn in this order: top, right, bottom, left.
284-
/// </p>
285-
/// <p>
286-
/// Given points specify the line which lies on the border of the content area,
287-
/// therefore the border itself should be drawn to the left from the drawing direction.
288-
/// </p>
289-
/// <p>
290-
/// <code>borderWidthBefore</code> and <code>borderWidthAfter</code> parameters are used to
291-
/// define the widths of the borders that are before and after the current border, e.g. for
292-
/// the bottom border, <code>borderWidthBefore</code> specifies width of the right border and
293-
/// <code>borderWidthAfter</code> - width of the left border. Those width are used to handle areas
294-
/// of border joins.
295-
/// </p>
296-
/// </remarks>
297-
/// <param name="canvas">PdfCanvas to be written to</param>
298-
/// <param name="x1">x coordinate of the beginning point of the element side, that should be bordered</param>
299-
/// <param name="y1">y coordinate of the beginning point of the element side, that should be bordered</param>
300-
/// <param name="x2">x coordinate of the ending point of the element side, that should be bordered</param>
301-
/// <param name="y2">y coordinate of the ending point of the element side, that should be bordered</param>
302-
/// <param name="borderRadius">border radius</param>
303-
/// <param name="borderWidthBefore">defines width of the border that is before the current one</param>
304-
/// <param name="borderWidthAfter">defines width of the border that is after the current one</param>
305-
[System.ObsoleteAttribute(@"Will be removed in 7.1.0. use Draw(iText.Kernel.Pdf.Canvas.PdfCanvas, float, float, float, float, float, Side, float, float) instead"
306-
)]
307-
public abstract void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float borderRadius, float
308-
borderWidthBefore, float borderWidthAfter);
269+
public abstract void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float borderRadius, Border.Side
270+
side, float borderWidthBefore, float borderWidthAfter);
309271

310272
/// <summary>Draws the border of a cell.</summary>
311273
/// <param name="canvas">PdfCanvas to be written to</param>
@@ -423,7 +385,14 @@ public override int GetHashCode() {
423385
/// the corresponded
424386
/// <see cref="Side">side</see>
425387
/// </returns>
388+
[System.ObsoleteAttribute(@"Will be removed in 7.1.0. use GetBorderSide(float, float, float, float, Side) instead"
389+
)]
426390
protected internal virtual Border.Side GetBorderSide(float x1, float y1, float x2, float y2) {
391+
return GetBorderSide(x1, y1, x2, y2, tmpSide);
392+
}
393+
394+
protected internal virtual Border.Side GetBorderSide(float x1, float y1, float x2, float y2, Border.Side tempSide
395+
) {
427396
bool isLeft = false;
428397
bool isRight = false;
429398
if (Math.Abs(y2 - y1) > 0.0005f) {
@@ -454,7 +423,7 @@ protected internal virtual Border.Side GetBorderSide(float x1, float y1, float x
454423
}
455424
}
456425
}
457-
return tmpSide;
426+
return tempSide;
458427
}
459428

460429
/// <summary>Enumerates the different sides of the rectangle.</summary>

itext/itext.layout/itext/layout/borders/Border3D.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,11 @@ public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float
190190
canvas.RestoreState();
191191
}
192192

193-
public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float borderRadius, float
194-
borderWidthBefore, float borderWidthAfter) {
193+
public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float borderRadius, Border.Side
194+
side, float borderWidthBefore, float borderWidthAfter) {
195+
Draw(canvas, x1, y1, x2, y2, borderWidthBefore, borderWidthAfter);
195196
}
196197

197-
// TODO
198198
/// <summary><inheritDoc/></summary>
199199
public override void DrawCellBorder(PdfCanvas canvas, float x1, float y1, float x2, float y2) {
200200
canvas.SaveState().SetStrokeColor(transparentColor.GetColor());

itext/itext.layout/itext/layout/borders/DashedBorder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ public override void DrawCellBorder(PdfCanvas canvas, float x1, float y1, float
143143
, y2).Stroke().RestoreState();
144144
}
145145

146-
public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float outerRadius, float
147-
borderWidthBefore, float borderWidthAfter) {
146+
public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float outerRadius, Border.Side
147+
side, float borderWidthBefore, float borderWidthAfter) {
148148
float curv = 0.447f;
149149
float initialGap = width * GAP_MODIFIER;
150150
float dash = width * DASH_MODIFIER;
@@ -170,7 +170,7 @@ public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float
170170
Point clipPoint1;
171171
Point clipPoint2;
172172
Point clipPoint;
173-
Border.Side borderSide = GetBorderSide(x1, y1, x2, y2);
173+
Border.Side borderSide = GetBorderSide(x1, y1, x2, y2, side);
174174
switch (borderSide) {
175175
case Border.Side.TOP: {
176176
x0 -= borderWidthBefore / 2;

itext/itext.layout/itext/layout/borders/DottedBorder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float
130130
();
131131
}
132132

133-
public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float outerRadius, float
134-
borderWidthBefore, float borderWidthAfter) {
133+
public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float outerRadius, Border.Side
134+
side, float borderWidthBefore, float borderWidthAfter) {
135135
float curv = 0.447f;
136136
float initialGap = width * GAP_MODIFIER;
137137
float dx = x2 - x1;
@@ -156,7 +156,7 @@ public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float
156156
Point clipPoint1;
157157
Point clipPoint2;
158158
Point clipPoint;
159-
Border.Side borderSide = GetBorderSide(x1, y1, x2, y2);
159+
Border.Side borderSide = GetBorderSide(x1, y1, x2, y2, side);
160160
switch (borderSide) {
161161
case Border.Side.TOP: {
162162
x0 -= borderWidthBefore / 2;

itext/itext.layout/itext/layout/borders/DoubleBorder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float
195195
canvas.MoveTo(x1, y1).LineTo(x2, y2).LineTo(x3, y3).LineTo(x4, y4).LineTo(x1, y1).Fill().RestoreState();
196196
}
197197

198-
public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float borderRadius, float
199-
borderWidthBefore, float borderWidthAfter) {
198+
public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float borderRadius, Border.Side
199+
side, float borderWidthBefore, float borderWidthAfter) {
200+
Draw(canvas, x1, y1, x2, y2, borderWidthBefore, borderWidthAfter);
200201
}
201202

202-
// TODO
203203
/// <summary><inheritDoc/></summary>
204204
public override void DrawCellBorder(PdfCanvas canvas, float x1, float y1, float x2, float y2) {
205205
float thirdOfWidth = width / 3;

itext/itext.layout/itext/layout/borders/RoundDotsBorder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ public override void DrawCellBorder(PdfCanvas canvas, float x1, float y1, float
145145
canvas.SetLineDash(0, adjustedGap, adjustedGap / 2).MoveTo(x1, y1).LineTo(x2, y2).Stroke();
146146
}
147147

148-
public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float outerRadius, float
149-
borderWidthBefore, float borderWidthAfter) {
148+
public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float outerRadius, Border.Side
149+
side, float borderWidthBefore, float borderWidthAfter) {
150150
float curv = 0.447f;
151151
float initialGap = width * GAP_MODIFIER;
152152
float dx = x2 - x1;
@@ -169,7 +169,7 @@ public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float
169169
Point clipPoint1;
170170
Point clipPoint2;
171171
Point clipPoint;
172-
Border.Side borderSide = GetBorderSide(x1, y1, x2, y2);
172+
Border.Side borderSide = GetBorderSide(x1, y1, x2, y2, side);
173173
switch (borderSide) {
174174
case Border.Side.TOP: {
175175
x0 -= borderWidthBefore / 2;

itext/itext.layout/itext/layout/borders/SolidBorder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,16 @@ public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float
121121
canvas.MoveTo(x1, y1).LineTo(x2, y2).LineTo(x3, y3).LineTo(x4, y4).LineTo(x1, y1).Fill().RestoreState();
122122
}
123123

124-
public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float outerRadius, float
125-
borderWidthBefore, float borderWidthAfter) {
124+
public override void Draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float outerRadius, Border.Side
125+
side, float borderWidthBefore, float borderWidthAfter) {
126126
float innerRadiusBefore = Math.Max(0, outerRadius - borderWidthBefore);
127127
float innerRadius = Math.Max(0, outerRadius - width);
128128
float innerRadiusAfter = Math.Max(0, outerRadius - borderWidthAfter);
129129
float x3 = 0;
130130
float y3 = 0;
131131
float x4 = 0;
132132
float y4 = 0;
133-
Border.Side borderSide = GetBorderSide(x1, y1, x2, y2);
133+
Border.Side borderSide = GetBorderSide(x1, y1, x2, y2, side);
134134
switch (borderSide) {
135135
case Border.Side.TOP: {
136136
x3 = x2 + borderWidthAfter;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ public virtual void DrawBorder(DrawContext drawContext) {
747747
canvas.OpenTag(new CanvasArtifact());
748748
}
749749
bool isAreaClipped = ClipBorderArea(drawContext, ApplyMargins(occupiedArea.GetBBox().Clone(), GetMargins()
750-
, true));
750+
, false));
751751
UnitValue borderRadius = this.GetProperty<UnitValue>(Property.BORDER_RADIUS);
752752
float radius = 0;
753753
if (null != borderRadius) {

port-hash

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

0 commit comments

Comments
 (0)