Skip to content

Commit

Permalink
Merge pull request #349 from FreemanZhang/master
Browse files Browse the repository at this point in the history
column's width is not kept when exporting to PDF/Word using plain HTML
  • Loading branch information
Yulin Wang committed Oct 7, 2016
2 parents 993423e + adc4b99 commit 140b451
Showing 1 changed file with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.awt.Color;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.birt.core.exception.BirtException;
Expand All @@ -28,7 +29,10 @@
import org.eclipse.birt.report.engine.content.IRowContent;
import org.eclipse.birt.report.engine.content.IStyle;
import org.eclipse.birt.report.engine.content.ITableContent;
import org.eclipse.birt.report.engine.content.impl.CellContent;
import org.eclipse.birt.report.engine.content.impl.ReportContent;
import org.eclipse.birt.report.engine.content.impl.RowContent;
import org.eclipse.birt.report.engine.content.impl.TableBandContent;
import org.eclipse.birt.report.engine.css.dom.StyleDeclaration;
import org.eclipse.birt.report.engine.css.engine.StyleConstants;
import org.eclipse.birt.report.engine.executor.ExecutionContext;
Expand Down Expand Up @@ -930,6 +934,47 @@ else if ( EngineIRConstants.UNITS_EM.equals( columns[i]
return resolvedColumnWidth;
}

private DimensionType getColWidthFromCellInFirstRow( int colIndex )
{
if ( table.getChildren( ) != null )
{
Iterator<Object> rowIterator = table.getChildren( ).iterator( );
if ( rowIterator.hasNext( ) )
{
Object content = rowIterator.next( );
RowContent rowContent = null;
// handle tables generated by report designer
if ( content instanceof TableBandContent )
{
rowContent = (RowContent) ( (TableBandContent) content )
.getChildren( ).iterator( ).next( );
}
// handle tables directly generated by native html tags
else if ( content instanceof RowContent )
{
rowContent = (RowContent) content;
}

// find i-th Cell width
if ( rowContent != null && rowContent.hasChildren( ) )
{
Iterator<CellContent> cellIterator = rowContent
.getChildren( ).iterator( );
for ( int i = 0; i <= colIndex
&& cellIterator.hasNext( ); i++ )
{
CellContent cell = cellIterator.next( );
if ( i == colIndex )
{
return cell.getWidth( );
}
}
}
}
}
return null;
}

public int[] resolveFixedLayout( int maxWidth )
{

Expand All @@ -948,7 +993,7 @@ public int[] resolveFixedLayout( int maxWidth )
endCol = i;
if ( w == null )
{
columns[i] = null;
columns[i] = getColWidthFromCellInFirstRow( i );
}
else
{
Expand Down

0 comments on commit 140b451

Please sign in to comment.