Skip to content

Commit

Permalink
Merge branch 'eclipse-birt:master' into preliminary-PDF-UA-support
Browse files Browse the repository at this point in the history
  • Loading branch information
hvbtup authored Nov 18, 2024
2 parents b749f86 + b95fb42 commit 15160c9
Show file tree
Hide file tree
Showing 20 changed files with 255 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ protected void addWords(WordRule rule, String[] tokens, IToken token) {
* syntax highlights
*/
private void fetchJSCommonObjectsMethods() {
this.globalObjectTokens.add("_jsContext"); //$NON-NLS-1$
this.globalObjectTokens.add("_statusHandle"); //$NON-NLS-1$
this.globalObjectTokens.add("report"); //$NON-NLS-1$
this.globalObjectTokens.add("reportContext"); //$NON-NLS-1$
this.globalObjectTokens.add("config"); //$NON-NLS-1$
this.globalObjectTokens.add("params"); //$NON-NLS-1$
this.globalObjectTokens.add("vars"); //$NON-NLS-1$
this.globalObjectTokens.add("row"); //$NON-NLS-1$
Expand All @@ -190,6 +194,7 @@ private void fetchJSCommonObjectsMethods() {
this.keywordMethods.add("value"); //$NON-NLS-1$
this.keywordMethods.add("data"); //$NON-NLS-1$
this.keywordMethods.add("displayText"); //$NON-NLS-1$
this.keywordMethods.add("currentPage"); //$NON-NLS-1$
this.keywordMethods.add("pageNumber"); //$NON-NLS-1$
this.keywordMethods.add("totalPage"); //$NON-NLS-1$

Expand Down
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 @@ -327,17 +325,18 @@ protected void writeForeign(IForeignContent foreignContent, boolean wrappedTable
}

protected void writeForeign(IForeignContent foreignContent) {
if (foreignContent.getRawValue() != null) {
String uri = "mhtText" + getMhtTextId() + ".mht";
MimeType type = MimeType.MHT;
String relationshipType = RelationshipTypes.AFCHUNK;
IPart mhtPart = part.getPart(uri, type, relationshipType);
handle = foreignContent.getReportContent().getDesign().getReportDesign();
writeMhtPart(mhtPart, foreignContent);
writer.openTag("w:altChunk");
writer.attribute("r:id", mhtPart.getRelationshipId());
writer.closeTag("w:altChunk");
}
if (foreignContent.getRawValue() == null)
foreignContent.setRawValue(new String(""));

String uri = "mhtText" + getMhtTextId() + ".mht";
MimeType type = MimeType.MHT;
String relationshipType = RelationshipTypes.AFCHUNK;
IPart mhtPart = part.getPart(uri, type, relationshipType);
handle = foreignContent.getReportContent().getDesign().getReportDesign();
writeMhtPart(mhtPart, foreignContent);
writer.openTag("w:altChunk");
writer.attribute("r:id", mhtPart.getRelationshipId());
writer.closeTag("w:altChunk");
}

private void writeMhtPart(IPart mhtPart, IForeignContent foreignContent) {
Expand Down Expand Up @@ -1175,16 +1174,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 @@ -479,7 +479,7 @@ public static int convertToPt(String size) {
} else if (size.endsWith("cm")) {
return (int) (s / 2.54 * 72);
} else if (size.endsWith("mm")) {
return (int) (s * 10 / 2.54 * 72);
return (int) (s / 10 / 2.54 * 72);
} else if (size.endsWith("pc")) {
return s;
} else {
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;
}

}
Loading

0 comments on commit 15160c9

Please sign in to comment.