Skip to content

Commit

Permalink
Table borderlines style implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
sguan-actuate committed Jun 20, 2014
1 parent bb2bd47 commit c731757
Show file tree
Hide file tree
Showing 2 changed files with 180 additions and 96 deletions.
Expand Up @@ -13,13 +13,18 @@
import org.eclipse.birt.report.engine.nLayout.area.impl.RowArea;
import org.eclipse.birt.report.engine.nLayout.area.impl.TableArea;
import org.eclipse.birt.report.engine.nLayout.area.style.BackgroundImageInfo;
import org.eclipse.birt.report.engine.nLayout.area.style.BorderInfo;
import org.eclipse.birt.report.engine.nLayout.area.style.BoxStyle;
import org.eclipse.birt.report.engine.nLayout.area.style.DiagonalInfo;
import org.eclipse.birt.report.engine.ooxml.writer.OOXmlWriter;

public class TableWriter
{


private static final String RIGHTBORDERLINE = "a:lnR";
private static final String LEFTBORDERLINE = "a:lnL";
private static final String TOPBORDERLINE = "a:lnT";
private static final String BOTTOMBORDERLINE = "a:lnB";
private int currentX;
private int currentY;
protected Stack<BoxStyle> rowStyleStack = new Stack<BoxStyle>();
Expand All @@ -29,7 +34,7 @@ public class TableWriter
private final PPTXCanvas canvas;
protected OOXmlWriter writer;
private static int TableIndex = 1;

public TableWriter( PPTXRender render )
{
this.render = render;
Expand All @@ -45,17 +50,18 @@ public void outputTable( TableArea table )
{
drawTable( table );
}

protected void drawTable( TableArea table)
{
if ( table.needClip( ) )
{
render.startClip( table);

}
startTable(table);

currentX += getX( table);
currentY += getY( table );
startTable(table);
Iterator<IArea> iter = table.getChildren( );
while ( iter.hasNext( ) )
{
Expand All @@ -74,10 +80,10 @@ protected void drawTable( TableArea table)
currentY -= getY( table);
endTable();
}

private void startTable( TableArea tablearea )
{

int X = PPTXUtil.convertToEnums( currentX );
int Y = PPTXUtil.convertToEnums( currentY );
int width = PPTXUtil.convertToEnums( tablearea.getWidth( ));
Expand All @@ -103,7 +109,7 @@ private void startTable( TableArea tablearea )
writer.openTag("a:tbl");
writeColumnsWidth(tablearea);
}

private void endTable()
{
writer.closeTag( "a:tbl" );
Expand All @@ -126,7 +132,7 @@ private void writeColumnsWidth( TableArea tablearea )
}
writer.closeTag( "a:tblGrid" );
}

protected void drawRow( RowArea row)
{
currentX += getX( row);
Expand All @@ -144,7 +150,7 @@ protected void drawRow( RowArea row)
currentX -= getX( row);
currentY -= getY( row);
}

private void startRow( RowArea row )
{
writer.openTag("a:tr");
Expand All @@ -155,11 +161,15 @@ private void startRow( RowArea row )
private void endRow( )
{
writer.closeTag( "a:tr" );

}

protected void drawCell( CellArea cell)
{
int rowid = cell.getRowID( );
System.out.println("rowid: "+ rowid );
int colid = cell.getColumnID( );
System.out.println("colid: "+ colid );
currentX += getX( cell);
currentY += getY( cell);
startCell( cell );
Expand All @@ -170,15 +180,15 @@ protected void drawCell( CellArea cell)
currentX -= getX( cell);
currentY -= getY( cell);
}


/**
* start cell tag with all properties: styling
* @param cell
*/
private void startCell( CellArea cell )
{
writer.openTag( "a:tc" );
writer.openTag( "a:tc" );

int colspan = cell.getColSpan( );
if( colspan > 1)
Expand Down Expand Up @@ -230,71 +240,60 @@ protected void visitChildren( IContainerArea container )
}
updateRenderXY();
}


/**
* draw the cells properties
* @param cell
*/
protected void drawCellBox( CellArea cell )
{
drawBorders( cell );
drawCellDiagonal( cell );
Color rowbc = null;
BackgroundImageInfo rowbi = null;
BoxStyle rowStyle = null;


// get the style of the row
if ( rowStyleStack.size( ) > 0 )
BoxStyle style = cell.getBoxStyle( );
Color backgroundcolor = style.getBackgroundColor( );
BackgroundImageInfo bgimginfo = style.getBackgroundImage( );

if( !rowStyleStack.isEmpty( ) && (backgroundcolor == null || bgimginfo == null) )
{
rowStyle = rowStyleStack.peek( );
if(rowStyle!=null)
BoxStyle rowStyle = rowStyleStack.peek( );
if(rowStyle!=null)
{
rowbc = rowStyle.getBackgroundColor( );
rowbi = rowStyle.getBackgroundImage( );
}
if(backgroundcolor == null )
{
backgroundcolor = rowStyle.getBackgroundColor( );
}
if(bgimginfo == null)
{
bgimginfo = rowStyle.getBackgroundImage( );
}
}
}

BoxStyle style = cell.getBoxStyle( );
Color bc = style.getBackgroundColor( );
BackgroundImageInfo bi = style.getBackgroundImage( );
// render.drawBorders( cell );

//String imageUrl = EmitterUtil.getBackgroundImageUrl( style,reportDesign );

if ( rowbc != null || rowbi != null || bc != null
|| bi != null )
{
// the container's start position (the left top corner of the
// container)
int startX = currentX;
int startY = currentY;

// the dimension of the container
int width = getWidth( cell );
int height = getHeight( cell );
// the container's start position (the left top corner of the
// container)
int startX = currentX;
int startY = currentY;
// the dimension of the container
int width = getWidth( cell );
int height = getHeight( cell );

if ( rowbc != null )
{
// graphics.drawBackgroundColor( rowbc, startX, startY, width, height );
canvas.setColor( rowbc );
}
if ( rowbi != null )
{
render.drawBackgroundImage( rowbi, startX, startY,width, height );
}
if ( bc != null )
{
// Draws background color for the container, if the background
// color is NOT set, draws nothing.
// graphics.drawBackgroundColor( bc, startX, startY, width, height );
canvas.setColor( bc );
}
if ( bi != null )
{
// Draws background image for the container. if the background
// image is NOT set, draws nothing.
render.drawBackgroundImage( bi, startX, startY, width, height );
}
if ( backgroundcolor != null )
{
canvas.setColor( backgroundcolor );
}
if ( bgimginfo != null )
{
render.drawBackgroundImage( bgimginfo, startX, startY,width, height );
// canvas.fillImage( bgimginfo., offsetX, offsetY, ToTile );
//call internal function to only get imagefill:
//current implementation produce bug as it is inside shape tag
}

}

protected void drawCellDiagonal( CellArea cell )
{
DiagonalInfo diagonalInfo = cell.getDiagonalInfo( );
Expand Down Expand Up @@ -341,10 +340,73 @@ protected void drawCellDiagonal( CellArea cell )
getScaledValue( dw ), diagonalInfo.getDiagonalColor( ), ds );
break;
}

}
}


/**
* assume leftborder is always draw
* @param container
*/
protected void drawBorders( IContainerArea container )
{
BoxStyle style = container.getBoxStyle( );
if( style == null) return;

BorderInfo baseborderinfo = style.getLeftBorder( );

writeSingleBorder( LEFTBORDERLINE, baseborderinfo );

BorderInfo currentborderinfo = style.getRightBorder( );
if( currentborderinfo != null)
{
writeSingleBorder( RIGHTBORDERLINE, currentborderinfo );
baseborderinfo = currentborderinfo;
}
else
{ //draw if border is empty:
writeSingleBorder( RIGHTBORDERLINE, baseborderinfo );
}

currentborderinfo = style.getTopBorder( );
if( currentborderinfo != null)
{
writeSingleBorder( TOPBORDERLINE, currentborderinfo);
baseborderinfo = currentborderinfo;
}
else
{ //draw if border is empty:
writeSingleBorder( TOPBORDERLINE, baseborderinfo );
}

currentborderinfo = style.getBottomBorder();
if( currentborderinfo != null)
{
writeSingleBorder( BOTTOMBORDERLINE, style.getBottomBorder());
}
else
{ //draw if border is empty:
writeSingleBorder( BOTTOMBORDERLINE, baseborderinfo );
}

}

private void writeSingleBorder( String borderSide, BorderInfo borderinfo )
{
if( borderinfo == null)
{
return;
}
writer.openTag( borderSide );
int width = PPTXUtil.convertToEnums( borderinfo.getWidth( ));
writer.attribute( "w", width ); //convert to EMU
canvas.setColor( borderinfo.getColor( ) );
writer.openTag( "a:prstDash");
//TODO: get the right style naming
writer.attribute( "val", PPTXUtil.parseStyle( borderinfo.getStyle( )) );
writer.closeTag( "a:prstDash" );
writer.closeTag( borderSide );
}

private int getY(IContainerArea area)
{
Expand All @@ -365,12 +427,12 @@ private int getWidth(CellArea area)
{
return getScaledValue( area.getWidth());
}

protected int getScaledValue( int value )
{
return (int) ( value * scale );
}

protected void updateRenderXY(){
render.setCurrentX( currentX );
render.setCurrentY( currentY );
Expand Down

0 comments on commit c731757

Please sign in to comment.