From 687d865889c808e7b29b98e04fc4ceca6c5235b8 Mon Sep 17 00:00:00 2001 From: Thomas Gutmann Date: Wed, 6 Nov 2024 23:39:09 +0100 Subject: [PATCH 1/2] Feature to add standard border handling of (dynamic) text (#1957) --- .../emitter/docx/writer/BasicComponent.java | 38 +++++++++++++++++++ .../wpml/writer/AbstractWordXmlWriter.java | 2 +- .../report/engine/emitter/EmitterUtil.java | 2 +- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/engine/org.eclipse.birt.report.engine.emitter.docx/src/org/eclipse/birt/report/engine/emitter/docx/writer/BasicComponent.java b/engine/org.eclipse.birt.report.engine.emitter.docx/src/org/eclipse/birt/report/engine/emitter/docx/writer/BasicComponent.java index 9e4a501d2f..b65c9bee7f 100644 --- a/engine/org.eclipse.birt.report.engine.emitter.docx/src/org/eclipse/birt/report/engine/emitter/docx/writer/BasicComponent.java +++ b/engine/org.eclipse.birt.report.engine.emitter.docx/src/org/eclipse/birt/report/engine/emitter/docx/writer/BasicComponent.java @@ -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; @@ -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()) { diff --git a/engine/org.eclipse.birt.report.engine.emitter.wpml/src/org/eclipse/birt/report/engine/emitter/wpml/writer/AbstractWordXmlWriter.java b/engine/org.eclipse.birt.report.engine.emitter.wpml/src/org/eclipse/birt/report/engine/emitter/wpml/writer/AbstractWordXmlWriter.java index a3dae81bee..c49597d52f 100644 --- a/engine/org.eclipse.birt.report.engine.emitter.wpml/src/org/eclipse/birt/report/engine/emitter/wpml/writer/AbstractWordXmlWriter.java +++ b/engine/org.eclipse.birt.report.engine.emitter.wpml/src/org/eclipse/birt/report/engine/emitter/wpml/writer/AbstractWordXmlWriter.java @@ -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)); } diff --git a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/emitter/EmitterUtil.java b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/emitter/EmitterUtil.java index 86c7732016..1ff8acf200 100644 --- a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/emitter/EmitterUtil.java +++ b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/emitter/EmitterUtil.java @@ -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 = ""; From 087df4d8af93e30c7810a14d52fd9b2cb69b8c2e Mon Sep 17 00:00:00 2001 From: Thomas Gutmann Date: Thu, 7 Nov 2024 00:17:28 +0100 Subject: [PATCH 2/2] Use empty paragraph like default if wrapper table of (dynamic) text is enabled --- .../birt/report/engine/emitter/wpml/AbstractEmitterImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/org.eclipse.birt.report.engine.emitter.wpml/src/org/eclipse/birt/report/engine/emitter/wpml/AbstractEmitterImpl.java b/engine/org.eclipse.birt.report.engine.emitter.wpml/src/org/eclipse/birt/report/engine/emitter/wpml/AbstractEmitterImpl.java index 742df6dd21..290115874a 100644 --- a/engine/org.eclipse.birt.report.engine.emitter.wpml/src/org/eclipse/birt/report/engine/emitter/wpml/AbstractEmitterImpl.java +++ b/engine/org.eclipse.birt.report.engine.emitter.wpml/src/org/eclipse/birt/report/engine/emitter/wpml/AbstractEmitterImpl.java @@ -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; }