internal unsafe void GetCells(int cCells, IntPtr *rgnmCell, PTS.FSTABLEKCELLMERGE *rgkcellmerge)
        {
            Invariant.Assert(cCells == this.Row.FormatCellCount);
            Invariant.Assert(cCells >= this.Row.Cells.Count);
            int num = 0;

            for (int i = 0; i < this.Row.Cells.Count; i++)
            {
                TableCell tableCell = this.Row.Cells[i];
                if (tableCell.RowSpan == 1)
                {
                    rgnmCell[(IntPtr)num * (IntPtr)sizeof(IntPtr) / (IntPtr)sizeof(IntPtr)] = this._cellParagraphs[i].Handle;
                    rgkcellmerge[num] = PTS.FSTABLEKCELLMERGE.fskcellmergeNo;
                    num++;
                }
            }
            Invariant.Assert(cCells == num + this._spannedCells.Length);
            if (this._spannedCells.Length != 0)
            {
                bool flag = this.Row.Index == this.Row.RowGroup.Rows.Count - 1;
                for (int j = 0; j < this._spannedCells.Length; j++)
                {
                    TableCell cell = this._spannedCells[j].Cell;
                    rgnmCell[(IntPtr)num * (IntPtr)sizeof(IntPtr) / (IntPtr)sizeof(IntPtr)] = this._spannedCells[j].Handle;
                    if (cell.RowIndex == this.Row.Index)
                    {
                        rgkcellmerge[num] = (flag ? PTS.FSTABLEKCELLMERGE.fskcellmergeNo : PTS.FSTABLEKCELLMERGE.fskcellmergeFirst);
                    }
                    else if (this.Row.Index - cell.RowIndex + 1 < cell.RowSpan)
                    {
                        rgkcellmerge[num] = (flag ? PTS.FSTABLEKCELLMERGE.fskcellmergeLast : PTS.FSTABLEKCELLMERGE.fskcellmergeMiddle);
                    }
                    else
                    {
                        rgkcellmerge[num] = PTS.FSTABLEKCELLMERGE.fskcellmergeLast;
                    }
                    num++;
                }
            }
        }
Example #2
0
        internal unsafe void GetCells(
            int cCells,
            IntPtr *rgnmCell,
            PTS.FSTABLEKCELLMERGE *rgkcellmerge)
        {
            Invariant.Assert(cCells == Row.FormatCellCount);

            // To protect against a buffer overflow, we must check that we aren't writing more
            // cells than were allocated.  So we check against the cell count we have -
            // Row.FormatCellCount.  But that's calculated elsewhere.  What if it's stale?
            // There aren't any direct values available to compare against at the start of
            // this function, so we need two separate asserts.  Bug 1149633.
            Invariant.Assert(cCells >= Row.Cells.Count); // Protect against buffer overflow


            int i = 0;

            //  first, submit all non vertically merged cells
            for (int j = 0; j < Row.Cells.Count; ++j)
            {
                TableCell cell = Row.Cells[j];
                if (cell.RowSpan == 1)
                {
                    rgnmCell[i]     = _cellParagraphs[j].Handle;
                    rgkcellmerge[i] = PTS.FSTABLEKCELLMERGE.fskcellmergeNo;
                    i++;
                }
            }

            // i now contains the exact number of non-rowspan cells on this row.  Use it to verify
            // total number of cells, before we possibly write off end of allocated array.
            Invariant.Assert(cCells == i + _spannedCells.Length); // Protect against buffer overflow

            //  second, submit all vertically merged cells
            if (_spannedCells.Length > 0)
            {
                bool lastRow = Row.Index == Row.RowGroup.Rows.Count - 1;

                for (int j = 0; j < _spannedCells.Length; ++j)
                {
                    Debug.Assert(_spannedCells[j] != null);

                    TableCell cell = _spannedCells[j].Cell;
                    rgnmCell[i] = _spannedCells[j].Handle;

                    if (cell.RowIndex == Row.Index)
                    {
                        rgkcellmerge[i] = lastRow
                            ? PTS.FSTABLEKCELLMERGE.fskcellmergeNo
                            : PTS.FSTABLEKCELLMERGE.fskcellmergeFirst;
                    }
                    else if (Row.Index - cell.RowIndex + 1 < cell.RowSpan)
                    {
                        rgkcellmerge[i] = lastRow
                            ? PTS.FSTABLEKCELLMERGE.fskcellmergeLast
                            : PTS.FSTABLEKCELLMERGE.fskcellmergeMiddle;
                    }
                    else
                    {
                        Debug.Assert(Row.Index - cell.RowIndex + 1 == cell.RowSpan);
                        rgkcellmerge[i] = PTS.FSTABLEKCELLMERGE.fskcellmergeLast;
                    }

                    i++;
                }
            }
        }