Beispiel #1
0
        /// <summary>
        /// Sets the number of columns, and column's widths.
        /// </summary>
        /// <param name="ColumnWidth">Array of column widths.</param>
        /// <remarks>
        /// <para>
        /// The length of the array sets the number of columns.
        /// </para>
        /// <para>
        /// This method builds two PdfTableCell arrays. One array for data cells, and
        /// the other array for header cells.
        /// </para>
        /// <para>
        /// The actual column widths will be calculated to fit the width of the table.
        /// </para>
        /// <para>
        /// The calculation is done as follows. First the library calculates the amount
        /// of net space available after border lines and grid lines width is taken off
        /// the width of the table as specified in TableArea. Second, the net space is divided
        /// in proportion to the requested widths.
        /// </para>
        /// </remarks>
        public void SetColumnWidth
        (
            params double[] ColumnWidth
        )
        {
            // save column width
            if (_ColumnWidth != null || ColumnWidth == null || ColumnWidth.Length == 0)
            {
                throw new ApplicationException("PdfTable: SetColumnWidth invalid argument or already defined.");
            }
            _ColumnWidth = ColumnWidth;

            // save number of columns
            Columns = _ColumnWidth.Length;

            // create cell and header arrays
            _Cell   = new PdfTableCell[Columns];
            _Header = new PdfTableCell[Columns];
            for (int Index = 0; Index < Columns; Index++)
            {
                _Cell[Index]   = new PdfTableCell(this, Index, false);
                _Header[Index] = new PdfTableCell(this, Index, true);
            }

            // vertical border control
            Borders.BordersInitialization();
            return;
        }
Beispiel #2
0
        /// <summary>
        /// PdfTable initialization.
        /// </summary>
        /// <remarks>
        /// Normally the system will call this method on first call to DrawRow().
        /// If called by user it must be called after initialization and before
        /// the first row is drawn. This method sets the active flag.
        /// </remarks>
        public void PdfTableInitialization()
        {
            // initialize table is done
            if (Active)
            {
                return;
            }

            // make sure we have columns width array
            if (_ColumnWidth == null)
            {
                throw new ApplicationException("PdfTable: SetColumnWidth array is missing.");
            }

            // net table width
            double NetWidth = _TableArea.Width - Borders.HorizontalBordersTotalWidth();

            // calculate column width adjustment factor
            double Total = 0;

            foreach (double Width in _ColumnWidth)
            {
                Total += Width;
            }
            double Factor = NetWidth / Total;

            // create column position for border and grid lines
            _ColumnPosition = new double[Columns + 1];

            // initial border/grid position
            double Position = _TableArea.Left;

            // left border line position
            _ColumnPosition[0] = Position;

            // first column position and width
            Position += Borders.VertBorderHalfWidth[0];
            PdfTableCell CellZero = _Cell[0];

            CellZero.FrameLeft  = Position;
            CellZero.FrameWidth = _ColumnWidth[0] * Factor;

            // first grid line position
            Position += CellZero.FrameWidth + Borders.VertBorderHalfWidth[1];

            // column width and position
            for (int Index = 1; Index < Columns; Index++)
            {
                // shortcut
                PdfTableCell Cell = _Cell[Index];

                // column net width
                Cell.FrameWidth = _ColumnWidth[Index] * Factor;

                // grid line position
                _ColumnPosition[Index] = Position;

                // cell left position
                Position      += Borders.VertBorderHalfWidth[Index];
                Cell.FrameLeft = Position;

                // next grid line position
                Position += Cell.FrameWidth + Borders.VertBorderHalfWidth[Index + 1];
            }

            // last grid line position
            _ColumnPosition[Columns] = Position;

            // columns width after adjustments
            for (int Index = 0; Index < Columns; Index++)
            {
                _ColumnWidth[Index] = _ColumnPosition[Index + 1] - _ColumnPosition[Index];
            }

            // copy horizontal info from cell to header
            for (int Index = 0; Index < Columns; Index++)
            {
                // shortcut
                PdfTableCell Cell   = _Cell[Index];
                PdfTableCell Header = _Header[Index];
                Header.FrameLeft  = Cell.FrameLeft;
                Header.FrameWidth = Cell.FrameWidth;
            }

            // user did not define initial row position
            if (_RowTopPosition == 0)
            {
                _RowTopPosition = _TableArea.Top;
            }

            // make sure initial row position is within table area
            else if (_RowTopPosition < _TableArea.Bottom || _RowTopPosition > _TableArea.Top)
            {
                throw new ApplicationException("PdfTable: Initial RowPosition outside table area.");
            }

            // border positions for border drawing
            BorderHeaderActive = false;
            BorderYPos         = new List <double>();
            BorderYPos.Add(_RowTopPosition);
            BorderRowTopPos = _RowTopPosition;
            BorderLeftPos   = TableArea.Left - Borders.VertBorderHalfWidth[0];
            BorderRightPos  = TableArea.Right + Borders.VertBorderHalfWidth[Columns];

            // initial row position
            _RowTopPosition -= Borders.TopBorder.HalfWidth;

            // table top and bottom limit for compare
            TableTopLimit    = TableArea.Top - Borders.TopBorder.HalfWidth;
            TableBottomLimit = TableArea.Bottom + Borders.BottomBorder.HalfWidth;

            // initialization is done, PdfTable is ready to draw
            Active = true;
            return;
        }
        // calculate row or header height
        private Double CalculateRowHeight(
			PdfTableCell[]	CellOrHeader
			)
        {
            // initial row height
            Double RowHeight = MinRowHeight;

            // loop through all cells
            foreach(PdfTableCell Cell in CellOrHeader)
            {
            // calculate cell height
            Double CellHeight = Cell.DrawCellInitialization();

            // adjust row height if required
            if(CellHeight > RowHeight) RowHeight = CellHeight;
            }

            return(RowHeight);
        }
        /// <summary>
        /// Sets the number of columns, and column's widths.
        /// </summary>
        /// <param name="ColumnWidth">Array of column widths.</param>
        /// <remarks>
        /// <para>
        /// The length of the array sets the number of columns.
        /// </para>
        /// <para>
        /// This method builds two PdfTableCell arrays. One array for data cells, and
        /// the other array for header cells.
        /// </para>
        /// <para>
        /// The actual column widths will be calculated to fit the width of the table. 
        /// </para>
        /// <para>
        /// The calculation is done as follows. First the library calculates the amount
        /// of net space available after border lines and grid lines width is taken off
        /// the width of the table as specified in TableArea. Second, the net space is divided
        /// in proportion to the requested widths.
        /// </para>
        /// </remarks>
        public void SetColumnWidth(
			params Double[] ColumnWidth
			)
        {
            // save column width
            if(_ColumnWidth != null || ColumnWidth == null || ColumnWidth.Length == 0) throw new ApplicationException("PdfTable: SetColumnWidth invalid argument or already defined.");
            _ColumnWidth = ColumnWidth;

            // save number of columns
            Columns = _ColumnWidth.Length;

            // create cell and header arrays
            _Cell = new PdfTableCell[Columns];
            _Header = new PdfTableCell[Columns];
            for(Int32 Index = 0; Index < Columns; Index++)
            {
            _Cell[Index] = new PdfTableCell(this, Index, false);
            _Header[Index] = new PdfTableCell(this, Index, true);
            }

            // vertical border control
            Borders.BordersInitialization();
            return;
        }