@@ -42,23 +42,32 @@ This file is part of the iText (R) project.
4242 */
4343package com .itextpdf .html2pdf .css .apply .util ;
4444
45+ import com .itextpdf .html2pdf .LogMessageConstant ;
4546import com .itextpdf .html2pdf .attach .ProcessorContext ;
4647import com .itextpdf .html2pdf .css .CssConstants ;
48+ import com .itextpdf .io .util .MessageFormatUtil ;
4749import com .itextpdf .layout .IPropertyContainer ;
4850import com .itextpdf .layout .property .AlignmentPropertyValue ;
4951import com .itextpdf .layout .property .JustifyContent ;
5052import com .itextpdf .layout .property .Property ;
5153import com .itextpdf .layout .property .UnitValue ;
5254import com .itextpdf .styledxmlparser .css .CommonCssConstants ;
5355import com .itextpdf .styledxmlparser .css .util .CssDimensionParsingUtils ;
56+ import org .slf4j .Logger ;
57+ import org .slf4j .LoggerFactory ;
5458
59+ import java .util .HashMap ;
60+ import java .util .HashSet ;
5561import java .util .Map ;
62+ import java .util .Set ;
5663
5764/**
5865 * Utilities class to apply flex properties.
5966 */
6067final public class FlexApplierUtil {
6168
69+ private static final Logger LOGGER = LoggerFactory .getLogger (FlexApplierUtil .class );
70+
6271 private FlexApplierUtil () {
6372 }
6473
@@ -72,6 +81,9 @@ private FlexApplierUtil() {
7281 public static void applyFlexItemProperties (Map <String , String > cssProps , ProcessorContext context ,
7382 IPropertyContainer element ) {
7483 element .setProperty (Property .COLLAPSING_MARGINS , null );
84+
85+ logWarningIfThereAreNotSupportedPropertyValues (createSupportedFlexItemPropertiesAndValuesMap (), cssProps );
86+
7587 final String flexGrow = cssProps .get (CommonCssConstants .FLEX_GROW );
7688 if (flexGrow != null ) {
7789 final Float flexGrowValue = CssDimensionParsingUtils .parseFloat (flexGrow );
@@ -106,6 +118,8 @@ public static void applyFlexItemProperties(Map<String, String> cssProps, Process
106118 } else {
107119 // The case when we don't set the flex-basis property should be identified
108120 // as flex-basis: content
121+ LOGGER .warn (MessageFormatUtil .format (LogMessageConstant .FLEX_PROPERTY_IS_NOT_SUPPORTED_YET ,
122+ CommonCssConstants .FLEX_BASIS , CommonCssConstants .CONTENT ));
109123 }
110124 }
111125
@@ -116,6 +130,7 @@ public static void applyFlexItemProperties(Map<String, String> cssProps, Process
116130 * @param element the element
117131 */
118132 public static void applyFlexContainerProperties (Map <String , String > cssProps , IPropertyContainer element ) {
133+ logWarningIfThereAreNotSupportedPropertyValues (createSupportedFlexContainerPropertiesAndValuesMap (), cssProps );
119134 applyAlignItems (cssProps , element );
120135 applyJustifyContent (cssProps , element );
121136 }
@@ -149,11 +164,12 @@ private static void applyAlignItems(Map<String, String> cssProps, IPropertyConta
149164 case CommonCssConstants .SELF_END :
150165 alignItems = AlignmentPropertyValue .SELF_END ;
151166 break ;
152- case CommonCssConstants .BASELINE :
153- alignItems = AlignmentPropertyValue .BASELINE ;
154- break ;
155167 case CommonCssConstants .STRETCH :
168+ alignItems = AlignmentPropertyValue .STRETCH ;
169+ break ;
156170 default :
171+ LOGGER .warn (MessageFormatUtil .format (LogMessageConstant .FLEX_PROPERTY_IS_NOT_SUPPORTED_YET ,
172+ CommonCssConstants .ALIGN_ITEMS , alignItemsString ));
157173 alignItems = AlignmentPropertyValue .STRETCH ;
158174 break ;
159175 }
@@ -193,12 +209,79 @@ private static void applyJustifyContent(Map<String, String> cssProps, IPropertyC
193209 case CommonCssConstants .CENTER :
194210 justifyContent = JustifyContent .CENTER ;
195211 break ;
212+ case CommonCssConstants .STRETCH :
213+ justifyContent = JustifyContent .STRETCH ;
214+ break ;
196215 case CommonCssConstants .FLEX_START :
216+ justifyContent = JustifyContent .FLEX_START ;
217+ break ;
197218 default :
219+ LOGGER .warn (MessageFormatUtil .format (LogMessageConstant .FLEX_PROPERTY_IS_NOT_SUPPORTED_YET ,
220+ CommonCssConstants .JUSTIFY_CONTENT , justifyContentString ));
198221 justifyContent = JustifyContent .FLEX_START ;
199222 break ;
200223 }
201224 element .setProperty (Property .JUSTIFY_CONTENT , justifyContent );
202225 }
203226 }
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+ }
204287}
0 commit comments