예제 #1
0
 /**
  * Makes a copy of an existing row.
  *
  * @param row
  */
 public PdfPRow(PdfPRow row)
 {
     maxHeight  = row.maxHeight;
     calculated = row.calculated;
     cells      = new PdfPCell[row.cells.Length];
     for (int k = 0; k < cells.Length; ++k)
     {
         if (row.cells[k] != null)
         {
             cells[k] = new PdfPCell(row.cells[k]);
         }
     }
     widths = new float[cells.Length];
     Array.Copy(row.widths, 0, widths, 0, cells.Length);
     InitExtraHeights();
 }
예제 #2
0
        /**
         * Splits a row to newHeight.
         * The returned row is the remainder. It will return null if the newHeight
         * was so small that only an empty row would result.
         *
         * @param new_height the new height
         * @return the remainder row or null if the newHeight was so small that only
         * an empty row would result
         */
        public PdfPRow SplitRow(PdfPTable table, int rowIndex, float new_height)
        {
            PdfPCell[] newCells = new PdfPCell[cells.Length];
            float[]    fixHs    = new float[cells.Length];
            float[]    minHs    = new float[cells.Length];
            bool       allEmpty = true;

            for (int k = 0; k < cells.Length; ++k)
            {
                float    newHeight = new_height;
                PdfPCell cell      = cells[k];
                if (cell == null)
                {
                    int index = rowIndex;
                    if (table.RowSpanAbove(index, k))
                    {
                        newHeight += table.GetRowHeight(index);
                        while (table.RowSpanAbove(--index, k))
                        {
                            newHeight += table.GetRowHeight(index);
                        }
                        PdfPRow row = table.GetRow(index);
                        if (row != null && row.GetCells()[k] != null)
                        {
                            newCells[k] = new PdfPCell(row.GetCells()[k]);
                            newCells[k].ConsumeHeight(newHeight);
                            newCells[k].Rowspan = row.GetCells()[k].Rowspan - rowIndex + index;
                            allEmpty            = false;
                        }
                    }
                    continue;
                }
                fixHs[k] = cell.FixedHeight;
                minHs[k] = cell.MinimumHeight;
                Image    img     = cell.Image;
                PdfPCell newCell = new PdfPCell(cell);
                if (img != null)
                {
                    if (newHeight > cell.EffectivePaddingBottom + cell.EffectivePaddingTop + 2)
                    {
                        newCell.Phrase = null;
                        allEmpty       = false;
                    }
                }
                else
                {
                    float      y;
                    ColumnText ct     = ColumnText.Duplicate(cell.Column);
                    float      left   = cell.Left + cell.EffectivePaddingLeft;
                    float      bottom = cell.Top + cell.EffectivePaddingBottom - newHeight;
                    float      right  = cell.Right - cell.EffectivePaddingRight;
                    float      top    = cell.Top - cell.EffectivePaddingTop;
                    switch (cell.Rotation)
                    {
                    case 90:
                    case 270:
                        y = SetColumn(ct, bottom, left, top, right);
                        break;

                    default:
                        y = SetColumn(ct, left, bottom, cell.NoWrap ? RIGHT_LIMIT : right, top);
                        break;
                    }
                    int status;
                    status = ct.Go(true);
                    bool thisEmpty = (ct.YLine == y);
                    if (thisEmpty)
                    {
                        newCell.Column = ColumnText.Duplicate(cell.Column);
                        ct.FilledWidth = 0;
                    }
                    else if ((status & ColumnText.NO_MORE_TEXT) == 0)
                    {
                        newCell.Column = ct;
                        ct.FilledWidth = 0;
                    }
                    else
                    {
                        newCell.Phrase = null;
                    }
                    allEmpty = (allEmpty && thisEmpty);
                }
                newCells[k]      = newCell;
                cell.FixedHeight = newHeight;
            }
            if (allEmpty)
            {
                for (int k = 0; k < cells.Length; ++k)
                {
                    PdfPCell cell = cells[k];
                    if (cell == null)
                    {
                        continue;
                    }
                    if (fixHs[k] > 0)
                    {
                        cell.FixedHeight = fixHs[k];
                    }
                    else
                    {
                        cell.MinimumHeight = minHs[k];
                    }
                }
                return(null);
            }
            CalculateHeights();
            PdfPRow split = new PdfPRow(newCells);

            split.widths = (float[])widths.Clone();
            split.CalculateHeights();
            return(split);
        }
예제 #3
0
        /**
        * Adds a cell element.
        *
        * @param cell the cell element
        */
        public void AddCell(PdfPCell cell)
        {
            rowCompleted = false;
            PdfPCell ncell = new PdfPCell(cell);

            int colspan = ncell.Colspan;
            colspan = Math.Max(colspan, 1);
            colspan = Math.Min(colspan, currentRow.Length - currentRowIdx);
            ncell.Colspan = colspan;

            if (colspan != 1)
                isColspan = true;
            int rdir = ncell.RunDirection;
            if (rdir == PdfWriter.RUN_DIRECTION_DEFAULT)
                ncell.RunDirection = runDirection;

            SkipColsWithRowspanAbove();

            bool cellAdded = false;
            if (currentRowIdx < currentRow.Length) {
                currentRow[currentRowIdx] = ncell;
                currentRowIdx += colspan;
                cellAdded = true;
            }

            SkipColsWithRowspanAbove();

            if (currentRowIdx >= currentRow.Length) {
                int numCols = NumberOfColumns;
                if (runDirection == PdfWriter.RUN_DIRECTION_RTL) {
                    PdfPCell[] rtlRow = new PdfPCell[numCols];
                    int rev = currentRow.Length;
                    for (int k = 0; k < currentRow.Length; ++k) {
                        PdfPCell rcell = currentRow[k];
                        int cspan = rcell.Colspan;
                        rev -= cspan;
                        rtlRow[rev] = rcell;
                        k += cspan - 1;
                    }
                    currentRow = rtlRow;
                }
                PdfPRow row = new PdfPRow(currentRow);
                if (totalWidth > 0) {
                    row.SetWidths(absoluteWidths);
                    totalHeight += row.MaxHeights;
                }
                rows.Add(row);
                currentRow = new PdfPCell[numCols];
                currentRowIdx = 0;
                rowCompleted = true;
            }

            if (!cellAdded) {
                currentRow[currentRowIdx] = ncell;
                currentRowIdx += colspan;
            }
        }
예제 #4
0
 /**
 * Calculates the extra height needed in a row because of rowspans.
 * @param    start   the index of the start row (the one to adjust)
 * @param    end     the index of the end row on the page
 * @since    2.1.6
 */
 protected PdfPRow AdjustCellsInRow(int start, int end)
 {
     PdfPRow row = new PdfPRow(GetRow(start));
     row.InitExtraHeights();
     PdfPCell cell;
     PdfPCell[] cells = row.GetCells();
     for (int i = 0; i < cells.Length; i++) {
         cell = cells[i];
         if (cell == null || cell.Rowspan == 1)
             continue;
         int stop = Math.Min(end, start + cell.Rowspan);
         float extra = 0;
         for (int k = start + 1; k < stop; k++) {
             extra += GetRowHeight(k);
         }
         row.SetExtraHeight(i, extra);
     }
     return row;
 }
예제 #5
0
 /** Constructs a copy of a <CODE>PdfPTable</CODE>.
 * @param table the <CODE>PdfPTable</CODE> to be copied
 */
 public PdfPTable(PdfPTable table)
 {
     CopyFormat(table);
     for (int k = 0; k < currentRow.Length; ++k) {
         if (table.currentRow[k] == null)
             break;
         currentRow[k] = new PdfPCell(table.currentRow[k]);
     }
     for (int k = 0; k < table.rows.Count; ++k) {
         PdfPRow row = (PdfPRow)(table.rows[k]);
         if (row != null)
             row = new PdfPRow(row);
         rows.Add(row);
     }
 }
예제 #6
0
        /**
        * Imports a PdfPRow and copies all settings
        *
        * @param row The PdfPRow to import
        * @since 2.1.3
        */
        private void ImportRow(PdfPRow 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;
            PdfPCell[] cells = row.GetCells();
            for (int i = 0; i < cells.Length; i++) {
                cellWidth = (int) (this.width * this.parentTable.GetProportionalWidths()[i] / 100);
                cellRight = cellRight + cellWidth;

                PdfPCell cell = cells[i];
                RtfCell rtfCell = new RtfCell(this.document, this, cell);
                rtfCell.SetCellRight(cellRight);
                rtfCell.SetCellWidth(cellWidth);
                this.cells.Add(rtfCell);
            }
        }
예제 #7
0
 /**
 * Constructs a RtfRow for a Row.
 *
 * @param doc The RtfDocument this RtfRow belongs to
 * @param rtfTable The RtfTable this RtfRow belongs to
 * @param row The Row this RtfRow is based on
 * @param rowNumber The number of this row
 * @since 2.1.3
 */
 protected internal RtfRow(RtfDocument doc, RtfTable rtfTable, PdfPRow row, int rowNumber)
     : base(doc)
 {
     this.parentTable = rtfTable;
     this.rowNumber = rowNumber;
     ImportRow(row);
 }
예제 #8
0
 /**
 * Splits a row to newHeight.
 * The returned row is the remainder. It will return null if the newHeight
 * was so small that only an empty row would result.
 *
 * @param new_height the new height
 * @return the remainder row or null if the newHeight was so small that only
 * an empty row would result
 */
 public PdfPRow SplitRow(PdfPTable table, int rowIndex, float new_height)
 {
     PdfPCell[] newCells = new PdfPCell[cells.Length];
     float[] fixHs = new float[cells.Length];
     float[] minHs = new float[cells.Length];
     bool allEmpty = true;
     for (int k = 0; k < cells.Length; ++k) {
         float newHeight = new_height;
         PdfPCell cell = cells[k];
         if (cell == null) {
             int index = rowIndex;
             if (table.RowSpanAbove(index, k)) {
                 newHeight += table.GetRowHeight(index);
                 while (table.RowSpanAbove(--index, k)) {
                     newHeight += table.GetRowHeight(index);
                 }
                 PdfPRow row = table.GetRow(index);
                 if (row != null && row.GetCells()[k] != null) {
                     newCells[k] = new PdfPCell(row.GetCells()[k]);
                     newCells[k].ConsumeHeight(newHeight);
                     newCells[k].Rowspan = row.GetCells()[k].Rowspan - rowIndex + index;
                     allEmpty = false;
                 }
             }
             continue;
         }
         fixHs[k] = cell.FixedHeight;
         minHs[k] = cell.MinimumHeight;
         Image img = cell.Image;
         PdfPCell newCell = new PdfPCell(cell);
         if (img != null) {
             if (newHeight > cell.EffectivePaddingBottom + cell.EffectivePaddingTop + 2) {
                 newCell.Phrase = null;
                 allEmpty = false;
             }
         }
         else {
             float y;
             ColumnText ct = ColumnText.Duplicate(cell.Column);
             float left = cell.Left + cell.EffectivePaddingLeft;
             float bottom = cell.Top + cell.EffectivePaddingBottom - newHeight;
             float right = cell.Right - cell.EffectivePaddingRight;
             float top = cell.Top - cell.EffectivePaddingTop;
             switch (cell.Rotation) {
                 case 90:
                 case 270:
                     y = SetColumn(ct, bottom, left, top, right);
                     break;
                 default:
                     y = SetColumn(ct, left, bottom, cell.NoWrap ? RIGHT_LIMIT : right, top);
                     break;
             }
             int status;
             status = ct.Go(true);
             bool thisEmpty = (ct.YLine == y);
             if (thisEmpty) {
                 newCell.Column = ColumnText.Duplicate(cell.Column);
                 ct.FilledWidth = 0;
             }
             else if ((status & ColumnText.NO_MORE_TEXT) == 0) {
                 newCell.Column = ct;
                 ct.FilledWidth = 0;
             }
             else
                 newCell.Phrase = null;
             allEmpty = (allEmpty && thisEmpty);
         }
         newCells[k] = newCell;
         cell.FixedHeight = newHeight;
     }
     if (allEmpty) {
         for (int k = 0; k < cells.Length; ++k) {
             PdfPCell cell = cells[k];
             if (cell == null)
                 continue;
             if (fixHs[k] > 0)
                 cell.FixedHeight = fixHs[k];
             else
                 cell.MinimumHeight = minHs[k];
         }
         return null;
     }
     CalculateHeights();
     PdfPRow split = new PdfPRow(newCells);
     split.widths = (float[]) widths.Clone();
     split.CalculateHeights();
     return split;
 }
예제 #9
0
 /**
 * Makes a copy of an existing row.
 *
 * @param row
 */
 public PdfPRow(PdfPRow row)
 {
     maxHeight = row.maxHeight;
     calculated = row.calculated;
     cells = new PdfPCell[row.cells.Length];
     for (int k = 0; k < cells.Length; ++k) {
         if (row.cells[k] != null)
             cells[k] = new PdfPCell(row.cells[k]);
     }
     widths = new float[cells.Length];
     Array.Copy(row.widths, 0, widths, 0, cells.Length);
     InitExtraHeights();
 }
예제 #10
0
        /**
         * Returns the height of the cell.
         * @return  the height of the cell
         * @since   3.0.0
         */
        public float GetMaxHeight()
        {
            bool  pivoted = (Rotation == 90 || Rotation == 270);
            Image img     = this.Image;

            if (img != null)
            {
                img.ScalePercent(100);
                float refWidth = pivoted ? img.ScaledHeight : img.ScaledWidth;
                float scale    = (Right - EffectivePaddingRight
                                  - EffectivePaddingLeft - Left) / refWidth;
                img.ScalePercent(scale * 100);
                float refHeight = pivoted ? img.ScaledWidth : img.ScaledHeight;
                Bottom = Top - EffectivePaddingTop - EffectivePaddingBottom - refHeight;
            }
            else
            {
                if (pivoted && HasFixedHeight())
                {
                    Bottom = Top - FixedHeight;
                }
                else
                {
                    ColumnText ct = ColumnText.Duplicate(Column);
                    float      right, top, left, bottom;
                    if (pivoted)
                    {
                        right  = PdfPRow.RIGHT_LIMIT;
                        top    = Right - EffectivePaddingRight;
                        left   = 0;
                        bottom = Left + EffectivePaddingLeft;
                    }
                    else
                    {
                        right  = NoWrap ? PdfPRow.RIGHT_LIMIT : Right - EffectivePaddingRight;
                        top    = Top - EffectivePaddingTop;
                        left   = Left + EffectivePaddingLeft;
                        bottom = HasFixedHeight() ? top + EffectivePaddingBottom - FixedHeight : PdfPRow.BOTTOM_LIMIT;
                    }
                    PdfPRow.SetColumn(ct, left, bottom, right, top);
                    ct.Go(true);
                    if (pivoted)
                    {
                        Bottom = Top - EffectivePaddingTop - EffectivePaddingBottom - ct.FilledWidth;
                    }
                    else
                    {
                        float yLine = ct.YLine;
                        if (UseDescender)
                        {
                            yLine += ct.Descender;
                        }
                        Bottom = yLine - EffectivePaddingBottom;
                    }
                }
            }
            float height = Height;

            if (height < FixedHeight)
            {
                height = FixedHeight;
            }
            else if (height < MinimumHeight)
            {
                height = MinimumHeight;
            }
            return(height);
        }