diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java index b2e3ccf4f..392465cb1 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java @@ -50,9 +50,11 @@ package com.fr.third.v2.lowagie.text.html.simpleparser; +import com.fr.third.v2.lowagie.text.html.utils.BackgroundUtil; import java.awt.Color; import java.util.HashMap; import java.util.Iterator; +import java.util.Map; import java.util.Properties; import java.util.StringTokenizer; import com.fr.third.v2.lowagie.text.Chunk; @@ -134,9 +136,12 @@ public class FactoryProperties { else if (value.equalsIgnoreCase("justify")) p.setAlignment(Element.ALIGN_JUSTIFIED); } - if(props.hasPropertyInChain("div", "background")){ - p.setBackground(props.getPropertyFromChain("div", "background")); - } + Map bgAttrMap = BackgroundUtil.parseBgAttr4BlockTag(props); + if (null != bgAttrMap) { + for (Map.Entry entry : bgAttrMap.entrySet()) { + p.setAttribute(entry.getKey(), entry.getValue()); + } + } if(props.hasProperty("line-height")){ p.setAttribute("line-height", props.getProperty("line-height")); } diff --git a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/utils/BackgroundUtil.java b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/utils/BackgroundUtil.java index 23cc892df..3e95ef0c9 100644 --- a/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/utils/BackgroundUtil.java +++ b/fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/utils/BackgroundUtil.java @@ -45,4 +45,40 @@ public class BackgroundUtil { } return backgroundRules; } + + /** + * 将块元素的背景属性转换成mp + * + * @param props + * @return + */ + public static Map parseBgAttr4BlockTag(ChainedProperties props) { + Map backgroundRules = new HashMap(); + String value = props.getPropertyFromChain("div", "background-color"); + if (value != null) { + backgroundRules.put("background-color", value); + } + value = props.getPropertyFromChain("div", "background-size"); + if (value != null) { + backgroundRules.put("background-size", value); + } + value = props.getPropertyFromChain("div", "background"); + if (value != null) { + Map backgroundStyles = CSSUtils.processBackground(value); + backgroundRules.putAll(backgroundStyles); + } + value = props.getPropertyFromChain("div", "background-position"); + if (value != null) { + backgroundRules.put("background-position", value); + } + value = props.getPropertyFromChain("div", "background-repeat"); + if (value != null) { + backgroundRules.put("background-repeat", value); + } + value = props.getPropertyFromChain("div", "background-image"); + if (value != null) { + backgroundRules.put("background-image", value); + } + return backgroundRules; + } }