diff --git a/pom.xml b/pom.xml
index 6f64128a6..fbba93088 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,12 +5,12 @@
com.itextpdfroot
- 8.0.4
+ 8.0.5html2pdf
- 5.0.4
+ 5.0.5pdfHTMLpdfHTML is an iText add-on that lets you to parse (X)HTML snippets and the associated CSS and converts
@@ -25,25 +25,6 @@
${project.parent.version}
-
-
-
- true
-
- itext-snapshot
- iText Repository - snapshots
- https://repo.itextsupport.com/snapshot
-
-
-
- false
-
- itext-releases
- iText Repository - releases
- https://repo.itextsupport.com/releases
-
-
-
com.itextpdf
@@ -79,6 +60,25 @@
+
+
+
+ true
+
+ itext-snapshot
+ iText Repository - snapshots
+ https://repo.itextsupport.com/snapshot
+
+
+
+ false
+
+ itext-releases
+ iText Repository - releases
+ https://repo.itextsupport.com/releases
+
+
+
diff --git a/src/main/java/com/itextpdf/html2pdf/actions/data/PdfHtmlProductData.java b/src/main/java/com/itextpdf/html2pdf/actions/data/PdfHtmlProductData.java
index d133a933a..fe8358ff6 100644
--- a/src/main/java/com/itextpdf/html2pdf/actions/data/PdfHtmlProductData.java
+++ b/src/main/java/com/itextpdf/html2pdf/actions/data/PdfHtmlProductData.java
@@ -30,7 +30,7 @@ This file is part of the iText (R) project.
*/
public final class PdfHtmlProductData {
private static final String PDF_HTML_PUBLIC_PRODUCT_NAME = "pdfHTML";
- private static final String PDF_HTML_VERSION = "5.0.4";
+ private static final String PDF_HTML_VERSION = "5.0.5";
private static final int PDF_HTML_COPYRIGHT_SINCE = 2000;
private static final int PDF_HTML_COPYRIGHT_TO = 2024;
diff --git a/src/main/java/com/itextpdf/html2pdf/attach/impl/DefaultTagWorkerMapping.java b/src/main/java/com/itextpdf/html2pdf/attach/impl/DefaultTagWorkerMapping.java
index a95c8ca20..47849498c 100644
--- a/src/main/java/com/itextpdf/html2pdf/attach/impl/DefaultTagWorkerMapping.java
+++ b/src/main/java/com/itextpdf/html2pdf/attach/impl/DefaultTagWorkerMapping.java
@@ -34,6 +34,7 @@ This file is part of the iText (R) project.
import com.itextpdf.html2pdf.attach.impl.tags.ColTagWorker;
import com.itextpdf.html2pdf.attach.impl.tags.ColgroupTagWorker;
import com.itextpdf.html2pdf.attach.impl.tags.DisplayFlexTagWorker;
+import com.itextpdf.html2pdf.attach.impl.tags.DisplayGridTagWorker;
import com.itextpdf.html2pdf.attach.impl.tags.DisplayTableRowTagWorker;
import com.itextpdf.html2pdf.attach.impl.tags.DisplayTableTagWorker;
import com.itextpdf.html2pdf.attach.impl.tags.DivTagWorker;
@@ -204,6 +205,8 @@ class DefaultTagWorkerMapping {
(lhs, rhs) -> new DisplayFlexTagWorker(lhs, rhs));
workerMapping.putMapping(TagConstants.SPAN, CssConstants.FLEX,
(lhs, rhs) -> new DisplayFlexTagWorker(lhs, rhs));
+ workerMapping.putMapping(TagConstants.DIV, CssConstants.GRID,
+ (lhs, rhs) -> new DisplayGridTagWorker(lhs, rhs));
// pseudo elements mapping
String beforePseudoElemName = CssPseudoElementUtil.createPseudoElementTagName(CssConstants.BEFORE);
diff --git a/src/main/java/com/itextpdf/html2pdf/attach/impl/tags/DisplayGridTagWorker.java b/src/main/java/com/itextpdf/html2pdf/attach/impl/tags/DisplayGridTagWorker.java
new file mode 100644
index 000000000..463a1daa8
--- /dev/null
+++ b/src/main/java/com/itextpdf/html2pdf/attach/impl/tags/DisplayGridTagWorker.java
@@ -0,0 +1,59 @@
+/*
+ This file is part of the iText (R) project.
+ Copyright (c) 1998-2024 Apryse Group NV
+ Authors: Apryse Software.
+
+ This program is offered under a commercial and under the AGPL license.
+ For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
+
+ AGPL licensing:
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+ */
+package com.itextpdf.html2pdf.attach.impl.tags;
+
+import com.itextpdf.html2pdf.attach.ITagWorker;
+import com.itextpdf.html2pdf.attach.ProcessorContext;
+import com.itextpdf.layout.IPropertyContainer;
+import com.itextpdf.layout.element.GridContainer;
+import com.itextpdf.layout.element.IElement;
+import com.itextpdf.styledxmlparser.node.IElementNode;
+
+/**
+ * {@link ITagWorker} implementation for elements with {@code display: grid}.
+ */
+public class DisplayGridTagWorker extends DivTagWorker {
+
+ /**
+ * Creates a new {@link DisplayGridTagWorker} instance.
+ *
+ * @param element the element
+ * @param context the context
+ */
+ public DisplayGridTagWorker(IElementNode element, ProcessorContext context) {
+ super(element, context, new GridContainer());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean processTagChild(ITagWorker childTagWorker, ProcessorContext context) {
+ final IPropertyContainer element = childTagWorker.getElementResult();
+ if (childTagWorker instanceof BrTagWorker) {
+ return super.processTagChild(childTagWorker, context);
+ } else {
+ return addBlockChild((IElement) element);
+ }
+ }
+}
diff --git a/src/main/java/com/itextpdf/html2pdf/attach/impl/tags/DivTagWorker.java b/src/main/java/com/itextpdf/html2pdf/attach/impl/tags/DivTagWorker.java
index d7123a194..33504c890 100644
--- a/src/main/java/com/itextpdf/html2pdf/attach/impl/tags/DivTagWorker.java
+++ b/src/main/java/com/itextpdf/html2pdf/attach/impl/tags/DivTagWorker.java
@@ -66,7 +66,18 @@ public class DivTagWorker implements ITagWorker, IDisplayAware {
* @param context the context
*/
public DivTagWorker(IElementNode element, ProcessorContext context) {
- div = new Div();
+ this(element, context, new Div());
+ }
+
+ /**
+ * Creates a new {@link DivTagWorker} instance.
+ *
+ * @param element the element
+ * @param context the context
+ * @param container div element container
+ */
+ protected DivTagWorker(IElementNode element, ProcessorContext context, Div container) {
+ div = container;
Map styles = element.getStyles();
if (styles != null && (styles.containsKey(CssConstants.COLUMN_COUNT) || styles.containsKey(CssConstants.COLUMN_WIDTH))) {
multicolContainer = new MulticolContainer();
diff --git a/src/main/java/com/itextpdf/html2pdf/css/CssConstants.java b/src/main/java/com/itextpdf/html2pdf/css/CssConstants.java
index 7e16ec515..bd9c6d200 100644
--- a/src/main/java/com/itextpdf/html2pdf/css/CssConstants.java
+++ b/src/main/java/com/itextpdf/html2pdf/css/CssConstants.java
@@ -31,6 +31,12 @@ This file is part of the iText (R) project.
public class CssConstants extends CommonCssConstants {
+ /** The Constant AUTO_FIT. */
+ public static final String AUTO_FIT = "auto-fit";
+
+ /** The Constant AUTO_FILL. */
+ public static final String AUTO_FILL = "auto-fill";
+
/** The Constant BLEED. */
public static final String BLEED = "bleed";
@@ -71,6 +77,9 @@ public class CssConstants extends CommonCssConstants {
/** The Constant MIN_WIDTH. */
public static final String MIN_WIDTH = "min-width";
+ /** The Constant MIN_MAX. */
+ public static final String MINMAX = "minmax";
+
/**
* The Constant OBJECT_FIT.
*/
@@ -138,8 +147,8 @@ public class CssConstants extends CommonCssConstants {
/** The Constant FIRST_EXCEPT. */
public static final String FIRST_EXCEPT = "first-except";
- /** The Constant GRID. */
- public static final String GRID = "grid";
+ /** The Constant GRID_AREA. */
+ public static final String GRID_AREA = "grid-area";
/** The Constant INLINE. */
public static final String INLINE = "inline";
@@ -223,6 +232,9 @@ public class CssConstants extends CommonCssConstants {
/** The Constant SUB. */
public static final String SUB = "sub";
+ /** The Constant SUBGRID. */
+ public static final String SUBGRID = "subgrid";
+
/** The Constant SUPER. */
public static final String SUPER = "super";
diff --git a/src/main/java/com/itextpdf/html2pdf/css/apply/impl/BlockCssApplier.java b/src/main/java/com/itextpdf/html2pdf/css/apply/impl/BlockCssApplier.java
index 6eecf0d07..b240a51b4 100644
--- a/src/main/java/com/itextpdf/html2pdf/css/apply/impl/BlockCssApplier.java
+++ b/src/main/java/com/itextpdf/html2pdf/css/apply/impl/BlockCssApplier.java
@@ -33,6 +33,7 @@ This file is part of the iText (R) project.
import com.itextpdf.html2pdf.css.apply.util.FlexApplierUtil;
import com.itextpdf.html2pdf.css.apply.util.FloatApplierUtil;
import com.itextpdf.html2pdf.css.apply.util.FontStyleApplierUtil;
+import com.itextpdf.html2pdf.css.apply.util.GridApplierUtil;
import com.itextpdf.html2pdf.css.apply.util.HyphenationApplierUtil;
import com.itextpdf.html2pdf.css.apply.util.MarginApplierUtil;
import com.itextpdf.html2pdf.css.apply.util.OpacityApplierUtil;
@@ -81,6 +82,7 @@ public void apply(ProcessorContext context, IStylesContainer stylesContainer, IT
OrphansWidowsApplierUtil.applyOrphansAndWidows(cssProps, container);
VerticalAlignmentApplierUtil.applyVerticalAlignmentForBlocks(cssProps, container, isInlineItem(tagWorker));
MultiColumnCssApplierUtil.applyMultiCol(cssProps, context, container);
+ GridApplierUtil.applyGridItemProperties(cssProps, stylesContainer, container);
if (isFlexItem(stylesContainer)) {
FlexApplierUtil.applyFlexItemProperties(cssProps, context, container);
} else {
diff --git a/src/main/java/com/itextpdf/html2pdf/css/apply/impl/DefaultTagCssApplierMapping.java b/src/main/java/com/itextpdf/html2pdf/css/apply/impl/DefaultTagCssApplierMapping.java
index 5b326f84f..45ad93403 100644
--- a/src/main/java/com/itextpdf/html2pdf/css/apply/impl/DefaultTagCssApplierMapping.java
+++ b/src/main/java/com/itextpdf/html2pdf/css/apply/impl/DefaultTagCssApplierMapping.java
@@ -152,6 +152,7 @@ class DefaultTagCssApplierMapping {
mapping.putMapping(TagConstants.DIV, CssConstants.TABLE_ROW, () -> new DisplayTableRowTagCssApplier());
mapping.putMapping(TagConstants.DIV, CssConstants.FLEX, () -> new DisplayFlexTagCssApplier());
mapping.putMapping(TagConstants.SPAN, CssConstants.FLEX, () -> new DisplayFlexTagCssApplier());
+ mapping.putMapping(TagConstants.DIV, CssConstants.GRID, () -> new DisplayGridTagCssApplier());
// pseudo elements mapping
String beforePseudoElemName = CssPseudoElementUtil.createPseudoElementTagName(CssConstants.BEFORE);
diff --git a/src/main/java/com/itextpdf/html2pdf/css/apply/impl/DisplayFlexTagCssApplier.java b/src/main/java/com/itextpdf/html2pdf/css/apply/impl/DisplayFlexTagCssApplier.java
index 1b3f5ab4d..a4cceffa4 100644
--- a/src/main/java/com/itextpdf/html2pdf/css/apply/impl/DisplayFlexTagCssApplier.java
+++ b/src/main/java/com/itextpdf/html2pdf/css/apply/impl/DisplayFlexTagCssApplier.java
@@ -46,6 +46,5 @@ public void apply(ProcessorContext context, IStylesContainer stylesContainer, IT
container.deleteOwnProperty(Property.OVERFLOW_X);
container.deleteOwnProperty(Property.OVERFLOW_Y);
}
- MultiColumnCssApplierUtil.applyMultiCol(stylesContainer.getStyles(), context, container);
}
}
diff --git a/src/main/java/com/itextpdf/html2pdf/css/apply/impl/DisplayGridTagCssApplier.java b/src/main/java/com/itextpdf/html2pdf/css/apply/impl/DisplayGridTagCssApplier.java
new file mode 100644
index 000000000..23a9253e8
--- /dev/null
+++ b/src/main/java/com/itextpdf/html2pdf/css/apply/impl/DisplayGridTagCssApplier.java
@@ -0,0 +1,51 @@
+/*
+ This file is part of the iText (R) project.
+ Copyright (c) 1998-2024 Apryse Group NV
+ Authors: Apryse Software.
+
+ This program is offered under a commercial and under the AGPL license.
+ For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
+
+ AGPL licensing:
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+ */
+package com.itextpdf.html2pdf.css.apply.impl;
+
+import com.itextpdf.html2pdf.attach.ITagWorker;
+import com.itextpdf.html2pdf.attach.ProcessorContext;
+import com.itextpdf.html2pdf.css.apply.ICssApplier;
+import com.itextpdf.html2pdf.css.apply.util.GridApplierUtil;
+import com.itextpdf.layout.IPropertyContainer;
+import com.itextpdf.styledxmlparser.node.IStylesContainer;
+
+import java.util.Map;
+
+/**
+ * {@link ICssApplier} implementation for elements with display grid.
+ */
+public class DisplayGridTagCssApplier extends BlockCssApplier {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void apply(ProcessorContext context, IStylesContainer stylesContainer, ITagWorker tagWorker) {
+ super.apply(context, stylesContainer, tagWorker);
+ final IPropertyContainer container = tagWorker.getElementResult();
+ if (container != null) {
+ Map cssProps = stylesContainer.getStyles();
+ GridApplierUtil.applyGridContainerProperties(cssProps, container, context);
+ }
+ }
+}
diff --git a/src/main/java/com/itextpdf/html2pdf/css/apply/impl/MultiColumnCssApplierUtil.java b/src/main/java/com/itextpdf/html2pdf/css/apply/impl/MultiColumnCssApplierUtil.java
index 017a988db..6182dde6f 100644
--- a/src/main/java/com/itextpdf/html2pdf/css/apply/impl/MultiColumnCssApplierUtil.java
+++ b/src/main/java/com/itextpdf/html2pdf/css/apply/impl/MultiColumnCssApplierUtil.java
@@ -64,6 +64,15 @@ public static void applyMultiCol(Map cssProps, ProcessorContext
element.setProperty(Property.COLUMN_WIDTH, width.getValue());
}
+ if (!element.hasProperty(Property.COLUMN_WIDTH) && !element.hasProperty(Property.COLUMN_COUNT)) {
+ if (CommonCssConstants.AUTO.equals(cssProps.get(CssConstants.COLUMN_COUNT))
+ || CommonCssConstants.AUTO.equals(cssProps.get(CssConstants.COLUMN_WIDTH))) {
+ element.setProperty(Property.COLUMN_COUNT, 1);
+ } else {
+ return;
+ }
+ }
+
final UnitValue gap = CssDimensionParsingUtils.parseLengthValueToPt(cssProps.get(CssConstants.COLUMN_GAP),
emValue, remValue);
if (gap != null) {
@@ -74,11 +83,6 @@ public static void applyMultiCol(Map cssProps, ProcessorContext
if (!element.hasProperty(Property.COLUMN_GAP)) {
element.setProperty(Property.COLUMN_GAP, CssDimensionParsingUtils.parseRelativeValue("1em", emValue));
}
- if (!element.hasProperty(Property.COLUMN_COUNT) && !element.hasProperty(Property.COLUMN_WIDTH)
- && (CommonCssConstants.AUTO.equals(cssProps.get(CssConstants.COLUMN_COUNT))
- || CommonCssConstants.AUTO.equals(cssProps.get(CssConstants.COLUMN_WIDTH)))) {
- element.setProperty(Property.COLUMN_COUNT, 1);
- }
final Border borderFromCssProperties = BorderStyleApplierUtil.getCertainBorder(
cssProps.get(CssConstants.COLUMN_RULE_WIDTH), cssProps.get(CssConstants.COLUMN_RULE_STYLE),
diff --git a/src/main/java/com/itextpdf/html2pdf/css/apply/util/GridApplierUtil.java b/src/main/java/com/itextpdf/html2pdf/css/apply/util/GridApplierUtil.java
new file mode 100644
index 000000000..1c334a0d9
--- /dev/null
+++ b/src/main/java/com/itextpdf/html2pdf/css/apply/util/GridApplierUtil.java
@@ -0,0 +1,755 @@
+/*
+ This file is part of the iText (R) project.
+ Copyright (c) 1998-2024 Apryse Group NV
+ Authors: Apryse Software.
+
+ This program is offered under a commercial and under the AGPL license.
+ For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below.
+
+ AGPL licensing:
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see .
+ */
+package com.itextpdf.html2pdf.css.apply.util;
+
+import com.itextpdf.commons.datastructures.Tuple2;
+import com.itextpdf.commons.utils.MapUtil;
+import com.itextpdf.commons.utils.MessageFormatUtil;
+import com.itextpdf.html2pdf.attach.ProcessorContext;
+import com.itextpdf.html2pdf.css.CssConstants;
+import com.itextpdf.html2pdf.logs.Html2PdfLogMessageConstant;
+import com.itextpdf.layout.IPropertyContainer;
+import com.itextpdf.layout.element.IAbstractElement;
+import com.itextpdf.layout.element.IElement;
+import com.itextpdf.layout.properties.Property;
+import com.itextpdf.layout.properties.UnitValue;
+import com.itextpdf.layout.properties.grid.AutoRepeatValue;
+import com.itextpdf.layout.properties.grid.AutoValue;
+import com.itextpdf.layout.properties.grid.BreadthValue;
+import com.itextpdf.layout.properties.grid.FitContentValue;
+import com.itextpdf.layout.properties.grid.FixedRepeatValue;
+import com.itextpdf.layout.properties.grid.FlexValue;
+import com.itextpdf.layout.properties.grid.GridFlow;
+import com.itextpdf.layout.properties.grid.GridValue;
+import com.itextpdf.layout.properties.grid.MaxContentValue;
+import com.itextpdf.layout.properties.grid.MinContentValue;
+import com.itextpdf.layout.properties.grid.MinMaxValue;
+import com.itextpdf.layout.properties.grid.PercentValue;
+import com.itextpdf.layout.properties.grid.PointValue;
+import com.itextpdf.layout.properties.grid.TemplateValue;
+import com.itextpdf.styledxmlparser.css.CommonCssConstants;
+import com.itextpdf.styledxmlparser.css.util.CssDimensionParsingUtils;
+import com.itextpdf.styledxmlparser.css.util.CssUtils;
+import com.itextpdf.styledxmlparser.node.IStylesContainer;
+import com.itextpdf.styledxmlparser.node.impl.jsoup.node.JsoupElementNode;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Utilities class to apply css grid properties and styles.
+ */
+public final class GridApplierUtil {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(GridApplierUtil.class);
+
+ private static final Pattern SPAN_PLACEMENT = Pattern.compile("^span\\s+(.+)$");
+
+ /**
+ * Property map which maps property order in grid-area css prop to layout property
+ */
+ private static final Map propsMap = new HashMap<>();
+
+ /**
+ * Property map which maps property order in grid-area css prop to grid span property
+ */
+ private static final Map spansMap = new HashMap<>();
+ static {
+ propsMap.put(0, Property.GRID_ROW_START);
+ propsMap.put(1, Property.GRID_COLUMN_START);
+ propsMap.put(2, Property.GRID_ROW_END);
+ propsMap.put(3, Property.GRID_COLUMN_END);
+
+ spansMap.put(0, Property.GRID_ROW_SPAN);
+ spansMap.put(1, Property.GRID_COLUMN_SPAN);
+ spansMap.put(2, Property.GRID_ROW_SPAN);
+ spansMap.put(3, Property.GRID_COLUMN_SPAN);
+ }
+
+ private GridApplierUtil() {
+ // empty constructor
+ }
+
+ /**
+ * Applies grid properties to a grid item.
+ *
+ * @param cssProps the CSS properties
+ * @param stylesContainer the styles container
+ * @param element the element
+ */
+ public static void applyGridItemProperties(Map cssProps, IStylesContainer stylesContainer,
+ IPropertyContainer element) {
+ if (!(stylesContainer instanceof JsoupElementNode)
+ || !(((JsoupElementNode) stylesContainer).parentNode() instanceof JsoupElementNode)) {
+ return;
+ }
+ final Map parentStyles = ((JsoupElementNode) ((JsoupElementNode) stylesContainer)
+ .parentNode()).getStyles();
+ if (!CssConstants.GRID.equals(parentStyles.get(CssConstants.DISPLAY))) {
+ // Not a grid - return
+ return;
+ }
+
+ applyGridArea(cssProps, element);
+
+ applyGridItemPlacement(cssProps.get(CssConstants.GRID_COLUMN_END), element, Property.GRID_COLUMN_END, Property.GRID_COLUMN_SPAN);
+ applyGridItemPlacement(cssProps.get(CssConstants.GRID_COLUMN_START), element, Property.GRID_COLUMN_START, Property.GRID_COLUMN_SPAN);
+ applyGridItemPlacement(cssProps.get(CssConstants.GRID_ROW_END), element, Property.GRID_ROW_END, Property.GRID_ROW_SPAN);
+ applyGridItemPlacement(cssProps.get(CssConstants.GRID_ROW_START), element, Property.GRID_ROW_START, Property.GRID_ROW_SPAN);
+ }
+
+ /**
+ * Applies grid properties to a grid container.
+ *
+ * @param cssProps the CSS properties
+ * @param container the grid container
+ * @param context the context
+ */
+ public static void applyGridContainerProperties(Map cssProps, IPropertyContainer container,
+ ProcessorContext context) {
+
+ final float emValue = CssDimensionParsingUtils.parseAbsoluteFontSize(cssProps.get(CssConstants.FONT_SIZE));
+ final float remValue = context.getCssContext().getRootFontSize();
+
+ NamedAreas namedAreas = applyNamedAreas(cssProps.get(CssConstants.GRID_TEMPLATE_AREAS), container);
+
+ applyTemplate(cssProps.get(CssConstants.GRID_TEMPLATE_COLUMNS), container, Property.GRID_TEMPLATE_COLUMNS,
+ emValue, remValue, namedAreas);
+ applyTemplate(cssProps.get(CssConstants.GRID_TEMPLATE_ROWS), container, Property.GRID_TEMPLATE_ROWS,
+ emValue, remValue, namedAreas);
+
+ applyAuto(cssProps.get(CssConstants.GRID_AUTO_ROWS), container, Property.GRID_AUTO_ROWS, emValue, remValue);
+ applyAuto(cssProps.get(CssConstants.GRID_AUTO_COLUMNS), container, Property.GRID_AUTO_COLUMNS, emValue, remValue);
+ applyFlow(cssProps.get(CssConstants.GRID_AUTO_FLOW), container);
+
+ applyGap(container, emValue, remValue, cssProps.get(CssConstants.COLUMN_GAP), Property.COLUMN_GAP);
+ applyGap(container, emValue, remValue, cssProps.get(CssConstants.GRID_COLUMN_GAP), Property.COLUMN_GAP);
+ applyGap(container, emValue, remValue, cssProps.get(CssConstants.ROW_GAP), Property.ROW_GAP);
+ applyGap(container, emValue, remValue, cssProps.get(CssConstants.GRID_ROW_GAP), Property.ROW_GAP);
+ }
+
+ private static void applyGap(IPropertyContainer container, float emValue, float remValue, String gap, int property) {
+ final UnitValue gapValue = CssDimensionParsingUtils.parseLengthValueToPt(gap, emValue, remValue);
+ if (gapValue != null) {
+ container.setProperty(property, gapValue.getValue());
+ }
+ }
+
+ private static void applyAuto(String autoStr, IPropertyContainer container, int property, float emValue, float remValue) {
+ if (autoStr != null) {
+ TemplateValue value = parseTemplateValue(autoStr, emValue, remValue);
+ if (value != null) {
+ container.setProperty(property, value);
+ }
+ }
+ }
+
+ private static void applyFlow(String flow, IPropertyContainer container) {
+ GridFlow value = GridFlow.ROW;
+ if (flow != null) {
+ if (flow.contains(CommonCssConstants.COLUMN)) {
+ if (flow.contains(CssConstants.DENSE)) {
+ value = GridFlow.COLUMN_DENSE;
+ } else {
+ value = GridFlow.COLUMN;
+ }
+ } else if (flow.contains(CssConstants.DENSE)) {
+ value = GridFlow.ROW_DENSE;
+ }
+ }
+ container.setProperty(Property.GRID_FLOW, value);
+ }
+
+ private static NamedAreas applyNamedAreas(String gridTemplateAreas, IPropertyContainer container) {
+ if (gridTemplateAreas == null || CommonCssConstants.NONE.equals(gridTemplateAreas)) {
+ return null;
+ }
+
+ NamedAreas namedAreas = parseGridTemplateAreas(gridTemplateAreas);
+ List children = ((IAbstractElement) container).getChildren();
+ for (IElement child : children) {
+ // Area name can be only in GRID_ROW_START
+ Object propValue = child.