public void AutoAdjustColumnWidths() { double[] array = new double[this.tableData[0].Count]; for (int i = 0; i < this.tableData.Count; i++) { List <Cell> list = this.tableData[i]; for (int j = 0; j < list.Count; j++) { Cell cell = list[j]; if (cell.GetColSpan() == 1 && cell.text != null) { cell.SetWidth((double)cell.font.StringWidth(cell.text)); if (array[j] == 0.0 || (double)cell.GetWidth() > array[j]) { array[j] = (double)cell.GetWidth(); } } } } for (int k = 0; k < this.tableData.Count; k++) { List <Cell> list2 = this.tableData[k]; for (int l = 0; l < list2.Count; l++) { Cell cell2 = list2[l]; cell2.SetWidth(array[l] + (double)(3f * this.padding)); } } }
private float[] DrawHeaderRows(Page page, int pageNumber) { float x = x1; float y = (pageNumber == 1) ? y1FirstPage : y1; float cellH; for (int i = 0; i < numOfHeaderRows; i++) { List <Cell> dataRow = tableData[i]; cellH = GetMaxCellHeight(dataRow); for (int j = 0; j < dataRow.Count; j++) { Cell cell = dataRow[j]; float cellW = cell.GetWidth(); int colspan = cell.GetColSpan(); for (int k = 1; k < colspan; k++) { cellW += dataRow[++j].GetWidth(); } if (page != null) { page.SetBrushColor(cell.GetBrushColor()); cell.Paint(page, x, y, cellW, cellH); } x += cellW; } x = x1; y += cellH; } return(new float[] { x, y }); }
public void FitToPage(float[] pageSize) { AutoAdjustColumnWidths(); float tableWidth = (pageSize[0] - this.x1) - rightMargin; float textColumnWidths = 0f; float otherColumnWidths = 0f; List <Cell> row = tableData[0]; for (int i = 0; i < row.Count; i++) { Cell cell = row[i]; if (IsTextColumn(i)) { textColumnWidths += cell.GetWidth(); } else { otherColumnWidths += cell.GetWidth(); } } float adjusted; if ((tableWidth - otherColumnWidths) > textColumnWidths) { adjusted = textColumnWidths + ((tableWidth - otherColumnWidths) - textColumnWidths); } else { adjusted = textColumnWidths - (textColumnWidths - (tableWidth - otherColumnWidths)); } float factor = adjusted / textColumnWidths; for (int i = 0; i < row.Count; i++) { if (IsTextColumn(i)) { SetColumnWidth(i, GetColumnWidth(i) * factor); } } AutoResizeColumnsWithColspanBiggerThanOne(); MergeOverlaidBorders(); }
/** * Auto adjusts the widths of all columns so that they are just wide enough to hold the text without truncation. */ public void AutoAdjustColumnWidths() { // Find the maximum text width for each column float[] max_col_widths = new float[tableData[0].Count]; for (int i = 0; i < tableData.Count; i++) { List <Cell> row = tableData[i]; for (int j = 0; j < row.Count; j++) { Cell cell = row[j]; if (cell.GetColSpan() == 1) { float cellWidth = 0f; if (cell.image != null) { cellWidth = cell.image.GetWidth(); } if (cell.text != null) { if (cell.font.StringWidth(cell.fallbackFont, cell.text) > cellWidth) { cellWidth = cell.font.StringWidth(cell.fallbackFont, cell.text); } } cell.SetWidth(cellWidth + cell.left_padding + cell.right_padding); if (max_col_widths[j] == 0f || cell.GetWidth() > max_col_widths[j]) { max_col_widths[j] = cell.GetWidth(); } } } } for (int i = 0; i < tableData.Count; i++) { List <Cell> row = tableData[i]; for (int j = 0; j < row.Count; j++) { Cell cell = row[j]; cell.SetWidth(max_col_widths[j]); } } }
private float[] DrawHeaderRows(Page page, bool draw) { float x = x1; float y = y1; float cell_w = 0f; float cell_h = 0f; for (int i = 0; i < numOfHeaderRows; i++) { List <Cell> dataRow = tableData[i]; cell_h = GetMaxCellHeight(dataRow); for (int j = 0; j < dataRow.Count; j++) { Cell cell = dataRow[j]; float cellHeight = cell.GetHeight(); if (cellHeight > cell_h) { cell_h = cellHeight; } cell_w = cell.GetWidth(); for (int k = 1; k < cell.GetColSpan(); k++) { cell_w += dataRow[++j].GetWidth(); } if (draw) { page.SetBrushColor(cell.GetBrushColor()); cell.Paint(page, x, y, cell_w, cell_h); } x += cell_w; } x = x1; y += cell_h; } return(new float[] { x, y, cell_w, cell_h }); }
private void AutoResizeColumnsWithColspanBiggerThanOne() { for (int i = 0; i < tableData.Count; i++) { List <Cell> dataRow = tableData[i]; for (int j = 0; j < dataRow.Count; j++) { Cell cell = dataRow[j]; int colspan = cell.GetColSpan(); if (colspan > 1) { if (cell.textBlock != null) { float sumOfWidths = cell.GetWidth(); for (int k = 1; k < colspan; k++) { sumOfWidths += dataRow[++j].GetWidth(); } cell.textBlock.SetWidth(sumOfWidths - (cell.leftPadding + cell.rightPadding)); } } } } }
/** * Wraps around the text in all cells so it fits the column width. * This method should be called after all calls to setColumnWidth and autoAdjustColumnWidths. */ public void WrapAroundCellText() { List <List <Cell> > tableData2 = new List <List <Cell> >(); for (int i = 0; i < tableData.Count; i++) { List <Cell> row = tableData[i]; for (int j = 0; j < row.Count; j++) { Cell cell = row[j]; int colspan = cell.GetColSpan(); for (int n = 1; n < colspan; n++) { Cell next = row[j + n]; cell.SetWidth(cell.GetWidth() + next.GetWidth()); next.SetWidth(0f); } } } // Adjust the number of header rows automatically! numOfHeaderRows = GetNumHeaderRows(); rendered = numOfHeaderRows; AddExtraTableRows(tableData2); for (int i = 0; i < tableData2.Count; i++) { List <Cell> row = tableData2[i]; for (int j = 0; j < row.Count; j++) { Cell cell = row[j]; if (cell.text != null) { int n = 0; float effectiveWidth = cell.width - (cell.leftPadding + cell.rightPadding); String[] tokens = TextUtils.SplitTextIntoTokens( cell.text, cell.font, cell.fallbackFont, effectiveWidth); StringBuilder buf = new StringBuilder(); foreach (String token in tokens) { if (cell.font.StringWidth(cell.fallbackFont, (buf.ToString() + " " + token).Trim()) > effectiveWidth) { tableData2[i + n][j].SetText(buf.ToString().Trim()); buf = new StringBuilder(token); n++; } else { buf.Append(" "); buf.Append(token); } } tableData2[i + n][j].SetText(buf.ToString().Trim()); } else { tableData2[i][j].SetCompositeTextLine(cell.GetCompositeTextLine()); } } } tableData = tableData2; }
private float[] DrawTableRows(Page page, float[] parameter) { float x = parameter[0]; float y = parameter[1]; float cellH; for (int i = rendered; i < tableData.Count; i++) { List <Cell> dataRow = tableData[i]; cellH = GetMaxCellHeight(dataRow); for (int j = 0; j < dataRow.Count; j++) { Cell cell = dataRow[j]; float cellW = cell.GetWidth(); int colspan = cell.GetColSpan(); for (int k = 1; k < colspan; k++) { cellW += dataRow[++j].GetWidth(); } if (page != null) { page.SetBrushColor(cell.GetBrushColor()); cell.Paint(page, x, y, cellW, cellH); } x += cellW; } x = x1; y += cellH; // Consider the height of the next row when checking if we must go to a new page if (i < (tableData.Count - 1)) { List <Cell> nextRow = tableData[i + 1]; for (int j = 0; j < nextRow.Count; j++) { Cell cell = nextRow[j]; float cellHeight = cell.GetHeight(); if (cellHeight > cellH) { cellH = cellHeight; } } } if (page != null && (y + cellH) > (page.height - bottomMargin)) { if (i == tableData.Count - 1) { rendered = -1; } else { rendered = i + 1; numOfPages++; } return(new float[] { x, y }); } } rendered = -1; return(new float[] { x, y }); }
/** * Wraps around the text in all cells so it fits the column width. * This method should be called after all calls to SetColumnWidth and AutoAdjustColumnWidths. * */ public void WrapAroundCellText() { List <List <Cell> > tableData2 = new List <List <Cell> >(); for (int i = 0; i < tableData.Count; i++) { List <Cell> row = tableData[i]; int maxNumVerCells = 1; for (int j = 0; j < row.Count; j++) { Cell cell = row[j]; int colspan = cell.GetColSpan(); for (int n = 1; n < colspan; n++) { Cell next = row[j + n]; cell.SetWidth(cell.GetWidth() + next.GetWidth()); next.SetWidth(0f); } int numVerCells = cell.GetNumVerCells(); if (numVerCells > maxNumVerCells) { maxNumVerCells = numVerCells; } } for (int j = 0; j < maxNumVerCells; j++) { List <Cell> row2 = new List <Cell>(); for (int k = 0; k < row.Count; k++) { Cell cell = row[k]; Cell cell2 = new Cell(cell.GetFont(), ""); cell2.SetFallbackFont(cell.GetFallbackFont()); cell2.SetPoint(cell.GetPoint()); cell2.SetWidth(cell.GetWidth()); if (j == 0) { cell2.SetTopPadding(cell.top_padding); } if (j == (maxNumVerCells - 1)) { cell2.SetBottomPadding(cell.bottom_padding); } cell2.SetLeftPadding(cell.left_padding); cell2.SetRightPadding(cell.right_padding); cell2.SetLineWidth(cell.GetLineWidth()); cell2.SetBgColor(cell.GetBgColor()); cell2.SetPenColor(cell.GetPenColor()); cell2.SetBrushColor(cell.GetBrushColor()); cell2.SetProperties(cell.GetProperties()); cell2.SetVerTextAlignment(cell.GetVerTextAlignment()); cell2.SetIgnoreImageHeight(cell.GetIgnoreImageHeight()); if (j == 0) { cell2.SetImage(cell.GetImage()); if (cell.GetCompositeTextLine() != null) { cell2.SetCompositeTextLine(cell.GetCompositeTextLine()); } else { cell2.SetText(cell.GetText()); } if (maxNumVerCells > 1) { cell2.SetBorder(Border.BOTTOM, false); } } else { cell2.SetBorder(Border.TOP, false); if (j < (maxNumVerCells - 1)) { cell2.SetBorder(Border.BOTTOM, false); } } row2.Add(cell2); } tableData2.Add(row2); } } for (int i = 0; i < tableData2.Count; i++) { List <Cell> row = tableData2[i]; for (int j = 0; j < row.Count; j++) { Cell cell = row[j]; if (cell.text != null) { int n = 0; String[] textLines = cell.GetText().Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); foreach (String textLine in textLines) { StringBuilder sb = new StringBuilder(); String[] tokens = Regex.Split(textLine, @"\s+"); if (tokens.Length == 1) { sb.Append(tokens[0]); } else { for (int k = 0; k < tokens.Length; k++) { String token = tokens[k]; if (cell.font.StringWidth(cell.fallbackFont, sb.ToString() + " " + token) > (cell.GetWidth() - (cell.left_padding + cell.right_padding))) { tableData2[i + n][j].SetText(sb.ToString()); sb = new StringBuilder(token); n++; } else { if (k > 0) { sb.Append(" "); } sb.Append(token); } } } tableData2[i + n][j].SetText(sb.ToString()); n++; } } else { tableData2[i][j].SetCompositeTextLine(cell.GetCompositeTextLine()); } } } tableData = tableData2; }
private Point DrawTableRows(Page page, bool draw, float[] parameter) { float x = parameter[0]; float y = parameter[1]; float cell_w = parameter[2]; float cell_h = parameter[3]; for (int i = rendered; i < tableData.Count; i++) { List <Cell> dataRow = tableData[i]; cell_h = GetMaxCellHeight(dataRow); for (int j = 0; j < dataRow.Count; j++) { Cell cell = dataRow[j]; float cellHeight = cell.GetHeight(); if (cellHeight > cell_h) { cell_h = cellHeight; } cell_w = cell.GetWidth(); for (int k = 1; k < cell.GetColSpan(); k++) { cell_w += dataRow[++j].GetWidth(); } if (draw) { page.SetBrushColor(cell.GetBrushColor()); cell.Paint(page, x, y, cell_w, cell_h); } x += cell_w; } x = x1; y += cell_h; // Consider the height of the next row when checking if we must go to a new page if (i < (tableData.Count - 1)) { List <Cell> nextRow = tableData[i + 1]; for (int j = 0; j < nextRow.Count; j++) { Cell cell = nextRow[j]; float cellHeight = cell.GetHeight(); if (cellHeight > cell_h) { cell_h = cellHeight; } } } if ((y + cell_h) > (page.height - bottom_margin)) { if (i == tableData.Count - 1) { rendered = -1; } else { rendered = i + 1; numOfPages++; } return(new Point(x, y)); } } rendered = -1; return(new Point(x, y)); }
public void WrapAroundCellText() { List <List <Cell> > list = new List <List <Cell> >(); for (int i = 0; i < this.tableData.Count; i++) { List <Cell> list2 = this.tableData[i]; int num = 1; for (int j = 0; j < list2.Count; j++) { Cell cell = list2[j]; int colSpan = cell.GetColSpan(); for (int k = 1; k < colSpan; k++) { Cell cell2 = list2[j + k]; cell.SetWidth((double)(cell.GetWidth() + cell2.GetWidth())); cell2.SetWidth(0.0); } int numVerCells = cell.GetNumVerCells(this.padding); if (numVerCells > num) { num = numVerCells; } } for (int l = 0; l < num; l++) { List <Cell> list3 = new List <Cell>(); for (int m = 0; m < list2.Count; m++) { Cell cell3 = list2[m]; Cell cell4 = new Cell(cell3.GetFont(), ""); cell4.SetPoint(cell3.GetPoint()); cell4.SetCompositeTextLine(cell3.GetCompositeTextLine()); cell4.SetWidth((double)cell3.GetWidth()); if (l == 0) { cell4.SetTopPadding(cell3.top_padding); } if (l == num - 1) { cell4.SetBottomPadding(cell3.bottom_padding); } cell4.SetLeftPadding(cell3.left_padding); cell4.SetRightPadding(cell3.right_padding); cell4.SetLineWidth(cell3.GetLineWidth()); cell4.SetBgColor(cell3.GetBgColor()); cell4.SetPenColor(cell3.GetPenColor()); cell4.SetBrushColor(cell3.GetBrushColor()); cell4.SetProperties(cell3.GetProperties()); if (l == 0) { cell4.SetText(cell3.GetText()); } else { if (l > 0) { cell4.SetBorder(65536, false); if (l < num - 1) { cell4.SetBorder(131072, false); } } } list3.Add(cell4); } list.Add(list3); } } for (int n = 0; n < list.Count; n++) { List <Cell> list4 = list[n]; for (int num2 = 0; num2 < list4.Count; num2++) { Cell cell5 = list4[num2]; if (cell5.text != null) { int num3 = 0; string[] array = Regex.Split(cell5.GetText(), "\\s+"); StringBuilder stringBuilder = new StringBuilder(); if (array.Length == 1) { stringBuilder.Append(array[0]); } else { for (int num4 = 0; num4 < array.Length; num4++) { string text = array[num4]; if (cell5.font.StringWidth(stringBuilder.ToString() + " " + text) > cell5.GetWidth() - (cell5.left_padding + cell5.right_padding + 2f * this.padding)) { list[n + num3][num2].SetText(stringBuilder.ToString()); stringBuilder = new StringBuilder(text); num3++; } else { if (num4 > 0) { stringBuilder.Append(" "); } stringBuilder.Append(text); } } } list[n + num3][num2].SetText(stringBuilder.ToString()); } } } this.tableData = list; }
public Point DrawOn(Page page, bool draw) { float num = this.x1; float num2 = this.y1; for (int i = 0; i < this.numOfHeaderRows; i++) { float num3 = 0f; List <Cell> list = this.tableData[i]; for (int j = 0; j < list.Count; j++) { Cell cell = list[j]; float num4 = cell.GetHeight() + 2f * this.padding; if (num4 > num3) { num3 = num4; } float num5 = cell.GetWidth(); for (int k = 1; k < cell.GetColSpan(); k++) { num5 += list[++j].GetWidth(); } if (draw) { page.SetBrushColor(cell.GetBrushColor()); cell.Paint(page, num, num2, num5, num3, this.padding); } num += num5; } num = this.x1; num2 += num3; } for (int l = this.rendered; l < this.tableData.Count; l++) { float num3 = 0f; List <Cell> list2 = this.tableData[l]; for (int m = 0; m < list2.Count; m++) { Cell cell2 = list2[m]; float num6 = cell2.GetHeight() + 2f * this.padding; if (num6 > num3) { num3 = num6; } float num5 = cell2.GetWidth(); for (int n = 1; n < cell2.GetColSpan(); n++) { num5 += list2[++m].GetWidth(); } if (draw) { page.SetBrushColor(cell2.GetBrushColor()); cell2.Paint(page, num, num2, num5, num3, this.padding); } num += num5; } num = this.x1; num2 += num3; if (l < this.tableData.Count - 1) { List <Cell> list3 = this.tableData[l + 1]; for (int num7 = 0; num7 < list3.Count; num7++) { Cell cell3 = list3[num7]; float num8 = cell3.GetHeight() + 2f * this.padding; if (num8 > num3) { num3 = num8; } } } if (num2 + num3 > page.height - this.bottom_margin) { if (l == this.tableData.Count - 1) { this.rendered = -1; } else { this.rendered = l + 1; this.numOfPages++; } return(new Point(num, num2)); } } this.rendered = -1; return(new Point(num, num2)); }