Browse Source

Pull request #469: REPORT-33569 无插件PDF导出-HTML解析:块元素(如:div、p)支持background-image、background-size 属性

Merge in CORE/base-third from ~HUGH.C/base-third:feature/10.0 to feature/10.0

* commit 'f537d21d8d37b9f4cdcb712462a558ce8e10dca0':
  REPORT-33569 review 改进
  REPORT-33569 无插件PDF导出-HTML解析:块元素(如:div、p)支持background-image、background-size 属性
research/11.0
Hugh.C 4 years ago
parent
commit
819cb05421
  1. 9
      fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/simpleparser/FactoryProperties.java
  2. 36
      fine-itext/src/main/java/com/fr/third/v2/lowagie/text/html/utils/BackgroundUtil.java

9
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,8 +136,11 @@ 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<String, String> bgAttrMap = BackgroundUtil.parseBgAttr4BlockTag(props);
if (null != bgAttrMap) {
for (Map.Entry<String, String> entry : bgAttrMap.entrySet()) {
p.setAttribute(entry.getKey(), entry.getValue());
}
}
if(props.hasProperty("line-height")){
p.setAttribute("line-height", props.getProperty("line-height"));

36
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<String, String> parseBgAttr4BlockTag(ChainedProperties props) {
Map<String, String> backgroundRules = new HashMap<String, String>();
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<String, String> 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;
}
}

Loading…
Cancel
Save