private void BreakRow(TableBase breakTo, int rowIndex, float rowHeight, float newRowHeight) { // set rows height TableRow rowTo = breakTo.Rows[rowIndex]; Rows[rowIndex].Height = rowHeight; rowTo.Height = newRowHeight; // break each cell in the row for (int i = 0; i < ColumnCount; i++) { TableCell cell = this[i, rowIndex]; TableCell cellTo = breakTo[i, rowIndex]; cell.Height = rowHeight; cell.Break(cellTo); // fix height if row is not autosized if (!rowTo.AutoSize) { float h = cellTo.CalcHeight(); if (h > rowTo.Height) { rowTo.Height = h; } } } }
private bool CanBreakRow(int rowIndex, float rowHeight) { if (!Rows[rowIndex].CanBreak) { return(false); } // check each cell in the row for (int i = 0; i < ColumnCount; i++) { TableCell breakable = this[i, rowIndex]; // use clone object because Break method will modify the Text property using (TableCell clone = new TableCell()) { clone.AssignAll(breakable); clone.Height = rowHeight; clone.SetReport(Report); if (!clone.Break(null)) { return(false); } } } return(true); }
private float GeneratePage(int startColumn, int startRow, int columnsFit, int rowsFit, RectangleF bounds, List <Rectangle> spans) { // break spans foreach (Rectangle span in spans) { TableCellData spannedCell = GetCellData(span.Left, span.Top); TableCellData newSpannedCell = null; if (span.Left < startColumn && span.Right > startColumn) { if ((RepeatHeaders || RepeatRowHeaders) && span.Left < FixedColumns) { spannedCell.ColSpan = Math.Min(span.Right, startColumn + columnsFit) - startColumn + FixedColumns; } else { newSpannedCell = GetCellData(startColumn, span.Top); newSpannedCell.RunTimeAssign(spannedCell.Cell, true); newSpannedCell.ColSpan = Math.Min(span.Right, startColumn + columnsFit) - startColumn; newSpannedCell.RowSpan = spannedCell.RowSpan; AdjustSpannedCellWidth(newSpannedCell); } } if (span.Left < startColumn + columnsFit && span.Right > startColumn + columnsFit) { spannedCell.ColSpan = startColumn + columnsFit - span.Left; AdjustSpannedCellWidth(spannedCell); } if (span.Top < startRow && span.Bottom > startRow) { if ((RepeatHeaders || RepeatColumnHeaders) && span.Top < FixedRows) { spannedCell.RowSpan = Math.Min(span.Bottom, startRow + rowsFit) - startRow + FixedRows; } } if (span.Top < startRow + rowsFit && span.Bottom > startRow + rowsFit) { spannedCell.RowSpan = startRow + rowsFit - span.Top; newSpannedCell = GetCellData(span.Left, startRow + rowsFit); newSpannedCell.RunTimeAssign(spannedCell.Cell, true); newSpannedCell.ColSpan = spannedCell.ColSpan; newSpannedCell.RowSpan = span.Bottom - (startRow + rowsFit); // break the cell text TableCell cell = spannedCell.Cell; using (TextObject tempObject = new TextObject()) { if (!cell.Break(tempObject)) { cell.Text = ""; } if (cell.CanBreak) { newSpannedCell.Text = tempObject.Text; } } // fix the row height float textHeight = newSpannedCell.Cell.CalcHeight(); float rowsHeight = 0; for (int i = 0; i < newSpannedCell.RowSpan; i++) { rowsHeight += Rows[i + startRow + rowsFit].Height; } if (rowsHeight < textHeight) { // fix the last row's height Rows[startRow + rowsFit + newSpannedCell.RowSpan - 1].Height += textHeight - rowsHeight; } } } // set visible columns ColumnsToSerialize.Clear(); if (RepeatHeaders || RepeatRowHeaders) { for (int i = 0; i < FixedColumns; i++) { if (Columns[i].Visible) { ColumnsToSerialize.Add(Columns[i]); } } if (startColumn < FixedColumns) { columnsFit -= FixedColumns - startColumn; startColumn = FixedColumns; } } // calc visible columns and last X coordinate of table for unlimited page width float tableEndX = Columns[0].Width; for (int i = startColumn; i < startColumn + columnsFit; i++) { if (Columns[i].Visible) { ColumnsToSerialize.Add(Columns[i]); tableEndX += Columns[i].Width; } } // set visible rows RowsToSerialize.Clear(); if (RepeatHeaders || RepeatColumnHeaders) { for (int i = 0; i < FixedRows; i++) { if (Rows[i].Visible) { RowsToSerialize.Add(Rows[i]); } } if (startRow < FixedRows) { rowsFit -= FixedRows - startRow; startRow = FixedRows; } } // calc visible rows and last Y coordinate of table for unlimited page height float tableEndY = Rows[0].Top; for (int i = startRow; i < startRow + rowsFit; i++) { if (Rows[i].Visible) { RowsToSerialize.Add(Rows[i]); tableEndY += Rows[i].Height; } } // include row header if (startRow != 0 && (RepeatHeaders || RepeatColumnHeaders)) { for (int i = 0; i < FixedRows; i++) { tableEndY += Rows[i].Height; } } // generate unlimited page if (Report.Engine.UnlimitedHeight || Report.Engine.UnlimitedWidth) { ReportPage page = Report.PreparedPages.GetPage(Report.Engine.CurPage); if (Report.Engine.UnlimitedHeight) { bounds.Height = tableEndY; } if (Report.Engine.UnlimitedWidth) { bounds.Width = tableEndX; } Report.PreparedPages.ModifyPage(Report.Engine.CurPage, page); } DataBand band = new DataBand(); band.Bounds = bounds; band.Objects.Add(this); Report.Engine.AddToPreparedPages(band); return(GetRowsHeight(startRow, rowsFit)); }
/// <inheritdoc/> public override bool Break(BreakableComponent breakTo) { if (Rows.Count == 0) { return(true); } if (Height < Rows[0].Height && !Rows[0].CanBreak) { return(false); } TableBase tableTo = breakTo as TableBase; if (tableTo == null) { return(true); } // find the break row index int breakRowIndex = 0; int breakRowIndexAdd = 0; bool rowBroken = false; float rowsHeight = 0; while (breakRowIndex < Rows.Count) { rowsHeight += Rows[breakRowIndex].Height; if (rowsHeight > Height) { float breakRowHeight = Rows[breakRowIndex].Height - (rowsHeight - Height); if (CanBreakRow(breakRowIndex, breakRowHeight)) { BreakRow(tableTo, breakRowIndex, breakRowHeight, rowsHeight - Height); breakRowIndexAdd = 1; rowBroken = true; } break; } breakRowIndex++; } // get the span list List <Rectangle> spans = GetSpanList(); // break the spans foreach (Rectangle span in spans) { if (span.Top < breakRowIndex + breakRowIndexAdd && span.Bottom > breakRowIndex) { TableCell cell = this[span.Left, span.Top]; TableCell cellTo = tableTo[span.Left, span.Top]; // update cell spans cell.RowSpan = breakRowIndex + breakRowIndexAdd - span.Top; cellTo.RowSpan = span.Bottom - breakRowIndex; // break the cell if (!rowBroken && !cell.Break(cellTo)) { cell.Text = ""; } // set the top span cell to the correct place tableTo[span.Left, span.Top] = new TableCell(); tableTo[span.Left, breakRowIndex] = cellTo; } } // remove unused rows from source (this table) while (breakRowIndex + breakRowIndexAdd < Rows.Count) { this.Rows.RemoveAt(Rows.Count - 1); } // remove unused rows from copy (tableTo) for (int i = 0; i < breakRowIndex; i++) { tableTo.Rows.RemoveAt(0); } return(true); }
/// <inheritdoc/> public override bool Break(BreakableComponent breakTo) { if (Rows.Count == 0) { return(true); } if (Height < Rows[0].Height) { return(false); } TableBase tableTo = breakTo as TableBase; if (tableTo == null) { return(true); } // get the span list List <Rectangle> spans = GetSpanList(); // find the break row index int breakRowIndex = 0; float rowsHeight = 0; while (breakRowIndex < Rows.Count && rowsHeight + Rows[breakRowIndex].Height < Height) { rowsHeight += Rows[breakRowIndex].Height; breakRowIndex++; } // break the spans foreach (Rectangle span in spans) { if (span.Top < breakRowIndex && span.Bottom > breakRowIndex) { TableCell cell = this[span.Left, span.Top]; TableCell cellTo = tableTo[span.Left, span.Top]; // update cell spans cell.RowSpan = breakRowIndex - span.Top; cellTo.RowSpan = span.Bottom - breakRowIndex; // break the cell if (!cell.Break(cellTo)) { cell.Text = ""; } tableTo[span.Left, span.Top] = new TableCell(); tableTo[span.Left, breakRowIndex] = cellTo; } } // delete last rows until all rows fit while (breakRowIndex < Rows.Count) { Rows.RemoveAt(Rows.Count - 1); } // delete first rows of the breakTo for (int i = 0; i < breakRowIndex; i++) { tableTo.Rows.RemoveAt(0); } return(true); }
private float GeneratePage(int startColumn, int startRow, int columnsFit, int rowsFit, RectangleF bounds, List <Rectangle> spans) { // break spans foreach (Rectangle span in spans) { TableCellData spannedCell = GetCellData(span.Left, span.Top); TableCellData newSpannedCell = null; if (span.Left < startColumn && span.Right > startColumn) { if (RepeatHeaders && span.Left < FixedColumns) { spannedCell.ColSpan = Math.Min(span.Right, startColumn + columnsFit) - startColumn + FixedColumns; } else { newSpannedCell = GetCellData(startColumn, span.Top); newSpannedCell.RunTimeAssign(spannedCell.Cell, true); newSpannedCell.ColSpan = Math.Min(span.Right, startColumn + columnsFit) - startColumn; newSpannedCell.RowSpan = spannedCell.RowSpan; } } if (span.Left < startColumn + columnsFit && span.Right > startColumn + columnsFit) { spannedCell.ColSpan = startColumn + columnsFit - span.Left; } if (span.Top < startRow && span.Bottom > startRow) { if (RepeatHeaders && span.Top < FixedRows) { spannedCell.RowSpan = Math.Min(span.Bottom, startRow + rowsFit) - startRow + FixedRows; } } if (span.Top < startRow + rowsFit && span.Bottom > startRow + rowsFit) { spannedCell.RowSpan = startRow + rowsFit - span.Top; newSpannedCell = GetCellData(span.Left, startRow + rowsFit); newSpannedCell.RunTimeAssign(spannedCell.Cell, true); newSpannedCell.ColSpan = spannedCell.ColSpan; newSpannedCell.RowSpan = span.Bottom - (startRow + rowsFit); // break the cell text TableCell cell = spannedCell.Cell; using (TextObject tempObject = new TextObject()) { if (!cell.Break(tempObject)) { cell.Text = ""; } if (cell.CanBreak) { newSpannedCell.Text = tempObject.Text; } } // fix the row height float textHeight = newSpannedCell.Cell.CalcHeight(); float rowsHeight = 0; for (int i = 0; i < newSpannedCell.RowSpan; i++) { rowsHeight += Rows[i + startRow + rowsFit].Height; } if (rowsHeight < textHeight) { // fix the last row's height Rows[startRow + rowsFit + newSpannedCell.RowSpan - 1].Height += textHeight - rowsHeight; } } } // set visible columns for (int i = 0; i < Columns.Count; i++) { if (!RepeatHeaders || i >= FixedColumns) { Columns[i].Visible = i >= startColumn && i < startColumn + columnsFit; } } // set visible rows for (int i = 0; i < Rows.Count; i++) { if (!RepeatHeaders || i >= FixedRows) { Rows[i].Visible = i >= startRow && i < startRow + rowsFit; } } DataBand band = new DataBand(); band.Bounds = bounds; band.Objects.Add(this); Report.Engine.AddToPreparedPages(band); return(GetRowsHeight(startRow, rowsFit)); }