@@ -42,23 +42,32 @@ 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 ;
45
46
import com .itextpdf .html2pdf .attach .ProcessorContext ;
46
47
import com .itextpdf .html2pdf .css .CssConstants ;
48
+ import com .itextpdf .io .util .MessageFormatUtil ;
47
49
import com .itextpdf .layout .IPropertyContainer ;
48
50
import com .itextpdf .layout .property .AlignmentPropertyValue ;
49
51
import com .itextpdf .layout .property .JustifyContent ;
50
52
import com .itextpdf .layout .property .Property ;
51
53
import com .itextpdf .layout .property .UnitValue ;
52
54
import com .itextpdf .styledxmlparser .css .CommonCssConstants ;
53
55
import com .itextpdf .styledxmlparser .css .util .CssDimensionParsingUtils ;
56
+ import org .slf4j .Logger ;
57
+ import org .slf4j .LoggerFactory ;
54
58
59
+ import java .util .HashMap ;
60
+ import java .util .HashSet ;
55
61
import java .util .Map ;
62
+ import java .util .Set ;
56
63
57
64
/**
58
65
* Utilities class to apply flex properties.
59
66
*/
60
67
final public class FlexApplierUtil {
61
68
69
+ private static final Logger LOGGER = LoggerFactory .getLogger (FlexApplierUtil .class );
70
+
62
71
private FlexApplierUtil () {
63
72
}
64
73
@@ -72,6 +81,9 @@ private FlexApplierUtil() {
72
81
public static void applyFlexItemProperties (Map <String , String > cssProps , ProcessorContext context ,
73
82
IPropertyContainer element ) {
74
83
element .setProperty (Property .COLLAPSING_MARGINS , null );
84
+
85
+ logWarningIfThereAreNotSupportedPropertyValues (createSupportedFlexItemPropertiesAndValuesMap (), cssProps );
86
+
75
87
final String flexGrow = cssProps .get (CommonCssConstants .FLEX_GROW );
76
88
if (flexGrow != null ) {
77
89
final Float flexGrowValue = CssDimensionParsingUtils .parseFloat (flexGrow );
@@ -106,6 +118,8 @@ public static void applyFlexItemProperties(Map<String, String> cssProps, Process
106
118
} else {
107
119
// The case when we don't set the flex-basis property should be identified
108
120
// as flex-basis: content
121
+ LOGGER .warn (MessageFormatUtil .format (LogMessageConstant .FLEX_PROPERTY_IS_NOT_SUPPORTED_YET ,
122
+ CommonCssConstants .FLEX_BASIS , CommonCssConstants .CONTENT ));
109
123
}
110
124
}
111
125
@@ -116,6 +130,7 @@ public static void applyFlexItemProperties(Map<String, String> cssProps, Process
116
130
* @param element the element
117
131
*/
118
132
public static void applyFlexContainerProperties (Map <String , String > cssProps , IPropertyContainer element ) {
133
+ logWarningIfThereAreNotSupportedPropertyValues (createSupportedFlexContainerPropertiesAndValuesMap (), cssProps );
119
134
applyAlignItems (cssProps , element );
120
135
applyJustifyContent (cssProps , element );
121
136
}
@@ -149,11 +164,12 @@ private static void applyAlignItems(Map<String, String> cssProps, IPropertyConta
149
164
case CommonCssConstants .SELF_END :
150
165
alignItems = AlignmentPropertyValue .SELF_END ;
151
166
break ;
152
- case CommonCssConstants .BASELINE :
153
- alignItems = AlignmentPropertyValue .BASELINE ;
154
- break ;
155
167
case CommonCssConstants .STRETCH :
168
+ alignItems = AlignmentPropertyValue .STRETCH ;
169
+ break ;
156
170
default :
171
+ LOGGER .warn (MessageFormatUtil .format (LogMessageConstant .FLEX_PROPERTY_IS_NOT_SUPPORTED_YET ,
172
+ CommonCssConstants .ALIGN_ITEMS , alignItemsString ));
157
173
alignItems = AlignmentPropertyValue .STRETCH ;
158
174
break ;
159
175
}
@@ -193,12 +209,79 @@ private static void applyJustifyContent(Map<String, String> cssProps, IPropertyC
193
209
case CommonCssConstants .CENTER :
194
210
justifyContent = JustifyContent .CENTER ;
195
211
break ;
212
+ case CommonCssConstants .STRETCH :
213
+ justifyContent = JustifyContent .STRETCH ;
214
+ break ;
196
215
case CommonCssConstants .FLEX_START :
216
+ justifyContent = JustifyContent .FLEX_START ;
217
+ break ;
197
218
default :
219
+ LOGGER .warn (MessageFormatUtil .format (LogMessageConstant .FLEX_PROPERTY_IS_NOT_SUPPORTED_YET ,
220
+ CommonCssConstants .JUSTIFY_CONTENT , justifyContentString ));
198
221
justifyContent = JustifyContent .FLEX_START ;
199
222
break ;
200
223
}
201
224
element .setProperty (Property .JUSTIFY_CONTENT , justifyContent );
202
225
}
203
226
}
227
+
228
+ private static void logWarningIfThereAreNotSupportedPropertyValues (Map <String , Set <String >> supportedPairs ,
229
+ Map <String , String > cssProps ) {
230
+ for (Map .Entry <String , Set <String >> entry : supportedPairs .entrySet ()) {
231
+ String supportedPair = entry .getKey ();
232
+ Set <String > supportedValues = entry .getValue ();
233
+ String propertyValue = cssProps .get (supportedPair );
234
+ if (propertyValue != null && !supportedValues .contains (propertyValue )) {
235
+ LOGGER .warn (MessageFormatUtil .format (
236
+ LogMessageConstant .FLEX_PROPERTY_IS_NOT_SUPPORTED_YET , supportedPair , propertyValue ));
237
+ }
238
+ }
239
+ }
240
+
241
+ private static Map <String , Set <String >> createSupportedFlexItemPropertiesAndValuesMap () {
242
+ final Map <String , Set <String >> supportedPairs = new HashMap <>();
243
+
244
+ final Set <String > supportedAlignSelfValues = new HashSet <>();
245
+ supportedAlignSelfValues .add (CommonCssConstants .AUTO );
246
+
247
+ supportedPairs .put (CommonCssConstants .ALIGN_SELF , supportedAlignSelfValues );
248
+
249
+ final Set <String > supportedOrderValues = new HashSet <>();
250
+
251
+ supportedPairs .put (CommonCssConstants .ORDER , supportedOrderValues );
252
+
253
+ return supportedPairs ;
254
+ }
255
+
256
+ private static Map <String , Set <String >> createSupportedFlexContainerPropertiesAndValuesMap () {
257
+ final Map <String , Set <String >> supportedPairs = new HashMap <>();
258
+
259
+ final Set <String > supportedFlexDirectionValues = new HashSet <>();
260
+ supportedFlexDirectionValues .add (CommonCssConstants .ROW );
261
+
262
+ supportedPairs .put (CommonCssConstants .FLEX_DIRECTION , supportedFlexDirectionValues );
263
+
264
+ final Set <String > supportedFlexWrapValues = new HashSet <>();
265
+ supportedFlexWrapValues .add (CommonCssConstants .NOWRAP );
266
+
267
+ supportedPairs .put (CommonCssConstants .FLEX_WRAP , supportedFlexWrapValues );
268
+
269
+ final Set <String > supportedAlignContentValues = new HashSet <>();
270
+ supportedAlignContentValues .add (CommonCssConstants .STRETCH );
271
+ supportedAlignContentValues .add (CommonCssConstants .NORMAL );
272
+
273
+ supportedPairs .put (CommonCssConstants .ALIGN_CONTENT , supportedAlignContentValues );
274
+
275
+ final Set <String > supportedRowGapValues = new HashSet <>();
276
+ supportedRowGapValues .add (CommonCssConstants .NORMAL );
277
+
278
+ supportedPairs .put (CommonCssConstants .ROW_GAP , supportedRowGapValues );
279
+
280
+ final Set <String > supportedColumnGapValues = new HashSet <>();
281
+ supportedColumnGapValues .add (CommonCssConstants .NORMAL );
282
+
283
+ supportedPairs .put (CommonCssConstants .COLUMN_GAP , supportedColumnGapValues );
284
+
285
+ return supportedPairs ;
286
+ }
204
287
}
0 commit comments