/** * Merge this cell into the parent cell. * * @param mergeParent The RtfCell to merge with */ protected internal void SetCellMergeChild(RtfCell mergeParent) { this.mergeType = MERGE_VERT_CHILD; this.cellWidth = mergeParent.GetCellWidth(); this.cellRight = mergeParent.GetCellRight(); this.cellPadding = mergeParent.GetCellpadding(); this.borders = mergeParent.GetBorders(); this.verticalAlignment = mergeParent.VerticalAlignment; this.backgroundColor = mergeParent.GetRtfBackgroundColor(); }
/** * Performs a second pass over all cells to handle cell row/column spanning. */ protected internal void HandleCellSpanning() { RtfCell deletedCell = new RtfCell(true); for (int i = 0; i < this.cells.Count; i++) { RtfCell rtfCell = (RtfCell)this.cells[i]; if (rtfCell.Colspan > 1) { int cSpan = rtfCell.Colspan; for (int j = i + 1; j < i + cSpan; j++) { if (j < this.cells.Count) { RtfCell rtfCellMerge = (RtfCell)this.cells[j]; rtfCell.SetCellRight(rtfCell.GetCellRight() + rtfCellMerge.GetCellWidth()); rtfCell.SetCellWidth(rtfCell.GetCellWidth() + rtfCellMerge.GetCellWidth()); this.cells[j] = deletedCell; } } } if (rtfCell.Rowspan > 1) { ArrayList rows = this.parentTable.GetRows(); for (int j = 1; j < rtfCell.Rowspan; j++) { RtfRow mergeRow = (RtfRow)rows[this.rowNumber + j]; if (this.rowNumber + j < rows.Count) { RtfCell rtfCellMerge = (RtfCell)mergeRow.GetCells()[i]; rtfCellMerge.SetCellMergeChild(rtfCell); } if (rtfCell.Colspan > 1) { int cSpan = rtfCell.Colspan; for (int k = i + 1; k < i + cSpan; k++) { if (k < mergeRow.GetCells().Count) { mergeRow.GetCells()[k] = deletedCell; } } } } } } }
/** * Writes the content of this RtfRow */ public override void WriteContent(Stream result) { WriteRowDefinition(result); for (int i = 0; i < this.cells.Count; i++) { RtfCell rtfCell = (RtfCell)this.cells[i]; rtfCell.WriteContent(result); } result.Write(DELIMITER, 0, DELIMITER.Length); if (this.document.GetDocumentSettings().IsOutputTableRowDefinitionAfter()) { WriteRowDefinition(result); } result.Write(ROW_END, 0, ROW_END.Length); this.document.OutputDebugLinebreak(result); }
/** * Imports a Row and copies all settings * * @param row The Row to import */ private void ImportRow(Row row) { this.cells = new ArrayList(); this.width = this.document.GetDocumentHeader().GetPageSetting().GetPageWidth() - this.document.GetDocumentHeader().GetPageSetting().GetMarginLeft() - this.document.GetDocumentHeader().GetPageSetting().GetMarginRight(); this.width = (int)(this.width * this.parentTable.GetTableWidthPercent() / 100); int cellRight = 0; int cellWidth = 0; for (int i = 0; i < row.Columns; i++) { cellWidth = (int)(this.width * this.parentTable.GetProportionalWidths()[i] / 100); cellRight = cellRight + cellWidth; Cell cell = (Cell)row.GetCell(i); RtfCell rtfCell = new RtfCell(this.document, this, cell); rtfCell.SetCellRight(cellRight); rtfCell.SetCellWidth(cellWidth); this.cells.Add(rtfCell); } }
/** * Writes the row definition/settings. * * @param result The <code>Stream</code> to write the definitions to. */ private void WriteRowDefinition(Stream result) { byte[] t; result.Write(ROW_BEGIN, 0, ROW_BEGIN.Length); this.document.OutputDebugLinebreak(result); result.Write(ROW_WIDTH_STYLE, 0, ROW_WIDTH_STYLE.Length); result.Write(ROW_WIDTH, 0, ROW_WIDTH.Length); result.Write(t = IntToByteArray(this.width), 0, t.Length); if (this.parentTable.GetCellsFitToPage()) { result.Write(ROW_KEEP_TOGETHER, 0, ROW_KEEP_TOGETHER.Length); } if (this.rowNumber <= this.parentTable.GetHeaderRows()) { result.Write(ROW_HEADER_ROW, 0, ROW_HEADER_ROW.Length); } switch (this.parentTable.GetAlignment()) { case Element.ALIGN_LEFT: result.Write(ROW_ALIGN_LEFT, 0, ROW_ALIGN_LEFT.Length); break; case Element.ALIGN_RIGHT: result.Write(ROW_ALIGN_RIGHT, 0, ROW_ALIGN_RIGHT.Length); break; case Element.ALIGN_CENTER: result.Write(ROW_ALIGN_CENTER, 0, ROW_ALIGN_CENTER.Length); break; case Element.ALIGN_JUSTIFIED: case Element.ALIGN_JUSTIFIED_ALL: result.Write(ROW_ALIGN_JUSTIFIED, 0, ROW_ALIGN_JUSTIFIED.Length); break; } result.Write(ROW_GRAPH, 0, ROW_GRAPH.Length); RtfBorderGroup borders = this.parentTable.GetBorders(); if (borders != null) { borders.WriteContent(result); } if (this.parentTable.GetCellSpacing() > 0) { result.Write(ROW_CELL_SPACING_LEFT, 0, ROW_CELL_SPACING_LEFT.Length); result.Write(t = IntToByteArray((int)(this.parentTable.GetCellSpacing() / 2)), 0, t.Length); result.Write(ROW_CELL_SPACING_LEFT_STYLE, 0, ROW_CELL_SPACING_LEFT_STYLE.Length); result.Write(ROW_CELL_SPACING_TOP, 0, ROW_CELL_SPACING_TOP.Length); result.Write(t = IntToByteArray((int)(this.parentTable.GetCellSpacing() / 2)), 0, t.Length); result.Write(ROW_CELL_SPACING_TOP_STYLE, 0, ROW_CELL_SPACING_TOP_STYLE.Length); result.Write(ROW_CELL_SPACING_RIGHT, 0, ROW_CELL_SPACING_RIGHT.Length); result.Write(t = IntToByteArray((int)(this.parentTable.GetCellSpacing() / 2)), 0, t.Length); result.Write(ROW_CELL_SPACING_RIGHT_STYLE, 0, ROW_CELL_SPACING_RIGHT_STYLE.Length); result.Write(ROW_CELL_SPACING_BOTTOM, 0, ROW_CELL_SPACING_BOTTOM.Length); result.Write(t = IntToByteArray((int)(this.parentTable.GetCellSpacing() / 2)), 0, t.Length); result.Write(ROW_CELL_SPACING_BOTTOM_STYLE, 0, ROW_CELL_SPACING_BOTTOM_STYLE.Length); } result.Write(ROW_CELL_PADDING_LEFT, 0, ROW_CELL_PADDING_LEFT.Length); result.Write(t = IntToByteArray((int)(this.parentTable.GetCellPadding() / 2)), 0, t.Length); result.Write(ROW_CELL_PADDING_RIGHT, 0, ROW_CELL_PADDING_RIGHT.Length); result.Write(t = IntToByteArray((int)(this.parentTable.GetCellPadding() / 2)), 0, t.Length); result.Write(ROW_CELL_PADDING_LEFT_STYLE, 0, ROW_CELL_PADDING_LEFT_STYLE.Length); result.Write(ROW_CELL_PADDING_RIGHT_STYLE, 0, ROW_CELL_PADDING_RIGHT_STYLE.Length); this.document.OutputDebugLinebreak(result); for (int i = 0; i < this.cells.Count; i++) { RtfCell rtfCell = (RtfCell)this.cells[i]; rtfCell.WriteDefinition(result); } }