Skip to content

Commit

Permalink
have same behavior as HTML for DOCX emitter
Browse files Browse the repository at this point in the history
Signed-off-by: sguan <sguan@actuate.com>
  • Loading branch information
sguan-actuate committed Jul 25, 2016
1 parent 7a92003 commit 8429ff1
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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 );
Expand All @@ -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 )
Expand Down Expand Up @@ -565,6 +651,7 @@ protected DimensionType getCellHeight( ICellContent cell )

public void startTable( ITableContent table )
{
tableColCount = table.getColumnCount( );
adjustInline( );
styles.push( table.getComputedStyle( ) );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public class TableBandContent extends AbstractBandContent
implements
ITableBandContent
{
private boolean lastTableBand = false;
private boolean firstTableBand = false;

TableBandContent( ITableBandContent band )
{
super( band );
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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( );
Expand All @@ -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( ) )
Expand Down

0 comments on commit 8429ff1

Please sign in to comment.