Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature for DOCX to add standard border handling of (dynamic) text (#1957) #1961

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading