void InitRendering()
        {
            TableFormatInfo formatInfo = (TableFormatInfo)this.renderInfo.FormatInfo;

            this.bottomBorderMap  = formatInfo.bottomBorderMap;
            this.connectedRowsMap = formatInfo.connectedRowsMap;
            this.formattedCells   = formatInfo.formattedCells;

            this.currRow  = formatInfo.startRow;
            this.startRow = formatInfo.startRow;
            this.endRow   = formatInfo.endRow;

            this.mergedCells   = formatInfo.mergedCells;
            this.lastHeaderRow = formatInfo.lastHeaderRow;
            this.startX        = this.renderInfo.LayoutInfo.ContentArea.X;
            this.startY        = this.renderInfo.LayoutInfo.ContentArea.Y;
        }
        void InitFormat(Area area, FormatInfo previousFormatInfo)
        {
            TableFormatInfo prevTableFormatInfo = (TableFormatInfo)previousFormatInfo;
            TableRenderInfo tblRenderInfo       = new TableRenderInfo();

            tblRenderInfo.table = this.table;

            this.renderInfo = tblRenderInfo;

            if (prevTableFormatInfo != null)
            {
                this.mergedCells      = prevTableFormatInfo.mergedCells;
                this.formattedCells   = prevTableFormatInfo.formattedCells;
                this.bottomBorderMap  = prevTableFormatInfo.bottomBorderMap;
                this.lastHeaderRow    = prevTableFormatInfo.lastHeaderRow;
                this.connectedRowsMap = prevTableFormatInfo.connectedRowsMap;
                this.startRow         = prevTableFormatInfo.endRow + 1;
            }
            else
            {
                this.mergedCells = new MergedCellList(this.table);
                FormatCells();
                CalcLastHeaderRow();
                CreateConnectedRows();
                CreateBottomBorderMap();
                if (this.doHorizontalBreak)
                {
                    CalcLastHeaderColumn();
                    CreateConnectedColumns();
                }
                this.startRow = this.lastHeaderRow + 1;
            }
            ((TableFormatInfo)tblRenderInfo.FormatInfo).mergedCells      = this.mergedCells;
            ((TableFormatInfo)tblRenderInfo.FormatInfo).formattedCells   = this.formattedCells;
            ((TableFormatInfo)tblRenderInfo.FormatInfo).bottomBorderMap  = this.bottomBorderMap;
            ((TableFormatInfo)tblRenderInfo.FormatInfo).connectedRowsMap = this.connectedRowsMap;
            ((TableFormatInfo)tblRenderInfo.FormatInfo).lastHeaderRow    = this.lastHeaderRow;
        }
        /// <summary>
        /// Formats (measures) the table.
        /// </summary>
        /// <param name="area">The area on which to fit the table.</param>
        /// <param name="previousFormatInfo"></param>
        internal override void Format(Area area, FormatInfo previousFormatInfo)
        {
            DocumentElements elements = DocumentRelations.GetParent(this.table) as DocumentElements;

            if (elements != null)
            {
                Section section = DocumentRelations.GetParent(elements) as Section;
                if (section != null)
                {
                    this.doHorizontalBreak = section.PageSetup.HorizontalPageBreak;
                }
            }

            this.renderInfo = new TableRenderInfo();
            InitFormat(area, previousFormatInfo);

            // Don't take any Rows higher then MaxElementHeight
            XUnit topHeight   = this.CalcStartingHeight();
            XUnit probeHeight = topHeight;
            XUnit offset      = 0;

            if (this.startRow > this.lastHeaderRow + 1 &&
                this.startRow < this.table.Rows.Count)
            {
                offset = (XUnit)this.bottomBorderMap[this.startRow] - topHeight;
            }
            else
            {
                offset = -CalcMaxTopBorderWidth(0);
            }

            int   probeRow       = this.startRow;
            XUnit currentHeight  = 0;
            XUnit startingHeight = 0;
            bool  isEmpty        = false;

            while (probeRow < this.table.Rows.Count)
            {
                bool firstProbe = probeRow == this.startRow;
                probeRow = (int)this.connectedRowsMap[probeRow];
                // Don't take any Rows higher then MaxElementHeight
                probeHeight = (XUnit)this.bottomBorderMap[probeRow + 1] - offset;
                if (firstProbe && probeHeight > MaxElementHeight - Tolerance)
                {
                    probeHeight = MaxElementHeight - Tolerance;
                }

                //The height for the first new row(s) + headerrows:
                if (startingHeight == 0)
                {
                    if (probeHeight > area.Height)
                    {
                        isEmpty = true;
                        break;
                    }
                    startingHeight = probeHeight;
                }

                if (probeHeight > area.Height)
                {
                    break;
                }

                else
                {
                    this.currRow  = probeRow;
                    currentHeight = probeHeight;
                    ++probeRow;
                }
            }
            if (!isEmpty)
            {
                TableFormatInfo formatInfo = (TableFormatInfo)this.renderInfo.FormatInfo;
                formatInfo.startRow = this.startRow;
                formatInfo.isEnding = currRow >= this.table.Rows.Count - 1;
                formatInfo.endRow   = this.currRow;
            }
            FinishLayoutInfo(area, currentHeight, startingHeight);
        }