@@ -492,7 +492,7 @@ public void drawBackground(DrawContext drawContext) {
492
492
Rectangle backgroundArea = applyMargins (bBox , false );
493
493
if (backgroundArea .getWidth () <= 0 || backgroundArea .getHeight () <= 0 ) {
494
494
Logger logger = LoggerFactory .getLogger (AbstractRenderer .class );
495
- logger .error (MessageFormatUtil .format (LogMessageConstant .RECTANGLE_HAS_NEGATIVE_OR_ZERO_SIZES , "background" ));
495
+ logger .warn (MessageFormatUtil .format (LogMessageConstant .RECTANGLE_HAS_NEGATIVE_OR_ZERO_SIZES , "background" ));
496
496
return ;
497
497
}
498
498
boolean backgroundAreaIsClipped = false ;
@@ -517,7 +517,7 @@ public void drawBackground(DrawContext drawContext) {
517
517
backgroundImage .getImage ().getWidth (), backgroundImage .getImage ().getHeight ());
518
518
if (imageRectangle .getWidth () <= 0 || imageRectangle .getHeight () <= 0 ) {
519
519
Logger logger = LoggerFactory .getLogger (AbstractRenderer .class );
520
- logger .error (MessageFormatUtil .format (LogMessageConstant .RECTANGLE_HAS_NEGATIVE_OR_ZERO_SIZES , "background-image" ));
520
+ logger .warn (MessageFormatUtil .format (LogMessageConstant .RECTANGLE_HAS_NEGATIVE_OR_ZERO_SIZES , "background-image" ));
521
521
return ;
522
522
}
523
523
applyBorderBox (backgroundArea , true );
@@ -991,26 +991,93 @@ static boolean isBorderBoxSizing(IRenderer renderer) {
991
991
992
992
/**
993
993
* Retrieves element's fixed content box width, if it's set.
994
- * Takes into account {@link Property#BOX_SIZING} property value.
994
+ * Takes into account {@link Property#BOX_SIZING}, {@link Property#MIN_WIDTH},
995
+ * and {@link Property#MAX_WIDTH} properties.
995
996
* @param parentBoxWidth width of the parent element content box.
996
997
* If element has relative width, it will be
997
998
* calculated relatively to this parameter.
998
999
* @return element's fixed content box width or null if it's not set.
1000
+ * @see AbstractRenderer#hasAbsoluteUnitValue(int)
999
1001
*/
1000
1002
protected Float retrieveWidth (float parentBoxWidth ) {
1003
+ Float minWidth = retrieveUnitValue (parentBoxWidth , Property .MIN_WIDTH );
1004
+
1005
+ Float maxWidth = retrieveUnitValue (parentBoxWidth , Property .MAX_WIDTH );
1006
+ if (maxWidth != null && minWidth != null && minWidth > maxWidth ) {
1007
+ maxWidth = minWidth ;
1008
+ }
1009
+
1001
1010
Float width = retrieveUnitValue (parentBoxWidth , Property .WIDTH );
1011
+ if (width != null ) {
1012
+ if (maxWidth != null ) {
1013
+ width = width > maxWidth ? maxWidth : width ;
1014
+ } else if (minWidth != null ) {
1015
+ width = width < minWidth ? minWidth : width ;
1016
+ }
1017
+ } else if (maxWidth != null ) {
1018
+ width = maxWidth < parentBoxWidth ? maxWidth : null ;
1019
+ }
1020
+
1002
1021
if (width != null && isBorderBoxSizing (this )) {
1003
- width = Math .max (0 , (float )width - calculatePaddingBorderWidth (this ));
1022
+ width -= calculatePaddingBorderWidth (this );
1023
+ }
1024
+
1025
+ return width != null ? Math .max (0 , (float ) width ) : null ;
1026
+ }
1027
+
1028
+ /**
1029
+ * Retrieves element's fixed content box max width, if it's set.
1030
+ * Takes into account {@link Property#BOX_SIZING} and {@link Property#MIN_WIDTH} properties.
1031
+ * @param parentBoxWidth width of the parent element content box.
1032
+ * If element has relative width, it will be
1033
+ * calculated relatively to this parameter.
1034
+ * @return element's fixed content box max width or null if it's not set.
1035
+ * @see AbstractRenderer#hasAbsoluteUnitValue(int)
1036
+ */
1037
+ protected Float retrieveMaxWidth (float parentBoxWidth ) {
1038
+ Float maxWidth = retrieveUnitValue (parentBoxWidth , Property .MAX_WIDTH );
1039
+ if (maxWidth != null ) {
1040
+ Float minWidth = retrieveUnitValue (parentBoxWidth , Property .MIN_WIDTH );
1041
+ if (minWidth != null && minWidth > maxWidth ) {
1042
+ maxWidth = minWidth ;
1043
+ }
1044
+
1045
+ if (isBorderBoxSizing (this )) {
1046
+ maxWidth -= calculatePaddingBorderWidth (this );
1047
+ }
1048
+ return maxWidth > 0 ? maxWidth : 0 ;
1049
+ } else {
1050
+ return null ;
1051
+ }
1052
+ }
1053
+
1054
+ /**
1055
+ * Retrieves element's fixed content box max width, if it's set.
1056
+ * Takes into account {@link Property#BOX_SIZING} property value.
1057
+ * @param parentBoxWidth width of the parent element content box.
1058
+ * If element has relative width, it will be
1059
+ * calculated relatively to this parameter.
1060
+ * @return element's fixed content box max width or null if it's not set.
1061
+ * @see AbstractRenderer#hasAbsoluteUnitValue(int)
1062
+ */
1063
+ protected Float retrieveMinWidth (float parentBoxWidth ) {
1064
+ Float minWidth = retrieveUnitValue (parentBoxWidth , Property .MIN_WIDTH );
1065
+ if (minWidth != null ) {
1066
+ if (isBorderBoxSizing (this )) {
1067
+ minWidth -= calculatePaddingBorderWidth (this );
1068
+ }
1069
+ return minWidth > 0 ? minWidth : 0 ;
1070
+ } else {
1071
+ return null ;
1004
1072
}
1005
- return width ;
1006
1073
}
1007
1074
1008
1075
/**
1009
1076
* Updates fixed content box width value for this renderer.
1010
1077
* Takes into account {@link Property#BOX_SIZING} property value.
1011
1078
* @param updatedWidthValue element's new fixed content box width.
1012
1079
*/
1013
- protected void updateWidth (UnitValue updatedWidthValue ) {
1080
+ void updateWidth (UnitValue updatedWidthValue ) {
1014
1081
if (updatedWidthValue .isPointValue () && isBorderBoxSizing (this )) {
1015
1082
updatedWidthValue .setValue (updatedWidthValue .getValue () + calculatePaddingBorderWidth (this ));
1016
1083
}
@@ -1035,7 +1102,7 @@ protected Float retrieveHeight() {
1035
1102
* Takes into account {@link Property#BOX_SIZING} property value.
1036
1103
* @param updatedHeightValue element's new fixed content box height, shall be not null.
1037
1104
*/
1038
- protected void updateHeight (Float updatedHeightValue ) {
1105
+ void updateHeight (Float updatedHeightValue ) {
1039
1106
if (isBorderBoxSizing (this )) {
1040
1107
updatedHeightValue += calculatePaddingBorderHeight (this );
1041
1108
}
@@ -1060,7 +1127,7 @@ protected Float retrieveMaxHeight() {
1060
1127
* Takes into account {@link Property#BOX_SIZING} property value.
1061
1128
* @param updatedMaxHeightValue element's new content box max-height, shall be not null.
1062
1129
*/
1063
- protected void updateMaxHeight (Float updatedMaxHeightValue ) {
1130
+ void updateMaxHeight (Float updatedMaxHeightValue ) {
1064
1131
if (isBorderBoxSizing (this )) {
1065
1132
updatedMaxHeightValue += calculatePaddingBorderHeight (this );
1066
1133
}
@@ -1085,7 +1152,7 @@ protected Float retrieveMinHeight() {
1085
1152
* Takes into account {@link Property#BOX_SIZING} property value.
1086
1153
* @param updatedMinHeightValue element's new content box min-height, shall be not null.
1087
1154
*/
1088
- protected void updateMinHeight (Float updatedMinHeightValue ) {
1155
+ void updateMinHeight (Float updatedMinHeightValue ) {
1089
1156
if (isBorderBoxSizing (this )) {
1090
1157
updatedMinHeightValue += calculatePaddingBorderHeight (this );
1091
1158
}
@@ -1095,12 +1162,11 @@ protected void updateMinHeight(Float updatedMinHeightValue) {
1095
1162
protected Float retrieveUnitValue (float basePercentValue , int property ) {
1096
1163
UnitValue value = this .<UnitValue >getProperty (property );
1097
1164
if (value != null ) {
1098
- if (value .getUnitType () == UnitValue .POINT ) {
1099
- return value .getValue ();
1100
- } else if (value .getUnitType () == UnitValue .PERCENT ) {
1165
+ if (value .getUnitType () == UnitValue .PERCENT ) {
1101
1166
return value .getValue () * basePercentValue / 100 ;
1102
1167
} else {
1103
- throw new IllegalStateException ("invalid unit type" );
1168
+ assert value .getUnitType () == UnitValue .POINT ;
1169
+ return value .getValue ();
1104
1170
}
1105
1171
} else {
1106
1172
return null ;
@@ -1346,12 +1412,15 @@ protected MinMaxWidth getMinMaxWidth(float availableWidth) {
1346
1412
}
1347
1413
1348
1414
protected boolean setMinMaxWidthBasedOnFixedWidth (MinMaxWidth minMaxWidth ) {
1349
- UnitValue widthProp = this .<UnitValue >getProperty (Property .WIDTH );
1350
- Float width = retrieveWidth (0 );
1351
- if (width != null && widthProp != null && !widthProp .isPercentValue ()) {
1352
- minMaxWidth .setChildrenMaxWidth ((float ) width );
1353
- minMaxWidth .setChildrenMinWidth ((float ) width );
1354
- return true ;
1415
+ // retrieve returns max width, if there is no width.
1416
+ if (hasAbsoluteUnitValue (Property .WIDTH )) {
1417
+ //Renderer may override retrieveWidth, double check is required.
1418
+ Float width = retrieveWidth (0 );
1419
+ if (width != null ) {
1420
+ minMaxWidth .setChildrenMaxWidth ((float ) width );
1421
+ minMaxWidth .setChildrenMinWidth ((float ) width );
1422
+ return true ;
1423
+ }
1355
1424
}
1356
1425
return false ;
1357
1426
}
@@ -1618,6 +1687,17 @@ protected void overrideHeightProperties() {
1618
1687
}
1619
1688
}
1620
1689
1690
+ /**
1691
+ * Check if corresponding property has point value.
1692
+ *
1693
+ * @param property {@link Property}
1694
+ * @return false if property value either null, or percent, otherwise true.
1695
+ */
1696
+ protected boolean hasAbsoluteUnitValue (int property ) {
1697
+ UnitValue value = this .<UnitValue >getProperty (property );
1698
+ return value != null && value .isPointValue ();
1699
+ }
1700
+
1621
1701
boolean isFirstOnRootArea () {
1622
1702
boolean isFirstOnRootArea = true ;
1623
1703
AbstractRenderer ancestor = this ;
0 commit comments