예제 #1
0
 /**
  * Gets the TableWrapper from the Stack and adds a new row.
  * @since 5.0.6
  */
 virtual public void ProcessRow() {
     List<PdfPCell> row = new List<PdfPCell>();
     List<float> cellWidths = new List<float>();
     bool percentage = false;
     float width;
     float totalWidth = 0;
     int zeroWidth = 0;
     TableWrapper table = null;
     while (true) {
         IElement obj = stack.Pop();
         if (obj is CellWrapper) {
             CellWrapper cell = (CellWrapper)obj;
             width = cell.Width;
             cellWidths.Add(width);
             percentage |= cell.IsPercentage;
             if (width == 0) {
                 zeroWidth++;
             }
             else {
                 totalWidth += width;
             }
             row.Add(cell.Cell);
         }
         if (obj is TableWrapper) {
             table = (TableWrapper) obj;
             break;
         }
     }
     table.AddRow(row);
     if (cellWidths.Count > 0) {
         // cells come off the stack in reverse, naturally
         totalWidth = 100 - totalWidth;
         cellWidths.Reverse();
         float[] widths = new float[cellWidths.Count];
         bool hasZero = false;
         for (int i = 0; i < widths.Length; i++) {
             widths[i] = cellWidths[i];
             if (widths[i] == 0 && percentage && zeroWidth > 0) {
                 widths[i] = totalWidth / zeroWidth;
             }
             if (widths[i] == 0) {
                 hasZero = true;
                 break;
             }
         }
         if (!hasZero)
             table.ColWidths = widths;
     }
     stack.Push(table);
 }
예제 #2
0
 /**
  * Adds a new row to the table.
  * @param row a list of PdfPCell elements
  */
 public void AddRow(IList<PdfPCell> row) {
     if (row != null) {
         List<PdfPCell> t = new List<PdfPCell>(row);
         t.Reverse();
         rows.Add(t);
     }
 }