From 8429ff1a7481687162179cb3e5ca34fde762fcb9 Mon Sep 17 00:00:00 2001 From: sguan Date: Mon, 25 Jul 2016 15:28:51 -0700 Subject: [PATCH] have same behavior as HTML for DOCX emitter Signed-off-by: sguan --- .../emitter/wpml/AbstractEmitterImpl.java | 89 ++++++++++++++++++- .../engine/content/impl/TableBandContent.java | 23 +++++ .../layout/html/HTMLBlockStackingLM.java | 19 +++- 3 files changed, 129 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 90dc8492b1a..4b38c256807 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 @@ -56,6 +56,7 @@ import org.eclipse.birt.report.engine.content.ITableContent; import org.eclipse.birt.report.engine.content.ITableGroupContent; import org.eclipse.birt.report.engine.content.ITextContent; +import org.eclipse.birt.report.engine.content.impl.TableBandContent; import org.eclipse.birt.report.engine.content.impl.TextContent; import org.eclipse.birt.report.engine.css.engine.StyleConstants; import org.eclipse.birt.report.engine.css.engine.value.DataFormatValue; @@ -69,7 +70,6 @@ import org.eclipse.birt.report.engine.ir.EngineIRConstants; import org.eclipse.birt.report.engine.ir.SimpleMasterPageDesign; import org.eclipse.birt.report.engine.layout.emitter.Image; -import org.eclipse.birt.report.engine.layout.pdf.font.FontInfo; import org.eclipse.birt.report.engine.layout.pdf.font.FontMappingManager; import org.eclipse.birt.report.engine.layout.pdf.font.FontMappingManagerFactory; import org.eclipse.birt.report.engine.layout.pdf.font.FontSplitter; @@ -198,8 +198,20 @@ public static enum TextFlag { private boolean fixedLayout; protected int reportDpi; + + private int tableColCount = 0; protected static final String EMPTY_FOOTER = " "; + + protected static final String NO_STYLE = "none"; //$NON-NLS-1$ + + protected final int RIGHT = 0; + + protected final int LEFT = 1; + + protected final int TOP = 2; + + protected final int BOTTOM = 3; public void initialize( IEmitterServices service ) throws EngineException { @@ -501,7 +513,39 @@ public void startCell( ICellContent cell ) int cellWidth = context.getCellWidth( columnId, columnSpan ); IStyle style = computeStyle( cell.getComputedStyle( ) ); +// style.get + + IStyle tableStyle = context.getTableStyle( ); + int rowId = cell.getRow( ); // does not work! + String[] borderStyles = new String[4]; + if ( isFirstBand( cell ) && hasBorder( tableStyle.getBorderTopStyle( ) ) + && hasBorder( style.getBorderTopStyle( ) ) ) + { + borderStyles[TOP] = style.getBorderTopStyle( ); + style.setBorderTopStyle( NO_STYLE ); + } + if ( columnId == 0 && hasBorder( tableStyle.getBorderLeftStyle( ) ) + && hasBorder( style.getBorderLeftStyle( ) ) )// first column + { + borderStyles[LEFT] = style.getBorderLeftStyle( ); + style.setBorderLeftStyle( NO_STYLE ); + } + if ( columnId == tableColCount - 1 + && hasBorder( tableStyle.getBorderRightStyle( ) ) + && hasBorder( style.getBorderRightStyle( ) ) ) + { + borderStyles[RIGHT] = style.getBorderRightStyle( ); + style.setBorderRightStyle( NO_STYLE ); + } + if ( isLastBand( cell ) + && hasBorder( tableStyle.getBorderBottomStyle( ) ) + && hasBorder( style.getBorderBottomStyle( ) ) ) + { + borderStyles[BOTTOM] = style.getBorderBottomStyle( ); + style.setBorderBottomStyle( NO_STYLE ); + } + if ( rowSpan > 1 ) { context.addSpan( columnId, columnSpan, cellWidth, rowSpan, style ); @@ -521,6 +565,48 @@ public void startCell( ICellContent cell ) { drawDiagonalLine( cell, WordUtil.twipToPt( cellWidth ) ); } + // return to original + if ( borderStyles[RIGHT] != null ) + { + style.setBorderRightStyle( borderStyles[RIGHT] ); + } + if ( borderStyles[LEFT] != null ) + { + style.setBorderLeftStyle( borderStyles[LEFT] ); + } + if ( borderStyles[TOP] != null ) + { + style.setBorderTopStyle( borderStyles[TOP] ); + } + if ( borderStyles[BOTTOM] != null ) + { + style.setBorderBottomStyle( borderStyles[BOTTOM] ); + } + } + + private boolean isLastBand( ICellContent cell ) + { + IContent tableBand = (IContent) ( (IContent) cell.getParent( ) ).getParent( ); + if( tableBand instanceof TableBandContent ) + { + return ( (TableBandContent) tableBand).isLastTableBand( ); + } + return false; + } + + private boolean isFirstBand( ICellContent cell ) + { + IContent tableBand = (IContent) ( (IContent) cell.getParent( ) ).getParent( ); + if( tableBand instanceof TableBandContent ) + { + return ( (TableBandContent) tableBand).isFirstTableBand( ); + } + return false; + } + + private boolean hasBorder( String borderStyle ) + { + return !( borderStyle == null || "none".equalsIgnoreCase( borderStyle ) ); } private void drawDiagonalLine( ICellContent cell, double cellWidth ) @@ -565,6 +651,7 @@ protected DimensionType getCellHeight( ICellContent cell ) public void startTable( ITableContent table ) { + tableColCount = table.getColumnCount( ); adjustInline( ); styles.push( table.getComputedStyle( ) ); diff --git a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/content/impl/TableBandContent.java b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/content/impl/TableBandContent.java index 842f4016b39..a229e5bd9fc 100644 --- a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/content/impl/TableBandContent.java +++ b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/content/impl/TableBandContent.java @@ -27,6 +27,9 @@ public class TableBandContent extends AbstractBandContent implements ITableBandContent { + private boolean lastTableBand = false; + private boolean firstTableBand = false; + TableBandContent( ITableBandContent band ) { super( band ); @@ -58,4 +61,24 @@ protected IContent cloneContent() { return new TableBandContent(this); } + + public void setLastTableBand( boolean lastTableBand ) + { + this.lastTableBand = lastTableBand; + } + + public boolean isLastTableBand( ) + { + return lastTableBand; + } + + public void setFirstTableBand( boolean firstTableBand ) + { + this.firstTableBand = firstTableBand; + } + + public boolean isFirstTableBand( ) + { + return firstTableBand; + } } \ No newline at end of file diff --git a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/layout/html/HTMLBlockStackingLM.java b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/layout/html/HTMLBlockStackingLM.java index 709dc0d70f5..01e3c140b82 100644 --- a/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/layout/html/HTMLBlockStackingLM.java +++ b/engine/org.eclipse.birt.report.engine/src/org/eclipse/birt/report/engine/layout/html/HTMLBlockStackingLM.java @@ -13,6 +13,7 @@ import org.eclipse.birt.core.exception.BirtException; import org.eclipse.birt.report.engine.content.IContent; +import org.eclipse.birt.report.engine.content.impl.TableBandContent; import org.eclipse.birt.report.engine.extension.IReportItemExecutor; import org.eclipse.birt.report.engine.layout.ILayoutManager; @@ -59,6 +60,7 @@ protected boolean layoutNodes( ) throws BirtException } } // then layout the next content + boolean firstIteration = true; while ( executor.hasNextChild( ) && !context.getCancelFlag( ) ) { childExecutor = (IReportItemExecutor) executor.getNextChild( ); @@ -67,8 +69,23 @@ protected boolean layoutNodes( ) throws BirtException { childLayout = engine.createLayoutManager( this, childContent, childExecutor, emitter ); - hasNext = childLayout.layout( ); + if ( childContent instanceof TableBandContent ) + { + if ( !executor.hasNextChild( ) ) + { + ( (TableBandContent) childContent ) + .setLastTableBand( true ); + } + if ( firstIteration ) + { + ( (TableBandContent) childContent ) + .setFirstTableBand( true ); + } + } + firstIteration = false; + hasNext = childLayout.layout( ); + if ( hasNext ) { if ( childLayout.isFinished( ) )