Skip to content

Commit

Permalink
The designer advanced register provide the configuration for the word…
Browse files Browse the repository at this point in the history
… layout (#1969) (#1970)
  • Loading branch information
speckyspooky authored Nov 15, 2024
1 parent 8b7e66c commit 4084221
Show file tree
Hide file tree
Showing 16 changed files with 232 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ public void initialize(IEmitterServices service) throws EngineException {
this.embedHtml = (Boolean) value;
}

wordWriter = new DocxWriter(out, tempFileDir, getCompressionMode(service).getValue(), getWordVersion(),
wrappedTableHeaderFooter);
wordWriter = new DocxWriter(out, tempFileDir, getCompressionMode(service).getValue(), getWordVersion());
}

private CompressionMode getCompressionMode(IEmitterServices service) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ public abstract class BasicComponent extends AbstractWordXmlWriter {

protected boolean wrappedTable = true;

protected boolean wrappedTableHeaderFooter = true;

protected BasicComponent(IPart part) throws IOException {
this.part = part;
this.imageManager = (ImageManager) part.getPackage().getExtensionData();
Expand Down Expand Up @@ -1175,16 +1173,4 @@ private void getCorrectFontSize(Node nodeTag, HashMap<Node, Object> cssStyles) {
}
}

protected void startHeaderFooterContainer(int headerHeight, int headerWidth, boolean writeColumns) {
if (wrappedTableHeaderFooter) {
super.startHeaderFooterContainer(headerHeight, headerWidth, writeColumns);
}
}

@Override
protected void endHeaderFooterContainer() {
if (wrappedTableHeaderFooter) {
super.endHeaderFooterContainer();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -311,20 +311,20 @@ void writeFooterReference(BasicComponent footer) {
writer.closeTag("w:footerReference");
}

Header createHeader(int headerHeight, int headerWidth) throws IOException {
Header createHeader(int headerHeight, int headerWidth, boolean wrapHeader) throws IOException {
String uri = "header" + getHeaderID() + ".xml";
String type = ContentTypes.WORD_HEADER;
String relationshipType = RelationshipTypes.HEADER;
IPart headerPart = part.getPart(uri, type, relationshipType);
return new Header(headerPart, this, headerHeight, headerWidth);
return new Header(headerPart, this, headerHeight, headerWidth, wrapHeader);
}

Footer createFooter(int footerHeight, int footerWidth) throws IOException {
Footer createFooter(int footerHeight, int footerWidth, boolean wrapHeader) throws IOException {
String uri = "footer" + getFooterID() + ".xml";
String type = ContentTypes.WORD_FOOTER;
String relationshipType = RelationshipTypes.FOOTER;
IPart footerPart = part.getPart(uri, type, relationshipType);
return new Footer(footerPart, this, footerHeight, footerWidth);
return new Footer(footerPart, this, footerHeight, footerWidth, wrapHeader);
}

private int getHeaderID() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,10 @@ public class DocxWriter implements IWordWriter {
* @param compressionMode compression mode
* @param wordVersion word version
*/
public DocxWriter(OutputStream out, String tempFileDir, int compressionMode, int wordVersion,
boolean wrappedTableHeaderFooter) {
public DocxWriter(OutputStream out, String tempFileDir, int compressionMode, int wordVersion) {
pkg = Package.createInstance(out, tempFileDir, compressionMode);
pkg.setExtensionData(new ImageManager());
this.wordVersion = wordVersion;
this.wrappedTableHeaderFooter = wrappedTableHeaderFooter;
}

@Override
Expand Down Expand Up @@ -137,7 +135,6 @@ private void initializeDocumentPart(String backgroundColor, String backgroundIma
rtl, wordVersion, this.getDocumentLanguage());
document.start();
currentComponent = document;
currentComponent.wrappedTableHeaderFooter = this.wrappedTableHeaderFooter;
}

@Override
Expand All @@ -162,7 +159,7 @@ public void endSection() {

@Override
public void startHeader(boolean showHeaderOnFirst, int headerHeight, int headerWidth) throws IOException {
currentComponent = document.createHeader(headerHeight, headerWidth);
currentComponent = document.createHeader(headerHeight, headerWidth, this.wrappedTableHeaderFooter);
currentComponent.start();
this.showHeaderOnFirst = showHeaderOnFirst;
}
Expand All @@ -176,7 +173,7 @@ public void endHeader() {

@Override
public void startFooter(int footerHeight, int footerWidth) throws IOException {
currentComponent = document.createFooter(footerHeight, footerWidth);
currentComponent = document.createFooter(footerHeight, footerWidth, this.wrappedTableHeaderFooter);
currentComponent.start();
}

Expand Down Expand Up @@ -368,4 +365,13 @@ public String getDocumentLanguage() {
return this.documentLanguage;
}

@Override
public void setWrappedTableHeaderFooter(boolean useWrappedTable) {
this.wrappedTableHeaderFooter = useWrappedTable;
}

@Override
public boolean getWrappedTableHeaderFooter() {
return this.wrappedTableHeaderFooter;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/*******************************************************************************
* Copyright (c) 2013 Actuate Corporation.
*
* Copyright (c) 2013, 2024 Actuate Corporation and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/.
*
*
* SPDX-License-Identifier: EPL-2.0
*
*
*
* Contributors:
* Actuate Corporation - initial API and implementation
* Actuate Corporation - initial API and implementation
* Thomas Gutmann - add option to handle footer wrapper
*******************************************************************************/

package org.eclipse.birt.report.engine.emitter.docx.writer;
Expand All @@ -23,25 +24,39 @@ public class Footer extends BasicComponent {
Document document;
int footerHeight;
int footerWidth;
boolean wrapFooter;

/**
* Constructor 1
*/
Footer(IPart part, Document document, int footerHeight, int footerWidth) throws IOException {
this(part, document, footerHeight, footerWidth, true);
}

/**
* Constructor 2
*/
Footer(IPart part, Document document, int footerHeight, int footerWidth, boolean wrapFooter) throws IOException {
super(part);
this.document = document;
this.footerHeight = footerHeight;
this.footerWidth = footerWidth;
this.wrapFooter = wrapFooter;
}

@Override
void start() {
writer.startWriter();
writer.openTag("w:ftr");
writeXmlns();
startHeaderFooterContainer(footerHeight, footerWidth);
if (this.wrapFooter)
startHeaderFooterContainer(footerHeight, footerWidth);
}

@Override
void end() {
endHeaderFooterContainer();
if (wrapFooter)
endHeaderFooterContainer();
writer.closeTag("w:ftr");
writer.endWriter();
writer.close();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/*******************************************************************************
* Copyright (c) 2013 Actuate Corporation.
*
* Copyright (c) 2013, 2024 Actuate Corporation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/.
*
*
* SPDX-License-Identifier: EPL-2.0
*
*
*
* Contributors:
* Actuate Corporation - initial API and implementation
* Actuate Corporation - initial API and implementation
* Thomas Gutmann - add option to handle header wrapper
*******************************************************************************/

package org.eclipse.birt.report.engine.emitter.docx.writer;
Expand All @@ -32,25 +33,39 @@ public class Header extends BasicComponent {
Document document;
int headerHeight;
int headerWidth;
boolean wrapHeader;

/**
* Constructor 1
*/
Header(IPart part, Document document, int headerHeight, int headerWidth) throws IOException {
this(part, document, headerHeight, headerWidth, true);
}

/**
* Constructor 2
*/
Header(IPart part, Document document, int headerHeight, int headerWidth, boolean wrapHeader) throws IOException {
super(part);
this.document = document;
this.headerHeight = headerHeight;
this.headerWidth = headerWidth;
this.wrapHeader = wrapHeader;
}

@Override
void start() {
writer.startWriter();
writer.openTag("w:hdr");
writeXmlns();
startHeaderFooterContainer(headerHeight, headerWidth, true);
if (this.wrapHeader)
startHeaderFooterContainer(headerHeight, headerWidth, true);
}

@Override
void end() {
endHeaderFooterContainer();
if (this.wrapHeader)
endHeaderFooterContainer();
writer.closeTag("w:hdr");
writer.endWriter();
writer.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.Stack;
import java.util.logging.Level;
Expand Down Expand Up @@ -347,9 +346,10 @@ public void start(IReportContent report) {
// header & footer: wrap header and footer with table
if (EmitterServices.booleanOption(null, report, DocEmitter.WORD_HEADER_FOOTER_WRAPPED_TABLE, false)) {
wrappedTableHeaderFooter = true;
wordWriter.setWrappedTableHeaderFooter(wrappedTableHeaderFooter);
}
// foreign text: add empty paragraph to wrapper table cell
if (EmitterServices.booleanOption(null, report, DocEmitter.WORD_ADD_EMPTY_PARAGRAPH_FOR_ALL_CELLS, wrappedTableForMarginPadding)) {
if (wrappedTableForMarginPadding || EmitterServices.booleanOption(null, report, DocEmitter.WORD_ADD_EMPTY_PARAGRAPH_FOR_ALL_CELLS, false)) {
addEmptyParagraphToForAllCells = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,18 @@ protected static Object getUserProperty(IContent birtContent, String propName) {
private static Object getReportDesignConfiguration(IReportContent reportContent, String name) {
Object value = null;

// TODO: implementation of designer options
if (name.equalsIgnoreCase(DocEmitter.WORD_MARGIN_PADDING_WRAPPED_TABLE)) {
// value = reportContent.getDesign().getReportDesign().getWordWrappedTable();
value = reportContent.getDesign().getReportDesign().getWordWrapTableForMarginPadding();

} else if (name.equalsIgnoreCase(DocEmitter.WORD_MARGIN_PADDING_COMBINE)) {
// value = reportContent.getDesign().getReportDesign().getWordMarginPaddingCombined();
value = reportContent.getDesign().getReportDesign().getWordCombineMarginPadding();

} else if (name.equalsIgnoreCase(DocEmitter.WORD_HEADER_FOOTER_WRAPPED_TABLE)) {
value = reportContent.getDesign().getReportDesign().getWordWrapTableForHeaderFooter();

} else if (name.equalsIgnoreCase(DocEmitter.WORD_ADD_EMPTY_PARAGRAPH_FOR_LIST_CELL)) {
value = reportContent.getDesign().getReportDesign().getWordListCellAddEmptyPara();

}
return value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,4 +377,23 @@ void writeContent(int type, String txt, IStyle style, IStyle inlineStyle, String
* End page
*/
void endPage();

/**
* Set the layout attribute for header and footer wrapping
*
* @param useWrappedTable use layout grid to wrap header and footer
*/
default void setWrappedTableHeaderFooter(boolean useWrappedTable) {
// do nothing
}

/**
* Get the configuration of layout-grid usage for header and footer
*
* @return the configuration of layout-grid usage for header and footer
*/
default boolean getWrappedTableHeaderFooter() {
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The following list get an overview of all supported user properties, the content
false, margin will be used for text indent (without padding)
Default true
Since 4.18
Designer 4.18

**WordEmitter.AddEmptyParagraphForAllCells**

Expand All @@ -34,6 +35,7 @@ The following list get an overview of all supported user properties, the content
true, if wrappedTableForMarginPadding is set to true
Relation WordEmitter.WrappedTableForMarginPadding
Since 4.18
Designer 4.18

**WordEmitter.AddEmptyParagraphForListCell**

Expand All @@ -44,6 +46,7 @@ The following list get an overview of all supported user properties, the content
false, avoid empty paragraph at list table cell end
Default false
Since 4.18
Designer 4.18

**WordEmitter.WrappedTableForMarginPadding**

Expand All @@ -55,6 +58,7 @@ The following list get an overview of all supported user properties, the content
Default false
Relation WordEmitter.AddEmptyParagraphForAllCells
Since 4.18
Designer 4.18


**WordEmitter.WrappedTableHeaderFooter**
Expand All @@ -66,3 +70,5 @@ The following list get an overview of all supported user properties, the content
false, use optimized handling and avoid wrapper layout table for page header and footer
Default false
Since 4.18
Designer 4.18

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public abstract class AbstractWordXmlWriter {

protected boolean combineMarginPadding = true;

protected boolean wrappedTableHeaderFooter = false;

/** constant property: space */
public static final char SPACE = ' ';

Expand Down Expand Up @@ -1457,4 +1459,12 @@ private void drawLine(double width, String style, String color, Line line) {
private int getLineId() {
return lineId++;
}

public void setWrappedTableHeaderFooter(boolean useWrappedTable) {
this.wrappedTableHeaderFooter = useWrappedTable;
}

public boolean getWrappedTableHeaderFooter() {
return this.wrappedTableHeaderFooter;
}
}
Loading

0 comments on commit 4084221

Please sign in to comment.