Skip to content

Commit

Permalink
fixes #52 Support background-color on inline tags
Browse files Browse the repository at this point in the history
  • Loading branch information
draco1023 committed Oct 13, 2022
1 parent e12f4a1 commit e59c0cb
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/main/java/org/ddr/poi/html/HtmlRenderContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSectPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTShd;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyle;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTUnderline;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STShd;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STStyleType;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STThemeColor;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STUnderline;
Expand Down Expand Up @@ -844,7 +846,6 @@ private void applyTextStyle(CTR ctr) {
rPr.addNewI();
}

// FIXME cssparser目前不支持以空格为分隔符的rgb颜色,仅支持逗号分隔符
// 颜色
String color = getPropertyValue(HtmlConstants.CSS_COLOR);
if (StringUtils.isNotBlank(color)) {
Expand Down Expand Up @@ -887,6 +888,17 @@ private void applyTextStyle(CTR ctr) {

// FIXME 段落边框与行内边框分离,行内只有全边框,段落分四边

// 背景色
String backgroundColor = getPropertyValue(HtmlConstants.CSS_BACKGROUND_COLOR, true);
if (StringUtils.isNotBlank(backgroundColor)) {
String hex = Colors.fromStyle(backgroundColor, null);
if (hex != null) {
CTShd ctShd = rPr.addNewShd();
ctShd.setFill(hex);
ctShd.setVal(STShd.CLEAR);
}
}

// 可见性
String visibility = getPropertyValue(HtmlConstants.CSS_VISIBILITY);
if (HtmlConstants.HIDDEN.equals(visibility) || HtmlConstants.COLLAPSE.equals(visibility)) {
Expand Down

0 comments on commit e59c0cb

Please sign in to comment.