@@ -42,7 +42,6 @@ This file is part of the iText (R) project.
4242 */
4343package com .itextpdf .html2pdf .css .apply .util ;
4444
45- import com .itextpdf .html2pdf .LogMessageConstant ;
4645import com .itextpdf .html2pdf .attach .ProcessorContext ;
4746import com .itextpdf .html2pdf .css .CssConstants ;
4847import com .itextpdf .html2pdf .css .util .CssUtils ;
@@ -62,7 +61,9 @@ This file is part of the iText (R) project.
6261 */
6362public final class WidthHeightApplierUtil {
6463
65- /** The logger. */
64+ /**
65+ * The logger.
66+ */
6667 private static final Logger logger = LoggerFactory .getLogger (WidthHeightApplierUtil .class );
6768
6869 /**
@@ -75,8 +76,8 @@ private WidthHeightApplierUtil() {
7576 * Applies a width or a height to an element.
7677 *
7778 * @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
8081 */
8182 public static void applyWidthHeight (Map <String , String > cssProps , ProcessorContext context , IPropertyContainer element ) {
8283 float em = CssUtils .parseAbsoluteLength (cssProps .get (CssConstants .FONT_SIZE ));
@@ -109,53 +110,44 @@ public static void applyWidthHeight(Map<String, String> cssProps, ProcessorConte
109110 if (!CssConstants .AUTO .equals (heightVal )) {
110111 height = CssUtils .parseLengthValueToPt (heightVal , em , rem );
111112 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 );
120117 }
121118 }
122119 }
123120 }
124121
125122 String maxHeightVal = cssProps .get (CssConstants .MAX_HEIGHT );
126123 float maxHeightToApply = 0 ;
124+ UnitValue maxHeight = new UnitValue (UnitValue .POINT , 0 );
127125 if (maxHeightVal != null ) {
128- UnitValue maxHeight = CssUtils .parseLengthValueToPt (maxHeightVal , em , rem );
126+ maxHeight = CssUtils .parseLengthValueToPt (maxHeightVal , em , rem );
129127 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 ();
137131 }
138132 }
139133 }
140134 if (maxHeightToApply > 0 ) {
141- element .setProperty (Property .MAX_HEIGHT , maxHeightToApply );
135+ element .setProperty (Property .MAX_HEIGHT , maxHeight );
142136 }
143137
144138 String minHeightVal = cssProps .get (CssConstants .MIN_HEIGHT );
145139 float minHeightToApply = 0 ;
140+ UnitValue minHeight = new UnitValue (UnitValue .POINT , 0 );
146141 if (minHeightVal != null ) {
147- UnitValue minHeight = CssUtils .parseLengthValueToPt (minHeightVal , em , rem );
142+ minHeight = CssUtils .parseLengthValueToPt (minHeightVal , em , rem );
148143 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 ();
156147 }
157148 }
158149 }
150+
159151 // About tables:
160152 // The height of a table is given by the 'height' property for the 'table' or 'inline-table' element.
161153 // 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
165157 // 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,
166158 // and the minimum height (MIN) required by the cells. MIN depends on cell box heights and cell box alignment.
167159 // 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 ) {
169161 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+ }
173169 }
174170
175171 if (CssConstants .BORDER_BOX .equals (cssProps .get (CssConstants .BOX_SIZING ))) {
0 commit comments