@@ -58,6 +58,7 @@ This file is part of the iText (R) project.
5858import com .itextpdf .layout .border .OutsetBorder ;
5959import com .itextpdf .layout .border .RidgeBorder ;
6060import com .itextpdf .layout .border .SolidBorder ;
61+ import com .itextpdf .layout .property .BorderRadius ;
6162import com .itextpdf .layout .property .Property ;
6263import com .itextpdf .layout .property .UnitValue ;
6364import org .slf4j .Logger ;
@@ -69,8 +70,10 @@ This file is part of the iText (R) project.
6970 * Utilities class to apply border styles.
7071 */
7172public class BorderStyleApplierUtil {
72-
73- /** The logger. */
73+
74+ /**
75+ * The logger.
76+ */
7477 private static final Logger LOGGER = LoggerFactory .getLogger (BorderStyleApplierUtil .class );
7578
7679 /**
@@ -83,8 +86,8 @@ private BorderStyleApplierUtil() {
8386 * Applies borders to an element.
8487 *
8588 * @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
8891 */
8992 public static void applyBorders (Map <String , String > cssProps , ProcessorContext context , IPropertyContainer element ) {
9093 float em = CssUtils .parseAbsoluteLength (cssProps .get (CssConstants .FONT_SIZE ));
@@ -102,23 +105,35 @@ public static void applyBorders(Map<String, String> cssProps, ProcessorContext c
102105 if (bordersArray [2 ] != null ) {
103106 element .setProperty (Property .BORDER_BOTTOM , bordersArray [2 ]);
104107 }
105-
108+
106109 if (bordersArray [3 ] != null ) {
107110 element .setProperty (Property .BORDER_LEFT , bordersArray [3 ]);
108111 }
109112
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 ]);
113128 }
114129 }
115-
130+
116131 /**
117132 * Gets the array that defines the borders.
118133 *
119134 * @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
122137 * @return the borders array
123138 */
124139 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
130145 Border rightBorder = getCertainBorder (styles .get (CssConstants .BORDER_RIGHT_WIDTH ),
131146 styles .get (CssConstants .BORDER_RIGHT_STYLE ), getSpecificBorderColorOrDefaultColor (styles , CssConstants .BORDER_RIGHT_COLOR ), em , rem );
132147 borders [1 ] = rightBorder ;
133-
148+
134149 Border bottomBorder = getCertainBorder (styles .get (CssConstants .BORDER_BOTTOM_WIDTH ),
135150 styles .get (CssConstants .BORDER_BOTTOM_STYLE ), getSpecificBorderColorOrDefaultColor (styles , CssConstants .BORDER_BOTTOM_COLOR ), em , rem );
136151 borders [2 ] = bottomBorder ;
137152
138153 Border leftBorder = getCertainBorder (styles .get (CssConstants .BORDER_LEFT_WIDTH ),
139154 styles .get (CssConstants .BORDER_LEFT_STYLE ), getSpecificBorderColorOrDefaultColor (styles , CssConstants .BORDER_LEFT_COLOR ), em , rem );
140155 borders [3 ] = leftBorder ;
141-
156+
142157 return borders ;
143158 }
144159
@@ -148,8 +163,8 @@ public static Border[] getBordersArray(Map<String, String> styles, float em, flo
148163 * @param borderWidth the border width
149164 * @param borderStyle the border style
150165 * @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
153168 * @return the border
154169 */
155170 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
194209 } else {
195210 opacity = 0f ;
196211 }
197- } else if (CssConstants .GROOVE .equals (borderStyle ) || CssConstants .RIDGE .equals (borderStyle )
212+ } else if (CssConstants .GROOVE .equals (borderStyle ) || CssConstants .RIDGE .equals (borderStyle )
198213 || CssConstants .INSET .equals (borderStyle ) || CssConstants .OUTSET .equals (borderStyle )) {
199214 color = new DeviceRgb (212 , 208 , 200 );
200215 }
@@ -235,10 +250,49 @@ public static Border getCertainBorder(String borderWidth, String borderStyle, St
235250 * Gets the array that defines the borders.
236251 *
237252 * @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
240292 * @return the borders array
293+ * @deprecated use {@link #getBorderRadiiArray(Map, float, float)} instead
241294 */
295+ @ Deprecated
242296 public static UnitValue getBorderRadius (Map <String , String > styles , float em , float rem ) {
243297 String borderRadius = styles .get (CssConstants .BORDER_RADIUS );
244298 return CssUtils .parseLengthValueToPt (borderRadius , em , rem );
0 commit comments