Exemple #1
0
        protected internal virtual void BuildBordersArrays(CellRenderer cell, int row, bool isNeighbourCell)
        {
            int colspan = (int)cell.GetPropertyAsInteger(Property.COLSPAN);
            int rowspan = (int)cell.GetPropertyAsInteger(Property.ROWSPAN);
            int colN    = ((Cell)cell.GetModelElement()).GetCol();

            Border[] cellBorders = cell.GetBorders();
            // cell with big rowspan was splitted
            if (row + 1 - rowspan < 0)
            {
                rowspan = row + 1;
            }
            // consider top border
            for (int i = 0; i < colspan; i++)
            {
                CheckAndReplaceBorderInArray(horizontalBorders, row + 1 - rowspan, colN + i, cellBorders[0], false);
            }
            // consider bottom border
            for (int i = 0; i < colspan; i++)
            {
                CheckAndReplaceBorderInArray(horizontalBorders, row + 1, colN + i, cellBorders[2], true);
            }
            // consider left border
            for (int j = row - rowspan + 1; j <= row; j++)
            {
                CheckAndReplaceBorderInArray(verticalBorders, colN, j, cellBorders[3], false);
            }
            // consider right border
            for (int i = row - rowspan + 1; i <= row; i++)
            {
                CheckAndReplaceBorderInArray(verticalBorders, colN + colspan, i, cellBorders[1], true);
            }
        }
Exemple #2
0
        //endregion
        protected internal override void BuildBordersArrays(CellRenderer cell, int row, int col, int[] rowspansToDeduct
                                                            )
        {
            // We should check if the row number is less than horizontal borders array size. It can happen if the cell with
            // big rowspan doesn't fit current area and is going to be placed partial.
            if (row > horizontalBorders.Count)
            {
                row--;
            }
            int currCellColspan = (int)cell.GetPropertyAsInteger(Property.COLSPAN);
            int nextCellRow;
            int j;

            // consider the cell on the left side of the current one
            if (col != 0 && null == rows[row][col - 1])
            {
                j = col;
                do
                {
                    j--;
                    nextCellRow = row;
                    while (rows.Count != nextCellRow && null == rows[nextCellRow][j])
                    {
                        nextCellRow++;
                    }
                }while (j > 0 && rows.Count != nextCellRow && (j + (int)rows[nextCellRow][j].GetPropertyAsInteger(Property.
                                                                                                                  COLSPAN) != col || (int)nextCellRow - rows[(int)nextCellRow][j].GetPropertyAsInteger(Property.ROWSPAN)
                                                               + 1 + rowspansToDeduct[j] != row));
                // process only valid cells which hasn't been processed yet
                if (j >= 0 && nextCellRow != rows.Count && nextCellRow > row)
                {
                    CellRenderer nextCell = rows[nextCellRow][j];
                    nextCell.SetProperty(Property.ROWSPAN, ((int)nextCell.GetPropertyAsInteger(Property.ROWSPAN)) - rowspansToDeduct
                                         [j]);
                    int nextCellColspan = (int)nextCell.GetPropertyAsInteger(Property.COLSPAN);
                    for (int i = j; i < j + nextCellColspan; i++)
                    {
                        rowspansToDeduct[i] = 0;
                    }
                    BuildBordersArrays(nextCell, nextCellRow, true);
                }
            }
            // consider cells under the current one
            j = 0;
            while (j < currCellColspan)
            {
                nextCellRow = row + 1;
                while (nextCellRow < rows.Count && null == rows[nextCellRow][col + j])
                {
                    nextCellRow++;
                }
                if (nextCellRow == rows.Count)
                {
                    break;
                }
                CellRenderer nextCell = rows[nextCellRow][col + j];
                // otherwise the border was considered previously
                if (row == nextCellRow - (int)nextCell.GetPropertyAsInteger(Property.ROWSPAN))
                {
                    BuildBordersArrays(nextCell, nextCellRow, true);
                }
                j += (int)nextCell.GetPropertyAsInteger(Property.COLSPAN);
            }
            // consider cells on the right side of the current one
            if (col + currCellColspan < rows[row].Length)
            {
                nextCellRow = row;
                while (nextCellRow < rows.Count && null == rows[nextCellRow][col + currCellColspan])
                {
                    nextCellRow++;
                }
                if (nextCellRow != rows.Count)
                {
                    CellRenderer nextCell = rows[nextCellRow][col + currCellColspan];
                    nextCell.SetProperty(Property.ROWSPAN, ((int)nextCell.GetPropertyAsInteger(Property.ROWSPAN)) - rowspansToDeduct
                                         [col + currCellColspan]);
                    int nextCellColspan = (int)nextCell.GetPropertyAsInteger(Property.COLSPAN);
                    for (int i = col + currCellColspan; i < col + currCellColspan + nextCellColspan; i++)
                    {
                        rowspansToDeduct[i] = 0;
                    }
                    BuildBordersArrays(nextCell, nextCellRow, true);
                }
            }
            // consider current cell
            BuildBordersArrays(cell, row, false);
        }
Exemple #3
0
 public override IList <Border> GetHorizontalBorder(int index)
 {
     if (index == startRow)
     {
         IList <Border> firstBorderOnCurrentPage = TableBorderUtil.CreateAndFillBorderList(topBorderCollapseWith, tableBoundingBorders
                                                                                           [0], numberOfColumns);
         if (index == largeTableIndexOffset)
         {
             return(GetCollapsedList(horizontalBorders[index - largeTableIndexOffset], firstBorderOnCurrentPage));
         }
         if (0 != rows.Count)
         {
             int col = 0;
             int row = index;
             while (col < numberOfColumns)
             {
                 if (null != rows[row - largeTableIndexOffset][col] && row - index + 1 <= (int)((Cell)rows[row - largeTableIndexOffset
                                                                                                ][col].GetModelElement()).GetRowspan())
                 {
                     CellRenderer cell = rows[row - largeTableIndexOffset][col];
                     Border       cellModelTopBorder = TableBorderUtil.GetCellSideBorder(((Cell)cell.GetModelElement()), Property.BORDER_TOP
                                                                                         );
                     int colspan = (int)cell.GetPropertyAsInteger(Property.COLSPAN);
                     if (null == firstBorderOnCurrentPage[col] || (null != cellModelTopBorder && cellModelTopBorder.GetWidth()
                                                                   > firstBorderOnCurrentPage[col].GetWidth()))
                     {
                         for (int i = col; i < col + colspan; i++)
                         {
                             firstBorderOnCurrentPage[i] = cellModelTopBorder;
                         }
                     }
                     col += colspan;
                     row  = index;
                 }
                 else
                 {
                     row++;
                     if (row == rows.Count)
                     {
                         break;
                     }
                 }
             }
         }
         return(firstBorderOnCurrentPage);
     }
     else
     {
         if ((index == finishRow + 1))
         {
             IList <Border> lastBorderOnCurrentPage = TableBorderUtil.CreateAndFillBorderList(bottomBorderCollapseWith,
                                                                                              tableBoundingBorders[2], numberOfColumns);
             if (index - largeTableIndexOffset == horizontalBorders.Count - 1)
             {
                 return(GetCollapsedList(horizontalBorders[index - largeTableIndexOffset], lastBorderOnCurrentPage));
             }
             if (0 != rows.Count)
             {
                 int col = 0;
                 int row = index - 1;
                 while (col < numberOfColumns)
                 {
                     // TODO
                     if (null != rows[row - largeTableIndexOffset][col])
                     {
                         CellRenderer cell = rows[row - largeTableIndexOffset][col];
                         Border       cellModelBottomBorder = TableBorderUtil.GetCellSideBorder(((Cell)cell.GetModelElement()), Property.
                                                                                                BORDER_BOTTOM);
                         int colspan = (int)cell.GetPropertyAsInteger(Property.COLSPAN);
                         if (null == lastBorderOnCurrentPage[col] || (null != cellModelBottomBorder && cellModelBottomBorder.GetWidth
                                                                          () > lastBorderOnCurrentPage[col].GetWidth()))
                         {
                             for (int i = col; i < col + colspan; i++)
                             {
                                 lastBorderOnCurrentPage[i] = cellModelBottomBorder;
                             }
                         }
                         col += colspan;
                         row  = index - 1;
                     }
                     else
                     {
                         row++;
                         if (row == rows.Count)
                         {
                             break;
                         }
                     }
                 }
             }
             return(lastBorderOnCurrentPage);
         }
         else
         {
             return(horizontalBorders[index - largeTableIndexOffset]);
         }
     }
 }