@@ -42,7 +42,6 @@ This file is part of the iText (R) project.
42
42
*/
43
43
package com .itextpdf .html2pdf .css .apply .util ;
44
44
45
- import com .itextpdf .html2pdf .LogMessageConstant ;
46
45
import com .itextpdf .html2pdf .attach .ProcessorContext ;
47
46
import com .itextpdf .html2pdf .css .CssConstants ;
48
47
import com .itextpdf .html2pdf .css .util .CssUtils ;
@@ -62,7 +61,9 @@ This file is part of the iText (R) project.
62
61
*/
63
62
public final class WidthHeightApplierUtil {
64
63
65
- /** The logger. */
64
+ /**
65
+ * The logger.
66
+ */
66
67
private static final Logger logger = LoggerFactory .getLogger (WidthHeightApplierUtil .class );
67
68
68
69
/**
@@ -75,8 +76,8 @@ private WidthHeightApplierUtil() {
75
76
* Applies a width or a height to an element.
76
77
*
77
78
* @param cssProps the CSS properties
78
- * @param context the processor context
79
- * @param element the element
79
+ * @param context the processor context
80
+ * @param element the element
80
81
*/
81
82
public static void applyWidthHeight (Map <String , String > cssProps , ProcessorContext context , IPropertyContainer element ) {
82
83
float em = CssUtils .parseAbsoluteLength (cssProps .get (CssConstants .FONT_SIZE ));
@@ -109,53 +110,44 @@ public static void applyWidthHeight(Map<String, String> cssProps, ProcessorConte
109
110
if (!CssConstants .AUTO .equals (heightVal )) {
110
111
height = CssUtils .parseLengthValueToPt (heightVal , em , rem );
111
112
if (height != null ) {
112
- if (height .isPointValue ()) {
113
- // For tables, height does not have any effect. The height value will be used when
114
- // calculating effective min height value below
115
- if (!applyToTable && !applyToCell ) {
116
- element .setProperty (Property .HEIGHT , height .getValue ());
117
- }
118
- } else {
119
- logger .error (LogMessageConstant .HEIGHT_VALUE_IN_PERCENT_NOT_SUPPORTED );
113
+ // For tables, height does not have any effect. The height value will be used when
114
+ // calculating effective min height value below
115
+ if (!applyToTable && !applyToCell ) {
116
+ element .setProperty (Property .HEIGHT , height );
120
117
}
121
118
}
122
119
}
123
120
}
124
121
125
122
String maxHeightVal = cssProps .get (CssConstants .MAX_HEIGHT );
126
123
float maxHeightToApply = 0 ;
124
+ UnitValue maxHeight = new UnitValue (UnitValue .POINT , 0 );
127
125
if (maxHeightVal != null ) {
128
- UnitValue maxHeight = CssUtils .parseLengthValueToPt (maxHeightVal , em , rem );
126
+ maxHeight = CssUtils .parseLengthValueToPt (maxHeightVal , em , rem );
129
127
if (maxHeight != null ) {
130
- if (maxHeight .isPointValue ()) {
131
- // For tables and cells, max height does not have any effect. See also comments below when MIN_HEIGHT is applied.
132
- if (!applyToTable && !applyToCell ) {
133
- maxHeightToApply = maxHeight .getValue ();
134
- }
135
- } else {
136
- logger .error (LogMessageConstant .HEIGHT_VALUE_IN_PERCENT_NOT_SUPPORTED );
128
+ // For tables and cells, max height does not have any effect. See also comments below when MIN_HEIGHT is applied.
129
+ if (!applyToTable && !applyToCell ) {
130
+ maxHeightToApply = maxHeight .getValue ();
137
131
}
138
132
}
139
133
}
140
134
if (maxHeightToApply > 0 ) {
141
- element .setProperty (Property .MAX_HEIGHT , maxHeightToApply );
135
+ element .setProperty (Property .MAX_HEIGHT , maxHeight );
142
136
}
143
137
144
138
String minHeightVal = cssProps .get (CssConstants .MIN_HEIGHT );
145
139
float minHeightToApply = 0 ;
140
+ UnitValue minHeight = new UnitValue (UnitValue .POINT , 0 );
146
141
if (minHeightVal != null ) {
147
- UnitValue minHeight = CssUtils .parseLengthValueToPt (minHeightVal , em , rem );
142
+ minHeight = CssUtils .parseLengthValueToPt (minHeightVal , em , rem );
148
143
if (minHeight != null ) {
149
- if (minHeight .isPointValue ()) {
150
- // For cells, min height does not have any effect. See also comments below when MIN_HEIGHT is applied.
151
- if (!applyToCell ) {
152
- minHeightToApply = minHeight .getValue ();
153
- }
154
- } else {
155
- logger .error (LogMessageConstant .HEIGHT_VALUE_IN_PERCENT_NOT_SUPPORTED );
144
+ // For cells, min height does not have any effect. See also comments below when MIN_HEIGHT is applied.
145
+ if (!applyToCell ) {
146
+ minHeightToApply = minHeight .getValue ();
156
147
}
157
148
}
158
149
}
150
+
159
151
// About tables:
160
152
// The height of a table is given by the 'height' property for the 'table' or 'inline-table' element.
161
153
// A value of 'auto' means that the height is the sum of the row heights plus any cell spacing or borders.
@@ -165,11 +157,15 @@ public static void applyWidthHeight(Map<String, String> cssProps, ProcessorConte
165
157
// The height of a 'table-row' element's box is the maximum of the row's computed 'height', the computed 'height' of each cell in the row,
166
158
// and the minimum height (MIN) required by the cells. MIN depends on cell box heights and cell box alignment.
167
159
// In CSS 2.1, the height of a cell box is the minimum height required by the content.
168
- if ((applyToTable || applyToCell ) && height != null && height .isPointValue () && height . getValue () > minHeightToApply ) {
160
+ if ((applyToTable || applyToCell ) && height != null && height .getValue () > minHeightToApply ) {
169
161
minHeightToApply = height .getValue ();
170
- }
171
- if (minHeightToApply > 0 ) {
172
- element .setProperty (Property .MIN_HEIGHT , minHeightToApply );
162
+ if (minHeightToApply > 0 ) {
163
+ element .setProperty (Property .MIN_HEIGHT , height );
164
+ }
165
+ } else {
166
+ if (minHeightToApply > 0 ) {
167
+ element .setProperty (Property .MIN_HEIGHT , minHeight );
168
+ }
173
169
}
174
170
175
171
if (CssConstants .BORDER_BOX .equals (cssProps .get (CssConstants .BOX_SIZING ))) {
0 commit comments