<commit_before>/***********************************************************************
 * Copyright (c) 2008 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Actuate Corporation - initial API and implementation
 ***********************************************************************/

package org.eclipse.birt.report.engine.layout.pdf.emitter;

import java.util.ArrayList;
import java.util.Iterator;

import org.eclipse.birt.report.engine.content.IBandContent;
import org.eclipse.birt.report.engine.content.ICellContent;
import org.eclipse.birt.report.engine.content.IColumn;
import org.eclipse.birt.report.engine.content.IContent;
import org.eclipse.birt.report.engine.content.ILabelContent;
import org.eclipse.birt.report.engine.content.IReportContent;
import org.eclipse.birt.report.engine.content.IRowContent;
import org.eclipse.birt.report.engine.content.IStyle;
import org.eclipse.birt.report.engine.content.ITableBandContent;
import org.eclipse.birt.report.engine.content.ITableContent;
import org.eclipse.birt.report.engine.css.engine.StyleConstants;
import org.eclipse.birt.report.engine.ir.DimensionType;
import org.eclipse.birt.report.engine.ir.EngineIRConstants;
import org.eclipse.birt.report.engine.layout.area.impl.AbstractArea;
import org.eclipse.birt.report.engine.layout.area.impl.AreaFactory;
import org.eclipse.birt.report.engine.layout.area.impl.CellArea;
import org.eclipse.birt.report.engine.layout.area.impl.RowArea;
import org.eclipse.birt.report.engine.layout.area.impl.TableArea;
import org.eclipse.birt.report.engine.layout.pdf.util.PropertyUtil;


public class TableLayout extends RepeatableLayout
{

	
	
	/**
	 * table content
	 */
	private ITableContent tableContent;


	/**
	 * number of table column
	 */
	protected int columnNumber;
	
	/**
	 * the first visible column id of the table.
	 */
	protected int startCol = -1;
	
	/**
	 * the last visible column id of the table.
	 */
	protected int endCol = -1;

	/**
	 * table width
	 */
	protected int tableWidth;

	protected TableLayoutInfo layoutInfo = null;

	protected TableContext tableContext = null;
	
	protected ColumnWidthResolver columnWidthResolver;

	
	protected TableAreaLayout regionLayout = null;
	
	public TableLayout( LayoutEngineContext context,
			ContainerLayout parent, IContent content )
	{
		super( context, parent, content );
		tableContent = (ITableContent) content;
		columnWidthResolver = new ColumnWidthResolver( tableContent );
		columnNumber = tableContent.getColumnCount( );
		boolean isBlock = !PropertyUtil.isInlineElement(content);
		isInBlockStacking &= isBlock;
	}

	protected void createRoot( )
	{
		currentContext.root = AreaFactory.createTableArea( (ITableContent) content );
		currentContext.root.setWidth( tableWidth );
	}

	public TableLayoutInfo getLayoutInfo( )
	{
		return layoutInfo;
	}

	protected void buildTableLayoutInfo( )
	{
		this.layoutInfo = resolveTableFixedLayout((TableArea)currentContext.root );

	}
	
	public int getColumnCount()
	{
		if(tableContent!=null)
		{
			return tableContent.getColumnCount();
		}
		return 0;
	}

	protected void initialize( )
	{
		currentContext = new TableContext( );
		contextList.add( currentContext );
		tableContext = (TableContext)currentContext;
		createRoot( );
		buildTableLayoutInfo( );
		currentContext.root.setWidth( layoutInfo.getTableWidth( ) );
		currentContext.maxAvaWidth = layoutInfo.getTableWidth( );

		if ( parent != null )
		{
			currentContext.root.setAllocatedHeight( parent.getCurrentMaxContentHeight( ) );
		}
		else
		{
			currentContext.root.setAllocatedHeight( context.getMaxHeight( ) );
		}
		if ( tableContext.layout == null )
		{
			int start = 0;
			int end = tableContent.getColumnCount( ) -1;
			tableContext.layout = new TableAreaLayout( tableContent, layoutInfo, start,
					end );
			//layout.initTableLayout( context.getUnresolvedRowHint( tableContent ) );
		}
		currentContext.maxAvaHeight = currentContext.root.getContentHeight( ) - getBottomBorderWidth( );
		repeatHeader();
		addCaption( tableContent.getCaption( ) );
	}

	protected void closeLayout( ContainerContext currentContext, int index, boolean finished )
	{
		/*
		 * 1. resolve all unresolved cell 2. resolve table bottom border 3.
		 * update height of Root area 4. update the status of TableAreaLayout
		 */
		TableContext tableContext = (TableContext)currentContext;
		int borderHeight = 0;
		if ( tableContext.layout != null )
		{
			int height = tableContext.layout.resolveAll( );
			if ( 0 != height)
			{
				currentContext.currentBP = currentContext.currentBP + height;
			}
			borderHeight = tableContext.layout.resolveBottomBorder( );<commit_msg>Fix Bugzilla  Bug 235984 [Regression] There are extra empty rows when preview the sample report [0301] [1200]<commit_after>/***********************************************************************
 * Copyright (c) 2008 Actuate Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Actuate Corporation - initial API and implementation
 ***********************************************************************/

package org.eclipse.birt.report.engine.layout.pdf.emitter;

import java.util.ArrayList;
import java.util.Iterator;

import org.eclipse.birt.report.engine.content.IBandContent;
import org.eclipse.birt.report.engine.content.ICellContent;
import org.eclipse.birt.report.engine.content.IColumn;
import org.eclipse.birt.report.engine.content.IContent;
import org.eclipse.birt.report.engine.content.ILabelContent;
import org.eclipse.birt.report.engine.content.IReportContent;
import org.eclipse.birt.report.engine.content.IRowContent;
import org.eclipse.birt.report.engine.content.IStyle;
import org.eclipse.birt.report.engine.content.ITableBandContent;
import org.eclipse.birt.report.engine.content.ITableContent;
import org.eclipse.birt.report.engine.css.engine.StyleConstants;
import org.eclipse.birt.report.engine.ir.DimensionType;
import org.eclipse.birt.report.engine.ir.EngineIRConstants;
import org.eclipse.birt.report.engine.layout.area.impl.AbstractArea;
import org.eclipse.birt.report.engine.layout.area.impl.AreaFactory;
import org.eclipse.birt.report.engine.layout.area.impl.CellArea;
import org.eclipse.birt.report.engine.layout.area.impl.RowArea;
import org.eclipse.birt.report.engine.layout.area.impl.TableArea;
import org.eclipse.birt.report.engine.layout.pdf.util.PropertyUtil;


public class TableLayout extends RepeatableLayout
{

	
	
	/**
	 * table content
	 */
	private ITableContent tableContent;


	/**
	 * number of table column
	 */
	protected int columnNumber;
	
	/**
	 * the first visible column id of the table.
	 */
	protected int startCol = -1;
	
	/**
	 * the last visible column id of the table.
	 */
	protected int endCol = -1;

	/**
	 * table width
	 */
	protected int tableWidth;

	protected TableLayoutInfo layoutInfo = null;

	protected TableContext tableContext = null;
	
	protected ColumnWidthResolver columnWidthResolver;

	
	protected TableAreaLayout regionLayout = null;
	
	public TableLayout( LayoutEngineContext context,
			ContainerLayout parent, IContent content )
	{
		super( context, parent, content );
		tableContent = (ITableContent) content;
		columnWidthResolver = new ColumnWidthResolver( tableContent );
		columnNumber = tableContent.getColumnCount( );
		boolean isBlock = !PropertyUtil.isInlineElement(content);
		isInBlockStacking &= isBlock;
	}

	protected void createRoot( )
	{
		currentContext.root = AreaFactory.createTableArea( (ITableContent) content );
		currentContext.root.setWidth( tableWidth );
	}

	public TableLayoutInfo getLayoutInfo( )
	{
		return layoutInfo;
	}

	protected void buildTableLayoutInfo( )
	{
		this.layoutInfo = resolveTableFixedLayout((TableArea)currentContext.root );

	}
	
	public int getColumnCount()
	{
		if(tableContent!=null)
		{
			return tableContent.getColumnCount();
		}
		return 0;
	}

	protected void initialize( )
	{
		currentContext = new TableContext( );
		contextList.add( currentContext );
		tableContext = (TableContext)currentContext;
		createRoot( );
		buildTableLayoutInfo( );
		currentContext.root.setWidth( layoutInfo.getTableWidth( ) );
		currentContext.maxAvaWidth = layoutInfo.getTableWidth( );

		if ( parent != null )
		{
			currentContext.root.setAllocatedHeight( parent.getCurrentMaxContentHeight( ) );
		}
		else
		{
			currentContext.root.setAllocatedHeight( context.getMaxHeight( ) );
		}
		if ( tableContext.layout == null )
		{
			int start = 0;
			int end = tableContent.getColumnCount( ) -1;
			tableContext.layout = new TableAreaLayout( tableContent, layoutInfo, start,
					end );
			//layout.initTableLayout( context.getUnresolvedRowHint( tableContent ) );
		}
		currentContext.maxAvaHeight = currentContext.root.getContentHeight( ) - getBottomBorderWidth( );
		repeatHeader();
		addCaption( tableContent.getCaption( ) );
	}

	protected void closeLayout( ContainerContext currentContext, int index, boolean finished )
	{
		if(currentContext.root==null || currentContext.root.getChildrenCount()==0)
		{
			return;
		}
		/*
		 * 1. resolve all unresolved cell 2. resolve table bottom border 3.
		 * update height of Root area 4. update the status of TableAreaLayout
		 */
		TableContext tableContext = (TableContext)currentContext;
		int borderHeight = 0;
		if ( tableContext.layout != null )
		{
			int height = tableContext.layout.resolveAll( );
			if ( 0 != height)
			{
				currentContext.currentBP = currentContext.currentBP + height;
			}
			borderHeight = tableContext.layout.resolveBottomBorder( );
{'fraction_non_alphanumeric': 0.1279830832745947, 'fraction_numerical': 0.005336824086194744, 'mean_word_length': 4.598647125140925, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2567850', 'n_tokens_mistral': 3109, 'n_tokens_neox': 2827, 'n_words': 624}