Skip to content

Commit 8b1afc0

Browse files
committed
Initial border-radius support.
Support one common border-radius property. Support different border-colors and border-widths. DEVSIX-1311
1 parent 28bdf7f commit 8b1afc0

File tree

11 files changed

+990
-144
lines changed

11 files changed

+990
-144
lines changed

io/src/main/java/com/itextpdf/io/LogMessageConstant.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public final class LogMessageConstant {
9696
public static final String ONE_OF_GROUPED_SOURCES_CLOSING_FAILED = "Closing of one of the grouped sources failed.";
9797
public static final String ONLY_ONE_OF_ARTBOX_OR_TRIMBOX_CAN_EXIST_IN_THE_PAGE = "Only one of artbox or trimbox can exist on the page. The trimbox will be deleted";
9898
public static final String PDF_OBJECT_FLUSHING_NOT_PERFORMED = "PdfObject flushing is not performed: PdfDocument is opened in append mode and the object is not marked as modified ( see PdfObject#setModified() ).";
99+
public static final String PROPERTY_IN_PERCENTS_NOT_SUPPORTED = "Property {0} in percents is not supported";
99100
public static final String RECTANGLE_HAS_NEGATIVE_SIZE = "The {0} rectangle has negative size. It will not be displayed.";
100101
public static final String RECTANGLE_HAS_NEGATIVE_OR_ZERO_SIZES = "The {0} rectangle has negative or zero sizes. It will not be displayed.";
101102
public static final String REGISTERING_DIRECTORY = "Registering directory";

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

Lines changed: 102 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -58,52 +58,62 @@ public abstract class Border {
5858
public static final Border NO_BORDER = null;
5959
/**
6060
* The solid border.
61+
*
6162
* @see SolidBorder
6263
*/
6364
public static final int SOLID = 0;
6465
/**
6566
* The dashed border.
67+
*
6668
* @see DashedBorder
6769
*/
6870
public static final int DASHED = 1;
6971
/**
7072
* The dotted border.
73+
*
7174
* @see DottedBorder
7275
*/
7376
public static final int DOTTED = 2;
7477
/**
7578
* The double border.
79+
*
7680
* @see DoubleBorder
7781
*/
7882
public static final int DOUBLE = 3;
7983
/**
8084
* The round-dots border.
85+
*
8186
* @see RoundDotsBorder
8287
*/
8388
public static final int ROUND_DOTS = 4;
8489
/**
8590
* The 3D groove border.
91+
*
8692
* @see GrooveBorder
8793
*/
8894
public static final int _3D_GROOVE = 5;
8995
/**
9096
* The 3D inset border.
97+
*
9198
* @see InsetBorder
9299
*/
93100
public static final int _3D_INSET = 6;
94101
/**
95102
* The 3D outset border.
103+
*
96104
* @see OutsetBorder
97105
*/
98106
public static final int _3D_OUTSET = 7;
99107
/**
100108
* The 3D ridge border.
109+
*
101110
* @see RidgeBorder
102111
*/
103112
public static final int _3D_RIDGE = 8;
104113

105114
/**
106115
* The color of the border.
116+
*
107117
* @see Color
108118
* @deprecated use {@link Border#transparentColor} instead
109119
*/
@@ -112,6 +122,7 @@ public abstract class Border {
112122

113123
/**
114124
* The color of the border.
125+
*
115126
* @see TransparentColor
116127
*/
117128
protected TransparentColor transparentColor;
@@ -156,16 +167,16 @@ protected Border(Color color, float width) {
156167
/**
157168
* Creates a {@link Border border} with given width, {@link Color color} and opacity.
158169
*
159-
* @param color the color which the border should have
160-
* @param width the width which the border should have
170+
* @param color the color which the border should have
171+
* @param width the width which the border should have
161172
* @param opacity the opacity which border should have; a float between 0 and 1, where 1 stands for fully opaque color and 0 - for fully transparent
162173
*/
163174
protected Border(Color color, float width, float opacity) {
164175
this.color = color;
165176
this.transparentColor = new TransparentColor(color, opacity);
166177
this.width = width;
167178
}
168-
179+
169180
/**
170181
* <p>
171182
* All borders are supposed to be drawn in such way, that inner content of the element is on the right from the
@@ -182,14 +193,14 @@ protected Border(Color color, float width, float opacity) {
182193
* <code>borderWidthAfter</code> - width of the left border. Those width are used to handle areas
183194
* of border joins.
184195
* </p>
185-
* @param canvas PdfCanvas to be written to
186-
* @param x1 x coordinate of the beginning point of the element side, that should be bordered
187-
* @param y1 y coordinate of the beginning point of the element side, that should be bordered
188-
* @param x2 x coordinate of the ending point of the element side, that should be bordered
189-
* @param y2 y coordinate of the ending point of the element side, that should be bordered
190-
* @param borderWidthBefore defines width of the border that is before the current one
191-
* @param borderWidthAfter defines width of the border that is after the current one
192196
*
197+
* @param canvas PdfCanvas to be written to
198+
* @param x1 x coordinate of the beginning point of the element side, that should be bordered
199+
* @param y1 y coordinate of the beginning point of the element side, that should be bordered
200+
* @param x2 x coordinate of the ending point of the element side, that should be bordered
201+
* @param y2 y coordinate of the ending point of the element side, that should be bordered
202+
* @param borderWidthBefore defines width of the border that is before the current one
203+
* @param borderWidthAfter defines width of the border that is after the current one
193204
* @deprecated Will be removed in 7.1.0. use {@link Border#draw(PdfCanvas, float, float, float, float, Side, float, float)} instead
194205
*/
195206
@Deprecated
@@ -211,29 +222,93 @@ protected Border(Color color, float width, float opacity) {
211222
* <code>borderWidthAfter</code> - width of the left border. Those width are used to handle areas
212223
* of border joins.
213224
* </p>
214-
* @param canvas PdfCanvas to be written to
215-
* @param x1 x coordinate of the beginning point of the element side, that should be bordered
216-
* @param y1 y coordinate of the beginning point of the element side, that should be bordered
217-
* @param x2 x coordinate of the ending point of the element side, that should be bordered
218-
* @param y2 y coordinate of the ending point of the element side, that should be bordered
219-
* @param side the {@link Border.Side}, that represents element side, that should be bordered
225+
*
226+
* @param canvas PdfCanvas to be written to
227+
* @param x1 x coordinate of the beginning point of the element side, that should be bordered
228+
* @param y1 y coordinate of the beginning point of the element side, that should be bordered
229+
* @param x2 x coordinate of the ending point of the element side, that should be bordered
230+
* @param y2 y coordinate of the ending point of the element side, that should be bordered
231+
* @param side the {@link Border.Side}, that represents element side, that should be bordered
220232
* @param borderWidthBefore defines width of the border that is before the current one
221-
* @param borderWidthAfter defines width of the border that is after the current one
233+
* @param borderWidthAfter defines width of the border that is after the current one
222234
*/
223235
public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, Side side, float borderWidthBefore, float borderWidthAfter) {
224236
tmpSide = side;
225237
draw(canvas, x1, y1, x2, y2, borderWidthBefore, borderWidthAfter);
226238
tmpSide = Side.NONE;
227239
}
228240

241+
/**
242+
* <p>
243+
* All borders are supposed to be drawn in such way, that inner content of the element is on the right from the
244+
* drawing direction. Borders are drawn in this order: top, right, bottom, left.
245+
* </p>
246+
* <p>
247+
* Given points specify the line which lies on the border of the content area,
248+
* therefore the border itself should be drawn to the left from the drawing direction.
249+
* </p>
250+
* <p>
251+
* <code>borderWidthBefore</code> and <code>borderWidthAfter</code> parameters are used to
252+
* define the widths of the borders that are before and after the current border, e.g. for
253+
* the bottom border, <code>borderWidthBefore</code> specifies width of the right border and
254+
* <code>borderWidthAfter</code> - width of the left border. Those width are used to handle areas
255+
* of border joins.
256+
* </p>
257+
*
258+
* @param canvas PdfCanvas to be written to
259+
* @param x1 x coordinate of the beginning point of the element side, that should be bordered
260+
* @param y1 y coordinate of the beginning point of the element side, that should be bordered
261+
* @param x2 x coordinate of the ending point of the element side, that should be bordered
262+
* @param y2 y coordinate of the ending point of the element side, that should be bordered
263+
* @param borderRadius border radius
264+
* @param side the {@link Border.Side}, that represents element side, that should be bordered
265+
* @param borderWidthBefore defines width of the border that is before the current one
266+
* @param borderWidthAfter defines width of the border that is after the current one
267+
*/
268+
public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float borderRadius, Side side, float borderWidthBefore, float borderWidthAfter) {
269+
tmpSide = side;
270+
draw(canvas, x1, y1, x2, y2, borderRadius, borderWidthBefore, borderWidthAfter);
271+
tmpSide = Side.NONE;
272+
}
273+
274+
/**
275+
* <p>
276+
* All borders are supposed to be drawn in such way, that inner content of the element is on the right from the
277+
* drawing direction. Borders are drawn in this order: top, right, bottom, left.
278+
* </p>
279+
* <p>
280+
* Given points specify the line which lies on the border of the content area,
281+
* therefore the border itself should be drawn to the left from the drawing direction.
282+
* </p>
283+
* <p>
284+
* <code>borderWidthBefore</code> and <code>borderWidthAfter</code> parameters are used to
285+
* define the widths of the borders that are before and after the current border, e.g. for
286+
* the bottom border, <code>borderWidthBefore</code> specifies width of the right border and
287+
* <code>borderWidthAfter</code> - width of the left border. Those width are used to handle areas
288+
* of border joins.
289+
* </p>
290+
*
291+
* @param canvas PdfCanvas to be written to
292+
* @param x1 x coordinate of the beginning point of the element side, that should be bordered
293+
* @param y1 y coordinate of the beginning point of the element side, that should be bordered
294+
* @param x2 x coordinate of the ending point of the element side, that should be bordered
295+
* @param y2 y coordinate of the ending point of the element side, that should be bordered
296+
* @param borderRadius border radius
297+
* @param borderWidthBefore defines width of the border that is before the current one
298+
* @param borderWidthAfter defines width of the border that is after the current one
299+
* @deprecated Will be removed in 7.1.0. use {@link Border#draw(PdfCanvas, float, float, float, float, float, Side, float, float)} instead
300+
*/
301+
@Deprecated
302+
public abstract void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float borderRadius, float borderWidthBefore, float borderWidthAfter);
303+
229304
/**
230305
* Draws the border of a cell.
231306
*
232307
* @param canvas PdfCanvas to be written to
233-
* @param x1 x coordinate of the beginning point of the element side, that should be bordered
234-
* @param y1 y coordinate of the beginning point of the element side, that should be bordered
235-
* @param x2 x coordinate of the ending point of the element side, that should be bordered
236-
* @param y2 y coordinate of the ending point of the element side, that should be bordered
308+
* @param x1 x coordinate of the beginning point of the element side, that should be bordered
309+
* @param y1 y coordinate of the beginning point of the element side, that should be bordered
310+
* @param x2 x coordinate of the ending point of the element side, that should be bordered
311+
* @param y2 y coordinate of the ending point of the element side, that should be bordered
237312
*/
238313
public abstract void drawCellBorder(PdfCanvas canvas, float x1, float y1, float x2, float y2);
239314

@@ -253,7 +328,7 @@ public Color getColor() {
253328

254329
/**
255330
* Gets the opacity of the {@link Border border}
256-
*
331+
*
257332
* @return the border opacity; a float between 0 and 1, where 1 stands for fully opaque color and 0 - for fully transparent
258333
*/
259334
public float getOpacity() {
@@ -345,13 +420,13 @@ protected Side getBorderSide(float x1, float y1, float x2, float y2) {
345420

346421
boolean isTop = false;
347422
boolean isBottom = false;
348-
if (Math.abs(x2-x1) > 0.0005f) {
423+
if (Math.abs(x2 - x1) > 0.0005f) {
349424
isTop = x2 - x1 > 0;
350425
isBottom = x2 - x1 < 0;
351426
}
352427

353428
if (isTop) {
354-
return Side.TOP;
429+
return isLeft ? Side.LEFT : Side.TOP;
355430
} else if (isRight) {
356431
return Side.RIGHT;
357432
} else if (isBottom) {
@@ -368,5 +443,7 @@ protected Side getBorderSide(float x1, float y1, float x2, float y2) {
368443
* The rectangle sides are expected to be parallel to corresponding page sides
369444
* Otherwise the result is Side.NONE
370445
*/
371-
public enum Side {NONE, TOP, RIGHT, BOTTOM, LEFT}
446+
public enum Side {
447+
NONE, TOP, RIGHT, BOTTOM, LEFT
448+
}
372449
}

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ protected Border3D(DeviceGray color, float width) {
101101
/**
102102
* Creates a Border3D instance with the specified width, color and opacity.
103103
*
104-
* @param color color of the border
105-
* @param width width of the border
104+
* @param color color of the border
105+
* @param width width of the border
106106
* @param opacity opacity of the border
107107
*/
108108
protected Border3D(DeviceRgb color, float width, float opacity) {
@@ -112,8 +112,8 @@ protected Border3D(DeviceRgb color, float width, float opacity) {
112112
/**
113113
* Creates a Border3D instance with the specified width, color and opacity.
114114
*
115-
* @param color color of the border
116-
* @param width width of the border
115+
* @param color color of the border
116+
* @param width width of the border
117117
* @param opacity opacity of the border
118118
*/
119119
protected Border3D(DeviceCmyk color, float width, float opacity) {
@@ -123,8 +123,8 @@ protected Border3D(DeviceCmyk color, float width, float opacity) {
123123
/**
124124
* Creates a Border3D instance with the specified width, color and opacity.
125125
*
126-
* @param color color of the border
127-
* @param width width of the border
126+
* @param color color of the border
127+
* @param width width of the border
128128
* @param opacity opacity of the border
129129
*/
130130
protected Border3D(DeviceGray color, float width, float opacity) {
@@ -206,6 +206,11 @@ public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float
206206
canvas.restoreState();
207207
}
208208

209+
@Override
210+
public void draw(PdfCanvas canvas, float x1, float y1, float x2, float y2, float borderRadius, float borderWidthBefore, float borderWidthAfter) {
211+
// TODO
212+
}
213+
209214
/**
210215
* {@inheritDoc}
211216
*/
@@ -242,15 +247,15 @@ else if (color instanceof DeviceGray)
242247
* Sets the fill color for the inner half of {@link Border3D 3D Border}
243248
*
244249
* @param canvas PdfCanvas the color will be applied on
245-
* @param side the {@link com.itextpdf.layout.border.Border.Side side} the color will be applied on
250+
* @param side the {@link com.itextpdf.layout.border.Border.Side side} the color will be applied on
246251
*/
247252
protected abstract void setInnerHalfColor(PdfCanvas canvas, Side side);
248253

249254
/**
250255
* Sets the fill color for the outer half of {@link Border3D 3D Border}
251256
*
252257
* @param canvas PdfCanvas the color will be applied on
253-
* @param side the {@link com.itextpdf.layout.border.Border.Side side} the color will be applied on
258+
* @param side the {@link com.itextpdf.layout.border.Border.Side side} the color will be applied on
254259
*/
255260
protected abstract void setOuterHalfColor(PdfCanvas canvas, Side side);
256261
}

0 commit comments

Comments
 (0)