From ffa726d72b12e916ef3d5b1eb7f0e83c89ea117f Mon Sep 17 00:00:00 2001 From: Thomas Gutmann Date: Thu, 5 Sep 2024 21:46:53 +0200 Subject: [PATCH] Add margin handling to the element "Label" (#1895) --- .../wpml/writer/AbstractWordXmlWriter.java | 41 +++++++++++++++---- 1 file changed, 33 insertions(+), 8 deletions(-) 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 0ed4d8208c..c4a63acd5c 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 @@ -569,7 +569,7 @@ public void startParagraph(IStyle style, boolean isInline, int paragraphWidth) { } /** - * Used only in inline text .The text align style of inline text is ignored,but + * Used only in inline text .The text align style of inline text is ignored, but * its parent text align should be applied. * * @param style @@ -614,7 +614,22 @@ private void writeSpacing(CSSValue height) { private void writeSpacing(CSSValue top, CSSValue bottom) { float topSpacingValue = PropertyUtil.getDimensionValue(top); float bottomSpacingValue = PropertyUtil.getDimensionValue(bottom); - writeSpacing(WordUtil.milliPt2Twips(topSpacingValue) / 2, WordUtil.milliPt2Twips(bottomSpacingValue) / 2); + writeSpacing(WordUtil.milliPt2Twips(topSpacingValue), WordUtil.milliPt2Twips(bottomSpacingValue)); + } + + private void writeSpacing(CSSValue height, CSSValue top, CSSValue bottom) { + writer.openTag("w:spacing"); + if (height != null) { + float spacingValue = PropertyUtil.getDimensionValue(height); + int spacing = WordUtil.milliPt2Twips(spacingValue); + writer.attribute("w:lineRule", "exact"); + writer.attribute("w:line", spacing); + } + int beforeTop = WordUtil.milliPt2Twips(PropertyUtil.getDimensionValue(top)); + int afterBottom = WordUtil.milliPt2Twips(PropertyUtil.getDimensionValue(bottom)); + writer.attribute("w:before", beforeTop); + writer.attribute("w:after", afterBottom); + writer.closeTag("w:spacing"); } private void writeSpacing(int beforeValue, int afterValue) { @@ -1092,17 +1107,27 @@ private void writeTextInParagraph(int type, String txt, IStyle style, String fon CSSValue lineHeight = style.getProperty(StyleConstants.STYLE_LINE_HEIGHT); if (!"normal".equalsIgnoreCase(lineHeight.getCssText())) { - writeSpacing(lineHeight); + writeSpacing(lineHeight, style.getProperty(StyleConstants.STYLE_MARGIN_TOP), + style.getProperty(StyleConstants.STYLE_MARGIN_BOTTOM)); + } else { + writeSpacing(style.getProperty(StyleConstants.STYLE_MARGIN_TOP), + style.getProperty(StyleConstants.STYLE_MARGIN_BOTTOM)); } writeAlign(style.getTextAlign(), style.getDirection()); writeBackgroundColor(style.getBackgroundColor()); writeParagraphBorders(style); - int indent = PropertyUtil.getDimensionValue(style.getProperty(StyleConstants.STYLE_TEXT_INDENT), - paragraphWidth * 1000) / 1000 * 20; - if (indent != 0) { - writeIndent(indent); - } + + int indent = PropertyUtil.getDimensionValue(style.getProperty(StyleConstants.STYLE_TEXT_INDENT), paragraphWidth) + / 1000 * 20; + + int leftMargin = PropertyUtil.getDimensionValue(style.getProperty(StyleConstants.STYLE_MARGIN_LEFT), + paragraphWidth) / 1000 * 20; + + int rightMargin = PropertyUtil.getDimensionValue(style.getProperty(StyleConstants.STYLE_MARGIN_RIGHT), + paragraphWidth) / 1000 * 20; + writeIndent(leftMargin, rightMargin, indent); + writeBidi(CSSConstants.CSS_RTL_VALUE.equals(style.getDirection())); // bidi_hcg // We need to apply the text font style to the paragraph. It is useful // if the end user want to paste some text into this paragraph and