Skip to content

Commit

Permalink
Support repeat cell content when horizontal page-break occurs(T13474 …
Browse files Browse the repository at this point in the history
…T13062)
  • Loading branch information
Gang Liu committed Apr 22, 2009
1 parent bfefb12 commit bfb811d
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 24 deletions.
Expand Up @@ -244,6 +244,7 @@ public IStyle getComputedStyle( )
static final protected short FIELD_DROP = 111;
static final protected short FIELD_HEADERS = 112;
static final protected short FIELD_SCOPE = 113;
static final protected short FIELD_REPEAT_CONTENT = 114;

protected void writeFields( DataOutputStream out ) throws IOException
{
Expand Down Expand Up @@ -283,6 +284,11 @@ protected void writeFields( DataOutputStream out ) throws IOException
IOUtil.writeShort( out, FIELD_SCOPE );
IOUtil.writeString( out, scope );
}
if ( repeatContent )
{
IOUtil.writeShort( out, FIELD_REPEAT_CONTENT );
IOUtil.writeBool( out, true );
}
}

protected void readField( int version, int filedId, DataInputStream in,
Expand Down Expand Up @@ -314,6 +320,9 @@ protected void readField( int version, int filedId, DataInputStream in,
case FIELD_SCOPE :
scope = IOUtil.readString( in );
break;
case FIELD_REPEAT_CONTENT :
repeatContent = IOUtil.readBool( in );
break;
default :
super.readField( version, filedId, in, loader );
break;
Expand Down
Expand Up @@ -87,6 +87,10 @@ public TableContentLayout( ITableContent tableContent, String format,
List hints = context.getTableColumnHint( tableId );

this.adjustedColumnIds = new int[colCount];
for(int i=0; i<colCount; i++)
{
adjustedColumnIds[i] = -1;
}

if(hints.size()>0)
{
Expand All @@ -106,13 +110,13 @@ public TableContentLayout( ITableContent tableContent, String format,
adjustedColumnIds[i] = ( current >= 0 ? current : 0 );
}
}

current = adjustedColumnIds[0];
for ( int i = 1; i < colCount; i++ )
int maxColId = Math.max( 0, current) ;
current = 0;
for ( int i = 0; i < colCount; i++ )
{
if ( adjustedColumnIds[i] < current )
{
adjustedColumnIds[i] = current;
adjustedColumnIds[i] = Math.min( maxColId, current + 1 );
}
else
{
Expand Down
Expand Up @@ -40,7 +40,9 @@ public class TableBreakBuffer implements IPageBuffer
int repeatStart = 0;
int repeatEnd = 0;
boolean isRepeatStatus = false;
boolean isRepeatCellContent = false;
ArrayList<ContentEvent> repeatEvent = new ArrayList<ContentEvent>();
ArrayList<ContentEvent> repeatCellContentEvent = new ArrayList<ContentEvent>();

public TableBreakBuffer( IPageBuffer parentBuffer, HTMLLayoutContext context )
{
Expand Down Expand Up @@ -153,13 +155,36 @@ && isRepeatedCell( (ICellContent) content ) )
{
isRepeatStatus = true;
}
int index = getPageIndex( (ICellContent) content );
int index = getStartPageIndex( (ICellContent) content );

if ( index != currentIndex )
{
currentIndex = index;
repeatCells( emitter);
}
currentBuffer = buffers[currentIndex];
//flush repeat cell content
if ( isRepeatCellContent )
{
repeatCellContent( emitter );
repeatCellContentEvent.clear( );
isRepeatCellContent = false;
}
//cache repeat cell content
if ( ( (ICellContent) content ).repeatContent( ) )
{

int colSpan = ( (ICellContent) content ).getColSpan( );
if ( colSpan > 1 )
{
int col = ( (ICellContent) content ).getColumn( );
if ( col + colSpan > pageBreakIndexs[currentIndex] + 1 )
{
isRepeatCellContent = true;
}
}
}

}
currentBuffer.startContainer( content, isFirst, emitter,
visible );
Expand All @@ -174,17 +199,39 @@ && isRepeatedCell( (ICellContent) content ) )
{
repeatEvent.add(new ContentEvent(content, visible, ContentEvent.START_CONTAINER_EVENT));
}
if ( isRepeatCellContent )
{
repeatCellContentEvent.add( new ContentEvent( content, visible,
ContentEvent.START_CONTAINER_EVENT ) );
}
}


protected void repeatCellContent( IContentEmitter emitter )
throws BirtException
{
int size = repeatCellContentEvent.size( );
if ( size > 0 )
{
ContentEvent last = repeatCellContentEvent.get( size - 1 );
last.isFirst = false;
Iterator iter = repeatCellContentEvent.iterator( );
while ( iter.hasNext( ) )
{
ContentEvent child = (ContentEvent) iter.next( );
visitEvent( child, emitter );
}
}
}


protected void repeatCells( IContentEmitter emitter ) throws BirtException
{
int size = repeatEvent.size( );
if(size>1)
{

ContentEvent last = repeatEvent.get( size-1 );
last.isFirst = false;

Iterator iter = repeatEvent.iterator( );
while ( iter.hasNext( ) )
{
Expand Down Expand Up @@ -231,6 +278,11 @@ public void startContent( IContent content, IContentEmitter emitter,
{
repeatEvent.add(new ContentEvent(content, visible, ContentEvent.START_LEAF_EVENT));
}
if ( isRepeatCellContent )
{
repeatCellContentEvent.add( ( new ContentEvent( content, visible,
ContentEvent.START_LEAF_EVENT ) ) );
}
}

public void endContainer( IContent content, boolean finished,
Expand Down Expand Up @@ -271,13 +323,23 @@ public void endContainer( IContent content, boolean finished,
case IContent.ROW_CONTENT :
if ( currentTableIndex == nestCount && currentTableIndex > 0 )
{
if ( pageBreakIndexs.length-1 != currentIndex )
if ( pageBreakIndexs.length - 1 != currentIndex )
{
for(int i=currentIndex; i<pageBreakIndexs.length; i++)
for ( int i = currentIndex; i < pageBreakIndexs.length; i++ )
{
currentIndex = i;
currentBuffer = buffers[currentIndex];
repeatCells( emitter);
repeatCells( emitter );
if ( isRepeatCellContent )
{
repeatCellContent( emitter );
}
}
repeatEvent.clear( );
if ( isRepeatCellContent )
{
isRepeatCellContent = false;
repeatCellContentEvent.clear( );
}
}
endContainerInPages( content, finished, emitter, visible );
Expand All @@ -291,19 +353,35 @@ public void endContainer( IContent content, boolean finished,
case IContent.CELL_CONTENT :
if ( currentTableIndex == nestCount && currentTableIndex > 0 )
{
int pageIndex = needPageBreak( (ICellContent) content );
if ( pageIndex >= 0 )
int pageIndex = getEndPageIndex( (ICellContent) content );
if ( pageIndex > currentIndex )
{
currentBuffer.endContainer( content, finished, emitter,
visible );
for ( int i = currentIndex + 1; i < pageIndex; i++ )
if(pageIndex > currentIndex+1)
{
currentBuffer = buffers[i];
repeatCells( emitter );
currentBuffer.startContainer( content, false,
emitter, visible );
currentBuffer.endContainer( content, finished,
emitter, visible );
// prepare repeat cell content
if ( isRepeatCellContent )
{
repeatCellContentEvent.add( new ContentEvent(
content, visible,
ContentEvent.END_CONTAINER_EVENT ) );
}
for ( int i = currentIndex + 1; i < pageIndex; i++ )
{
currentBuffer = buffers[i];
repeatCells( emitter );
if ( isRepeatCellContent )
{
repeatCellContent( emitter );
}
}
// restore the cache of repeat cell content
if ( isRepeatCellContent )
{
repeatCellContentEvent
.remove( repeatCellContentEvent.size( ) - 1 );
}
}
pageIndex = ( pageIndex == pageBreakIndexs.length
? pageIndex - 1
Expand Down Expand Up @@ -342,6 +420,11 @@ public void endContainer( IContent content, boolean finished,
{
repeatEvent.add(new ContentEvent(content, visible, ContentEvent.END_CONTAINER_EVENT));
}
if ( isRepeatCellContent )
{
repeatCellContentEvent.add( new ContentEvent( content, visible,
ContentEvent.END_CONTAINER_EVENT ) );
}

}

Expand Down Expand Up @@ -484,7 +567,7 @@ public boolean isRepeatedCell(ICellContent cell)
return false;
}

public int getPageIndex( ICellContent cell )
public int getStartPageIndex( ICellContent cell )
{
int start = cell.getColumn( );
int current = currentIndex;
Expand All @@ -502,11 +585,11 @@ public int getPageIndex( ICellContent cell )
}
return current;
}

public int needPageBreak( ICellContent cell )
public int getEndPageIndex( ICellContent cell )
{
int current = currentIndex;
int end = cell.getColumn( ) + cell.getColSpan( );
int end = cell.getColumn( ) + cell.getColSpan( ) ;
if ( end > pageBreakIndexs[current] )
{
while ( pageBreakIndexs[current] < end )
Expand All @@ -520,7 +603,7 @@ public int needPageBreak( ICellContent cell )
}
return current;
}
return -1;
return current;

}

Expand Down

0 comments on commit bfb811d

Please sign in to comment.