From 7c0d5b85533fb42f652b4da3c2df180c911f8d73 Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Mon, 15 Jun 2020 14:11:28 +0800 Subject: [PATCH 1/2] =?UTF-8?q?REPORT-33569=20=E6=97=A0=E6=8F=92=E4=BB=B6P?= =?UTF-8?q?DF=E5=AF=BC=E5=87=BA-HTML=E8=A7=A3=E6=9E=90=EF=BC=9A=E5=9D=97?= =?UTF-8?q?=E5=85=83=E7=B4=A0=EF=BC=88=E5=A6=82=EF=BC=9Adiv=E3=80=81p?= =?UTF-8?q?=EF=BC=89=E6=94=AF=E6=8C=81background-image=E3=80=81background-?= =?UTF-8?q?size=20=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../html/simpleparser/FactoryProperties.java | 11 +++-- .../text/html/utils/BackgroundUtil.java | 40 +++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) 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..040491656 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,44 @@ public class BackgroundUtil { } return backgroundRules; } + + /** + * 将块元素的背景属性转换成mp + * + * @param props + * @return + */ + public static Map parseBgAttr4BlockTag(ChainedProperties props) { + Map backgroundRules = new HashMap(); + String value = props.getPropertyFromChain("div", "bgcolor"); + 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-color"); + if (value != null) { + backgroundRules.put("background-color", value); + } + 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; + } } From f537d21d8d37b9f4cdcb712462a558ce8e10dca0 Mon Sep 17 00:00:00 2001 From: "Hugh.C" Date: Mon, 15 Jun 2020 15:12:14 +0800 Subject: [PATCH 2/2] =?UTF-8?q?REPORT-33569=20review=20=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/third/v2/lowagie/text/html/utils/BackgroundUtil.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) 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 040491656..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 @@ -54,7 +54,7 @@ public class BackgroundUtil { */ public static Map parseBgAttr4BlockTag(ChainedProperties props) { Map backgroundRules = new HashMap(); - String value = props.getPropertyFromChain("div", "bgcolor"); + String value = props.getPropertyFromChain("div", "background-color"); if (value != null) { backgroundRules.put("background-color", value); } @@ -67,10 +67,6 @@ public class BackgroundUtil { Map backgroundStyles = CSSUtils.processBackground(value); backgroundRules.putAll(backgroundStyles); } - value = props.getPropertyFromChain("div", "background-color"); - if (value != null) { - backgroundRules.put("background-color", value); - } value = props.getPropertyFromChain("div", "background-position"); if (value != null) { backgroundRules.put("background-position", value);