@@ -58,6 +58,7 @@ This file is part of the iText (R) project.
58
58
import com .itextpdf .layout .border .OutsetBorder ;
59
59
import com .itextpdf .layout .border .RidgeBorder ;
60
60
import com .itextpdf .layout .border .SolidBorder ;
61
+ import com .itextpdf .layout .property .BorderRadius ;
61
62
import com .itextpdf .layout .property .Property ;
62
63
import com .itextpdf .layout .property .UnitValue ;
63
64
import org .slf4j .Logger ;
@@ -69,8 +70,10 @@ This file is part of the iText (R) project.
69
70
* Utilities class to apply border styles.
70
71
*/
71
72
public class BorderStyleApplierUtil {
72
-
73
- /** The logger. */
73
+
74
+ /**
75
+ * The logger.
76
+ */
74
77
private static final Logger LOGGER = LoggerFactory .getLogger (BorderStyleApplierUtil .class );
75
78
76
79
/**
@@ -83,8 +86,8 @@ private BorderStyleApplierUtil() {
83
86
* Applies borders to an element.
84
87
*
85
88
* @param cssProps the CSS properties
86
- * @param context the Processor context
87
- * @param element the element
89
+ * @param context the Processor context
90
+ * @param element the element
88
91
*/
89
92
public static void applyBorders (Map <String , String > cssProps , ProcessorContext context , IPropertyContainer element ) {
90
93
float em = CssUtils .parseAbsoluteLength (cssProps .get (CssConstants .FONT_SIZE ));
@@ -102,23 +105,35 @@ public static void applyBorders(Map<String, String> cssProps, ProcessorContext c
102
105
if (bordersArray [2 ] != null ) {
103
106
element .setProperty (Property .BORDER_BOTTOM , bordersArray [2 ]);
104
107
}
105
-
108
+
106
109
if (bordersArray [3 ] != null ) {
107
110
element .setProperty (Property .BORDER_LEFT , bordersArray [3 ]);
108
111
}
109
112
110
- UnitValue radius = getBorderRadius (cssProps , em , rem );
111
- if (null != radius ) {
112
- element .setProperty (Property .BORDER_RADIUS , radius );
113
+ BorderRadius [] borderRadii = getBorderRadiiArray (cssProps , em , rem );
114
+ if (borderRadii [0 ] != null ) {
115
+ element .setProperty (Property .BORDER_TOP_LEFT_RADIUS , borderRadii [0 ]);
116
+ }
117
+
118
+ if (borderRadii [1 ] != null ) {
119
+ element .setProperty (Property .BORDER_TOP_RIGHT_RADIUS , borderRadii [1 ]);
120
+ }
121
+
122
+ if (borderRadii [2 ] != null ) {
123
+ element .setProperty (Property .BORDER_BOTTOM_RIGHT_RADIUS , borderRadii [2 ]);
124
+ }
125
+
126
+ if (borderRadii [3 ] != null ) {
127
+ element .setProperty (Property .BORDER_BOTTOM_LEFT_RADIUS , borderRadii [3 ]);
113
128
}
114
129
}
115
-
130
+
116
131
/**
117
132
* Gets the array that defines the borders.
118
133
*
119
134
* @param styles the styles mapping
120
- * @param em the em value
121
- * @param rem the root em value
135
+ * @param em the em value
136
+ * @param rem the root em value
122
137
* @return the borders array
123
138
*/
124
139
public static Border [] getBordersArray (Map <String , String > styles , float em , float rem ) {
@@ -130,15 +145,15 @@ public static Border[] getBordersArray(Map<String, String> styles, float em, flo
130
145
Border rightBorder = getCertainBorder (styles .get (CssConstants .BORDER_RIGHT_WIDTH ),
131
146
styles .get (CssConstants .BORDER_RIGHT_STYLE ), getSpecificBorderColorOrDefaultColor (styles , CssConstants .BORDER_RIGHT_COLOR ), em , rem );
132
147
borders [1 ] = rightBorder ;
133
-
148
+
134
149
Border bottomBorder = getCertainBorder (styles .get (CssConstants .BORDER_BOTTOM_WIDTH ),
135
150
styles .get (CssConstants .BORDER_BOTTOM_STYLE ), getSpecificBorderColorOrDefaultColor (styles , CssConstants .BORDER_BOTTOM_COLOR ), em , rem );
136
151
borders [2 ] = bottomBorder ;
137
152
138
153
Border leftBorder = getCertainBorder (styles .get (CssConstants .BORDER_LEFT_WIDTH ),
139
154
styles .get (CssConstants .BORDER_LEFT_STYLE ), getSpecificBorderColorOrDefaultColor (styles , CssConstants .BORDER_LEFT_COLOR ), em , rem );
140
155
borders [3 ] = leftBorder ;
141
-
156
+
142
157
return borders ;
143
158
}
144
159
@@ -148,8 +163,8 @@ public static Border[] getBordersArray(Map<String, String> styles, float em, flo
148
163
* @param borderWidth the border width
149
164
* @param borderStyle the border style
150
165
* @param borderColor the border color
151
- * @param em the em value
152
- * @param rem the root em value
166
+ * @param em the em value
167
+ * @param rem the root em value
153
168
* @return the border
154
169
*/
155
170
public static Border getCertainBorder (String borderWidth , String borderStyle , String borderColor , float em , float rem ) {
@@ -194,7 +209,7 @@ public static Border getCertainBorder(String borderWidth, String borderStyle, St
194
209
} else {
195
210
opacity = 0f ;
196
211
}
197
- } else if (CssConstants .GROOVE .equals (borderStyle ) || CssConstants .RIDGE .equals (borderStyle )
212
+ } else if (CssConstants .GROOVE .equals (borderStyle ) || CssConstants .RIDGE .equals (borderStyle )
198
213
|| CssConstants .INSET .equals (borderStyle ) || CssConstants .OUTSET .equals (borderStyle )) {
199
214
color = new DeviceRgb (212 , 208 , 200 );
200
215
}
@@ -235,10 +250,49 @@ public static Border getCertainBorder(String borderWidth, String borderStyle, St
235
250
* Gets the array that defines the borders.
236
251
*
237
252
* @param styles the styles mapping
238
- * @param em the em value
239
- * @param rem the root em value
253
+ * @param em the em value
254
+ * @param rem the root em value
255
+ * @return the borders array
256
+ */
257
+ public static BorderRadius [] getBorderRadiiArray (Map <String , String > styles , float em , float rem ) {
258
+ BorderRadius [] borderRadii = new BorderRadius [4 ];
259
+
260
+ BorderRadius borderRadius = null ;
261
+ UnitValue borderRadiusUV = CssUtils .parseLengthValueToPt (styles .get (CssConstants .BORDER_RADIUS ), em , rem );
262
+ if (null != borderRadiusUV ) {
263
+ borderRadius = new BorderRadius (borderRadiusUV );
264
+ }
265
+
266
+ UnitValue [] borderTopLeftRadiusUV = CssUtils .parseSpecificCornerBorderRadius (styles .get (CssConstants .BORDER_TOP_LEFT_RADIUS ), em , rem );
267
+ borderRadii [0 ] = null == borderTopLeftRadiusUV
268
+ ? borderRadius
269
+ : new BorderRadius (borderTopLeftRadiusUV [0 ], borderTopLeftRadiusUV [1 ]);
270
+ UnitValue [] borderTopRightRadiusUV = CssUtils .parseSpecificCornerBorderRadius (styles .get (CssConstants .BORDER_TOP_RIGHT_RADIUS ), em , rem );
271
+ borderRadii [1 ] = null == borderTopRightRadiusUV
272
+ ? borderRadius
273
+ : new BorderRadius (borderTopRightRadiusUV [0 ], borderTopRightRadiusUV [1 ]);
274
+ UnitValue [] borderBottomRightRadiusUV = CssUtils .parseSpecificCornerBorderRadius (styles .get (CssConstants .BORDER_BOTTOM_RIGHT_RADIUS ), em , rem );
275
+ borderRadii [2 ] = null == borderBottomRightRadiusUV
276
+ ? borderRadius
277
+ : new BorderRadius (borderBottomRightRadiusUV [0 ], borderBottomRightRadiusUV [1 ]);
278
+ UnitValue [] borderBottomLeftRadiusUV = CssUtils .parseSpecificCornerBorderRadius (styles .get (CssConstants .BORDER_BOTTOM_LEFT_RADIUS ), em , rem );
279
+ borderRadii [3 ] = null == borderBottomLeftRadiusUV
280
+ ? borderRadius
281
+ : new BorderRadius (borderBottomLeftRadiusUV [0 ], borderBottomLeftRadiusUV [1 ]);
282
+
283
+ return borderRadii ;
284
+ }
285
+
286
+ /**
287
+ * Gets the array that defines the borders.
288
+ *
289
+ * @param styles the styles mapping
290
+ * @param em the em value
291
+ * @param rem the root em value
240
292
* @return the borders array
293
+ * @deprecated use {@link #getBorderRadiiArray(Map, float, float)} instead
241
294
*/
295
+ @ Deprecated
242
296
public static UnitValue getBorderRadius (Map <String , String > styles , float em , float rem ) {
243
297
String borderRadius = styles .get (CssConstants .BORDER_RADIUS );
244
298
return CssUtils .parseLengthValueToPt (borderRadius , em , rem );
0 commit comments