Skip to content

Commit

Permalink
Feature for DOCX to add standard border handling of (dynamic) text (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
speckyspooky authored Nov 7, 2024
1 parent 29525b6 commit 7338b0d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,9 @@ private void buildForeignStyles(IForeignContent foreignContent, StringBuffer for
IStyle style = foreignContent.getComputedStyle();
foreignStyles.setLength(0);
buildTextAlign(foreignStyles, style);
if (!wrappedTable) {
buildForeignBorders(foreignStyles, style);
}
style = getElementStyle(foreignContent);
if (style == null) {
return;
Expand All @@ -522,6 +525,41 @@ private void buildForeignStyles(IForeignContent foreignContent, StringBuffer for
buildTextDecoration(foreignStyles, style);
}

protected void buildForeignBorders(StringBuffer foreignStyles, IStyle style) {
String borderStyle = style.getBorderBottomStyle();
if (hasBorder(borderStyle)) {
buildBorder(HTMLTags.ATTR_BORDER_BOTTOM, foreignStyles, borderStyle, style.getBorderBottomColor(),
style.getProperty(StyleConstants.STYLE_BORDER_BOTTOM_WIDTH));
}

borderStyle = style.getBorderTopStyle();
if (hasBorder(borderStyle)) {
buildBorder(HTMLTags.ATTR_BORDER_TOP, foreignStyles, borderStyle, style.getBorderTopColor(),
style.getProperty(StyleConstants.STYLE_BORDER_TOP_WIDTH));
}

borderStyle = style.getBorderLeftStyle();
if (hasBorder(borderStyle)) {
buildBorder(HTMLTags.ATTR_BORDER_LEFT, foreignStyles, borderStyle, style.getBorderLeftColor(),
style.getProperty(StyleConstants.STYLE_BORDER_LEFT_WIDTH));
}

borderStyle = style.getBorderRightStyle();
if (hasBorder(borderStyle)) {
buildBorder(HTMLTags.ATTR_BORDER_RIGHT, foreignStyles, borderStyle, style.getBorderRightColor(),
style.getProperty(StyleConstants.STYLE_BORDER_RIGHT_WIDTH));
}

}

private void buildBorder(String borderAttributeName, StringBuffer styleBuffer, String style, String color,
CSSValue width) {
addPropName(styleBuffer, borderAttributeName);
addPropValue(styleBuffer, width.getCssText() + " " + style + " #"
+ WordUtil.parseColor(color));
styleBuffer.append(';');
}

private IStyle getElementStyle(IContent content) {
IStyle style = content.getInlineStyle();
if (style == null || style.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ public void start(IReportContent report) {
if (EmitterServices.booleanOption(null, report, DocEmitter.WORD_HEADER_FOOTER_WRAPPED_TABLE, false)) {
wrappedTableHeaderFooter = true;
}
// list: add empty paragraph to list table cell
if (EmitterServices.booleanOption(null, report, DocEmitter.WORD_ADD_EMPTY_PARAGRAPH_FOR_ALL_CELLS, false)) {
// foreign text: add empty paragraph to wrapper table cell
if (EmitterServices.booleanOption(null, report, DocEmitter.WORD_ADD_EMPTY_PARAGRAPH_FOR_ALL_CELLS, wrappedTableForMarginPadding)) {
addEmptyParagraphToForAllCells = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ protected void writeRunBorders(IStyle style) {
}
}

private boolean hasBorder(String borderStyle) {
protected boolean hasBorder(String borderStyle) {
return !(borderStyle == null || "none".equalsIgnoreCase(borderStyle));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ public static String parseColor(String color) {
} else if (color.equalsIgnoreCase("Maroon")) {
return "800000";
} else if (color.equalsIgnoreCase("Orange")) {
return "#FFA500";
return "FFA500";
}
String[] values = color.substring(color.indexOf("(") + 1, color.length() - 1).split(",");
String value = "";
Expand Down

0 comments on commit 7338b0d

Please sign in to comment.