Skip to content

Commit 79e118a

Browse files
committed
Refactor draw method. Fix bug in border clipping. Minor fixes.
DEVSIX-1311
1 parent a0c7e7f commit 79e118a

File tree

8 files changed

+25
-49
lines changed

8 files changed

+25
-49
lines changed

layout/src/main/java/com/itextpdf/layout/border/Border.java

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ public abstract class Border {
141141
*/
142142
private int hash;
143143

144+
@Deprecated
145+
/**
146+
* @deprecated Will be removed in 7.1.0.
147+
*/
144148
private Side tmpSide = Side.NONE;
145149

146150
/**
@@ -266,41 +270,7 @@ public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, Side
266270
* @param borderWidthBefore defines width of the border that is before the current one
267271
* @param borderWidthAfter defines width of the border that is after the current one
268272
*/
269-
public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float borderRadius, Side side, float borderWidthBefore, float borderWidthAfter) {
270-
tmpSide = side;
271-
draw(canvas, x1, y1, x2, y2, borderRadius, borderWidthBefore, borderWidthAfter);
272-
tmpSide = Side.NONE;
273-
}
274-
275-
/**
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. Borders are drawn in this order: top, right, bottom, left.
279-
* </p>
280-
* <p>
281-
* Given points specify the line which lies on the border of the content area,
282-
* therefore the border itself should be drawn to the left from the drawing direction.
283-
* </p>
284-
* <p>
285-
* <code>borderWidthBefore</code> and <code>borderWidthAfter</code> parameters are used to
286-
* define the widths of the borders that are before and after the current border, e.g. for
287-
* the bottom border, <code>borderWidthBefore</code> specifies width of the right border and
288-
* <code>borderWidthAfter</code> - width of the left border. Those width are used to handle areas
289-
* of border joins.
290-
* </p>
291-
*
292-
* @param canvas PdfCanvas to be written to
293-
* @param x1 x coordinate of the beginning point of the element side, that should be bordered
294-
* @param y1 y coordinate of the beginning point of the element side, that should be bordered
295-
* @param x2 x coordinate of the ending point of the element side, that should be bordered
296-
* @param y2 y coordinate of the ending point of the element side, that should be bordered
297-
* @param borderRadius border radius
298-
* @param borderWidthBefore defines width of the border that is before the current one
299-
* @param borderWidthAfter defines width of the border that is after the current one
300-
* @deprecated Will be removed in 7.1.0. use {@link Border#draw(PdfCanvas, float, float, float, float, float, Side, float, float)} instead
301-
*/
302-
@Deprecated
303-
public abstract void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float borderRadius, float borderWidthBefore, float borderWidthAfter);
273+
public abstract void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float borderRadius, Side side, float borderWidthBefore, float borderWidthAfter);
304274

305275
/**
306276
* Draws the border of a cell.
@@ -410,8 +380,14 @@ public int hashCode() {
410380
* @param x2 the abscissa of the right-top point
411381
* @param y2 the ordinate of the right-top point
412382
* @return the corresponded {@link Side side}
383+
* @deprecated Will be removed in 7.1.0. use {@link Border#getBorderSide(float, float, float, float, Side)} instead
413384
*/
385+
@Deprecated
414386
protected Side getBorderSide(float x1, float y1, float x2, float y2) {
387+
return getBorderSide(x1, y1, x2, y2, tmpSide);
388+
}
389+
390+
protected Side getBorderSide(float x1, float y1, float x2, float y2, Side tempSide) {
415391
boolean isLeft = false;
416392
boolean isRight = false;
417393
if (Math.abs(y2 - y1) > 0.0005f) {
@@ -436,7 +412,7 @@ protected Side getBorderSide(float x1, float y1, float x2, float y2) {
436412
return Side.LEFT;
437413
}
438414

439-
return tmpSide;
415+
return tempSide;
440416
}
441417

442418
/**

layout/src/main/java/com/itextpdf/layout/border/Border3D.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float
207207
}
208208

209209
@Override
210-
public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float borderRadius, float borderWidthBefore, float borderWidthAfter) {
211-
// TODO
210+
public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float borderRadius, Side side, float borderWidthBefore, float borderWidthAfter) {
211+
draw(canvas, x1, y1, x2, y2, borderWidthBefore, borderWidthAfter);
212212
}
213213

214214
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public void drawCellBorder(PdfCanvas canvas, float x1, float y1, float x2, float
179179
}
180180

181181
@Override
182-
public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float outerRadius, float borderWidthBefore, float borderWidthAfter) {
182+
public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float outerRadius, Side side, float borderWidthBefore, float borderWidthAfter) {
183183
float curv = 0.447f;
184184
float initialGap = width * GAP_MODIFIER;
185185
float dash = width * DASH_MODIFIER;
@@ -209,7 +209,7 @@ public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float
209209
canvas.setLineDash(dash, adjustedGap, dash + adjustedGap / 2);
210210

211211
Point clipPoint1, clipPoint2, clipPoint;
212-
Border.Side borderSide = getBorderSide(x1, y1, x2, y2);
212+
Border.Side borderSide = getBorderSide(x1, y1, x2, y2, side);
213213
switch (borderSide) {
214214
case TOP:
215215
x0 -= borderWidthBefore / 2;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float
147147
}
148148

149149
@Override
150-
public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float outerRadius, float borderWidthBefore, float borderWidthAfter) {
150+
public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float outerRadius, Side side, float borderWidthBefore, float borderWidthAfter) {
151151
float curv = 0.447f;
152152
float initialGap = width * GAP_MODIFIER;
153153
float dx = x2 - x1;
@@ -176,7 +176,7 @@ public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float
176176
canvas.setLineDash(width, adjustedGap, width + adjustedGap / 2);
177177

178178
Point clipPoint1, clipPoint2, clipPoint;
179-
Border.Side borderSide = getBorderSide(x1, y1, x2, y2);
179+
Border.Side borderSide = getBorderSide(x1, y1, x2, y2, side);
180180
switch (borderSide) {
181181
case TOP:
182182
x0 -= borderWidthBefore / 2;

layout/src/main/java/com/itextpdf/layout/border/DoubleBorder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float
187187
}
188188

189189
@Override
190-
public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float borderRadius, float borderWidthBefore, float borderWidthAfter) {
191-
// TODO
190+
public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float borderRadius, Side side, float borderWidthBefore, float borderWidthAfter) {
191+
draw(canvas, x1, y1, x2, y2, borderWidthBefore, borderWidthAfter);
192192
}
193193

194194
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public void drawCellBorder(PdfCanvas canvas, float x1, float y1, float x2, float
170170
}
171171

172172
@Override
173-
public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float outerRadius, float borderWidthBefore, float borderWidthAfter) {
173+
public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float outerRadius, Side side, float borderWidthBefore, float borderWidthAfter) {
174174
float curv = 0.447f;
175175
float initialGap = width * GAP_MODIFIER;
176176
float dx = x2 - x1;
@@ -198,7 +198,7 @@ public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float
198198
.setLineDash(0, adjustedGap, adjustedGap / 2);
199199

200200
Point clipPoint1, clipPoint2, clipPoint;
201-
Border.Side borderSide = getBorderSide(x1, y1, x2, y2);
201+
Border.Side borderSide = getBorderSide(x1, y1, x2, y2, side);
202202
switch (borderSide) {
203203
case TOP:
204204
x0 -= borderWidthBefore / 2;

layout/src/main/java/com/itextpdf/layout/border/SolidBorder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,15 @@ public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float
135135
}
136136

137137
@Override
138-
public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float outerRadius, float borderWidthBefore, float borderWidthAfter) {
138+
public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float outerRadius, Side side, float borderWidthBefore, float borderWidthAfter) {
139139

140140
float innerRadiusBefore = Math.max(0, outerRadius - borderWidthBefore),
141141
innerRadius = Math.max(0, outerRadius - width),
142142
innerRadiusAfter = Math.max(0, outerRadius - borderWidthAfter);
143143
float x3 = 0, y3 = 0;
144144
float x4 = 0, y4 = 0;
145145

146-
Border.Side borderSide = getBorderSide(x1, y1, x2, y2);
146+
Border.Side borderSide = getBorderSide(x1, y1, x2, y2, side);
147147
switch (borderSide) {
148148
case TOP:
149149
x3 = x2 + borderWidthAfter;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ public void drawBorder(DrawContext drawContext) {
841841
canvas.openTag(new CanvasArtifact());
842842
}
843843

844-
boolean isAreaClipped = clipBorderArea(drawContext, applyMargins(occupiedArea.getBBox().clone(), getMargins(), true));
844+
boolean isAreaClipped = clipBorderArea(drawContext, applyMargins(occupiedArea.getBBox().clone(), getMargins(), false));
845845
UnitValue borderRadius = this.<UnitValue>getProperty(Property.BORDER_RADIUS);
846846
float radius = 0;
847847
if (null != borderRadius) {

0 commit comments

Comments
 (0)